From: Fabien Potencier Date: Wed, 26 Oct 2011 20:04:54 +0000 (+0200) Subject: added more unit tests (some do not pass... yet) X-Git-Url: http://git.silmor.de/gitweb/?a=commitdiff_plain;h=52a8afd67cac3dc30641d907fd5084f7973887c5;p=web%2Fkonrad%2Ftwig.git added more unit tests (some do not pass... yet) --- diff --git a/test/Twig/Tests/Fixtures/filters/default.test b/test/Twig/Tests/Fixtures/filters/default.test index d518332..66b9ffa 100644 --- a/test/Twig/Tests/Fixtures/filters/default.test +++ b/test/Twig/Tests/Fixtures/filters/default.test @@ -2,28 +2,29 @@ "default" filter --TEMPLATE-- Variable: -{{ definedVar |default('default') is sameas('default') ? 'ko' : 'ok' }} -{{ zeroVar |default('default') is sameas('default') ? 'ko' : 'ok' }} -{{ emptyVar |default('default') is sameas('default') ? 'ok' : 'ko' }} -{{ nullVar |default('default') is sameas('default') ? 'ok' : 'ko' }} -{{ undefinedVar |default('default') is sameas('default') ? 'ok' : 'ko' }} +{{ definedVar |default('default') is sameas('default') ? 'ko' : 'ok' }} +{{ zeroVar |default('default') is sameas('default') ? 'ko' : 'ok' }} +{{ emptyVar |default('default') is sameas('default') ? 'ok' : 'ko' }} +{{ nullVar |default('default') is sameas('default') ? 'ok' : 'ko' }} +{{ undefinedVar |default('default') is sameas('default') ? 'ok' : 'ko' }} Array access: -{{ nested.definedVar |default('default') is sameas('default') ? 'ko' : 'ok' }} -{{ nested.zeroVar |default('default') is sameas('default') ? 'ko' : 'ok' }} -{{ nested.emptyVar |default('default') is sameas('default') ? 'ok' : 'ko' }} -{{ nested.nullVar |default('default') is sameas('default') ? 'ok' : 'ko' }} -{{ nested.undefinedVar|default('default') is sameas('default') ? 'ok' : 'ko' }} -{{ undefinedVar.foo |default('default') is sameas('default') ? 'ok' : 'ko' }} +{{ nested.definedVar |default('default') is sameas('default') ? 'ko' : 'ok' }} +{{ nested.zeroVar |default('default') is sameas('default') ? 'ko' : 'ok' }} +{{ nested.emptyVar |default('default') is sameas('default') ? 'ok' : 'ko' }} +{{ nested.nullVar |default('default') is sameas('default') ? 'ok' : 'ko' }} +{{ nested.undefinedVar |default('default') is sameas('default') ? 'ok' : 'ko' }} +{{ undefinedVar.foo |default('default') is sameas('default') ? 'ok' : 'ko' }} Plain values: -{{ 'defined' |default('default') is sameas('default') ? 'ko' : 'ok' }} -{{ 0 |default('default') is sameas('default') ? 'ko' : 'ok' }} -{{ '' |default('default') is sameas('default') ? 'ok' : 'ko' }} -{{ null |default('default') is sameas('default') ? 'ok' : 'ko' }} +{{ 'defined' |default('default') is sameas('default') ? 'ko' : 'ok' }} +{{ 0 |default('default') is sameas('default') ? 'ko' : 'ok' }} +{{ '' |default('default') is sameas('default') ? 'ok' : 'ko' }} +{{ null |default('default') is sameas('default') ? 'ok' : 'ko' }} Precedence: -{{ 'o' ~ nullVar|default('k') }} -{{ 'o' ~ nested.nullVar|default('k') }} +{{ 'o' ~ nullVar |default('k') }} +{{ 'o' ~ nested.nullVar |default('k') }} Deep nested: -{{ nested.undefinedVar.foo.bar|default('default') is sameas('default') ? 'ok' : 'ko' }} +{{ nested.undefinedVar.foo.bar |default('default') is sameas('default') ? 'ok' : 'ko' }} +{{ nested.definedArray.0 |default('default') is sameas('default') ? 'ko' : 'ok' }} --DATA-- return array( 'definedVar' => 'defined', @@ -31,10 +32,11 @@ return array( 'emptyVar' => '', 'nullVar' => null, 'nested' => array( - 'definedVar' => 'defined', - 'zeroVar' => 0, - 'emptyVar' => '', - 'nullVar' => null, + 'definedVar' => 'defined', + 'zeroVar' => 0, + 'emptyVar' => '', + 'nullVar' => null, + 'definedArray' => array(0), ), ) --CONFIG-- @@ -63,6 +65,7 @@ ok ok Deep nested: ok +ok --DATA-- return array( 'definedVar' => 'defined', @@ -70,10 +73,11 @@ return array( 'emptyVar' => '', 'nullVar' => null, 'nested' => array( - 'definedVar' => 'defined', - 'zeroVar' => 0, - 'emptyVar' => '', - 'nullVar' => null, + 'definedVar' => 'defined', + 'zeroVar' => 0, + 'emptyVar' => '', + 'nullVar' => null, + 'definedArray' => array(0), ), ) --CONFIG-- @@ -102,3 +106,4 @@ ok ok Deep nested: ok +ok diff --git a/test/Twig/Tests/Fixtures/tests/defined.test b/test/Twig/Tests/Fixtures/tests/defined.test index 8f2b63a..bb7c60d 100644 --- a/test/Twig/Tests/Fixtures/tests/defined.test +++ b/test/Twig/Tests/Fixtures/tests/defined.test @@ -1,27 +1,29 @@ --TEST-- "defined" test --TEMPLATE-- -{{ definedVar is defined ? 'ok' : 'ko' }} -{{ definedVar is not defined ? 'ko' : 'ok' }} -{{ undefinedVar is defined ? 'ko' : 'ok' }} -{{ undefinedVar is not defined ? 'ok' : 'ko' }} -{{ zeroVar is defined ? 'ok' : 'ko' }} -{{ nullVar is defined ? 'ok' : 'ko' }} -{{ nested.definedVar is defined ? 'ok' : 'ko' }} -{{ nested.definedVar is not defined ? 'ko' : 'ok' }} -{{ nested.undefinedVar is defined ? 'ko' : 'ok' }} -{{ nested.undefinedVar is not defined ? 'ok' : 'ko' }} -{{ nested.zeroVar is defined ? 'ok' : 'ko' }} -{{ nested.nullVar is defined ? 'ok' : 'ko' }} +{{ definedVar is defined ? 'ok' : 'ko' }} +{{ definedVar is not defined ? 'ko' : 'ok' }} +{{ undefinedVar is defined ? 'ko' : 'ok' }} +{{ undefinedVar is not defined ? 'ok' : 'ko' }} +{{ zeroVar is defined ? 'ok' : 'ko' }} +{{ nullVar is defined ? 'ok' : 'ko' }} +{{ nested.definedVar is defined ? 'ok' : 'ko' }} +{{ nested.definedVar is not defined ? 'ko' : 'ok' }} +{{ nested.undefinedVar is defined ? 'ko' : 'ok' }} +{{ nested.undefinedVar is not defined ? 'ok' : 'ko' }} +{{ nested.zeroVar is defined ? 'ok' : 'ko' }} +{{ nested.nullVar is defined ? 'ok' : 'ko' }} +{{ nested.definedArray.0 is defined ? 'ok' : 'ko' }} --DATA-- return array( 'definedVar' => 'defined', 'zeroVar' => 0, 'nullVar' => null, 'nested' => array( - 'definedVar' => 'defined', - 'zeroVar' => 0, - 'nullVar' => null, + 'definedVar' => 'defined', + 'zeroVar' => 0, + 'nullVar' => null, + 'definedArray' => array(0), ) ); --EXPECT-- @@ -37,3 +39,32 @@ ok ok ok ok +ok +--DATA-- +return array( + 'definedVar' => 'defined', + 'zeroVar' => 0, + 'nullVar' => null, + 'nested' => array( + 'definedVar' => 'defined', + 'zeroVar' => 0, + 'nullVar' => null, + 'definedArray' => array(0), + ) +); +--CONFIG-- +return array('strict_variables' => false) +--EXPECT-- +ok +ok +ok +ok +ok +ok +ok +ok +ok +ok +ok +ok +ok