update('SSViewer', 'source_file_comments', false); Config::inst()->update('SSViewer_FromString', 'cache_template', false); $this->oldServer = $_SERVER; } public function tearDown() { $_SERVER = $this->oldServer; parent::tearDown(); } /** * Tests for {@link Config::inst()->get('SSViewer', 'theme')} for different behaviour * of user defined themes via {@link SiteConfig} and default theme * when no user themes are defined. */ public function testCurrentTheme() { //TODO: SiteConfig moved to CMS Config::inst()->update('SSViewer', 'theme', 'mytheme'); $this->assertEquals('mytheme', Config::inst()->get('SSViewer', 'theme'), 'Current theme is the default - user has not defined one'); } /** * Test that a template without a
tag still renders. */ public function testTemplateWithoutHeadRenders() { $data = new ArrayData(array( 'Var' => 'var value' )); $result = $data->renderWith("SSViewerTestPartialTemplate"); $this->assertEquals('Test partial template: var value', trim(preg_replace("//U",'',$result))); } public function testIncludeScopeInheritance() { $data = $this->getScopeInheritanceTestData(); $expected = array( 'Item 1 - First-ODD top:Item 1', 'Item 2 - EVEN top:Item 2', 'Item 3 - ODD top:Item 3', 'Item 4 - EVEN top:Item 4', 'Item 5 - ODD top:Item 5', 'Item 6 - Last-EVEN top:Item 6', ); $result = $data->renderWith('SSViewerTestIncludeScopeInheritance'); $this->assertExpectedStrings($result, $expected); // reset results for the tests that include arguments (the title is passed as an arg) $expected = array( 'Item 1 _ Item 1 - First-ODD top:Item 1', 'Item 2 _ Item 2 - EVEN top:Item 2', 'Item 3 _ Item 3 - ODD top:Item 3', 'Item 4 _ Item 4 - EVEN top:Item 4', 'Item 5 _ Item 5 - ODD top:Item 5', 'Item 6 _ Item 6 - Last-EVEN top:Item 6', ); $result = $data->renderWith('SSViewerTestIncludeScopeInheritanceWithArgs'); $this->assertExpectedStrings($result, $expected); } public function testIncludeTruthyness() { $data = new ArrayData(array( 'Title' => 'TruthyTest', 'Items' => new ArrayList(array( new ArrayData(array('Title' => 'Item 1')), new ArrayData(array('Title' => '')), new ArrayData(array('Title' => true)), new ArrayData(array('Title' => false)), new ArrayData(array('Title' => null)), new ArrayData(array('Title' => 0)), new ArrayData(array('Title' => 7)) )) )); $result = $data->renderWith('SSViewerTestIncludeScopeInheritanceWithArgs'); // We should not end up with empty values appearing as empty $expected = array( 'Item 1 _ Item 1 - First-ODD top:Item 1', 'Untitled - EVEN top:', '1 _ 1 - ODD top:1', 'Untitled - EVEN top:', 'Untitled - ODD top:', 'Untitled - EVEN top:0', '7 _ 7 - Last-ODD top:7' ); $this->assertExpectedStrings($result, $expected); } private function getScopeInheritanceTestData() { return new ArrayData(array( 'Title' => 'TopTitleValue', 'Items' => new ArrayList(array( new ArrayData(array('Title' => 'Item 1')), new ArrayData(array('Title' => 'Item 2')), new ArrayData(array('Title' => 'Item 3')), new ArrayData(array('Title' => 'Item 4')), new ArrayData(array('Title' => 'Item 5')), new ArrayData(array('Title' => 'Item 6')) )) )); } private function assertExpectedStrings($result, $expected) { foreach ($expected as $expectedStr) { $this->assertTrue( (boolean) preg_match("/{$expectedStr}/", $result), "Didn't find '{$expectedStr}' in:\n{$result}" ); } } /** * Small helper to render templates from strings */ public function render($templateString, $data = null) { if(!$data) $data = new SSViewerTestFixture(); return SSViewer::execute_string($templateString, $data); } public function testRequirements() { $requirements = $this->getMock("Requirements_Backend", array("javascript", "css")); $jsFile = FRAMEWORK_DIR . '/tests/forms/a.js'; $cssFile = FRAMEWORK_DIR . '/tests/forms/a.js'; $requirements->expects($this->once())->method('javascript')->with($jsFile); $requirements->expects($this->once())->method('css')->with($cssFile); Requirements::set_backend($requirements); $template = $this->render("<% require javascript($jsFile) %> <% require css($cssFile) %>"); $this->assertFalse((bool)trim($template), "Should be no content in this return."); } public function testRequirementsCombine(){ $oldBackend = Requirements::backend(); $testBackend = new Requirements_Backend(); Requirements::set_backend($testBackend); $combinedTestFilePath = BASE_PATH . '/' . $testBackend->getCombinedFilesFolder() . '/testRequirementsCombine.js'; $jsFile = FRAMEWORK_DIR . '/tests/view/themes/javascript/bad.js'; $jsFileContents = file_get_contents(BASE_PATH . '/' . $jsFile); Requirements::combine_files('testRequirementsCombine.js', array($jsFile)); require_once('thirdparty/jsmin/jsmin.php'); // first make sure that our test js file causes an exception to be thrown try{ $content = JSMin::minify($content); Requirements::set_backend($oldBackend); $this->fail('JSMin did not throw exception on minify bad file: '); }catch(Exception $e){ // exception thrown... good } // secondly, make sure that requirements combine throws the correct warning, and only that warning @unlink($combinedTestFilePath); try{ Requirements::process_combined_files(); }catch(PHPUnit_Framework_Error_Warning $e){ if(strstr($e->getMessage(), 'Failed to minify') === false){ Requirements::set_backend($oldBackend); $this->fail('Requirements::process_combined_files raised a warning, which is good, but this is not the expected warning ("Failed to minify..."): '.$e); } }catch(Exception $e){ Requirements::set_backend($oldBackend); $this->fail('Requirements::process_combined_files did not catch exception caused by minifying bad js file: '.$e); } // and make sure the combined content matches the input content, i.e. no loss of functionality if(!file_exists($combinedTestFilePath)){ Requirements::set_backend($oldBackend); $this->fail('No combined file was created at expected path: '.$combinedTestFilePath); } $combinedTestFileContents = file_get_contents($combinedTestFilePath); $this->assertContains($jsFileContents, $combinedTestFileContents); // reset Requirements::set_backend($oldBackend); } public function testComments() { $output = $this->render(<<test
'; $this->assertRegExp('/test
'; $this->assertRegExp('/test
'; $this->assertRegExp('/[out:Arg1]
[out:Arg2]
' ); $this->assertEquals( $this->render('<% include SSViewerTestIncludeWithArguments Arg1=A %>'), 'A
[out:Arg2]
' ); $this->assertEquals( $this->render('<% include SSViewerTestIncludeWithArguments Arg1=A, Arg2=B %>'), 'A
B
' ); $this->assertEquals( $this->render('<% include SSViewerTestIncludeWithArguments Arg1=A Bare String, Arg2=B Bare String %>'), 'A Bare String
B Bare String
' ); $this->assertEquals( $this->render('<% include SSViewerTestIncludeWithArguments Arg1="A", Arg2=$B %>', new ArrayData(array('B' => 'Bar'))), 'A
Bar
' ); $this->assertEquals( $this->render('<% include SSViewerTestIncludeWithArguments Arg1="A" %>', new ArrayData(array('Arg1' => 'Foo', 'Arg2' => 'Bar'))), 'A
Bar
' ); $data = new ArrayData(array( 'Nested' => new ArrayData(array( 'Object' => new ArrayData(array('Key' => 'A')) )), 'Object' => new ArrayData(array('Key' => 'B')) )); $tmpl = SSViewer::fromString('<% include SSViewerTestIncludeObjectArguments A=$Nested.Object, B=$Object %>'); $res = $tmpl->process($data); $this->assertEqualIgnoringWhitespace('A B', $res, 'Objects can be passed as named arguments'); } public function testRecursiveInclude() { $view = new SSViewer(array('SSViewerTestRecursiveInclude')); $data = new ArrayData(array( 'Title' => 'A', 'Children' => new ArrayList(array( new ArrayData(array( 'Title' => 'A1', 'Children' => new ArrayList(array( new ArrayData(array( 'Title' => 'A1 i', )), new ArrayData(array( 'Title' => 'A1 ii', )), )), )), new ArrayData(array( 'Title' => 'A2', )), new ArrayData(array( 'Title' => 'A3', )), )), )); $result = $view->process($data); // We don't care about whitespace $rationalisedResult = trim(preg_replace('/\s+/', ' ', $result)); $this->assertEquals('A A1 A1 i A1 ii A2 A3', $rationalisedResult); } public function assertEqualIgnoringWhitespace($a, $b) { $this->assertEquals(preg_replace('/\s+/', '', $a), preg_replace('/\s+/', '', $b)); } /** * See {@link ViewableDataTest} for more extensive casting tests, * this test just ensures that basic casting is correctly applied during template parsing. */ public function testCastingHelpers() { $vd = new SSViewerTest_ViewableData(); $vd->TextValue = 'html'; $vd->HTMLValue = 'html'; $vd->UncastedValue = 'html'; // Value casted as "Text" $this->assertEquals( '<b>html</b>', $t = SSViewer::fromString('$TextValue')->process($vd) ); $this->assertEquals( 'html', $t = SSViewer::fromString('$TextValue.RAW')->process($vd) ); $this->assertEquals( '<b>html</b>', $t = SSViewer::fromString('$TextValue.XML')->process($vd) ); // Value casted as "HTMLText" $this->assertEquals( 'html', $t = SSViewer::fromString('$HTMLValue')->process($vd) ); $this->assertEquals( 'html', $t = SSViewer::fromString('$HTMLValue.RAW')->process($vd) ); $this->assertEquals( '<b>html</b>', $t = SSViewer::fromString('$HTMLValue.XML')->process($vd) ); // Uncasted value (falls back to ViewableData::$default_cast="HTMLText") $vd = new SSViewerTest_ViewableData(); // TODO Fix caching $vd->UncastedValue = 'html'; $this->assertEquals( 'html', $t = SSViewer::fromString('$UncastedValue')->process($vd) ); $vd = new SSViewerTest_ViewableData(); // TODO Fix caching $vd->UncastedValue = 'html'; $this->assertEquals( 'html', $t = SSViewer::fromString('$UncastedValue.RAW')->process($vd) ); $vd = new SSViewerTest_ViewableData(); // TODO Fix caching $vd->UncastedValue = 'html'; $this->assertEquals( '<b>html</b>', $t = SSViewer::fromString('$UncastedValue.XML')->process($vd) ); } public function testSSViewerBasicIteratorSupport() { $data = new ArrayData(array( 'Set' => new ArrayList(array( new SSViewerTest_Object("1"), new SSViewerTest_Object("2"), new SSViewerTest_Object("3"), new SSViewerTest_Object("4"), new SSViewerTest_Object("5"), new SSViewerTest_Object("6"), new SSViewerTest_Object("7"), new SSViewerTest_Object("8"), new SSViewerTest_Object("9"), new SSViewerTest_Object("10"), )) )); //base test $result = $this->render('<% loop Set %>$Number<% end_loop %>',$data); $this->assertEquals("12345678910",$result,"Numbers rendered in order"); //test First $result = $this->render('<% loop Set %><% if First %>$Number<% end_if %><% end_loop %>',$data); $this->assertEquals("1",$result,"Only the first number is rendered"); //test Last $result = $this->render('<% loop Set %><% if Last %>$Number<% end_if %><% end_loop %>',$data); $this->assertEquals("10",$result,"Only the last number is rendered"); //test Even $result = $this->render('<% loop Set %><% if Even() %>$Number<% end_if %><% end_loop %>',$data); $this->assertEquals("246810",$result,"Even numbers rendered in order"); //test Even with quotes $result = $this->render('<% loop Set %><% if Even("1") %>$Number<% end_if %><% end_loop %>',$data); $this->assertEquals("246810",$result,"Even numbers rendered in order"); //test Even without quotes $result = $this->render('<% loop Set %><% if Even(1) %>$Number<% end_if %><% end_loop %>',$data); $this->assertEquals("246810",$result,"Even numbers rendered in order"); //test Even with zero-based start index $result = $this->render('<% loop Set %><% if Even("0") %>$Number<% end_if %><% end_loop %>',$data); $this->assertEquals("13579",$result,"Even (with zero-based index) numbers rendered in order"); //test Odd $result = $this->render('<% loop Set %><% if Odd %>$Number<% end_if %><% end_loop %>',$data); $this->assertEquals("13579",$result,"Odd numbers rendered in order"); //test FirstLast $result = $this->render('<% loop Set %><% if FirstLast %>$Number$FirstLast<% end_if %><% end_loop %>',$data); $this->assertEquals("1first10last",$result,"First and last numbers rendered in order"); //test Middle $result = $this->render('<% loop Set %><% if Middle %>$Number<% end_if %><% end_loop %>',$data); $this->assertEquals("23456789",$result,"Middle numbers rendered in order"); //test MiddleString $result = $this->render('<% loop Set %><% if MiddleString == "middle" %>$Number$MiddleString<% end_if %>' . '<% end_loop %>',$data); $this->assertEquals("2middle3middle4middle5middle6middle7middle8middle9middle",$result, "Middle numbers rendered in order"); //test EvenOdd $result = $this->render('<% loop Set %>$EvenOdd<% end_loop %>',$data); $this->assertEquals("oddevenoddevenoddevenoddevenoddeven",$result, "Even and Odd is returned in sequence numbers rendered in order"); //test Pos $result = $this->render('<% loop Set %>$Pos<% end_loop %>',$data); $this->assertEquals("12345678910",$result,"Even and Odd is returned in sequence numbers rendered in order"); //test Total $result = $this->render('<% loop Set %>$TotalItems<% end_loop %>',$data); $this->assertEquals("10101010101010101010",$result,"10 total items X 10 are returned"); //test Modulus $result = $this->render('<% loop Set %>$Modulus(2,1)<% end_loop %>',$data); $this->assertEquals("1010101010",$result,"1-indexed pos modular divided by 2 rendered in order"); //test MultipleOf 3 $result = $this->render('<% loop Set %><% if MultipleOf(3) %>$Number<% end_if %><% end_loop %>',$data); $this->assertEquals("369",$result,"Only numbers that are multiples of 3 are returned"); //test MultipleOf 4 $result = $this->render('<% loop Set %><% if MultipleOf(4) %>$Number<% end_if %><% end_loop %>',$data); $this->assertEquals("48",$result,"Only numbers that are multiples of 4 are returned"); //test MultipleOf 5 $result = $this->render('<% loop Set %><% if MultipleOf(5) %>$Number<% end_if %><% end_loop %>',$data); $this->assertEquals("510",$result,"Only numbers that are multiples of 5 are returned"); //test MultipleOf 10 $result = $this->render('<% loop Set %><% if MultipleOf(10,1) %>$Number<% end_if %><% end_loop %>',$data); $this->assertEquals("10",$result,"Only numbers that are multiples of 10 (with 1-based indexing) are returned"); //test MultipleOf 9 zero-based $result = $this->render('<% loop Set %><% if MultipleOf(9,0) %>$Number<% end_if %><% end_loop %>',$data); $this->assertEquals("110",$result, "Only numbers that are multiples of 9 with zero-based indexing are returned. (The first and last item)"); //test MultipleOf 11 $result = $this->render('<% loop Set %><% if MultipleOf(11) %>$Number<% end_if %><% end_loop %>',$data); $this->assertEquals("",$result,"Only numbers that are multiples of 11 are returned. I.e. nothing returned"); } /** * Test $Up works when the scope $Up refers to was entered with a "with" block */ public function testUpInWith() { // Data to run the loop tests on - three levels deep $data = new ArrayData(array( 'Name' => 'Top', 'Foo' => new ArrayData(array( 'Name' => 'Foo', 'Bar' => new ArrayData(array( 'Name' => 'Bar', 'Baz' => new ArrayData(array( 'Name' => 'Baz' )), 'Qux' => new ArrayData(array( 'Name' => 'Qux' )) )) )) )); // Basic functionality $this->assertEquals('BarFoo', $this->render('<% with Foo %><% with Bar %>{$Name}{$Up.Name}<% end_with %><% end_with %>', $data)); // Two level with block, up refers to internally referenced Bar $this->assertEquals('BarFoo', $this->render('<% with Foo.Bar %>{$Name}{$Up.Name}<% end_with %>', $data)); // Stepping up & back down the scope tree $this->assertEquals('BazBarQux', $this->render('<% with Foo.Bar.Baz %>{$Name}{$Up.Name}{$Up.Qux.Name}<% end_with %>', $data)); // Using $Up in a with block $this->assertEquals('BazBarQux', $this->render('<% with Foo.Bar.Baz %>{$Name}<% with $Up %>{$Name}{$Qux.Name}<% end_with %>' .'<% end_with %>', $data)); // Stepping up & back down the scope tree with with blocks $this->assertEquals('BazBarQuxBarBaz', $this->render('<% with Foo.Bar.Baz %>{$Name}<% with $Up %>{$Name}<% with Qux %>{$Name}<% end_with %>' . '{$Name}<% end_with %>{$Name}<% end_with %>', $data)); // Using $Up.Up, where first $Up points to a previous scope entered using $Up, thereby skipping up to Foo $this->assertEquals('Foo', $this->render('<% with Foo.Bar.Baz %><% with Up %><% with Qux %>{$Up.Up.Name}<% end_with %><% end_with %>' . '<% end_with %>', $data)); // Using $Up.Up, where first $Up points to an Up used in a local scope lookup, should still skip to Foo $this->assertEquals('Foo', $this->render('<% with Foo.Bar.Baz.Up.Qux %>{$Up.Up.Name}<% end_with %>', $data)); } /** * Test $Up works when the scope $Up refers to was entered with a "loop" block */ public function testUpInLoop(){ // Data to run the loop tests on - one sequence of three items, each with a subitem $data = new ArrayData(array( 'Name' => 'Top', 'Foo' => new ArrayList(array( new ArrayData(array( 'Name' => '1', 'Sub' => new ArrayData(array( 'Name' => 'Bar' )) )), new ArrayData(array( 'Name' => '2', 'Sub' => new ArrayData(array( 'Name' => 'Baz' )) )), new ArrayData(array( 'Name' => '3', 'Sub' => new ArrayData(array( 'Name' => 'Qux' )) )) )) )); // Make sure inside a loop, $Up refers to the current item of the loop $this->assertEqualIgnoringWhitespace( '111 222 333', $this->render( '<% loop $Foo %>$Name<% with $Sub %>$Up.Name<% end_with %>$Name<% end_loop %>', $data ) ); // Make sure inside a loop, looping over $Up uses a separate iterator, // and doesn't interfere with the original iterator $this->assertEqualIgnoringWhitespace( '1Bar123Bar1 2Baz123Baz2 3Qux123Qux3', $this->render( '<% loop $Foo %> $Name <% with $Sub %> $Name <% loop $Up %>$Name<% end_loop %> $Name <% end_with %> $Name <% end_loop %>', $data ) ); // Make sure inside a loop, looping over $Up uses a separate iterator, // and doesn't interfere with the original iterator or local lookups $this->assertEqualIgnoringWhitespace( '1 Bar1 123 1Bar 1 2 Baz2 123 2Baz 2 3 Qux3 123 3Qux 3', $this->render( '<% loop $Foo %> $Name <% with $Sub %> {$Name}{$Up.Name} <% loop $Up %>$Name<% end_loop %> {$Up.Name}{$Name} <% end_with %> $Name <% end_loop %>', $data ) ); } /** * Test that nested loops restore the loop variables correctly when pushing and popping states */ public function testNestedLoops(){ // Data to run the loop tests on - one sequence of three items, one with child elements // (of a different size to the main sequence) $data = new ArrayData(array( 'Foo' => new ArrayList(array( new ArrayData(array( 'Name' => '1', 'Children' => new ArrayList(array( new ArrayData(array( 'Name' => 'a' )), new ArrayData(array( 'Name' => 'b' )), )), )), new ArrayData(array( 'Name' => '2', 'Children' => new ArrayList(), )), new ArrayData(array( 'Name' => '3', 'Children' => new ArrayList(), )), )), )); // Make sure that including a loop inside a loop will not destroy the internal count of // items, checked by using "Last" $this->assertEqualIgnoringWhitespace( '1ab23last', $this->render('<% loop $Foo %>$Name<% loop Children %>$Name<% end_loop %><% if Last %>last<% end_if %>' . '<% end_loop %>', $data ) ); } protected function useTestTheme($theme, $callback) { global $project; $themeBaseDir = dirname(__FILE__); $manifest = new SS_TemplateManifest($themeBaseDir, $project, true, true); SS_TemplateLoader::instance()->pushManifest($manifest); $origTheme = Config::inst()->get('SSViewer', 'theme'); Config::inst()->update('SSViewer', 'theme', $theme); $e = null; try { $callback(); } catch (Exception $e) { /* NOP for now, just save $e */ } // Remove all the test themes we created SS_TemplateLoader::instance()->popManifest(); Config::inst()->update('SSViewer', 'theme', $origTheme); if ($e) throw $e; } public function testLayout() { $self = $this; $this->useTestTheme('layouttest', function() use ($self) { $template = new SSViewer(array('Page')); $self->assertEquals('Foo', $template->process(new ArrayData(array()))); $template = new SSViewer(array('Shortcodes', 'Page')); $self->assertEquals('[file_link]', $template->process(new ArrayData(array()))); }); } /** * @covers SSViewer::get_templates_by_class() */ public function testGetTemplatesByClass() { $self = $this; $this->useTestTheme('layouttest', function() use ($self) { // Test passing a string $templates = SSViewer::get_templates_by_class('SSViewerTest_Controller', '', 'Controller'); $self->assertCount(2, $templates); // Test to ensure we're stopping at the base class. $templates = SSViewer::get_templates_by_class('SSViewerTest_Controller', '', 'SSViewerTest_Controller'); $self->assertCount(1, $templates); // Make sure we can filter our templates by suffix. $templates = SSViewer::get_templates_by_class('SSViewerTest', '_Controller'); $self->assertCount(1, $templates); // Test passing a valid object $templates = SSViewer::get_templates_by_class("SSViewerTest_Controller", '', 'Controller'); // Test that templates are returned in the correct order $self->assertEquals('SSViewerTest_Controller', array_shift($templates)); $self->assertEquals('Controller', array_shift($templates)); // Let's throw something random in there. $self->setExpectedException('InvalidArgumentException'); $templates = SSViewer::get_templates_by_class(array()); }); } /** * @covers SSViewer::get_themes() */ public function testThemeRetrieval() { $ds = DIRECTORY_SEPARATOR; $testThemeBaseDir = TEMP_FOLDER . $ds . 'test-themes'; if(file_exists($testThemeBaseDir)) Filesystem::removeFolder($testThemeBaseDir); mkdir($testThemeBaseDir); mkdir($testThemeBaseDir . $ds . 'blackcandy'); mkdir($testThemeBaseDir . $ds . 'blackcandy_blog'); mkdir($testThemeBaseDir . $ds . 'darkshades'); mkdir($testThemeBaseDir . $ds . 'darkshades_blog'); $this->assertEquals(array( 'blackcandy' => 'blackcandy', 'darkshades' => 'darkshades' ), SSViewer::get_themes($testThemeBaseDir), 'Our test theme directory contains 2 themes'); $this->assertEquals(array( 'blackcandy' => 'blackcandy', 'blackcandy_blog' => 'blackcandy_blog', 'darkshades' => 'darkshades', 'darkshades_blog' => 'darkshades_blog' ), SSViewer::get_themes($testThemeBaseDir, true), 'Our test theme directory contains 2 themes and 2 sub-themes'); // Remove all the test themes we created Filesystem::removeFolder($testThemeBaseDir); } public function testRewriteHashlinks() { $orig = Config::inst()->get('SSViewer', 'rewrite_hash_links'); Config::inst()->update('SSViewer', 'rewrite_hash_links', true); $_SERVER['HTTP_HOST'] = 'www.mysite.com'; $_SERVER['REQUEST_URI'] = '//file.com?foo"onclick="alert(\'xss\')""'; // Emulate SSViewer::process() // Note that leading double slashes have been rewritten to prevent these being mis-interepreted // as protocol-less absolute urls $base = Convert::raw2att('/file.com?foo"onclick="alert(\'xss\')""'); $tmplFile = TEMP_FOLDER . '/SSViewerTest_testRewriteHashlinks_' . sha1(rand()) . '.ss'; // Note: SSViewer_FromString doesn't rewrite hash links. file_put_contents($tmplFile, ' <% base_tag %> ExternalInlineLink $ExternalInsertedLink InlineLink $InsertedLink '); $tmpl = new SSViewer($tmplFile); $obj = new ViewableData(); $obj->InsertedLink = 'InsertedLink'; $obj->ExternalInsertedLink = 'ExternalInsertedLink'; $result = $tmpl->process($obj); $this->assertContains( 'InsertedLink', $result ); $this->assertContains( 'ExternalInsertedLink', $result ); $this->assertContains( 'InlineLink', $result ); $this->assertContains( 'ExternalInlineLink', $result ); $this->assertContains( '', $result, 'SSTemplateParser should only rewrite anchor hrefs' ); unlink($tmplFile); Config::inst()->update('SSViewer', 'rewrite_hash_links', $orig); } public function testRewriteHashlinksInPhpMode() { $orig = Config::inst()->get('SSViewer', 'rewrite_hash_links'); Config::inst()->update('SSViewer', 'rewrite_hash_links', 'php'); $tmplFile = TEMP_FOLDER . '/SSViewerTest_testRewriteHashlinksInPhpMode_' . sha1(rand()) . '.ss'; // Note: SSViewer_FromString doesn't rewrite hash links. file_put_contents($tmplFile, ' <% base_tag %> InlineLink $InsertedLink '); $tmpl = new SSViewer($tmplFile); $obj = new ViewableData(); $obj->InsertedLink = 'InsertedLink'; $result = $tmpl->process($obj); $code = <<<'EOC' #anchor">InsertedLink EOC; $this->assertContains($code, $result); // TODO Fix inline links in PHP mode // $this->assertContains( // '', $result, 'SSTemplateParser should only rewrite anchor hrefs' ); unlink($tmplFile); Config::inst()->update('SSViewer', 'rewrite_hash_links', $orig); } public function testRenderWithSourceFileComments() { $origEnv = Config::inst()->get('Director', 'environment_type'); Config::inst()->update('Director', 'environment_type', 'dev'); Config::inst()->update('SSViewer', 'source_file_comments', true); $f = FRAMEWORK_PATH . '/tests/templates/SSViewerTestComments'; $templates = array( array( 'name' => 'SSViewerTestCommentsFullSource', 'expected' => "" . "" . "" . "" . "\t" . "\t" . "" . "", ), array( 'name' => 'SSViewerTestCommentsFullSourceHTML4Doctype', 'expected' => "" . "" . "" . "" . "\t" . "\t" . "" . "", ), array( 'name' => 'SSViewerTestCommentsFullSourceNoDoctype', 'expected' => "" . "" . "\t" . "\t" . "", ), array( 'name' => 'SSViewerTestCommentsFullSourceIfIE', 'expected' => "" . "" . "" . "" . "" . " " . "\t" . "\t" . "" . "", ), array( 'name' => 'SSViewerTestCommentsFullSourceIfIENoDoctype', 'expected' => "" . "" . "" . " " . "" . " " . "\t" . "\t" . "", ), array( 'name' => 'SSViewerTestCommentsPartialSource', 'expected' => "" . "" . "", ), array( 'name' => 'SSViewerTestCommentsWithInclude', 'expected' => "" . "