Skip to content
This repository has been archived by the owner on Apr 13, 2020. It is now read-only.

Commit

Permalink
Update double qouted string test
Browse files Browse the repository at this point in the history
  • Loading branch information
uwetews committed Oct 12, 2017
1 parent 4bad9a9 commit cff7d20
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 141 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -26,154 +29,66 @@ public function testInit()
}

/**
* test simple double quoted string
* Test double qouted strings
*
* @preserveGlobalState disabled
* @dataProvider dataTestDoubleQuoted
*/
public function testSimpleDoubleQuotedString()
{
$tpl = $this->smarty->createTemplate('eval:{$foo="Hello World"}{$foo}', null, null, $this->smarty);
$this->assertEquals('Hello World', $this->smarty->fetch($tpl));
}

/**
* test expression tags in double quoted strings
*/
public function testTagsInDoubleQuotedString()
{
$tpl = $this->smarty->createTemplate('eval:{$foo="Hello {1+2} World"}{$foo}', null, null, $this->smarty);
$this->assertEquals('Hello 3 World', $this->smarty->fetch($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));
public function testDoubleQuoted($code, $result, $testName, $testNumber)
{
$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 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
*
* test unclosed block tag
*
* @expectedException SmartyCompilerException
* @expectedExceptionMessage unclosed "{if}" in doubled quoted string
*/
public function testExpressionBacktickInDoubleQuotedString()
public function testtestDoubleQuotedUnclosedBlock_001()
{
$tpl = $this->smarty->createTemplate('eval:{$a=1}{"`$a+1`"}', null, null, $this->smarty);
$this->assertEquals('2', $this->smarty->fetch($tpl));
$this->smarty->fetch('001_unclosedBlock.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));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"hello {if true} world"}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
dummy

0 comments on commit cff7d20

Please sign in to comment.