From cfefb7467022d5b3795b0aea967294e4e0aef80d Mon Sep 17 00:00:00 2001 From: David Grudl Date: Mon, 27 Jun 2016 11:30:43 +0200 Subject: [PATCH] tests: added new tests --- tests/Latte/Compiler.htmlNode.phpt | 2 + tests/Latte/Compiler.unquoted.phpt | 8 ++- tests/Latte/Parser.parse.phpt | 69 ++++++++++++++++--- .../expected/Compiler.unquoted.attrs.html | 6 ++ .../expected/Compiler.unquoted.attrs.phtml | 32 ++++++++- tests/Latte/expected/contentType.xml.html | 3 +- tests/Latte/expected/contentType.xml.phtml | 42 +++++------ tests/Latte/templates/contentType.xml.latte | 3 +- 8 files changed, 129 insertions(+), 36 deletions(-) diff --git a/tests/Latte/Compiler.htmlNode.phpt b/tests/Latte/Compiler.htmlNode.phpt index ee31c8469..2469033d9 100644 --- a/tests/Latte/Compiler.htmlNode.phpt +++ b/tests/Latte/Compiler.htmlNode.phpt @@ -26,6 +26,7 @@ class MockMacro implements IMacro 1 => ['a' => '', 'b' => '123', 'c' => 'abc', 'd' => 'text', 'e' => 'xxx', 'f' => TRUE], 2 => ['a' => '', 'b' => '456', 'c' => 'abc', 'd' => 'text', 'e' => 'xxx', 'f' => TRUE, 'g' => TRUE], 3 => ['a' => '', 'b' => '456', 'c' => 'abc', 'd' => 'text', 'e' => 'xxx', 'f' => TRUE, 'g' => TRUE], + 4 => ['href' => TRUE], ]; Assert::same($res[$node->args], $node->htmlNode->attrs); } @@ -38,3 +39,4 @@ $parser = new Parser; $compiler = new Compiler; $compiler->addMacro('foo', new MockMacro); $compiler->compile($parser->parse('
{foo 3/}'), 'Template'); +$compiler->compile($parser->parse(''), 'Template'); diff --git a/tests/Latte/Compiler.unquoted.phpt b/tests/Latte/Compiler.unquoted.phpt index f407d205b..50897fd87 100644 --- a/tests/Latte/Compiler.unquoted.phpt +++ b/tests/Latte/Compiler.unquoted.phpt @@ -14,10 +14,16 @@ $latte = new Latte\Engine; $latte->setLoader(new Latte\Loaders\StringLoader); $template = <<<'EOD' - + + + + + + + EOD; diff --git a/tests/Latte/Parser.parse.phpt b/tests/Latte/Parser.parse.phpt index 51112cd68..c5caf8b30 100644 --- a/tests/Latte/Parser.parse.phpt +++ b/tests/Latte/Parser.parse.phpt @@ -16,18 +16,18 @@ function parse($s) { $parser = new Latte\Parser; return array_map(function (Token $token) { - return [$token->type, $token->text]; + return array_filter([$token->type, $token->text, $token->name, $token->value]); }, $parser->parse($s)); } Assert::same([ - ['text', '<0>'] + ['text', '<0>'], ], parse('<0>')); Assert::same([ ['htmlTagBegin', ''], ['text', 'text'], @@ -49,7 +49,7 @@ Assert::same([ ], parse('text')); Assert::same([ - ['macroTag', '{contentType xml}'], + ['macroTag', '{contentType xml}', 'contentType', 'xml'], ['htmlTagBegin', 'text'], ], parse('{contentType xml}text')); @@ -83,16 +83,65 @@ Assert::same([ ], parse('text')); Assert::same([ - ['htmlTagBegin', ''], - ['htmlTagBegin', ''], ['text', '{foo}'], - ['htmlTagBegin', ''], ['text', '{bar}'], - ['htmlTagBegin', ''], - ['macroTag', '{lorem}'], + ['macroTag', '{lorem}', 'lorem'], ], parse('
{foo}
{bar}
{lorem}')); + +// html attributes +Assert::same([ + ['htmlTagBegin', ''], + ['htmlTagBegin', ''], +], parse('
')); + +Assert::same([ + ['htmlTagBegin', ''], + ['htmlTagBegin', ''], +], parse('
')); + +// macro attributes +Assert::same([ + ['htmlTagBegin', ''], + ['htmlTagBegin', ''], +], parse('
')); diff --git a/tests/Latte/expected/Compiler.unquoted.attrs.html b/tests/Latte/expected/Compiler.unquoted.attrs.html index d0751e007..c22c277d4 100644 --- a/tests/Latte/expected/Compiler.unquoted.attrs.html +++ b/tests/Latte/expected/Compiler.unquoted.attrs.html @@ -1,3 +1,9 @@ + + + + + + diff --git a/tests/Latte/expected/Compiler.unquoted.attrs.phtml b/tests/Latte/expected/Compiler.unquoted.attrs.phtml index 8b3f0aaed..40b3316de 100644 --- a/tests/Latte/expected/Compiler.unquoted.attrs.phtml +++ b/tests/Latte/expected/Compiler.unquoted.attrs.phtml @@ -7,11 +7,39 @@ class Template%a% extends Latte\Runtime\Template function main() { %A% - ?>> + ?> class=> > -=> +> + +"item"> + + "item"> + +=> + + diff --git a/tests/Latte/expected/contentType.xml.phtml b/tests/Latte/expected/contentType.xml.phtml index 8ab92b991..283782084 100644 --- a/tests/Latte/expected/contentType.xml.phtml +++ b/tests/Latte/expected/contentType.xml.phtml @@ -10,8 +10,8 @@ class Template%a% extends Latte\Runtime\Template { extract($this->params); if (empty($this->global->coreCaptured) && in_array($this->getReferenceType(), ["extends", NULL], TRUE)) header('Content-Type: application/xml; charset=utf-8'); -?> - + ?><?xml version="1.0" encoding="utf-8"?> +<?xml-stylesheet type="text/css" href=""?>

);alert("hello");' - title='"' +'alert();alert("hello");' + title='"' style = - "color:;'" - alt='' - onfocus="alert()" + "color:;'" + alt='' + onfocus="alert()" >click on me

- + @@ -66,7 +66,7 @@ var html = ;
  • + ?>
  • ; } ?>>

    -

    val2=>

    +

    val2=>

    -

    >

    +

    >

    -

    +

    ; function prepare() { extract($this->params); - if (isset($this->params['person'])) trigger_error('Variable $person overwritten in foreach on line 49'); + if (isset($this->params['person'])) trigger_error('Variable $person overwritten in foreach on line 50'); } diff --git a/tests/Latte/templates/contentType.xml.latte b/tests/Latte/templates/contentType.xml.latte index 4e01f5631..ac489755e 100644 --- a/tests/Latte/templates/contentType.xml.latte +++ b/tests/Latte/templates/contentType.xml.latte @@ -1,5 +1,6 @@ {contentType application/xml; charset=utf-8} - + +