From: nikic <+@ni-po.com> Date: Fri, 10 Jun 2011 14:50:20 +0000 (+0200) Subject: Refactor and add additional default filter tests X-Git-Url: http://git.silmor.de/gitweb/?a=commitdiff_plain;h=f2a1c2b539244eb9a710cf9918bc75735235a003;p=web%2Fkonrad%2Ftwig.git Refactor and add additional default filter tests --- diff --git a/test/Twig/Tests/Fixtures/filters/default.test b/test/Twig/Tests/Fixtures/filters/default.test index 04c11d1..f17b96b 100644 --- a/test/Twig/Tests/Fixtures/filters/default.test +++ b/test/Twig/Tests/Fixtures/filters/default.test @@ -1,22 +1,59 @@ --TEST-- "default" filter --TEMPLATE-- -{{ foo|default('bar') }} -{{ bar|default('foo') }} -{{ baz.foo|default('bar') }} -{{ baz.bar|default('foo') }} -{{ not_defined|default('bar') }} -{{ 'a' ~ foo|default('b') }} -{{ 'a' ~ baz.foo|default('b') }} -{{ 0|default('bar') }} +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' }} +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' }} +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' }} +Precedence: +{{ 'o' ~ nullVar|default('k') }} +{{ 'o' ~ nested.nullVar|default('k') }} --DATA-- -return array('foo' => null, 'bar' => 'bar', 'baz' => array('foo' => null, 'bar' => 'bar')) +return array( + 'definedVar' => 'defined', + 'zeroVar' => 0, + 'emptyVar' => '', + 'nullVar' => null, + 'nested' => array( + 'definedVar' => 'defined', + 'zeroVar' => 0, + 'emptyVar' => '', + 'nullVar' => null, + ), +) --EXPECT-- -bar -bar -bar -bar -bar -ab -ab -0 +Variable: +ok +ok +ok +ok +ok +Array access: +ok +ok +ok +ok +ok +ok +Plain values: +ok +ok +ok +ok +Precedence: +ok +ok \ No newline at end of file