Add lint-clean and cleanup code linting

This commit is contained in:
Damian Mooyman 2017-05-12 15:17:23 +12:00 committed by Sam Minnée
parent 3da1587289
commit 7a8dfd2785
3 changed files with 608 additions and 634 deletions

View File

@ -84,7 +84,8 @@
"thirdparty/" "thirdparty/"
], ],
"scripts": { "scripts": {
"lint": "phpcs --standard=tests/phpcs/ruleset.xml src/ tests/php", "lint": "phpcs src/ tests/php",
"lint-clean": "phpcbf src/ tests/php",
"php-peg": "php thirdparty/php-peg/cli.php src/View/SSTemplateParser.peg > src/View/SSTemplateParser.php" "php-peg": "php thirdparty/php-peg/cli.php src/View/SSTemplateParser.peg > src/View/SSTemplateParser.php"
}, },
"minimum-stability": "dev", "minimum-stability": "dev",

View File

@ -2,6 +2,7 @@
namespace SilverStripe\View\Tests; namespace SilverStripe\View\Tests;
use PHPUnit_Framework_MockObject_MockObject;
use SilverStripe\Control\Controller; use SilverStripe\Control\Controller;
use SilverStripe\Control\Director; use SilverStripe\Control\Director;
use SilverStripe\Control\ContentNegotiator; use SilverStripe\Control\ContentNegotiator;
@ -69,9 +70,9 @@ class SSViewerTest extends SapphireTest
{ {
SSViewer::config()->update('theme', 'mytheme'); SSViewer::config()->update('theme', 'mytheme');
$this->assertEquals( $this->assertEquals(
'mytheme', 'mytheme',
SSViewer::config()->uninherited('theme'), SSViewer::config()->uninherited('theme'),
'Current theme is the default - user has not defined one' 'Current theme is the default - user has not defined one'
); );
} }
@ -80,12 +81,7 @@ class SSViewerTest extends SapphireTest
*/ */
public function testTemplateWithoutHeadRenders() public function testTemplateWithoutHeadRenders()
{ {
$data = new ArrayData( $data = new ArrayData([ 'Var' => 'var value' ]);
array(
'Var' => 'var value'
)
);
$result = $data->renderWith("SSViewerTestPartialTemplate"); $result = $data->renderWith("SSViewerTestPartialTemplate");
$this->assertEquals('Test partial template: var value', trim(preg_replace("/<!--.*-->/U", '', $result))); $this->assertEquals('Test partial template: var value', trim(preg_replace("/<!--.*-->/U", '', $result)));
} }
@ -121,62 +117,54 @@ class SSViewerTest extends SapphireTest
public function testIncludeTruthyness() public function testIncludeTruthyness()
{ {
$data = new ArrayData( $data = new ArrayData([
array( 'Title' => 'TruthyTest',
'Title' => 'TruthyTest', 'Items' => new ArrayList([
'Items' => new ArrayList( new ArrayData(['Title' => 'Item 1']),
array( new ArrayData(['Title' => '']),
new ArrayData(array('Title' => 'Item 1')), new ArrayData(['Title' => true]),
new ArrayData(array('Title' => '')), new ArrayData(['Title' => false]),
new ArrayData(array('Title' => true)), new ArrayData(['Title' => null]),
new ArrayData(array('Title' => false)), new ArrayData(['Title' => 0]),
new ArrayData(array('Title' => null)), new ArrayData(['Title' => 7])
new ArrayData(array('Title' => 0)), ])
new ArrayData(array('Title' => 7)) ]);
)
)
)
);
$result = $data->renderWith('SSViewerTestIncludeScopeInheritanceWithArgs'); $result = $data->renderWith('SSViewerTestIncludeScopeInheritanceWithArgs');
// We should not end up with empty values appearing as empty // We should not end up with empty values appearing as empty
$expected = array( $expected = [
'Item 1 _ Item 1 - First-ODD top:Item 1', 'Item 1 _ Item 1 - First-ODD top:Item 1',
'Untitled - EVEN top:', 'Untitled - EVEN top:',
'1 _ 1 - ODD top:1', '1 _ 1 - ODD top:1',
'Untitled - EVEN top:', 'Untitled - EVEN top:',
'Untitled - ODD top:', 'Untitled - ODD top:',
'Untitled - EVEN top:0', 'Untitled - EVEN top:0',
'7 _ 7 - Last-ODD top:7' '7 _ 7 - Last-ODD top:7',
); ];
$this->assertExpectedStrings($result, $expected); $this->assertExpectedStrings($result, $expected);
} }
private function getScopeInheritanceTestData() private function getScopeInheritanceTestData()
{ {
return new ArrayData( return new ArrayData([
array( 'Title' => 'TopTitleValue',
'Title' => 'TopTitleValue', 'Items' => new ArrayList([
'Items' => new ArrayList( new ArrayData(['Title' => 'Item 1']),
array( new ArrayData(['Title' => 'Item 2']),
new ArrayData(array('Title' => 'Item 1')), new ArrayData(['Title' => 'Item 3']),
new ArrayData(array('Title' => 'Item 2')), new ArrayData(['Title' => 'Item 4']),
new ArrayData(array('Title' => 'Item 3')), new ArrayData(['Title' => 'Item 5']),
new ArrayData(array('Title' => 'Item 4')), new ArrayData(['Title' => 'Item 6'])
new ArrayData(array('Title' => 'Item 5')), ])
new ArrayData(array('Title' => 'Item 6')) ]);
)
)
)
);
} }
private function assertExpectedStrings($result, $expected) private function assertExpectedStrings($result, $expected)
{ {
foreach ($expected as $expectedStr) { foreach ($expected as $expectedStr) {
$this->assertTrue( $this->assertTrue(
(boolean) preg_match("/{$expectedStr}/", $result), (boolean) preg_match("/{$expectedStr}/", $result),
"Didn't find '{$expectedStr}' in:\n{$result}" "Didn't find '{$expectedStr}' in:\n{$result}"
); );
} }
} }
@ -200,8 +188,11 @@ class SSViewerTest extends SapphireTest
public function testRequirements() public function testRequirements()
{ {
$requirements = $this->getMockBuilder(Requirements_Backend::class)->setMethods(array("javascript", "css")) /** @var Requirements_Backend|PHPUnit_Framework_MockObject_MockObject $requirements */
->getMock(); $requirements = $this
->getMockBuilder(Requirements_Backend::class)
->setMethods(array("javascript", "css"))
->getMock();
$jsFile = FRAMEWORK_DIR . '/tests/forms/a.js'; $jsFile = FRAMEWORK_DIR . '/tests/forms/a.js';
$cssFile = FRAMEWORK_DIR . '/tests/forms/a.js'; $cssFile = FRAMEWORK_DIR . '/tests/forms/a.js';
@ -211,7 +202,7 @@ class SSViewerTest extends SapphireTest
$origReq = Requirements::backend(); $origReq = Requirements::backend();
Requirements::set_backend($requirements); Requirements::set_backend($requirements);
$template = $this->render( $template = $this->render(
"<% require javascript($jsFile) %> "<% require javascript($jsFile) %>
<% require css($cssFile) %>" <% require css($cssFile) %>"
); );
Requirements::set_backend($origReq); Requirements::set_backend($origReq);
@ -272,8 +263,8 @@ class SSViewerTest extends SapphireTest
$testBackend->processCombinedFiles(); $testBackend->processCombinedFiles();
$this->setExpectedExceptionRegExp( $this->setExpectedExceptionRegExp(
Exception::class, Exception::class,
'/minification service/' '/minification service/'
); );
$testBackend->setMinifyCombinedFiles(true); $testBackend->setMinifyCombinedFiles(true);
@ -285,8 +276,7 @@ class SSViewerTest extends SapphireTest
public function testComments() public function testComments()
{ {
$output = $this->render( $input = <<<SS
<<<SS
This is my template<%-- this is a comment --%>This is some content<%-- this is another comment --%>Final content This is my template<%-- this is a comment --%>This is some content<%-- this is another comment --%>Final content
<%-- Alone multi <%-- Alone multi
line comment --%> line comment --%>
@ -294,8 +284,8 @@ Some more content
Mixing content and <%-- multi Mixing content and <%-- multi
line comment --%> Final final line comment --%> Final final
content content
SS SS;
); $output = $this->render($input);
$shouldbe = <<<SS $shouldbe = <<<SS
This is my templateThis is some contentFinal content This is my templateThis is some contentFinal content
@ -303,7 +293,6 @@ Some more content
Mixing content and Final final Mixing content and Final final
content content
SS; SS;
$this->assertEquals($shouldbe, $output); $this->assertEquals($shouldbe, $output);
} }
@ -328,9 +317,9 @@ SS;
$this->assertEquals('{$Test}', $this->render('{\\$Test}'), 'Escapes can be used to avoid injection'); $this->assertEquals('{$Test}', $this->render('{\\$Test}'), 'Escapes can be used to avoid injection');
$this->assertEquals( $this->assertEquals(
'{\\[out:Test]}', '{\\[out:Test]}',
$this->render('{\\\\$Test}'), $this->render('{\\\\$Test}'),
'Escapes before injections are correctly unescaped' 'Escapes before injections are correctly unescaped'
); );
} }
@ -347,12 +336,12 @@ SS;
$this->assertEquals('zz', $this->render('$SSViewerTest_GlobalThatTakesArguments')); $this->assertEquals('zz', $this->render('$SSViewerTest_GlobalThatTakesArguments'));
$this->assertEquals('zFooz', $this->render('$SSViewerTest_GlobalThatTakesArguments("Foo")')); $this->assertEquals('zFooz', $this->render('$SSViewerTest_GlobalThatTakesArguments("Foo")'));
$this->assertEquals( $this->assertEquals(
'zFoo:Bar:Bazz', 'zFoo:Bar:Bazz',
$this->render('$SSViewerTest_GlobalThatTakesArguments("Foo", "Bar", "Baz")') $this->render('$SSViewerTest_GlobalThatTakesArguments("Foo", "Bar", "Baz")')
); );
$this->assertEquals( $this->assertEquals(
'zreferencez', 'zreferencez',
$this->render('$SSViewerTest_GlobalThatTakesArguments($SSViewerTest_GlobalReferencedByString)') $this->render('$SSViewerTest_GlobalThatTakesArguments($SSViewerTest_GlobalReferencedByString)')
); );
} }
@ -362,101 +351,101 @@ SS;
$this->assertEquals('&lt;div&gt;&lt;/div&gt;', $this->render('$SSViewerTest_GlobalHTMLEscaped')); $this->assertEquals('&lt;div&gt;&lt;/div&gt;', $this->render('$SSViewerTest_GlobalHTMLEscaped'));
$this->assertEquals( $this->assertEquals(
'z<div></div>z', 'z<div></div>z',
$this->render('$SSViewerTest_GlobalThatTakesArguments($SSViewerTest_GlobalHTMLFragment)') $this->render('$SSViewerTest_GlobalThatTakesArguments($SSViewerTest_GlobalHTMLFragment)')
); );
$this->assertEquals( $this->assertEquals(
'z&lt;div&gt;&lt;/div&gt;z', 'z&lt;div&gt;&lt;/div&gt;z',
$this->render('$SSViewerTest_GlobalThatTakesArguments($SSViewerTest_GlobalHTMLEscaped)') $this->render('$SSViewerTest_GlobalThatTakesArguments($SSViewerTest_GlobalHTMLEscaped)')
); );
} }
public function testCoreGlobalVariableCalls() public function testCoreGlobalVariableCalls()
{ {
$this->assertEquals( $this->assertEquals(
Director::absoluteBaseURL(), Director::absoluteBaseURL(),
$this->render('{$absoluteBaseURL}'), $this->render('{$absoluteBaseURL}'),
'Director::absoluteBaseURL can be called from within template' 'Director::absoluteBaseURL can be called from within template'
); );
$this->assertEquals( $this->assertEquals(
Director::absoluteBaseURL(), Director::absoluteBaseURL(),
$this->render('{$AbsoluteBaseURL}'), $this->render('{$AbsoluteBaseURL}'),
'Upper-case %AbsoluteBaseURL can be called from within template' 'Upper-case %AbsoluteBaseURL can be called from within template'
); );
$this->assertEquals( $this->assertEquals(
Director::is_ajax(), Director::is_ajax(),
$this->render('{$isAjax}'), $this->render('{$isAjax}'),
'All variations of is_ajax result in the correct call' 'All variations of is_ajax result in the correct call'
); );
$this->assertEquals( $this->assertEquals(
Director::is_ajax(), Director::is_ajax(),
$this->render('{$IsAjax}'), $this->render('{$IsAjax}'),
'All variations of is_ajax result in the correct call' 'All variations of is_ajax result in the correct call'
); );
$this->assertEquals( $this->assertEquals(
Director::is_ajax(), Director::is_ajax(),
$this->render('{$is_ajax}'), $this->render('{$is_ajax}'),
'All variations of is_ajax result in the correct call' 'All variations of is_ajax result in the correct call'
); );
$this->assertEquals( $this->assertEquals(
Director::is_ajax(), Director::is_ajax(),
$this->render('{$Is_ajax}'), $this->render('{$Is_ajax}'),
'All variations of is_ajax result in the correct call' 'All variations of is_ajax result in the correct call'
); );
$this->assertEquals( $this->assertEquals(
i18n::get_locale(), i18n::get_locale(),
$this->render('{$i18nLocale}'), $this->render('{$i18nLocale}'),
'i18n template functions result correct result' 'i18n template functions result correct result'
); );
$this->assertEquals( $this->assertEquals(
i18n::get_locale(), i18n::get_locale(),
$this->render('{$get_locale}'), $this->render('{$get_locale}'),
'i18n template functions result correct result' 'i18n template functions result correct result'
); );
$this->assertEquals( $this->assertEquals(
(string)Member::currentUser(), (string)Member::currentUser(),
$this->render('{$CurrentMember}'), $this->render('{$CurrentMember}'),
'Member template functions result correct result' 'Member template functions result correct result'
); );
$this->assertEquals( $this->assertEquals(
(string)Member::currentUser(), (string)Member::currentUser(),
$this->render('{$CurrentUser}'), $this->render('{$CurrentUser}'),
'Member template functions result correct result' 'Member template functions result correct result'
); );
$this->assertEquals( $this->assertEquals(
(string)Member::currentUser(), (string)Member::currentUser(),
$this->render('{$currentMember}'), $this->render('{$currentMember}'),
'Member template functions result correct result' 'Member template functions result correct result'
); );
$this->assertEquals( $this->assertEquals(
(string)Member::currentUser(), (string)Member::currentUser(),
$this->render('{$currentUser}'), $this->render('{$currentUser}'),
'Member template functions result correct result' 'Member template functions result correct result'
); );
$this->assertEquals( $this->assertEquals(
SecurityToken::getSecurityID(), SecurityToken::getSecurityID(),
$this->render('{$getSecurityID}'), $this->render('{$getSecurityID}'),
'SecurityToken template functions result correct result' 'SecurityToken template functions result correct result'
); );
$this->assertEquals( $this->assertEquals(
SecurityToken::getSecurityID(), SecurityToken::getSecurityID(),
$this->render('{$SecurityID}'), $this->render('{$SecurityID}'),
'SecurityToken template functions result correct result' 'SecurityToken template functions result correct result'
); );
$this->assertEquals( $this->assertEquals(
Permission::check("ADMIN"), Permission::check("ADMIN"),
(bool)$this->render('{$HasPerm(\'ADMIN\')}'), (bool)$this->render('{$HasPerm(\'ADMIN\')}'),
'Permissions template functions result correct result' 'Permissions template functions result correct result'
); );
$this->assertEquals( $this->assertEquals(
Permission::check("ADMIN"), Permission::check("ADMIN"),
(bool)$this->render('{$hasPerm(\'ADMIN\')}'), (bool)$this->render('{$hasPerm(\'ADMIN\')}'),
'Permissions template functions result correct result' 'Permissions template functions result correct result'
); );
} }
@ -464,31 +453,29 @@ SS;
{ {
// check if Link without $ in front of variable // check if Link without $ in front of variable
$result = $this->render( $result = $this->render(
'A<% if Link %>$Link<% end_if %>B', 'A<% if Link %>$Link<% end_if %>B',
new SSViewerTest\TestObject() new SSViewerTest\TestObject()
); );
$this->assertEquals('Asome/url.htmlB', $result, 'casting helper not used for <% if Link %>'); $this->assertEquals('Asome/url.htmlB', $result, 'casting helper not used for <% if Link %>');
// check if Link with $ in front of variable // check if Link with $ in front of variable
$result = $this->render( $result = $this->render(
'A<% if $Link %>$Link<% end_if %>B', 'A<% if $Link %>$Link<% end_if %>B',
new SSViewerTest\TestObject() new SSViewerTest\TestObject()
); );
$this->assertEquals('Asome/url.htmlB', $result, 'casting helper not used for <% if $Link %>'); $this->assertEquals('Asome/url.htmlB', $result, 'casting helper not used for <% if $Link %>');
} }
public function testLocalFunctionsTakePriorityOverGlobals() public function testLocalFunctionsTakePriorityOverGlobals()
{ {
$data = new ArrayData( $data = new ArrayData([
array( 'Page' => new SSViewerTest\TestObject()
'Page' => new SSViewerTest\TestObject() ]);
)
);
//call method with lots of arguments //call method with lots of arguments
$result = $this->render( $result = $this->render(
'<% with Page %>$lotsOfArguments11("a","b","c","d","e","f","g","h","i","j","k")<% end_with %>', '<% with Page %>$lotsOfArguments11("a","b","c","d","e","f","g","h","i","j","k")<% end_with %>',
$data $data
); );
$this->assertEquals("abcdefghijk", $result, "public function can accept up to 11 arguments"); $this->assertEquals("abcdefghijk", $result, "public function can accept up to 11 arguments");
@ -503,57 +490,43 @@ SS;
//call method with same name as a global method (local call should take priority) //call method with same name as a global method (local call should take priority)
$result = $this->render('<% with Page %>$absoluteBaseURL<% end_with %>', $data); $result = $this->render('<% with Page %>$absoluteBaseURL<% end_with %>', $data);
$this->assertEquals( $this->assertEquals(
"testLocalFunctionPriorityCalled", "testLocalFunctionPriorityCalled",
$result, $result,
"Local Object's public function called. Did not return the actual baseURL of the current site" "Local Object's public function called. Did not return the actual baseURL of the current site"
); );
} }
public function testCurrentScopeLoopWith() public function testCurrentScopeLoopWith()
{ {
// Data to run the loop tests on - one sequence of three items, each with a subitem // Data to run the loop tests on - one sequence of three items, each with a subitem
$data = new ArrayData( $data = new ArrayData([
array( 'Foo' => new ArrayList([
'Foo' => new ArrayList( 'Subocean' => new ArrayData([
array(
'Subocean' => new ArrayData(
array(
'Name' => 'Higher' 'Name' => 'Higher'
) ]),
), new ArrayData([
new ArrayData( 'Sub' => new ArrayData([
array( 'Name' => 'SubKid1'
'Sub' => new ArrayData( ])
array( ]),
'Name' => 'SubKid1' new ArrayData([
) 'Sub' => new ArrayData([
) 'Name' => 'SubKid2'
) ])
), ]),
new ArrayData( new SSViewerTest\TestObject('Number6')
array( ])
'Sub' => new ArrayData( ]);
array(
'Name' => 'SubKid2'
)
)
)
),
new SSViewerTest\TestObject('Number6')
)
)
)
);
$result = $this->render( $result = $this->render(
'<% loop Foo %>$Number<% if Sub %><% with Sub %>$Name<% end_with %><% end_if %><% end_loop %>', '<% loop Foo %>$Number<% if Sub %><% with Sub %>$Name<% end_with %><% end_if %><% end_loop %>',
$data $data
); );
$this->assertEquals("SubKid1SubKid2Number6", $result, "Loop works"); $this->assertEquals("SubKid1SubKid2Number6", $result, "Loop works");
$result = $this->render( $result = $this->render(
'<% loop Foo %>$Number<% if Sub %><% with Sub %>$Name<% end_with %><% end_if %><% end_loop %>', '<% loop Foo %>$Number<% if Sub %><% with Sub %>$Name<% end_with %><% end_if %><% end_loop %>',
$data $data
); );
$this->assertEquals("SubKid1SubKid2Number6", $result, "Loop works"); $this->assertEquals("SubKid1SubKid2Number6", $result, "Loop works");
@ -561,16 +534,16 @@ SS;
$this->assertEquals("4", $result, "4 items in the DataObjectSet"); $this->assertEquals("4", $result, "4 items in the DataObjectSet");
$result = $this->render( $result = $this->render(
'<% with Foo %><% loop Up.Foo %>$Number<% if Sub %><% with Sub %>$Name<% end_with %>' '<% with Foo %><% loop Up.Foo %>$Number<% if Sub %><% with Sub %>$Name<% end_with %>'
. '<% end_if %><% end_loop %><% end_with %>', . '<% end_if %><% end_loop %><% end_with %>',
$data $data
); );
$this->assertEquals("SubKid1SubKid2Number6", $result, "Loop in with Up.Foo scope works"); $this->assertEquals("SubKid1SubKid2Number6", $result, "Loop in with Up.Foo scope works");
$result = $this->render( $result = $this->render(
'<% with Foo %><% loop %>$Number<% if Sub %><% with Sub %>$Name<% end_with %>' '<% with Foo %><% loop %>$Number<% if Sub %><% with Sub %>$Name<% end_with %>'
. '<% end_if %><% end_loop %><% end_with %>', . '<% end_if %><% end_loop %><% end_with %>',
$data $data
); );
$this->assertEquals("SubKid1SubKid2Number6", $result, "Loop in current scope works"); $this->assertEquals("SubKid1SubKid2Number6", $result, "Loop in current scope works");
} }
@ -578,7 +551,7 @@ SS;
public function testObjectDotArguments() public function testObjectDotArguments()
{ {
$this->assertEquals( $this->assertEquals(
'[out:TestObject.methodWithOneArgument(one)] '[out:TestObject.methodWithOneArgument(one)]
[out:TestObject.methodWithTwoArguments(one,two)] [out:TestObject.methodWithTwoArguments(one,two)]
[out:TestMethod(Arg1,Arg2).Bar.Val] [out:TestMethod(Arg1,Arg2).Bar.Val]
[out:TestMethod(Arg1,Arg2).Bar] [out:TestMethod(Arg1,Arg2).Bar]
@ -586,8 +559,8 @@ SS;
[out:TestMethod(Arg1).Bar.Val] [out:TestMethod(Arg1).Bar.Val]
[out:TestMethod(Arg1).Bar] [out:TestMethod(Arg1).Bar]
[out:TestMethod(Arg1)]', [out:TestMethod(Arg1)]',
$this->render( $this->render(
'$TestObject.methodWithOneArgument(one) '$TestObject.methodWithOneArgument(one)
$TestObject.methodWithTwoArguments(one,two) $TestObject.methodWithTwoArguments(one,two)
$TestMethod(Arg1, Arg2).Bar.Val $TestMethod(Arg1, Arg2).Bar.Val
$TestMethod(Arg1, Arg2).Bar $TestMethod(Arg1, Arg2).Bar
@ -595,14 +568,14 @@ SS;
$TestMethod(Arg1).Bar.Val $TestMethod(Arg1).Bar.Val
$TestMethod(Arg1).Bar $TestMethod(Arg1).Bar
$TestMethod(Arg1)' $TestMethod(Arg1)'
) )
); );
} }
public function testEscapedArguments() public function testEscapedArguments()
{ {
$this->assertEquals( $this->assertEquals(
'[out:Foo(Arg1,Arg2).Bar.Val].Suffix '[out:Foo(Arg1,Arg2).Bar.Val].Suffix
[out:Foo(Arg1,Arg2).Val]_Suffix [out:Foo(Arg1,Arg2).Val]_Suffix
[out:Foo(Arg1,Arg2)]/Suffix [out:Foo(Arg1,Arg2)]/Suffix
[out:Foo(Arg1).Bar.Val]textSuffix [out:Foo(Arg1).Bar.Val]textSuffix
@ -611,8 +584,8 @@ SS;
[out:Foo.Bar.Val].Suffix [out:Foo.Bar.Val].Suffix
[out:Foo.Bar].Suffix [out:Foo.Bar].Suffix
[out:Foo].Suffix', [out:Foo].Suffix',
$this->render( $this->render(
'{$Foo(Arg1, Arg2).Bar.Val}.Suffix '{$Foo(Arg1, Arg2).Bar.Val}.Suffix
{$Foo(Arg1, Arg2).Val}_Suffix {$Foo(Arg1, Arg2).Val}_Suffix
{$Foo(Arg1, Arg2)}/Suffix {$Foo(Arg1, Arg2)}/Suffix
{$Foo(Arg1).Bar.Val}textSuffix {$Foo(Arg1).Bar.Val}textSuffix
@ -621,44 +594,44 @@ SS;
{$Foo.Bar.Val}.Suffix {$Foo.Bar.Val}.Suffix
{$Foo.Bar}.Suffix {$Foo.Bar}.Suffix
{$Foo}.Suffix' {$Foo}.Suffix'
) )
); );
} }
public function testLoopWhitespace() public function testLoopWhitespace()
{ {
$this->assertEquals( $this->assertEquals(
'before[out:SingleItem.Test]after 'before[out:SingleItem.Test]after
beforeTestafter', beforeTestafter',
$this->render( $this->render(
'before<% loop SingleItem %>$Test<% end_loop %>after 'before<% loop SingleItem %>$Test<% end_loop %>after
before<% loop SingleItem %>Test<% end_loop %>after' before<% loop SingleItem %>Test<% end_loop %>after'
) )
); );
// The control tags are removed from the output, but no whitespace // The control tags are removed from the output, but no whitespace
// This is a quirk that could be changed, but included in the test to make the current // This is a quirk that could be changed, but included in the test to make the current
// behaviour explicit // behaviour explicit
$this->assertEquals( $this->assertEquals(
'before 'before
[out:SingleItem.ItemOnItsOwnLine] [out:SingleItem.ItemOnItsOwnLine]
after', after',
$this->render( $this->render(
'before 'before
<% loop SingleItem %> <% loop SingleItem %>
$ItemOnItsOwnLine $ItemOnItsOwnLine
<% end_loop %> <% end_loop %>
after' after'
) )
); );
// The whitespace within the control tags is preserve in a loop // The whitespace within the control tags is preserve in a loop
// This is a quirk that could be changed, but included in the test to make the current // This is a quirk that could be changed, but included in the test to make the current
// behaviour explicit // behaviour explicit
$this->assertEquals( $this->assertEquals(
'before 'before
[out:Loop3.ItemOnItsOwnLine] [out:Loop3.ItemOnItsOwnLine]
@ -667,13 +640,13 @@ after'
[out:Loop3.ItemOnItsOwnLine] [out:Loop3.ItemOnItsOwnLine]
after', after',
$this->render( $this->render(
'before 'before
<% loop Loop3 %> <% loop Loop3 %>
$ItemOnItsOwnLine $ItemOnItsOwnLine
<% end_loop %> <% end_loop %>
after' after'
) )
); );
} }
@ -681,44 +654,44 @@ after'
{ {
// Single item controls // Single item controls
$this->assertEquals( $this->assertEquals(
'a[out:Foo.Bar.Item]b 'a[out:Foo.Bar.Item]b
[out:Foo.Bar(Arg1).Item] [out:Foo.Bar(Arg1).Item]
[out:Foo(Arg1).Item] [out:Foo(Arg1).Item]
[out:Foo(Arg1,Arg2).Item] [out:Foo(Arg1,Arg2).Item]
[out:Foo(Arg1,Arg2,Arg3).Item]', [out:Foo(Arg1,Arg2,Arg3).Item]',
$this->render( $this->render(
'<% with Foo.Bar %>a{$Item}b<% end_with %> '<% with Foo.Bar %>a{$Item}b<% end_with %>
<% with Foo.Bar(Arg1) %>$Item<% end_with %> <% with Foo.Bar(Arg1) %>$Item<% end_with %>
<% with Foo(Arg1) %>$Item<% end_with %> <% with Foo(Arg1) %>$Item<% end_with %>
<% with Foo(Arg1, Arg2) %>$Item<% end_with %> <% with Foo(Arg1, Arg2) %>$Item<% end_with %>
<% with Foo(Arg1, Arg2, Arg3) %>$Item<% end_with %>' <% with Foo(Arg1, Arg2, Arg3) %>$Item<% end_with %>'
) )
); );
// Loop controls // Loop controls
$this->assertEquals( $this->assertEquals(
'a[out:Foo.Loop2.Item]ba[out:Foo.Loop2.Item]b', 'a[out:Foo.Loop2.Item]ba[out:Foo.Loop2.Item]b',
$this->render('<% loop Foo.Loop2 %>a{$Item}b<% end_loop %>') $this->render('<% loop Foo.Loop2 %>a{$Item}b<% end_loop %>')
); );
$this->assertEquals( $this->assertEquals(
'[out:Foo.Loop2(Arg1).Item][out:Foo.Loop2(Arg1).Item]', '[out:Foo.Loop2(Arg1).Item][out:Foo.Loop2(Arg1).Item]',
$this->render('<% loop Foo.Loop2(Arg1) %>$Item<% end_loop %>') $this->render('<% loop Foo.Loop2(Arg1) %>$Item<% end_loop %>')
); );
$this->assertEquals( $this->assertEquals(
'[out:Loop2(Arg1).Item][out:Loop2(Arg1).Item]', '[out:Loop2(Arg1).Item][out:Loop2(Arg1).Item]',
$this->render('<% loop Loop2(Arg1) %>$Item<% end_loop %>') $this->render('<% loop Loop2(Arg1) %>$Item<% end_loop %>')
); );
$this->assertEquals( $this->assertEquals(
'[out:Loop2(Arg1,Arg2).Item][out:Loop2(Arg1,Arg2).Item]', '[out:Loop2(Arg1,Arg2).Item][out:Loop2(Arg1,Arg2).Item]',
$this->render('<% loop Loop2(Arg1, Arg2) %>$Item<% end_loop %>') $this->render('<% loop Loop2(Arg1, Arg2) %>$Item<% end_loop %>')
); );
$this->assertEquals( $this->assertEquals(
'[out:Loop2(Arg1,Arg2,Arg3).Item][out:Loop2(Arg1,Arg2,Arg3).Item]', '[out:Loop2(Arg1,Arg2,Arg3).Item][out:Loop2(Arg1,Arg2,Arg3).Item]',
$this->render('<% loop Loop2(Arg1, Arg2, Arg3) %>$Item<% end_loop %>') $this->render('<% loop Loop2(Arg1, Arg2, Arg3) %>$Item<% end_loop %>')
); );
} }
@ -726,139 +699,139 @@ after'
{ {
// Basic test // Basic test
$this->assertEquals( $this->assertEquals(
'AC', 'AC',
$this->render('A<% if NotSet %>B$NotSet<% end_if %>C') $this->render('A<% if NotSet %>B$NotSet<% end_if %>C')
); );
// Nested test // Nested test
$this->assertEquals( $this->assertEquals(
'AB1C', 'AB1C',
$this->render('A<% if IsSet %>B$NotSet<% if IsSet %>1<% else %>2<% end_if %><% end_if %>C') $this->render('A<% if IsSet %>B$NotSet<% if IsSet %>1<% else %>2<% end_if %><% end_if %>C')
); );
// else_if // else_if
$this->assertEquals( $this->assertEquals(
'ACD', 'ACD',
$this->render('A<% if NotSet %>B<% else_if IsSet %>C<% end_if %>D') $this->render('A<% if NotSet %>B<% else_if IsSet %>C<% end_if %>D')
); );
$this->assertEquals( $this->assertEquals(
'AD', 'AD',
$this->render('A<% if NotSet %>B<% else_if AlsoNotset %>C<% end_if %>D') $this->render('A<% if NotSet %>B<% else_if AlsoNotset %>C<% end_if %>D')
); );
$this->assertEquals( $this->assertEquals(
'ADE', 'ADE',
$this->render('A<% if NotSet %>B<% else_if AlsoNotset %>C<% else_if IsSet %>D<% end_if %>E') $this->render('A<% if NotSet %>B<% else_if AlsoNotset %>C<% else_if IsSet %>D<% end_if %>E')
); );
$this->assertEquals( $this->assertEquals(
'ADE', 'ADE',
$this->render('A<% if NotSet %>B<% else_if AlsoNotset %>C<% else_if IsSet %>D<% end_if %>E') $this->render('A<% if NotSet %>B<% else_if AlsoNotset %>C<% else_if IsSet %>D<% end_if %>E')
); );
// Dot syntax // Dot syntax
$this->assertEquals( $this->assertEquals(
'ACD', 'ACD',
$this->render('A<% if Foo.NotSet %>B<% else_if Foo.IsSet %>C<% end_if %>D') $this->render('A<% if Foo.NotSet %>B<% else_if Foo.IsSet %>C<% end_if %>D')
); );
$this->assertEquals( $this->assertEquals(
'ACD', 'ACD',
$this->render('A<% if Foo.Bar.NotSet %>B<% else_if Foo.Bar.IsSet %>C<% end_if %>D') $this->render('A<% if Foo.Bar.NotSet %>B<% else_if Foo.Bar.IsSet %>C<% end_if %>D')
); );
// Params // Params
$this->assertEquals( $this->assertEquals(
'ACD', 'ACD',
$this->render('A<% if NotSet(Param) %>B<% else %>C<% end_if %>D') $this->render('A<% if NotSet(Param) %>B<% else %>C<% end_if %>D')
); );
$this->assertEquals( $this->assertEquals(
'ABD', 'ABD',
$this->render('A<% if IsSet(Param) %>B<% else %>C<% end_if %>D') $this->render('A<% if IsSet(Param) %>B<% else %>C<% end_if %>D')
); );
// Negation // Negation
$this->assertEquals( $this->assertEquals(
'AC', 'AC',
$this->render('A<% if not IsSet %>B<% end_if %>C') $this->render('A<% if not IsSet %>B<% end_if %>C')
); );
$this->assertEquals( $this->assertEquals(
'ABC', 'ABC',
$this->render('A<% if not NotSet %>B<% end_if %>C') $this->render('A<% if not NotSet %>B<% end_if %>C')
); );
// Or // Or
$this->assertEquals( $this->assertEquals(
'ABD', 'ABD',
$this->render('A<% if IsSet || NotSet %>B<% else_if A %>C<% end_if %>D') $this->render('A<% if IsSet || NotSet %>B<% else_if A %>C<% end_if %>D')
); );
$this->assertEquals( $this->assertEquals(
'ACD', 'ACD',
$this->render('A<% if NotSet || AlsoNotSet %>B<% else_if IsSet %>C<% end_if %>D') $this->render('A<% if NotSet || AlsoNotSet %>B<% else_if IsSet %>C<% end_if %>D')
); );
$this->assertEquals( $this->assertEquals(
'AD', 'AD',
$this->render('A<% if NotSet || AlsoNotSet %>B<% else_if NotSet3 %>C<% end_if %>D') $this->render('A<% if NotSet || AlsoNotSet %>B<% else_if NotSet3 %>C<% end_if %>D')
); );
$this->assertEquals( $this->assertEquals(
'ACD', 'ACD',
$this->render('A<% if NotSet || AlsoNotSet %>B<% else_if IsSet || NotSet %>C<% end_if %>D') $this->render('A<% if NotSet || AlsoNotSet %>B<% else_if IsSet || NotSet %>C<% end_if %>D')
); );
$this->assertEquals( $this->assertEquals(
'AD', 'AD',
$this->render('A<% if NotSet || AlsoNotSet %>B<% else_if NotSet2 || NotSet3 %>C<% end_if %>D') $this->render('A<% if NotSet || AlsoNotSet %>B<% else_if NotSet2 || NotSet3 %>C<% end_if %>D')
); );
// Negated Or // Negated Or
$this->assertEquals( $this->assertEquals(
'ACD', 'ACD',
$this->render('A<% if not IsSet || AlsoNotSet %>B<% else_if A %>C<% end_if %>D') $this->render('A<% if not IsSet || AlsoNotSet %>B<% else_if A %>C<% end_if %>D')
); );
$this->assertEquals( $this->assertEquals(
'ABD', 'ABD',
$this->render('A<% if not NotSet || AlsoNotSet %>B<% else_if A %>C<% end_if %>D') $this->render('A<% if not NotSet || AlsoNotSet %>B<% else_if A %>C<% end_if %>D')
); );
$this->assertEquals( $this->assertEquals(
'ABD', 'ABD',
$this->render('A<% if NotSet || not AlsoNotSet %>B<% else_if A %>C<% end_if %>D') $this->render('A<% if NotSet || not AlsoNotSet %>B<% else_if A %>C<% end_if %>D')
); );
// And // And
$this->assertEquals( $this->assertEquals(
'ABD', 'ABD',
$this->render('A<% if IsSet && AlsoSet %>B<% else_if A %>C<% end_if %>D') $this->render('A<% if IsSet && AlsoSet %>B<% else_if A %>C<% end_if %>D')
); );
$this->assertEquals( $this->assertEquals(
'ACD', 'ACD',
$this->render('A<% if IsSet && NotSet %>B<% else_if IsSet %>C<% end_if %>D') $this->render('A<% if IsSet && NotSet %>B<% else_if IsSet %>C<% end_if %>D')
); );
$this->assertEquals( $this->assertEquals(
'AD', 'AD',
$this->render('A<% if NotSet && NotSet2 %>B<% else_if NotSet3 %>C<% end_if %>D') $this->render('A<% if NotSet && NotSet2 %>B<% else_if NotSet3 %>C<% end_if %>D')
); );
$this->assertEquals( $this->assertEquals(
'ACD', 'ACD',
$this->render('A<% if IsSet && NotSet %>B<% else_if IsSet && AlsoSet %>C<% end_if %>D') $this->render('A<% if IsSet && NotSet %>B<% else_if IsSet && AlsoSet %>C<% end_if %>D')
); );
$this->assertEquals( $this->assertEquals(
'AD', 'AD',
$this->render('A<% if NotSet && NotSet2 %>B<% else_if IsSet && NotSet3 %>C<% end_if %>D') $this->render('A<% if NotSet && NotSet2 %>B<% else_if IsSet && NotSet3 %>C<% end_if %>D')
); );
// Equality // Equality
$this->assertEquals( $this->assertEquals(
'ABC', 'ABC',
$this->render('A<% if RawVal == RawVal %>B<% end_if %>C') $this->render('A<% if RawVal == RawVal %>B<% end_if %>C')
); );
$this->assertEquals( $this->assertEquals(
'ACD', 'ACD',
$this->render('A<% if Right == Wrong %>B<% else_if RawVal == RawVal %>C<% end_if %>D') $this->render('A<% if Right == Wrong %>B<% else_if RawVal == RawVal %>C<% end_if %>D')
); );
$this->assertEquals( $this->assertEquals(
'ABC', 'ABC',
$this->render('A<% if Right != Wrong %>B<% end_if %>C') $this->render('A<% if Right != Wrong %>B<% end_if %>C')
); );
$this->assertEquals( $this->assertEquals(
'AD', 'AD',
$this->render('A<% if Right == Wrong %>B<% else_if RawVal != RawVal %>C<% end_if %>D') $this->render('A<% if Right == Wrong %>B<% else_if RawVal != RawVal %>C<% end_if %>D')
); );
// test inequalities with simple numbers // test inequalities with simple numbers
@ -881,30 +854,30 @@ after'
// the output would stop after A, thereby failing the assert // the output would stop after A, thereby failing the assert
$this->assertEquals('AD', $this->render('A<% if IsSet %><% else %><% end_if %>D')); $this->assertEquals('AD', $this->render('A<% if IsSet %><% else %><% end_if %>D'));
$this->assertEquals( $this->assertEquals(
'AD', 'AD',
$this->render('A<% if NotSet %><% else_if IsSet %><% else %><% end_if %>D') $this->render('A<% if NotSet %><% else_if IsSet %><% else %><% end_if %>D')
); );
$this->assertEquals( $this->assertEquals(
'AD', 'AD',
$this->render('A<% if NotSet %><% else_if AlsoNotSet %><% else %><% end_if %>D') $this->render('A<% if NotSet %><% else_if AlsoNotSet %><% else %><% end_if %>D')
); );
// Bare words with ending space // Bare words with ending space
$this->assertEquals( $this->assertEquals(
'ABC', 'ABC',
$this->render('A<% if "RawVal" == RawVal %>B<% end_if %>C') $this->render('A<% if "RawVal" == RawVal %>B<% end_if %>C')
); );
// Else // Else
$this->assertEquals( $this->assertEquals(
'ADE', 'ADE',
$this->render('A<% if Right == Wrong %>B<% else_if RawVal != RawVal %>C<% else %>D<% end_if %>E') $this->render('A<% if Right == Wrong %>B<% else_if RawVal != RawVal %>C<% else %>D<% end_if %>E')
); );
// Empty if with else // Empty if with else
$this->assertEquals( $this->assertEquals(
'ABC', 'ABC',
$this->render('A<% if NotSet %><% else %>B<% end_if %>C') $this->render('A<% if NotSet %><% else %>B<% end_if %>C')
); );
} }
@ -927,8 +900,8 @@ after'
<body><p>test</p><body> <body><p>test</p><body>
</html>'; </html>';
$this->assertRegExp( $this->assertRegExp(
'/<head><base href=".*"><!--\[if lte IE 6\]><\/base><!\[endif\]--><\/head>/', '/<head><base href=".*"><!--\[if lte IE 6\]><\/base><!\[endif\]--><\/head>/',
$this->render($tmpl2) $this->render($tmpl2)
); );
@ -938,8 +911,8 @@ after'
<body><p>test</p><body> <body><p>test</p><body>
</html>'; </html>';
$this->assertRegExp( $this->assertRegExp(
'/<head><base href=".*"><!--\[if lte IE 6\]><\/base><!\[endif\]--><\/head>/', '/<head><base href=".*"><!--\[if lte IE 6\]><\/base><!\[endif\]--><\/head>/',
$this->render($tmpl3) $this->render($tmpl3)
); );
// Check that the content negotiator converts to the equally legal formats // Check that the content negotiator converts to the equally legal formats
@ -948,8 +921,8 @@ after'
$response = new HTTPResponse($this->render($tmpl1)); $response = new HTTPResponse($this->render($tmpl1));
$negotiator->html($response); $negotiator->html($response);
$this->assertRegExp( $this->assertRegExp(
'/<head><base href=".*"><!--\[if lte IE 6\]><\/base><!\[endif\]--><\/head>/', '/<head><base href=".*"><!--\[if lte IE 6\]><\/base><!\[endif\]--><\/head>/',
$response->getBody() $response->getBody()
); );
$response = new HTTPResponse($this->render($tmpl1)); $response = new HTTPResponse($this->render($tmpl1));
@ -960,103 +933,103 @@ after'
public function testIncludeWithArguments() public function testIncludeWithArguments()
{ {
$this->assertEquals( $this->assertEquals(
$this->render('<% include SSViewerTestIncludeWithArguments %>'), $this->render('<% include SSViewerTestIncludeWithArguments %>'),
'<p>[out:Arg1]</p><p>[out:Arg2]</p>' '<p>[out:Arg1]</p><p>[out:Arg2]</p>'
); );
$this->assertEquals( $this->assertEquals(
$this->render('<% include SSViewerTestIncludeWithArguments Arg1=A %>'), $this->render('<% include SSViewerTestIncludeWithArguments Arg1=A %>'),
'<p>A</p><p>[out:Arg2]</p>' '<p>A</p><p>[out:Arg2]</p>'
); );
$this->assertEquals( $this->assertEquals(
$this->render('<% include SSViewerTestIncludeWithArguments Arg1=A, Arg2=B %>'), $this->render('<% include SSViewerTestIncludeWithArguments Arg1=A, Arg2=B %>'),
'<p>A</p><p>B</p>' '<p>A</p><p>B</p>'
); );
$this->assertEquals( $this->assertEquals(
$this->render('<% include SSViewerTestIncludeWithArguments Arg1=A Bare String, Arg2=B Bare String %>'), $this->render('<% include SSViewerTestIncludeWithArguments Arg1=A Bare String, Arg2=B Bare String %>'),
'<p>A Bare String</p><p>B Bare String</p>' '<p>A Bare String</p><p>B Bare String</p>'
); );
$this->assertEquals( $this->assertEquals(
$this->render( $this->render(
'<% include SSViewerTestIncludeWithArguments Arg1="A", Arg2=$B %>', '<% include SSViewerTestIncludeWithArguments Arg1="A", Arg2=$B %>',
new ArrayData(array('B' => 'Bar')) new ArrayData(array('B' => 'Bar'))
), ),
'<p>A</p><p>Bar</p>' '<p>A</p><p>Bar</p>'
); );
$this->assertEquals( $this->assertEquals(
$this->render( $this->render(
'<% include SSViewerTestIncludeWithArguments Arg1="A" %>', '<% include SSViewerTestIncludeWithArguments Arg1="A" %>',
new ArrayData(array('Arg1' => 'Foo', 'Arg2' => 'Bar')) new ArrayData(array('Arg1' => 'Foo', 'Arg2' => 'Bar'))
), ),
'<p>A</p><p>Bar</p>' '<p>A</p><p>Bar</p>'
); );
$this->assertEquals( $this->assertEquals(
$this->render( $this->render(
'<% include SSViewerTestIncludeScopeInheritanceWithArgsInLoop Title="SomeArg" %>', '<% include SSViewerTestIncludeScopeInheritanceWithArgsInLoop Title="SomeArg" %>',
new ArrayData( new ArrayData(
array('Items' => new ArrayList( array('Items' => new ArrayList(
array(
new ArrayData(array('Title' => 'Foo')),
new ArrayData(array('Title' => 'Bar'))
)
))
)
),
'SomeArg - Foo - Bar - SomeArg'
);
$this->assertEquals(
$this->render(
'<% include SSViewerTestIncludeScopeInheritanceWithArgsInWith Title="A" %>',
new ArrayData(array('Item' => new ArrayData(array('Title' =>'B'))))
),
'A - B - A'
);
$this->assertEquals(
$this->render(
'<% include SSViewerTestIncludeScopeInheritanceWithArgsInNestedWith Title="A" %>',
new ArrayData(
array( array(
new ArrayData(array('Title' => 'Foo')), 'Item' => new ArrayData(
new ArrayData(array('Title' => 'Bar')) array(
) 'Title' =>'B', 'NestedItem' => new ArrayData(array('Title' => 'C'))
)) )
) ))
), )
'SomeArg - Foo - Bar - SomeArg' ),
'A - B - C - B - A'
); );
$this->assertEquals( $this->assertEquals(
$this->render( $this->render(
'<% include SSViewerTestIncludeScopeInheritanceWithArgsInWith Title="A" %>', '<% include SSViewerTestIncludeScopeInheritanceWithUpAndTop Title="A" %>',
new ArrayData(array('Item' => new ArrayData(array('Title' =>'B')))) new ArrayData(
),
'A - B - A'
);
$this->assertEquals(
$this->render(
'<% include SSViewerTestIncludeScopeInheritanceWithArgsInNestedWith Title="A" %>',
new ArrayData(
array(
'Item' => new ArrayData(
array( array(
'Title' =>'B', 'NestedItem' => new ArrayData(array('Title' => 'C')) 'Item' => new ArrayData(
) array(
)) 'Title' =>'B', 'NestedItem' => new ArrayData(array('Title' => 'C'))
) )
), ))
'A - B - C - B - A' )
); ),
'A - A - A'
$this->assertEquals(
$this->render(
'<% include SSViewerTestIncludeScopeInheritanceWithUpAndTop Title="A" %>',
new ArrayData(
array(
'Item' => new ArrayData(
array(
'Title' =>'B', 'NestedItem' => new ArrayData(array('Title' => 'C'))
)
))
)
),
'A - A - A'
); );
$data = new ArrayData( $data = new ArrayData(
array(
'Nested' => new ArrayData(
array( array(
'Object' => new ArrayData(array('Key' => 'A')) 'Nested' => new ArrayData(
array(
'Object' => new ArrayData(array('Key' => 'A'))
)
),
'Object' => new ArrayData(array('Key' => 'B'))
) )
),
'Object' => new ArrayData(array('Key' => 'B'))
)
); );
$tmpl = SSViewer::fromString('<% include SSViewerTestIncludeObjectArguments A=$Nested.Object, B=$Object %>'); $tmpl = SSViewer::fromString('<% include SSViewerTestIncludeObjectArguments A=$Nested.Object, B=$Object %>');
@ -1069,15 +1042,15 @@ after'
$data = new ArrayData([]); $data = new ArrayData([]);
$this->assertEquals( $this->assertEquals(
"tests:( NamespaceInclude\n )", "tests:( NamespaceInclude\n )",
$this->render('tests:( <% include Namespace\NamespaceInclude %> )', $data), $this->render('tests:( <% include Namespace\NamespaceInclude %> )', $data),
'Backslashes work for namespace references in includes' 'Backslashes work for namespace references in includes'
); );
$this->assertEquals( $this->assertEquals(
"tests:( NamespaceInclude\n )", "tests:( NamespaceInclude\n )",
$this->render('tests:( <% include Namespace/NamespaceInclude %> )', $data), $this->render('tests:( <% include Namespace/NamespaceInclude %> )', $data),
'Forward slashes work for namespace references in includes' 'Forward slashes work for namespace references in includes'
); );
} }
@ -1087,26 +1060,26 @@ after'
$view = new SSViewer(array('Includes/SSViewerTestRecursiveInclude')); $view = new SSViewer(array('Includes/SSViewerTestRecursiveInclude'));
$data = new ArrayData( $data = new ArrayData(
array(
'Title' => 'A',
'Children' => new ArrayList(
array( array(
new ArrayData( 'Title' => 'A',
'Children' => new ArrayList(
array( array(
'Title' => 'A1', new ArrayData(
'Children' => new ArrayList(
array( array(
new ArrayData(array( 'Title' => 'A1 i', )), 'Title' => 'A1',
new ArrayData(array( 'Title' => 'A1 ii', )), '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', )),
) )
), ),
new ArrayData(array( 'Title' => 'A2', )),
new ArrayData(array( 'Title' => 'A3', )),
) )
),
)
); );
$result = $view->process($data); $result = $view->process($data);
@ -1134,68 +1107,68 @@ after'
// Value casted as "Text" // Value casted as "Text"
$this->assertEquals( $this->assertEquals(
'&lt;b&gt;html&lt;/b&gt;', '&lt;b&gt;html&lt;/b&gt;',
$t = SSViewer::fromString('$TextValue')->process($vd) $t = SSViewer::fromString('$TextValue')->process($vd)
); );
$this->assertEquals( $this->assertEquals(
'<b>html</b>', '<b>html</b>',
$t = SSViewer::fromString('$TextValue.RAW')->process($vd) $t = SSViewer::fromString('$TextValue.RAW')->process($vd)
); );
$this->assertEquals( $this->assertEquals(
'&lt;b&gt;html&lt;/b&gt;', '&lt;b&gt;html&lt;/b&gt;',
$t = SSViewer::fromString('$TextValue.XML')->process($vd) $t = SSViewer::fromString('$TextValue.XML')->process($vd)
); );
// Value casted as "HTMLText" // Value casted as "HTMLText"
$this->assertEquals( $this->assertEquals(
'<b>html</b>', '<b>html</b>',
$t = SSViewer::fromString('$HTMLValue')->process($vd) $t = SSViewer::fromString('$HTMLValue')->process($vd)
); );
$this->assertEquals( $this->assertEquals(
'<b>html</b>', '<b>html</b>',
$t = SSViewer::fromString('$HTMLValue.RAW')->process($vd) $t = SSViewer::fromString('$HTMLValue.RAW')->process($vd)
); );
$this->assertEquals( $this->assertEquals(
'&lt;b&gt;html&lt;/b&gt;', '&lt;b&gt;html&lt;/b&gt;',
$t = SSViewer::fromString('$HTMLValue.XML')->process($vd) $t = SSViewer::fromString('$HTMLValue.XML')->process($vd)
); );
// Uncasted value (falls back to ViewableData::$default_cast="Text") // Uncasted value (falls back to ViewableData::$default_cast="Text")
$vd = new SSViewerTest\TestViewableData(); $vd = new SSViewerTest\TestViewableData();
$vd->UncastedValue = '<b>html</b>'; $vd->UncastedValue = '<b>html</b>';
$this->assertEquals( $this->assertEquals(
'&lt;b&gt;html&lt;/b&gt;', '&lt;b&gt;html&lt;/b&gt;',
$t = SSViewer::fromString('$UncastedValue')->process($vd) $t = SSViewer::fromString('$UncastedValue')->process($vd)
); );
$this->assertEquals( $this->assertEquals(
'<b>html</b>', '<b>html</b>',
$t = SSViewer::fromString('$UncastedValue.RAW')->process($vd) $t = SSViewer::fromString('$UncastedValue.RAW')->process($vd)
); );
$this->assertEquals( $this->assertEquals(
'&lt;b&gt;html&lt;/b&gt;', '&lt;b&gt;html&lt;/b&gt;',
$t = SSViewer::fromString('$UncastedValue.XML')->process($vd) $t = SSViewer::fromString('$UncastedValue.XML')->process($vd)
); );
} }
public function testSSViewerBasicIteratorSupport() public function testSSViewerBasicIteratorSupport()
{ {
$data = new ArrayData( $data = new ArrayData(
array(
'Set' => new ArrayList(
array( array(
new SSViewerTest\TestObject("1"), 'Set' => new ArrayList(
new SSViewerTest\TestObject("2"), array(
new SSViewerTest\TestObject("3"), new SSViewerTest\TestObject("1"),
new SSViewerTest\TestObject("4"), new SSViewerTest\TestObject("2"),
new SSViewerTest\TestObject("5"), new SSViewerTest\TestObject("3"),
new SSViewerTest\TestObject("6"), new SSViewerTest\TestObject("4"),
new SSViewerTest\TestObject("7"), new SSViewerTest\TestObject("5"),
new SSViewerTest\TestObject("8"), new SSViewerTest\TestObject("6"),
new SSViewerTest\TestObject("9"), new SSViewerTest\TestObject("7"),
new SSViewerTest\TestObject("10"), new SSViewerTest\TestObject("8"),
new SSViewerTest\TestObject("9"),
new SSViewerTest\TestObject("10"),
)
)
) )
)
)
); );
//base test //base test
@ -1240,22 +1213,22 @@ after'
//test MiddleString //test MiddleString
$result = $this->render( $result = $this->render(
'<% loop Set %><% if MiddleString == "middle" %>$Number$MiddleString<% end_if %>' '<% loop Set %><% if MiddleString == "middle" %>$Number$MiddleString<% end_if %>'
. '<% end_loop %>', . '<% end_loop %>',
$data $data
); );
$this->assertEquals( $this->assertEquals(
"2middle3middle4middle5middle6middle7middle8middle9middle", "2middle3middle4middle5middle6middle7middle8middle9middle",
$result, $result,
"Middle numbers rendered in order" "Middle numbers rendered in order"
); );
//test EvenOdd //test EvenOdd
$result = $this->render('<% loop Set %>$EvenOdd<% end_loop %>', $data); $result = $this->render('<% loop Set %>$EvenOdd<% end_loop %>', $data);
$this->assertEquals( $this->assertEquals(
"oddevenoddevenoddevenoddevenoddeven", "oddevenoddevenoddevenoddevenoddeven",
$result, $result,
"Even and Odd is returned in sequence numbers rendered in order" "Even and Odd is returned in sequence numbers rendered in order"
); );
//test Pos //test Pos
@ -1301,9 +1274,9 @@ after'
//test MultipleOf 9 zero-based //test MultipleOf 9 zero-based
$result = $this->render('<% loop Set %><% if MultipleOf(9,0) %>$Number<% end_if %><% end_loop %>', $data); $result = $this->render('<% loop Set %><% if MultipleOf(9,0) %>$Number<% end_if %><% end_loop %>', $data);
$this->assertEquals( $this->assertEquals(
"110", "110",
$result, $result,
"Only numbers that are multiples of 9 with zero-based indexing are returned. (The first and last item)" "Only numbers that are multiples of 9 with zero-based indexing are returned. (The first and last item)"
); );
//test MultipleOf 11 //test MultipleOf 11
@ -1319,83 +1292,83 @@ after'
// Data to run the loop tests on - three levels deep // Data to run the loop tests on - three levels deep
$data = new ArrayData( $data = new ArrayData(
array(
'Name' => 'Top',
'Foo' => new ArrayData(
array( array(
'Name' => 'Foo', 'Name' => 'Top',
'Bar' => new ArrayData( 'Foo' => new ArrayData(
array( array(
'Name' => 'Bar', 'Name' => 'Foo',
'Baz' => new ArrayData( 'Bar' => new ArrayData(
array( array(
'Name' => 'Baz' 'Name' => 'Bar',
'Baz' => new ArrayData(
array(
'Name' => 'Baz'
)
),
'Qux' => new ArrayData(
array(
'Name' => 'Qux'
)
) )
),
'Qux' => new ArrayData(
array(
'Name' => 'Qux'
) )
) )
) )
) )
) )
)
)
); );
// Basic functionality // Basic functionality
$this->assertEquals( $this->assertEquals(
'BarFoo', 'BarFoo',
$this->render('<% with Foo %><% with Bar %>{$Name}{$Up.Name}<% end_with %><% end_with %>', $data) $this->render('<% with Foo %><% with Bar %>{$Name}{$Up.Name}<% end_with %><% end_with %>', $data)
); );
// Two level with block, up refers to internally referenced Bar // Two level with block, up refers to internally referenced Bar
$this->assertEquals( $this->assertEquals(
'BarFoo', 'BarFoo',
$this->render('<% with Foo.Bar %>{$Name}{$Up.Name}<% end_with %>', $data) $this->render('<% with Foo.Bar %>{$Name}{$Up.Name}<% end_with %>', $data)
); );
// Stepping up & back down the scope tree // Stepping up & back down the scope tree
$this->assertEquals( $this->assertEquals(
'BazBarQux', 'BazBarQux',
$this->render('<% with Foo.Bar.Baz %>{$Name}{$Up.Name}{$Up.Qux.Name}<% end_with %>', $data) $this->render('<% with Foo.Bar.Baz %>{$Name}{$Up.Name}{$Up.Qux.Name}<% end_with %>', $data)
); );
// Using $Up in a with block // Using $Up in a with block
$this->assertEquals( $this->assertEquals(
'BazBarQux', 'BazBarQux',
$this->render( $this->render(
'<% with Foo.Bar.Baz %>{$Name}<% with $Up %>{$Name}{$Qux.Name}<% end_with %>' '<% with Foo.Bar.Baz %>{$Name}<% with $Up %>{$Name}{$Qux.Name}<% end_with %>'
.'<% end_with %>', .'<% end_with %>',
$data $data
) )
); );
// Stepping up & back down the scope tree with with blocks // Stepping up & back down the scope tree with with blocks
$this->assertEquals( $this->assertEquals(
'BazBarQuxBarBaz', 'BazBarQuxBarBaz',
$this->render( $this->render(
'<% with Foo.Bar.Baz %>{$Name}<% with $Up %>{$Name}<% with Qux %>{$Name}<% end_with %>' '<% with Foo.Bar.Baz %>{$Name}<% with $Up %>{$Name}<% with Qux %>{$Name}<% end_with %>'
. '{$Name}<% end_with %>{$Name}<% end_with %>', . '{$Name}<% end_with %>{$Name}<% end_with %>',
$data $data
) )
); );
// Using $Up.Up, where first $Up points to a previous scope entered using $Up, thereby skipping up to Foo // Using $Up.Up, where first $Up points to a previous scope entered using $Up, thereby skipping up to Foo
$this->assertEquals( $this->assertEquals(
'Foo', 'Foo',
$this->render( $this->render(
'<% with Foo.Bar.Baz %><% with Up %><% with Qux %>{$Up.Up.Name}<% end_with %><% end_with %>' '<% with Foo.Bar.Baz %><% with Up %><% with Qux %>{$Up.Up.Name}<% end_with %><% end_with %>'
. '<% end_with %>', . '<% end_with %>',
$data $data
) )
); );
// Using $Up.Up, where first $Up points to an Up used in a local scope lookup, should still skip to Foo // Using $Up.Up, where first $Up points to an Up used in a local scope lookup, should still skip to Foo
$this->assertEquals( $this->assertEquals(
'Foo', 'Foo',
$this->render('<% with Foo.Bar.Baz.Up.Qux %>{$Up.Up.Name}<% end_with %>', $data) $this->render('<% with Foo.Bar.Baz.Up.Qux %>{$Up.Up.Name}<% end_with %>', $data)
); );
} }
@ -1407,60 +1380,60 @@ after'
// Data to run the loop tests on - one sequence of three items, each with a subitem // Data to run the loop tests on - one sequence of three items, each with a subitem
$data = new ArrayData( $data = new ArrayData(
array(
'Name' => 'Top',
'Foo' => new ArrayList(
array( array(
new ArrayData( 'Name' => 'Top',
'Foo' => new ArrayList(
array( array(
'Name' => '1', new ArrayData(
'Sub' => new ArrayData(
array( array(
'Name' => 'Bar' 'Name' => '1',
'Sub' => new ArrayData(
array(
'Name' => 'Bar'
)
) )
)
)
),
new ArrayData(
array(
'Name' => '2',
'Sub' => new ArrayData(
array(
'Name' => 'Baz'
) )
) ),
) new ArrayData(
),
new ArrayData(
array(
'Name' => '3',
'Sub' => new ArrayData(
array( array(
'Name' => 'Qux' '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 // Make sure inside a loop, $Up refers to the current item of the loop
$this->assertEqualIgnoringWhitespace( $this->assertEqualIgnoringWhitespace(
'111 222 333', '111 222 333',
$this->render( $this->render(
'<% loop $Foo %>$Name<% with $Sub %>$Up.Name<% end_with %>$Name<% end_loop %>', '<% loop $Foo %>$Name<% with $Sub %>$Up.Name<% end_with %>$Name<% end_loop %>',
$data $data
) )
); );
// Make sure inside a loop, looping over $Up uses a separate iterator, // Make sure inside a loop, looping over $Up uses a separate iterator,
// and doesn't interfere with the original iterator // and doesn't interfere with the original iterator
$this->assertEqualIgnoringWhitespace( $this->assertEqualIgnoringWhitespace(
'1Bar123Bar1 2Baz123Baz2 3Qux123Qux3', '1Bar123Bar1 2Baz123Baz2 3Qux123Qux3',
$this->render( $this->render(
'<% loop $Foo %> '<% loop $Foo %>
$Name $Name
<% with $Sub %> <% with $Sub %>
$Name $Name
@ -1469,16 +1442,16 @@ after'
<% end_with %> <% end_with %>
$Name $Name
<% end_loop %>', <% end_loop %>',
$data $data
) )
); );
// Make sure inside a loop, looping over $Up uses a separate iterator, // Make sure inside a loop, looping over $Up uses a separate iterator,
// and doesn't interfere with the original iterator or local lookups // and doesn't interfere with the original iterator or local lookups
$this->assertEqualIgnoringWhitespace( $this->assertEqualIgnoringWhitespace(
'1 Bar1 123 1Bar 1 2 Baz2 123 2Baz 2 3 Qux3 123 3Qux 3', '1 Bar1 123 1Bar 1 2 Baz2 123 2Baz 2 3 Qux3 123 3Qux 3',
$this->render( $this->render(
'<% loop $Foo %> '<% loop $Foo %>
$Name $Name
<% with $Sub %> <% with $Sub %>
{$Name}{$Up.Name} {$Name}{$Up.Name}
@ -1487,8 +1460,8 @@ after'
<% end_with %> <% end_with %>
$Name $Name
<% end_loop %>', <% end_loop %>',
$data $data
) )
); );
} }
@ -1501,69 +1474,69 @@ after'
// Data to run the loop tests on - one sequence of three items, one with child elements // Data to run the loop tests on - one sequence of three items, one with child elements
// (of a different size to the main sequence) // (of a different size to the main sequence)
$data = new ArrayData( $data = new ArrayData(
array(
'Foo' => new ArrayList(
array( array(
new ArrayData( 'Foo' => new ArrayList(
array( array(
'Name' => '1', new ArrayData(
'Children' => new ArrayList(
array( array(
new ArrayData( 'Name' => '1',
'Children' => new ArrayList(
array( array(
'Name' => 'a' new ArrayData(
) array(
), 'Name' => 'a'
new ArrayData( )
array( ),
'Name' => 'b' new ArrayData(
array(
'Name' => 'b'
)
),
) )
), ),
) )
), ),
) new ArrayData(
), array(
new ArrayData( 'Name' => '2',
array( 'Children' => new ArrayList(),
'Name' => '2', )
'Children' => new ArrayList(), ),
) new ArrayData(
), array(
new ArrayData( 'Name' => '3',
array( 'Children' => new ArrayList(),
'Name' => '3', )
'Children' => new ArrayList(), ),
) )
), ),
) )
),
)
); );
// Make sure that including a loop inside a loop will not destroy the internal count of // Make sure that including a loop inside a loop will not destroy the internal count of
// items, checked by using "Last" // items, checked by using "Last"
$this->assertEqualIgnoringWhitespace( $this->assertEqualIgnoringWhitespace(
'1ab23last', '1ab23last',
$this->render( $this->render(
'<% loop $Foo %>$Name<% loop Children %>$Name<% end_loop %><% if Last %>last<% end_if %>' '<% loop $Foo %>$Name<% loop Children %>$Name<% end_loop %><% if Last %>last<% end_if %>'
. '<% end_loop %>', . '<% end_loop %>',
$data $data
) )
); );
} }
public function testLayout() public function testLayout()
{ {
$this->useTestTheme( $this->useTestTheme(
__DIR__.'/SSViewerTest', __DIR__.'/SSViewerTest',
'layouttest', 'layouttest',
function () { function () {
$template = new SSViewer(array('Page')); $template = new SSViewer(array('Page'));
$this->assertEquals("Foo\n\n", $template->process(new ArrayData(array()))); $this->assertEquals("Foo\n\n", $template->process(new ArrayData(array())));
$template = new SSViewer(array('Shortcodes', 'Page')); $template = new SSViewer(array('Shortcodes', 'Page'));
$this->assertEquals("[file_link]\n\n", $template->process(new ArrayData(array()))); $this->assertEquals("[file_link]\n\n", $template->process(new ArrayData(array())));
} }
); );
} }
@ -1573,17 +1546,17 @@ after'
public function testGetTemplatesByClass() public function testGetTemplatesByClass()
{ {
$this->useTestTheme( $this->useTestTheme(
__DIR__ . '/SSViewerTest', __DIR__ . '/SSViewerTest',
'layouttest', 'layouttest',
function () { function () {
// Test passing a string // Test passing a string
$templates = SSViewer::get_templates_by_class( $templates = SSViewer::get_templates_by_class(
SSViewerTestModelController::class, SSViewerTestModelController::class,
'', '',
Controller::class Controller::class
); );
$this->assertEquals( $this->assertEquals(
[ [
SSViewerTestModelController::class, SSViewerTestModelController::class,
[ [
'type' => 'Includes', 'type' => 'Includes',
@ -1595,36 +1568,36 @@ after'
'type' => 'Includes', 'type' => 'Includes',
Controller::class, Controller::class,
], ],
], ],
$templates $templates
); );
// Test to ensure we're stopping at the base class. // Test to ensure we're stopping at the base class.
$templates = SSViewer::get_templates_by_class( $templates = SSViewer::get_templates_by_class(
SSViewerTestModelController::class, SSViewerTestModelController::class,
'', '',
SSViewerTestModelController::class SSViewerTestModelController::class
); );
$this->assertEquals( $this->assertEquals(
[ [
SSViewerTestModelController::class, SSViewerTestModelController::class,
[ [
'type' => 'Includes', 'type' => 'Includes',
SSViewerTestModelController::class, SSViewerTestModelController::class,
], ],
SSViewerTestModel::class, SSViewerTestModel::class,
], ],
$templates $templates
); );
// Make sure we can search templates by suffix. // Make sure we can search templates by suffix.
$templates = SSViewer::get_templates_by_class( $templates = SSViewer::get_templates_by_class(
SSViewerTestModel::class, SSViewerTestModel::class,
'Controller', 'Controller',
DataObject::class DataObject::class
); );
$this->assertEquals( $this->assertEquals(
[ [
SSViewerTestModelController::class, SSViewerTestModelController::class,
[ [
'type' => 'Includes', 'type' => 'Includes',
@ -1635,14 +1608,14 @@ after'
'type' => 'Includes', 'type' => 'Includes',
DataObject::class . 'Controller', DataObject::class . 'Controller',
], ],
], ],
$templates $templates
); );
// Let's throw something random in there. // Let's throw something random in there.
$this->setExpectedException('InvalidArgumentException'); $this->setExpectedException('InvalidArgumentException');
SSViewer::get_templates_by_class(array()); SSViewer::get_templates_by_class(array());
} }
); );
} }
@ -1662,8 +1635,8 @@ after'
// Note: SSViewer_FromString doesn't rewrite hash links. // Note: SSViewer_FromString doesn't rewrite hash links.
file_put_contents( file_put_contents(
$tmplFile, $tmplFile,
'<!DOCTYPE html> '<!DOCTYPE html>
<html> <html>
<head><% base_tag %></head> <head><% base_tag %></head>
<body> <body>
@ -1678,34 +1651,34 @@ after'
$tmpl = new SSViewer($tmplFile); $tmpl = new SSViewer($tmplFile);
$obj = new ViewableData(); $obj = new ViewableData();
$obj->InsertedLink = DBField::create_field( $obj->InsertedLink = DBField::create_field(
'HTMLFragment', 'HTMLFragment',
'<a class="inserted" href="#anchor">InsertedLink</a>' '<a class="inserted" href="#anchor">InsertedLink</a>'
); );
$obj->ExternalInsertedLink = DBField::create_field( $obj->ExternalInsertedLink = DBField::create_field(
'HTMLFragment', 'HTMLFragment',
'<a class="external-inserted" href="http://google.com#anchor">ExternalInsertedLink</a>' '<a class="external-inserted" href="http://google.com#anchor">ExternalInsertedLink</a>'
); );
$result = $tmpl->process($obj); $result = $tmpl->process($obj);
$this->assertContains( $this->assertContains(
'<a class="inserted" href="' . $base . '#anchor">InsertedLink</a>', '<a class="inserted" href="' . $base . '#anchor">InsertedLink</a>',
$result $result
); );
$this->assertContains( $this->assertContains(
'<a class="external-inserted" href="http://google.com#anchor">ExternalInsertedLink</a>', '<a class="external-inserted" href="http://google.com#anchor">ExternalInsertedLink</a>',
$result $result
); );
$this->assertContains( $this->assertContains(
'<a class="inline" href="' . $base . '#anchor">InlineLink</a>', '<a class="inline" href="' . $base . '#anchor">InlineLink</a>',
$result $result
); );
$this->assertContains( $this->assertContains(
'<a class="external-inline" href="http://google.com#anchor">ExternalInlineLink</a>', '<a class="external-inline" href="http://google.com#anchor">ExternalInlineLink</a>',
$result $result
); );
$this->assertContains( $this->assertContains(
'<svg><use xlink:href="#sprite"></use></svg>', '<svg><use xlink:href="#sprite"></use></svg>',
$result, $result,
'SSTemplateParser should only rewrite anchor hrefs' 'SSTemplateParser should only rewrite anchor hrefs'
); );
unlink($tmplFile); unlink($tmplFile);
@ -1719,8 +1692,8 @@ after'
// Note: SSViewer_FromString doesn't rewrite hash links. // Note: SSViewer_FromString doesn't rewrite hash links.
file_put_contents( file_put_contents(
$tmplFile, $tmplFile,
'<!DOCTYPE html> '<!DOCTYPE html>
<html> <html>
<head><% base_tag %></head> <head><% base_tag %></head>
<body> <body>
@ -1733,8 +1706,8 @@ after'
$tmpl = new SSViewer($tmplFile); $tmpl = new SSViewer($tmplFile);
$obj = new ViewableData(); $obj = new ViewableData();
$obj->InsertedLink = DBField::create_field( $obj->InsertedLink = DBField::create_field(
'HTMLFragment', 'HTMLFragment',
'<a class="inserted" href="#anchor">InsertedLink</a>' '<a class="inserted" href="#anchor">InsertedLink</a>'
); );
$result = $tmpl->process($obj); $result = $tmpl->process($obj);
@ -1748,9 +1721,9 @@ EOC;
// $result // $result
// ); // );
$this->assertContains( $this->assertContains(
'<svg><use xlink:href="#sprite"></use></svg>', '<svg><use xlink:href="#sprite"></use></svg>',
$result, $result,
'SSTemplateParser should only rewrite anchor hrefs' 'SSTemplateParser should only rewrite anchor hrefs'
); );
unlink($tmplFile); unlink($tmplFile);
@ -1870,11 +1843,11 @@ EOC;
$backend = Injector::inst()->create(Requirements_Backend::class); $backend = Injector::inst()->create(Requirements_Backend::class);
$backend->setCombinedFilesEnabled(false); $backend->setCombinedFilesEnabled(false);
$backend->combineFiles( $backend->combineFiles(
'RequirementsTest_ab.css', 'RequirementsTest_ab.css',
array( array(
$basePath . '/css/RequirementsTest_a.css', $basePath . '/css/RequirementsTest_a.css',
$basePath . '/css/RequirementsTest_b.css' $basePath . '/css/RequirementsTest_b.css'
) )
); );
Requirements::set_backend($backend); Requirements::set_backend($backend);
@ -1897,16 +1870,16 @@ EOC;
Requirements::set_suffix_requirements(false); Requirements::set_suffix_requirements(false);
$this->assertEquals( $this->assertEquals(
1, 1,
substr_count( substr_count(
$template->process(array()), $template->process(array()),
"tests/php/View/SSViewerTest/javascript/RequirementsTest_a.js" "tests/php/View/SSViewerTest/javascript/RequirementsTest_a.js"
) )
); );
} else { } else {
$this->markTestSkipped( $this->markTestSkipped(
'Requirement will always fail if the framework dir is not '. 'Requirement will always fail if the framework dir is not '.
'named \'framework\', since templates require hard coded paths' 'named \'framework\', since templates require hard coded paths'
); );
} }
} }
@ -1914,21 +1887,21 @@ EOC;
public function testCallsWithArguments() public function testCallsWithArguments()
{ {
$data = new ArrayData( $data = new ArrayData(
array(
'Set' => new ArrayList(
array( array(
new SSViewerTest\TestObject("1"), 'Set' => new ArrayList(
new SSViewerTest\TestObject("2"), array(
new SSViewerTest\TestObject("3"), new SSViewerTest\TestObject("1"),
new SSViewerTest\TestObject("4"), new SSViewerTest\TestObject("2"),
new SSViewerTest\TestObject("5"), new SSViewerTest\TestObject("3"),
) new SSViewerTest\TestObject("4"),
), new SSViewerTest\TestObject("5"),
'Level' => new SSViewerTest\LevelTestData(1), )
'Nest' => array( ),
'Level' => new SSViewerTest\LevelTestData(1),
'Nest' => array(
'Level' => new SSViewerTest\LevelTestData(2), 'Level' => new SSViewerTest\LevelTestData(2),
), ),
) )
); );
$tests = array( $tests = array(
@ -1969,9 +1942,9 @@ EOC;
$this->assertEquals('HiHi', preg_replace('/\s+/', '', $this->render($template, $data))); $this->assertEquals('HiHi', preg_replace('/\s+/', '', $this->render($template, $data)));
$this->assertEquals( $this->assertEquals(
1, 1,
$data->testWithCalls, $data->testWithCalls,
'SSViewerTest_CacheTestData::TestWithCall() should only be called once. Subsequent calls should be cached' 'SSViewerTest_CacheTestData::TestWithCall() should only be called once. Subsequent calls should be cached'
); );
$data = new SSViewerTest\CacheTestData(); $data = new SSViewerTest\CacheTestData();
@ -1984,9 +1957,9 @@ EOC;
$this->assertEquals('OneTwo', preg_replace('/\s+/', '', $this->render($template, $data))); $this->assertEquals('OneTwo', preg_replace('/\s+/', '', $this->render($template, $data)));
$this->assertEquals( $this->assertEquals(
1, 1,
$data->testLoopCalls, $data->testLoopCalls,
'SSViewerTest_CacheTestData::TestLoopCall() should only be called once. Subsequent calls should be cached' 'SSViewerTest_CacheTestData::TestLoopCall() should only be called once. Subsequent calls should be cached'
); );
} }
@ -1995,10 +1968,10 @@ EOC;
$count = 0; $count = 0;
$parser = new SSTemplateParser(); $parser = new SSTemplateParser();
$parser->addClosedBlock( $parser->addClosedBlock(
'test', 'test',
function ($res) use (&$count) { function ($res) use (&$count) {
$count++; $count++;
} }
); );
$template = new SSViewer_FromString("<% test %><% end_test %>", $parser); $template = new SSViewer_FromString("<% test %><% end_test %>", $parser);
@ -2012,10 +1985,10 @@ EOC;
$count = 0; $count = 0;
$parser = new SSTemplateParser(); $parser = new SSTemplateParser();
$parser->addOpenBlock( $parser->addOpenBlock(
'test', 'test',
function ($res) use (&$count) { function ($res) use (&$count) {
$count++; $count++;
} }
); );
$template = new SSViewer_FromString("<% test %>", $parser); $template = new SSViewer_FromString("<% test %>", $parser);