From 87186f250a40d1e3c6b2768e431ea4f1afc4eace Mon Sep 17 00:00:00 2001 From: GeorgeClark Date: Fri, 20 Aug 2010 15:12:58 +0000 Subject: [PATCH] Item9509: Restore stripping of nop|noautolink to View::_prepare, and add unit tests to verify skin=text;contenttype=text/plain rendering git-svn-id: http://svn.foswiki.org/trunk@8617 0b4bb1d4-4e5a-0410-9cc4-b2b747904278 --- UnitTestContrib/test/unit/ViewScriptTests.pm | 95 ++++++++++---------- core/lib/Foswiki/UI/View.pm | 1 + 2 files changed, 51 insertions(+), 45 deletions(-) diff --git a/UnitTestContrib/test/unit/ViewScriptTests.pm b/UnitTestContrib/test/unit/ViewScriptTests.pm index 2b82ede20d..282f22a1fe 100644 --- a/UnitTestContrib/test/unit/ViewScriptTests.pm +++ b/UnitTestContrib/test/unit/ViewScriptTests.pm @@ -19,10 +19,10 @@ HERE my $topic2 = <<'HERE'; ---- -WikiWord %BR% +MissingWikiWord %BR% !ExclamationEscape
NopEscape -%RED%
 adsf 
qwerty adsf qwerty

A Paragraph

#anchor asdf @@ -185,41 +185,15 @@ sub set_up { } sub setup_view { - my ( $this, $web, $topic, $tmpl, $parm ) = @_; - my $query = new Unit::Request( - { - webName => [$web], - topicName => [$topic], - template => [$tmpl], - } - ); - $query->path_info("/$web/$topic"); - $query->method('POST'); - $fatwilly = new Foswiki( $this->{test_user_login}, $query ); - my ($text) = $this->capture( - sub { - no strict 'refs'; - &$UI_FN($fatwilly); - use strict 'refs'; - $Foswiki::engine->finalize( $fatwilly->{response}, - $fatwilly->{request} ); - } - ); - - $fatwilly->finish(); - $text =~ s/\r//g; - $text =~ s/^.*?\n\n+//s; # remove CGI header - return $text; -} - -sub setup_rawview { - my ( $this, $web, $topic, $tmpl, $raw ) = @_; + my ( $this, $web, $topic, $tmpl, $raw, $ctype, $skin ) = @_; my $query = new Unit::Request( { webName => [$web], topicName => [$topic], template => [$tmpl], raw => [$raw], + contenttype => [$ctype], + skin => [$skin], } ); $query->path_info("/$web/$topic"); @@ -235,10 +209,12 @@ sub setup_rawview { } ); + my $editUrl = $fatwilly->getScriptUrl('0', 'edit', $this->{test_web}, '' ); + $fatwilly->finish(); $text =~ s/\r//g; $text =~ s/(^.*?\n\n+)//s; # remove CGI header - return ($text, $1); + return ($text, $1, $editUrl); } # This test verifies the rendering of the various raw views @@ -247,49 +223,78 @@ sub test_render_raw { my $text; my $hdr; - ($text, $hdr) = $this->setup_rawview( $this->{test_web}, 'TestTopic2', 'viewfour', 'text'); + ($text, $hdr) = $this->setup_view( $this->{test_web}, 'TestTopic2', 'viewfour', 'text'); $this->assert_equals( "$topic2", $text, "Unexpected output from raw=text" ); - $this->assert_matches( qr#text/plain;#, $hdr, "raw=text should return text/plain - got $hdr"); + $this->assert_matches( qr#^Content-Type: text/plain;#ms, $hdr, "raw=text should return text/plain - got $hdr"); - ($text, $hdr) = $this->setup_rawview( $this->{test_web}, 'TestTopic2', 'viewfour', 'all'); + ($text, $hdr) = $this->setup_view( $this->{test_web}, 'TestTopic2', 'viewfour', 'all'); $this->assert_matches( qr#$topic2meta$topic2#, $text, "Unexpected output from raw=all" ); - $this->assert_matches( qr#text/plain;#, $hdr, "raw=all should return text/plain - got $hdr"); + $this->assert_matches( qr#^Content-Type: text/plain;#ms, $hdr, "raw=all should return text/plain - got $hdr"); - ($text,$hdr) = $this->setup_rawview( $this->{test_web}, 'TestTopic2', 'viewfour', 'on'); + ($text,$hdr) = $this->setup_view( $this->{test_web}, 'TestTopic2', 'viewfour', 'on'); $this->assert_matches( qr#.*$topic2txtarea$topic2rawON.*#, $text, "Unexpected output from raw=on" ); - $this->assert_matches( qr#text/html;#, $hdr, "raw=on should return text/html - got $hdr"); + $this->assert_matches( qr#^Content-Type: text/html;#ms, $hdr, "raw=on should return text/html - got $hdr"); - ($text, $hdr) = $this->setup_rawview( $this->{test_web}, 'TestTopic2', 'viewfour', 'debug'); + ($text, $hdr) = $this->setup_view( $this->{test_web}, 'TestTopic2', 'viewfour', 'debug'); $this->assert_matches( qr#.*$topic2txtarea$topic2metaQ$topic2rawON.*#, $text, "Unexpected output from raw=debug" ); - $this->assert_matches( qr#text/html;#, $hdr, "raw=debug should return text/html - got $hdr"); + $this->assert_matches( qr#^Content-Type: text/html;#ms, $hdr, "raw=debug should return text/html - got $hdr"); } + +# This test verifies the rendering of the text/plain +sub test_render_textplain { + my $this = shift; + my $text; + my $hdr; + my $editUrl; + + ($text, $hdr, $editUrl) = $this->setup_view( $this->{test_web}, 'TestTopic2', 'viewfour', '', 'text/plain', 'text'); + $editUrl =~ s/WebHome/MissingWikiWord/; + + my $topic2plain = < +MissingWikiWord?
+ExclamationEscape
+NopEscape +
 adsf 
 qwerty 
