diff --git a/tests/UnitTests/TemplateSource/ValueTests/DoubleQuoted/DoubleQuotedStringTest.php b/tests/UnitTests/TemplateSource/ValueTests/DoubleQuoted/DoubleQuotedStringTest.php index 7581ffb3..9a2e3101 100644 --- a/tests/UnitTests/TemplateSource/ValueTests/DoubleQuoted/DoubleQuotedStringTest.php +++ b/tests/UnitTests/TemplateSource/ValueTests/DoubleQuoted/DoubleQuotedStringTest.php @@ -18,6 +18,9 @@ class DoubleQuotedStringTest extends PHPUnit_Smarty public function setUp() { $this->setUpSmarty(dirname(__FILE__)); + $this->smarty->addPluginsDir("../../../__shared/PHPunitplugins/"); + $this->smarty->addTemplateDir("../../../__shared/templates/"); + $this->smarty->addTemplateDir("./templates_tmp"); } public function testInit() @@ -26,154 +29,66 @@ class DoubleQuotedStringTest extends PHPUnit_Smarty } /** - * test simple double quoted string + * Test double qouted strings + * + * @preserveGlobalState disabled + * @dataProvider dataTestDoubleQuoted */ - public function testSimpleDoubleQuotedString() + public function testDoubleQuoted($code, $result, $testName, $testNumber) { - $tpl = $this->smarty->createTemplate('eval:{$foo="Hello World"}{$foo}', null, null, $this->smarty); - $this->assertEquals('Hello World', $this->smarty->fetch($tpl)); + $name = empty($testName) ? $testNumber : $testName; + $file = "testDoubleQuotes_{$name}.tpl"; + $this->makeTemplateFile($file, $code); + $this->smarty->assignGlobal('file', $file); + $this->smarty->assign('bar', 'buh'); + $this->assertEquals($this->strip($result), $this->strip($this->smarty->fetch($file)), + "testDoubleQuoted - {$code} - {$name}"); } + /* + * Data provider für testDoubleQuoted + */ + public function dataTestDoubleQuoted() + { + $i = 1; + /* + * Code + * result + * test name + * test number + */ + return array(array('{$foo="Hello World"}{$foo}', 'Hello World', 'simple', $i ++), + array('{$bar=1}{$foo="Hello {$bar+2} World"}{$foo}', 'Hello 3 World', 'withExpression', $i ++), + array('{$bar=\'blah\'}{$foo="Hello $bar World"}{$foo}', 'Hello blah World', 'withVariable', $i ++), + array('{$bar=\'blah\'}{$buh=\'wow\'}{$foo="Hello $bar$buh World"}{$foo}', 'Hello blahwow World', 'with2Variables', $i ++), + array('{$bar=\'blah\'}{$foo="Hello `$bar`.test World"}{$foo}', 'Hello blah.test World', 'withVarBacktick', $i ++), + array('{$bar=\'blah\'}{$buh=\'buh\'}{$foo="Hello `$bar``$buh`.test World"}{$foo}', 'Hello blahbuh.test World', 'with2VarBacktick', $i ++), + array('{$barbuh=\'blah\'}{$buh=\'buh\'}{$foo="Hello `$bar{$buh}`.test World"}{$foo}', 'Hello blah.test World', 'withVariableVarBacktick', $i ++), + array('{$bar[1][2]=\'blah\'}{$foo="Hello `$bar.1.2`.test World"}{$foo}', 'Hello blah.test World', 'withVarIndexSmartyBacktick', $i ++), + array('{$bar[1][2]=\'blah\'}{$foo="Hello `$bar[1][2]`.test World"}{$foo}', 'Hello blah.test World', 'withVarIndexPhPBacktick', $i ++), + array('{$a=1}{"`$a+1`"}', '2', 'withExpressionBacktick', $i ++), + array('{$foo="Hello {counter start=3} World"}{$foo}', 'Hello 3 World', 'withCounterTag', $i ++), + array('{$foo="Hello {counter start=2}{counter} World"}{$foo}', 'Hello 23 World', 'with2CounterTag', $i ++), + array('{$x=1}{$y=2}{$z=true}{"Hello{if $z} {$x} {else}{$y}{/if}World"}', 'Hello 1 World', 'withIfTag', $i ++), + array('{$bar=\'blah\'}{$foo="Hello {$bar}.test World"}{$foo}', 'Hello blah.test World', 'withDelimiter', $i ++), + array('{$foo="Hello \" World"}{$foo}', 'Hello " World', 'escaped', $i ++), + array('{$foo="Hello \'World\'"}{$foo}', 'Hello \'World\'', 'withSingleQuotes', $i ++), + array('{$foo="Hello {\'World\'} Test"}{$foo}', 'Hello World Test', 'withSingleQuoteTag', $i ++), + array('{$foo=""}{$foo}', '', 'empty', $i ++), + ); + } + + /** - * test expression tags in double quoted strings + * + * test unclosed block tag + * + * @expectedException SmartyCompilerException + * @expectedExceptionMessage unclosed "{if}" in doubled quoted string */ - public function testTagsInDoubleQuotedString() + public function testtestDoubleQuotedUnclosedBlock_001() { - $tpl = $this->smarty->createTemplate('eval:{$foo="Hello {1+2} World"}{$foo}', null, null, $this->smarty); - $this->assertEquals('Hello 3 World', $this->smarty->fetch($tpl)); + $this->smarty->fetch('001_unclosedBlock.tpl'); } - /** - * test vars in double quoted strings - */ - public function testVarsInDoubleQuotedString1() - { - $tpl = $this->smarty->createTemplate('eval:{$bar=\'blah\'}{$foo="Hello $bar World"}{$foo}', null, null, $this->smarty); - $this->assertEquals('Hello blah World', $this->smarty->fetch($tpl)); - } - - public function testVarsInDoubleQuotedString2() - { - $tpl = $this->smarty->createTemplate('eval:{$bar=\'blah\'}{$buh=\'buh\'}{$foo="Hello $bar$buh World"}{$foo}', null, null, $this->smarty); - $this->assertEquals('Hello blahbuh World', $this->smarty->fetch($tpl)); - } - - /** - * test vars with backtick in double quoted strings - */ - public function testVarsBacktickInDoubleQuotedString1() - { - $tpl = $this->smarty->createTemplate('eval:{$bar=\'blah\'}{$foo="Hello `$bar`.test World"}{$foo}', null, null, $this->smarty); - $this->assertEquals('Hello blah.test World', $this->smarty->fetch($tpl)); - } - - public function testVarsBacktickInDoubleQuotedString2() - { - $tpl = $this->smarty->createTemplate('eval:{$bar=\'blah\'}{$buh=\'buh\'}{$foo="Hello `$bar``$buh`.test World"}{$foo}', null, null, $this->smarty); - $this->assertEquals('Hello blahbuh.test World', $this->smarty->fetch($tpl)); - } - - /** - * test variable vars with backtick in double quoted strings - */ - public function testVariableVarsBacktickInDoubleQuotedString() - { - $tpl = $this->smarty->createTemplate('eval:{$barbuh=\'blah\'}{$buh=\'buh\'}{$foo="Hello `$bar{$buh}`.test World"}{$foo}', null, null, $this->smarty); - $this->assertEquals('Hello blah.test World', $this->smarty->fetch($tpl)); - } - - /** - * test array vars with backtick in double quoted strings - */ - public function testArrayVarsBacktickInDoubleQuotedString1() - { - $tpl = $this->smarty->createTemplate('eval:{$bar[1][2]=\'blah\'}{$foo="Hello `$bar.1.2`.test World"}{$foo}', null, null, $this->smarty); - $this->assertEquals('Hello blah.test World', $this->smarty->fetch($tpl)); - } - - public function testArrayVarsBacktickInDoubleQuotedString2() - { - $tpl = $this->smarty->createTemplate('eval:{$bar[1][2]=\'blah\'}{$foo="Hello `$bar[1][2]`.test World"}{$foo}', null, null, $this->smarty); - $this->assertEquals('Hello blah.test World', $this->smarty->fetch($tpl)); - } - - /** - * test expression in backtick in double quoted strings - */ - public function testExpressionBacktickInDoubleQuotedString() - { - $tpl = $this->smarty->createTemplate('eval:{$a=1}{"`$a+1`"}', null, null, $this->smarty); - $this->assertEquals('2', $this->smarty->fetch($tpl)); - } - - /** - * test smartytag in double quoted strings - */ - public function testSmartytagInDoubleQuotedString1() - { - $tpl = $this->smarty->createTemplate('eval:{$foo="Hello {counter start=1} World"}{$foo}', null, null, $this->smarty); - $this->assertEquals('Hello 1 World', $this->smarty->fetch($tpl)); - } - - public function testSmartytagInDoubleQuotedString2() - { - $tpl = $this->smarty->createTemplate('eval:{$foo="Hello {counter start=1}{counter} World"}{$foo}', null, null, $this->smarty); - $this->assertEquals('Hello 12 World', $this->smarty->fetch($tpl)); - } - - /** - * test block smartytag in double quoted strings - */ - public function testSmartyBlockTagInDoubleQuotedString1() - { - $this->smarty->assign('x', 1); - $this->smarty->assign('y', 1); - $this->smarty->assign('z', true); - $this->assertEquals('Hello 1 World', $this->smarty->fetch('string:{"Hello{if $z} {$x} {else}{$y}{/if}World"}')); - } - - /** - * test vars in delimiter in double quoted strings - */ - public function testVarsDelimiterInDoubleQuotedString() - { - $tpl = $this->smarty->createTemplate('eval:{$bar=\'blah\'}{$foo="Hello {$bar}.test World"}{$foo}', null, null, $this->smarty); - $this->assertEquals('Hello blah.test World', $this->smarty->fetch($tpl)); - } - - /** - * test escaped quotes in double quoted strings - */ - public function testEscapedQuotesInDoubleQuotedString() - { - $tpl = $this->smarty->createTemplate('eval:{$foo="Hello \" World"}{$foo}', null, null, $this->smarty); - $this->assertEquals('Hello " World', $this->smarty->fetch($tpl)); - } - - /** - * test single quotes in double quoted strings - */ - public function testSingleQuotesInDoubleQuotedString() - { - $tpl = $this->smarty->createTemplate('eval:{$foo="Hello \'World\'"}{$foo}', null, null, $this->smarty); - $this->assertEquals("Hello 'World'", $this->smarty->fetch($tpl)); - } - - /** - * test single quote tags in double quoted strings - */ - public function testSingleQuoteTagsInDoubleQuotedString() - { - $tpl = $this->smarty->createTemplate('eval:{$foo="Hello {\'World\'} Test"}{$foo}', null, null, $this->smarty); - $this->assertEquals("Hello World Test", $this->smarty->fetch($tpl)); - } - - /** - * test empty double quoted strings - */ - public function testEmptyDoubleQuotedString() - { - $tpl = $this->smarty->createTemplate('eval:{$foo=""}{$foo}', null, null, $this->smarty); - $this->assertEquals("", $this->smarty->fetch($tpl)); - } } diff --git a/tests/UnitTests/TemplateSource/ValueTests/DoubleQuoted/templates/001_unclosedBlock.tpl b/tests/UnitTests/TemplateSource/ValueTests/DoubleQuoted/templates/001_unclosedBlock.tpl new file mode 100644 index 00000000..4b009875 --- /dev/null +++ b/tests/UnitTests/TemplateSource/ValueTests/DoubleQuoted/templates/001_unclosedBlock.tpl @@ -0,0 +1 @@ +{"hello {if true} world"} \ No newline at end of file diff --git a/tests/UnitTests/TemplateSource/ValueTests/DoubleQuoted/templates_tmp/dummy.txt b/tests/UnitTests/TemplateSource/ValueTests/DoubleQuoted/templates_tmp/dummy.txt new file mode 100644 index 00000000..2995a4d0 --- /dev/null +++ b/tests/UnitTests/TemplateSource/ValueTests/DoubleQuoted/templates_tmp/dummy.txt @@ -0,0 +1 @@ +dummy \ No newline at end of file