Skip to content

Commit

Permalink
Item13897: Tests up to ResponseTests are converted.
Browse files Browse the repository at this point in the history
  • Loading branch information
vrurg committed Jun 20, 2016
1 parent 73f92ab commit 7d3ef0b
Show file tree
Hide file tree
Showing 11 changed files with 360 additions and 234 deletions.
318 changes: 208 additions & 110 deletions UnitTestContrib/test/unit/RenameTests.pm

Large diffs are not rendered by default.

39 changes: 19 additions & 20 deletions UnitTestContrib/test/unit/RenderFormTests.pm
Expand Up @@ -58,7 +58,7 @@ around set_up => sub {
HERE

# Force reload to pick up WebPreferences
$this->createNewFoswikiSession( undef, $this->session->request );
$this->reCreateFoswikiApp;

my ($meta) = Foswiki::Func::readTopic( $this->test_web, $testtopic1 );
$meta->put( 'FORM', { name => 'InitializationForm' } );
Expand Down Expand Up @@ -161,7 +161,7 @@ HERE

Foswiki::Func::saveTopic( $this->test_web, $testtopic1, $meta, 'TT1' );

$meta->finish();
undef $meta;
($meta) = Foswiki::Func::readTopic( $this->test_web, $testtopic2 );
$meta->put( 'FORM', { name => 'InitializationForm', } );
$meta->putKeyed(
Expand Down Expand Up @@ -292,7 +292,7 @@ sub test_render_formfield_raw {
my $this = shift;
my ($meta) = Foswiki::Func::readTopic( $this->test_web, $testtopic2 );
my $text = $meta->text;
my $render = $this->session->renderer;
my $render = $this->app->renderer;
my $res;

$res = $meta->renderFormFieldForDisplay(
Expand Down Expand Up @@ -363,10 +363,10 @@ Foo, Baz
</td></tr><tr style='vertical-align:top'><td class='foswikiFormTableRow foswikiFirstCol' style='text-align:right'> Issue 6 </td><td>
Three </td></tr></table></div>
HERE
$meta->finish();
undef $meta;
($meta) = Foswiki::Func::readTopic( $this->test_web, $testtopic1 );
$text = $meta->text;
$this->session->enterContext('preview');
$this->app->enterContext('preview');
$res = $meta->renderFormForDisplay();
$this->assert_html_equals( <<"HERE", $res );
<div class="foswikiForm foswikiFormStep"><noautolink><h3>TemporaryRenderFormTestsTestWebRenderFormTests.InitializationForm</h3></noautolink> <table class='foswikiFormTable' border='1' summary='%MAKETEXT{"Form data"}%'><noautolink><tr style='vertical-align:top'><td class='foswikiFormTableRow foswikiFirstCol' style='text-align:right'> Issue Name </td><td>
Expand All @@ -390,7 +390,7 @@ Two
</td></tr></noautolink>
</table></div>
HERE
$this->session->leaveContext('preview');
$this->app->leaveContext('preview');
return;
}

Expand All @@ -404,7 +404,7 @@ sub test_render_for_edit {
my ($meta) = Foswiki::Func::readTopic( $this->test_web, $testtopic1 );
my $text = $meta->text;
my $formDef =
Foswiki::Form->loadCached( $this->session, $this->test_web,
Foswiki::Form->loadCached( $this->app, $this->test_web,
"InitializationForm" );
my $res = $formDef->renderForEdit($meta);

Expand Down Expand Up @@ -436,7 +436,7 @@ HERE

#Foswiki::Func::writeDebug("-----------------\n$res\n------------------");

my $viewUrl = $this->session->getScriptUrl( 0, 'view' );
my $viewUrl = $this->app->cfg->getScriptUrl( 0, 'view' );
$expected =~ s/%VIEWURL%/$viewUrl/g;

$this->assert_html_equals( $expected, $res );
Expand All @@ -449,7 +449,7 @@ sub test_render_hidden {
my ($meta) = Foswiki::Func::readTopic( $this->test_web, $testtopic1 );
my $text = $meta->text;
my $formDef =
Foswiki::Form->loadCached( $this->session, $this->test_web,
Foswiki::Form->loadCached( $this->app, $this->test_web,
"InitializationForm" );
my $res = $formDef->renderHidden($meta);
$this->assert_html_equals( <<'HERE', $res );
Expand Down Expand Up @@ -598,7 +598,7 @@ sub test_getAvailableForms {
$this->expect_failure( 'Item11527 needs to be fixed!',
with_dep => 'Foswiki,<,1.2' );

$this->createNewFoswikiSession();
$this->createNewFoswikiApp;
my ($topicObj) =
Foswiki::Func::readTopic( $this->test_web,
$Foswiki::cfg{WebPrefsTopicName} );
Expand All @@ -612,7 +612,6 @@ sub test_getAvailableForms {
require Foswiki::Form;
my @forms = Foswiki::Form::getAvailableForms($topicObj);
$this->assert_str_equals( $expandedpref, join( ',', @forms ) );
$topicObj->finish();

return;
}
Expand Down Expand Up @@ -710,25 +709,25 @@ sub test_getAvailableForms {
#
# $Foswiki::cfg{Store}{ImplementationClasses} =
# ['Foswiki::Store::UnitTestFilter'];
# $this->createNewFoswikiSession( $Foswiki::cfg{AdminUserWikiName} );
# $this->createNewFoswikiApp( $Foswiki::cfg{AdminUserWikiName} );
# my $formObj =
# Foswiki::Form->loadCached( $this->session, $this->test_web,
# Foswiki::Form->loadCached( $this->app, $this->test_web,
# 'FoswikiReleaseForm' );
#
##query can be called twice - once as a QuerySearch, and once as the regex search underlying it
##print STDERR "HUH? "
##. scalar(@Foswiki::Store::UnitTestFilter::changeStack) . "\n";
# $this->assert( scalar(@Foswiki::Store::UnitTestFilter::changeStack) <= 2 );
#
# $this->createNewFoswikiSession( $Foswiki::cfg{AdminUserWikiName} );
# $this->createNewFoswikiApp( $Foswiki::cfg{AdminUserWikiName} );
# my ($topicObject) =
# Foswiki::Func::readTopic( $this->test_web, $this->test_topic );
# my $tmpl = $this->session->templates->readTemplate('view');
# my $tmpl = $this->app->templates->readTemplate('view');
# $tmpl =~ m/^(.*)%TEXT%(.*)$/s;
# my $end = $2;
# $topicObject->expandMacros($end);
#
# $this->createNewFoswikiSession( $Foswiki::cfg{AdminUserWikiName} );
# $this->createNewFoswikiApp( $Foswiki::cfg{AdminUserWikiName} );
#
# # my ( $web, $topic, $tmpl, $raw, $ctype, $skin ) = @_;
# my $web = $this->test_web;
Expand All @@ -748,14 +747,14 @@ sub test_getAvailableForms {
# );
# $query->path_info("/$web/$topic");
# $query->method('POST');
# $this->createNewFoswikiSession( $this->test_user_login, $query );
# $this->createNewFoswikiApp( $this->test_user_login, $query );
# my ( $text, $result, $stdout, $stderr ) = $this->capture(
# sub {
# no strict 'refs';
# &{$UI_FN}( $this->session );
# &{$UI_FN}( $this->app );
# use strict 'refs';
# $Foswiki::engine->finalize( $this->session->response,
# $this->session->request );
# $Foswiki::engine->finalize( $this->app->response,
# $this->app->request );
# }
# );
#
Expand Down
103 changes: 68 additions & 35 deletions UnitTestContrib/test/unit/RenderTests.pm
Expand Up @@ -18,55 +18,55 @@ around set_up => sub {
my ($topicObject) = Foswiki::Func::readTopic( $this->test_web, 'OkTopic' );
$topicObject->text("BLEEGLE blah/matchme.blah");
$topicObject->save( forcedate => $timestamp + 120 );
$topicObject->finish();
undef $topicObject;
($topicObject) = Foswiki::Func::readTopic( $this->test_web, 'OkATopic' );
$topicObject->text("BLEEGLE dontmatchme.blah");
$topicObject->save( forcedate => $timestamp + 240 );
$topicObject->finish();
undef $topicObject;
($topicObject) = Foswiki::Func::readTopic( $this->test_web, 'OkBTopic' );
$topicObject->text("BLEEGLE dont.matchmeblah");
$topicObject->save( forcedate => $timestamp + 480 );
$topicObject->finish();
undef $topicObject;

($topicObject) = Foswiki::Func::readTopic( $this->test_web, 'LunchLink' );
$topicObject->text("BLEEGLE [[Lunch'Link]] dont.matchmeblah");
$topicObject->save( forcedate => $timestamp + 480 );
$topicObject->finish();
undef $topicObject;

($topicObject) =
Foswiki::Func::readTopic( $this->test_web, 'OneSingleQuote' );
$topicObject->text("BLEEGLE [[OkBTopic][Lunch'nLearn]] dont.matchmeblah");
$topicObject->save( forcedate => $timestamp + 480 );
$topicObject->finish();
undef $topicObject;

($topicObject) =
Foswiki::Func::readTopic( $this->test_web, 'OneDoubleQuote' );
$topicObject->text('BLEEGLE [[OkBTopic][Lunch"nLearn]] dont.matchmeblah');
$topicObject->save( forcedate => $timestamp + 480 );
$topicObject->finish();
undef $topicObject;

($topicObject) = Foswiki::Func::readTopic( $this->test_web, 'SingleQuote' );
$topicObject->text("BLEEGLE [[OkBTopic][Lunch'n'Learn]] dont.matchmeblah");
$topicObject->save( forcedate => $timestamp + 480 );
$topicObject->finish();
undef $topicObject;

($topicObject) = Foswiki::Func::readTopic( $this->test_web, 'DoubleQuote' );
$topicObject->text('BLEEGLE [[OkBTopic][Lunch"n"Learn]] dont.matchmeblah');
$topicObject->save( forcedate => $timestamp + 480 );
$topicObject->finish();
undef $topicObject;

($topicObject) = Foswiki::Func::readTopic( $this->test_web, 'NoTopicLink' );
$topicObject->text(
"BLEEGLE [[LunchNLearn][Lunch n Learn]] dont.matchmeblah");
$topicObject->save( forcedate => $timestamp + 480 );
$topicObject->finish();
undef $topicObject;

($topicObject) =
Foswiki::Func::readTopic( $this->test_web, 'QuoteNoTopicLink' );
$topicObject->text(
"BLEEGLE [[LunchNLearn][Lunch'n'Learn]] dont.matchmeblah");
$topicObject->save( forcedate => $timestamp + 480 );
$topicObject->finish();
undef $topicObject;

($topicObject) =
Foswiki::Func::readTopic( $this->test_web, $this->test_topic );
Expand Down Expand Up @@ -96,15 +96,19 @@ around set_up => sub {
* ATTACHFILESIZELIMIT = %ATTACHFILESIZELIMIT%
HERE
$topicObject->save( forcedate => $timestamp + 480 );
$topicObject->finish();
undef $topicObject;

#give us a new session so the prefs are re-loaded
my $query = Unit::Request->new( initializer => '' );
$query->path_info( "/" . $this->test_web . "/" . $this->test_topic );
$this->createNewFoswikiSession( undef, $query );
$this->createNewFoswikiApp(
requestParams => { initializer => "" },
engineParams => {
initialAttributes =>
{ path_info => "/" . $this->test_web . "/" . $this->test_topic },
},
);

#need to be in view script context for tooltips to be processed.
Foswiki::Func::getContext()->{view} = 1;
$this->app->context->{view} = 1;

};

Expand All @@ -119,12 +123,25 @@ around tear_down => sub {
# See EmptyTests for an example
};

around createNewFoswikiApp => sub {
my $orig = shift;
my $this = shift;
my $app = $orig->( $this, @_ );

# Some plugins are interfering with rendering process.
# Special not on HomePagePlugin which unconditionally sets web/topic on
# request even whtn they're already set by the engine.
$app->cfg->data->{DisableAllPlugins} = 1;

return $app;
};

sub test_TOOLTIPS_on {
my $this = shift;

my $scriptUrlPath =
Foswiki::Func::getScriptUrlPath( $this->test_web, $this->test_topic,
'view' );
$this->app->cfg->getScriptUrl( 0, 'view', $this->test_web,
$this->test_topic );
my $test_topic = $this->test_topic;
$scriptUrlPath =~ s/$test_topic//;

Expand Down Expand Up @@ -163,7 +180,7 @@ HERE
$this->assert_str_equals( 'on', $linktooltipinfo );

my $sessionlinktooltipinfo =
$this->session->prefs->getPreference('LINKTOOLTIPINFO');
$this->app->prefs->getPreference('LINKTOOLTIPINFO');
$this->assert_str_equals( 'on', $sessionlinktooltipinfo );

my $ex1 = Foswiki::Func::expandCommonVariables(
Expand Down Expand Up @@ -198,28 +215,32 @@ sub test_TOOLTIPS_on_space {
* ATTACHFILESIZELIMIT = %ATTACHFILESIZELIMIT%
HERE
$topicObject->save();
$topicObject->finish();
undef $topicObject;

#give us a new session so the prefs are re-loaded
my $query = Unit::Request->new( initializer => '' );
$query->path_info( "/" . $this->test_web . "/" . $this->test_topic );
$this->createNewFoswikiSession( undef, $query );
$this->createNewFoswikiApp(
requestParams => { initializer => "" },
engineParams => {
initialAttributes =>
{ path_info => "/" . $this->test_web . "/" . $this->test_topic },
},
);

#need to be in view script context for tooltips to be processed.
Foswiki::Func::getContext()->{view} = 1;
$this->app->context->{view} = 1;

($topicObject) =
Foswiki::Func::readTopic( $this->test_web, $this->test_topic );
my $linktooltipinfo = $topicObject->getPreference('LINKTOOLTIPINFO');
$this->assert_str_equals( 'on ', $linktooltipinfo );

my $sessionlinktooltipinfo =
$this->session->prefs->getPreference('LINKTOOLTIPINFO');
$this->app->prefs->getPreference('LINKTOOLTIPINFO');
$this->assert_str_equals( 'on ', $sessionlinktooltipinfo );

my $scriptUrlPath =
Foswiki::Func::getScriptUrlPath( $this->test_web, $this->test_topic,
'view' );
$this->app->cfg->getScriptUrl( 0, 'view', $this->test_web,
$this->test_topic );
my $test_topic = $this->test_topic;
$scriptUrlPath =~ s/$test_topic//;

Expand Down Expand Up @@ -266,22 +287,28 @@ EXPECTED
sub test_TOOLTIPS_other_topic_context {
my $this = shift;

$this->createNewFoswikiSession();
$this->createNewFoswikiApp;

#need to be in view script context for tooltips to be processed.
Foswiki::Func::getContext()->{view} = 1;
$this->app->context->{view} = 1;

#Simulate command line context. Previously this context was magically set
#depdnding on presence of $query parameter in Foswiki session constructor
#call which is... er... somewhat dubios way.
$this->app->context->{command_line} = 1;

my ($topicObject) =
Foswiki::Func::readTopic( $this->test_web, $this->test_topic );
my $linktooltipinfo = $topicObject->getPreference('LINKTOOLTIPINFO');
$this->assert_str_equals( 'on', $linktooltipinfo );

my $sessionlinktooltipinfo =
$this->session->prefs->getPreference('LINKTOOLTIPINFO');
$this->app->prefs->getPreference('LINKTOOLTIPINFO');
$this->assert_str_equals( 'off', $sessionlinktooltipinfo );

my $scriptUrl =
Foswiki::Func::getScriptUrl( $this->test_web, $this->test_topic, 'view' );
$this->app->cfg->getScriptUrl( 1, 'view', $this->test_web,
$this->test_topic );
my $test_topic = $this->test_topic;
$scriptUrl =~ s/$test_topic//;

Expand Down Expand Up @@ -331,10 +358,10 @@ EXPECTED
sub test_EscapeInStyles {
my $this = shift;

$this->createNewFoswikiSession();
$this->createNewFoswikiApp;

#need to be in view script context for tooltips to be processed.
Foswiki::Func::getContext()->{view} = 1;
$this->app->context->{view} = 1;

my $topicText = <<TOPIC;
<style type="text/css">
Expand Down Expand Up @@ -362,10 +389,15 @@ TOPIC
sub test_GeneralEscaping {
my $this = shift;

$this->createNewFoswikiSession();
$this->createNewFoswikiApp;

#need to be in view script context for tooltips to be processed.
Foswiki::Func::getContext()->{view} = 1;
$this->app->context->{view} = 1;

#Simulate command line context. Previously this context was magically set
#depdnding on presence of $query parameter in Foswiki session constructor
#call which is... er... somewhat dubios way.
$this->app->context->{command_line} = 1;

my $topicText = <<'TOPIC';
Expand Down Expand Up @@ -402,7 +434,8 @@ TOPIC
$topicObject->text($topicText);

my $scriptUrl =
Foswiki::Func::getScriptUrl( $this->test_web, $this->test_topic, 'view' );
$this->app->cfg->getScriptUrl( 1, 'view', $this->test_web,
$this->test_topic );
my $test_topic = $this->test_topic;
$scriptUrl =~ s/\/$test_topic//; # Remove the topic

Expand Down

0 comments on commit 7d3ef0b

Please sign in to comment.