+

A Paragraph

+#anchor +asdf +NotTOAutoLink +
posttemplate +HERE + chomp $topic2plain; + $this->assert_matches( qr#^Content-Type: text/plain;#ms, $hdr, "contenttype=text/plain should return text/plain - got $hdr"); + $this->assert_does_not_match( qr#<(noautolink|nop)>#, $text, "autolink or nop found in text skin" ); + $this->assert_equals( "$topic2plain", $text, "Unexpected output from contentype=text/plain skin=text" ); + +} # This test verifies the handling of preamble (the text following # %STARTTEXT%) and postamble (the text between %TEXT% and %ENDTEXT%). sub test_prepostamble { my $this = shift; my $text; - $text = $this->setup_view( $this->{test_web}, 'TestTopic1', 'viewone' ); + ($text) = $this->setup_view( $this->{test_web}, 'TestTopic1', 'viewone' ); $text =~ s/\n+$//s; $this->assert_equals( 'pretemplatepreCONTENT postposttemplate', $text ); - $text = $this->setup_view( $this->{test_web}, 'TestTopic1', 'viewtwo' ); + ($text) = $this->setup_view( $this->{test_web}, 'TestTopic1', 'viewtwo' ); $this->assert_equals( 'pretemplateCONTENT postposttemplate', $text ); - $text = $this->setup_view( $this->{test_web}, 'TestTopic1', 'viewthree' ); + ($text) = $this->setup_view( $this->{test_web}, 'TestTopic1', 'viewthree' ); $this->assert_equals( 'pretemplatepreCONTENTposttemplate', $text ); - $text = $this->setup_view( $this->{test_web}, 'TestTopic1', 'viewfour' ); + ($text) = $this->setup_view( $this->{test_web}, 'TestTopic1', 'viewfour' ); $this->assert_equals( 'pretemplateCONTENTposttemplate', $text ); - $text = $this->setup_view( $this->{test_web}, 'TestTopic1', 'viewfive' ); + ($text) = $this->setup_view( $this->{test_web}, 'TestTopic1', 'viewfive' ); $this->assert_equals( 'pretemplateposttemplate', $text ); } diff --git a/core/lib/Foswiki/UI/View.pm b/core/lib/Foswiki/UI/View.pm index b7bc8da9bf..08eb974f41 100644 --- a/core/lib/Foswiki/UI/View.pm +++ b/core/lib/Foswiki/UI/View.pm @@ -398,6 +398,7 @@ sub _prepare { $text = $topicObject->expandMacros($text); $text = $topicObject->renderTML($text); + $text =~ s/( ?) *<\/?(nop|noautolink)\/?>\n?/$1/gois; if ($minimalist) { $text =~ s/]*>//gi; # remove image tags