public function Twig_Tests_Node_Expression_FilterTest::getTests in Zircon Profile 8.0
Same name and namespace in other branches
- 8 vendor/twig/twig/test/Twig/Tests/Node/Expression/FilterTest.php \Twig_Tests_Node_Expression_FilterTest::getTests()
Overrides Twig_Test_NodeTestCase::getTests
File
- vendor/
twig/ twig/ test/ Twig/ Tests/ Node/ Expression/ FilterTest.php, line 26
Class
Code
public function getTests() {
$environment = new Twig_Environment($this
->getMock('Twig_LoaderInterface'));
$environment
->addFilter(new Twig_SimpleFilter('bar', 'bar', array(
'needs_environment' => true,
)));
$environment
->addFilter(new Twig_SimpleFilter('barbar', 'twig_tests_filter_barbar', array(
'needs_context' => true,
'is_variadic' => true,
)));
$tests = array();
$expr = new Twig_Node_Expression_Constant('foo', 1);
$node = $this
->createFilter($expr, 'upper');
$node = $this
->createFilter($node, 'number_format', array(
new Twig_Node_Expression_Constant(2, 1),
new Twig_Node_Expression_Constant('.', 1),
new Twig_Node_Expression_Constant(',', 1),
));
if (function_exists('mb_get_info')) {
$tests[] = array(
$node,
'twig_number_format_filter($this->env, twig_upper_filter($this->env, "foo"), 2, ".", ",")',
);
}
else {
$tests[] = array(
$node,
'twig_number_format_filter($this->env, strtoupper("foo"), 2, ".", ",")',
);
}
// named arguments
$date = new Twig_Node_Expression_Constant(0, 1);
$node = $this
->createFilter($date, 'date', array(
'timezone' => new Twig_Node_Expression_Constant('America/Chicago', 1),
'format' => new Twig_Node_Expression_Constant('d/m/Y H:i:s P', 1),
));
$tests[] = array(
$node,
'twig_date_format_filter($this->env, 0, "d/m/Y H:i:s P", "America/Chicago")',
);
// skip an optional argument
$date = new Twig_Node_Expression_Constant(0, 1);
$node = $this
->createFilter($date, 'date', array(
'timezone' => new Twig_Node_Expression_Constant('America/Chicago', 1),
));
$tests[] = array(
$node,
'twig_date_format_filter($this->env, 0, null, "America/Chicago")',
);
// underscores vs camelCase for named arguments
$string = new Twig_Node_Expression_Constant('abc', 1);
$node = $this
->createFilter($string, 'reverse', array(
'preserve_keys' => new Twig_Node_Expression_Constant(true, 1),
));
$tests[] = array(
$node,
'twig_reverse_filter($this->env, "abc", true)',
);
$node = $this
->createFilter($string, 'reverse', array(
'preserveKeys' => new Twig_Node_Expression_Constant(true, 1),
));
$tests[] = array(
$node,
'twig_reverse_filter($this->env, "abc", true)',
);
// filter as an anonymous function
if (PHP_VERSION_ID >= 50300) {
$node = $this
->createFilter(new Twig_Node_Expression_Constant('foo', 1), 'anonymous');
$tests[] = array(
$node,
'call_user_func_array($this->env->getFilter(\'anonymous\')->getCallable(), array("foo"))',
);
}
// needs environment
$node = $this
->createFilter($string, 'bar');
$tests[] = array(
$node,
'bar($this->env, "abc")',
$environment,
);
$node = $this
->createFilter($string, 'bar', array(
new Twig_Node_Expression_Constant('bar', 1),
));
$tests[] = array(
$node,
'bar($this->env, "abc", "bar")',
$environment,
);
// arbitrary named arguments
$node = $this
->createFilter($string, 'barbar');
$tests[] = array(
$node,
'twig_tests_filter_barbar($context, "abc")',
$environment,
);
$node = $this
->createFilter($string, 'barbar', array(
'foo' => new Twig_Node_Expression_Constant('bar', 1),
));
$tests[] = array(
$node,
'twig_tests_filter_barbar($context, "abc", null, null, array("foo" => "bar"))',
$environment,
);
$node = $this
->createFilter($string, 'barbar', array(
'arg2' => new Twig_Node_Expression_Constant('bar', 1),
));
$tests[] = array(
$node,
'twig_tests_filter_barbar($context, "abc", null, "bar")',
$environment,
);
$node = $this
->createFilter($string, 'barbar', array(
new Twig_Node_Expression_Constant('1', 1),
new Twig_Node_Expression_Constant('2', 1),
new Twig_Node_Expression_Constant('3', 1),
'foo' => new Twig_Node_Expression_Constant('bar', 1),
));
$tests[] = array(
$node,
'twig_tests_filter_barbar($context, "abc", "1", "2", array(0 => "3", "foo" => "bar"))',
$environment,
);
return $tests;
}