2012-04-03 22:47:41 +02:00
|
|
|
<?php
|
|
|
|
|
2014-02-06 14:44:16 +01:00
|
|
|
namespace PhpParser;
|
|
|
|
|
|
|
|
class TemplateTest extends \PHPUnit_Framework_TestCase
|
2012-04-03 22:47:41 +02:00
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @dataProvider provideTestPlaceholderReplacement
|
2014-02-06 14:44:16 +01:00
|
|
|
* @covers Template
|
2012-04-03 22:47:41 +02:00
|
|
|
*/
|
|
|
|
public function testPlaceholderReplacement($templateCode, $placeholders, $expectedPrettyPrint) {
|
2014-02-06 14:44:16 +01:00
|
|
|
$parser = new Parser(new Lexer);
|
|
|
|
$prettyPrinter = new PrettyPrinter\Standard;
|
2012-04-03 22:47:41 +02:00
|
|
|
|
2014-02-06 14:44:16 +01:00
|
|
|
$template = new Template($parser, $templateCode);
|
2012-04-03 22:47:41 +02:00
|
|
|
$this->assertEquals(
|
|
|
|
$expectedPrettyPrint,
|
|
|
|
$prettyPrinter->prettyPrint($template->getStmts($placeholders))
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function provideTestPlaceholderReplacement() {
|
|
|
|
return array(
|
|
|
|
array(
|
|
|
|
'<?php $__name__ + $__Name__;',
|
|
|
|
array('name' => 'foo'),
|
|
|
|
'$foo + $Foo;'
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'<?php $__name__ + $__Name__;',
|
|
|
|
array('Name' => 'Foo'),
|
|
|
|
'$foo + $Foo;'
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'<?php $__name__ + $__Name__;',
|
|
|
|
array('name' => 'foo', 'Name' => 'Bar'),
|
|
|
|
'$foo + $Bar;'
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'<?php $__name__ + $__Name__;',
|
|
|
|
array('Name' => 'Bar', 'name' => 'foo'),
|
|
|
|
'$foo + $Bar;'
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'<?php $prefix__Name__Suffix;',
|
|
|
|
array('name' => 'infix'),
|
|
|
|
'$prefixInfixSuffix;'
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'<?php $___name___;',
|
|
|
|
array('name' => 'foo'),
|
|
|
|
'$_foo_;'
|
2012-05-06 17:58:31 +02:00
|
|
|
),
|
|
|
|
array(
|
|
|
|
'<?php $foobar;',
|
|
|
|
array(),
|
|
|
|
'$foobar;'
|
|
|
|
),
|
2012-04-03 22:47:41 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|