From 192b8e2568f499aa2ead98a24d8dd5541b1f315a Mon Sep 17 00:00:00 2001 From: Tristan Darricau Date: Sat, 2 Aug 2014 19:09:42 +0200 Subject: [ticket/11649] Expose Twig through the container PHPBB3-11649 --- tests/template/template_events_test.php | 23 ++++++++++++++++++++++- tests/template/template_test_case.php | 22 +++++++++++++++++++++- tests/template/template_test_case_with_tree.php | 22 +++++++++++++++++++++- 3 files changed, 64 insertions(+), 3 deletions(-) (limited to 'tests/template') diff --git a/tests/template/template_events_test.php b/tests/template/template_events_test.php index c415c969fe..e8ffea8d11 100644 --- a/tests/template/template_events_test.php +++ b/tests/template/template_events_test.php @@ -147,7 +147,28 @@ Zeta test event in all', $phpbb_root_path, $phpEx ); - $this->template = new \phpbb\template\twig\twig($path_helper, $config, $user, new \phpbb\template\context, $this->extension_manager); + + $container = new phpbb_mock_container_builder(); + $cache_path = $phpbb_root_path . 'cache/twig'; + $context = new \phpbb\template\context(); + $loader = new \phpbb\template\twig\loader(''); + $twig = new \phpbb\template\twig\environment( + $config, + $path_helper, + $container, + $cache_path, + $this->extension_manager, + $loader, + array( + 'cache' => false, + 'debug' => false, + 'auto_reload' => true, + 'autoescape' => false, + ) + ); + $this->template = new \phpbb\template\twig\twig($path_helper, $config, $user, $context, $twig, $cache_path, array(new \phpbb\template\twig\extension($context, $this->user)), $this->extension_manager); + $container->set('template.twig.lexer', new \phpbb\template\twig\lexer($twig)); + $this->template->set_custom_style(((!empty($style_names)) ? $style_names : 'silver'), array($this->template_path)); } } diff --git a/tests/template/template_test_case.php b/tests/template/template_test_case.php index 83446b5352..1f46d6ff71 100644 --- a/tests/template/template_test_case.php +++ b/tests/template/template_test_case.php @@ -78,7 +78,27 @@ class phpbb_template_template_test_case extends phpbb_test_case ); $this->template_path = $this->test_path . '/templates'; - $this->template = new \phpbb\template\twig\twig($path_helper, $config, $this->user, new \phpbb\template\context()); + + $container = new phpbb_mock_container_builder(); + $cache_path = $phpbb_root_path . 'cache/twig'; + $context = new \phpbb\template\context(); + $loader = new \phpbb\template\twig\loader(''); + $twig = new \phpbb\template\twig\environment( + $config, + $path_helper, + $container, + $cache_path, + null, + $loader, + array( + 'cache' => false, + 'debug' => false, + 'auto_reload' => true, + 'autoescape' => false, + ) + ); + $this->template = new phpbb\template\twig\twig($path_helper, $config, $user, $context, $twig, $cache_path, array(new \phpbb\template\twig\extension($context, $this->user))); + $container->set('template.twig.lexer', new \phpbb\template\twig\lexer($twig)); $this->template->set_custom_style('tests', $this->template_path); } diff --git a/tests/template/template_test_case_with_tree.php b/tests/template/template_test_case_with_tree.php index 68ecc4b706..c634e2051a 100644 --- a/tests/template/template_test_case_with_tree.php +++ b/tests/template/template_test_case_with_tree.php @@ -34,7 +34,27 @@ class phpbb_template_template_test_case_with_tree extends phpbb_template_templat $this->template_path = $this->test_path . '/templates'; $this->parent_template_path = $this->test_path . '/parent_templates'; - $this->template = new phpbb\template\twig\twig($this->phpbb_path_helper, $config, $user, new phpbb\template\context()); + + $container = new phpbb_mock_container_builder(); + $cache_path = $phpbb_root_path . 'cache/twig'; + $context = new \phpbb\template\context(); + $loader = new \phpbb\template\twig\loader(''); + $twig = new \phpbb\template\twig\environment( + $config, + $this->phpbb_path_helper, + $container, + $cache_path, + null, + $loader, + array( + 'cache' => false, + 'debug' => false, + 'auto_reload' => true, + 'autoescape' => false, + ) + ); + $this->template = new phpbb\template\twig\twig($this->phpbb_path_helper, $config, $user, $context, $twig, $cache_path, array(new \phpbb\template\twig\extension($context, $this->user))); + $container->set('template.twig.lexer', new \phpbb\template\twig\lexer($twig)); $this->template->set_custom_style('tests', array($this->template_path, $this->parent_template_path)); } } -- cgit v1.2.1 From 55a3c96fb008a96e43572329ed5127ce7d6f5f6f Mon Sep 17 00:00:00 2001 From: Tristan Darricau Date: Tue, 2 Sep 2014 22:12:11 +0200 Subject: [ticket/12661] Fix unit tests PHPBB3-12661 --- tests/template/template_allfolder_test.php | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) (limited to 'tests/template') diff --git a/tests/template/template_allfolder_test.php b/tests/template/template_allfolder_test.php index b4ad84e9c3..e87688a57c 100644 --- a/tests/template/template_allfolder_test.php +++ b/tests/template/template_allfolder_test.php @@ -51,9 +51,29 @@ class phpbb_template_allfolder_test extends phpbb_template_template_test_case ) ); + $container = new phpbb_mock_container_builder(); + $cache_path = $phpbb_root_path . 'cache/twig'; + $context = new \phpbb\template\context(); + $loader = new \phpbb\template\twig\loader(''); + $twig = new \phpbb\template\twig\environment( + $config, + $path_helper, + $container, + $cache_path, + $this->extension_manager, + $loader, + array( + 'cache' => false, + 'debug' => false, + 'auto_reload' => true, + 'autoescape' => false, + ) + ); + $this->template = new \phpbb\template\twig\twig($path_helper, $config, $this->user, $context, $twig, $cache_path, array(new \phpbb\template\twig\extension($context, $this->user)), $this->extension_manager); + $container->set('template.twig.lexer', new \phpbb\template\twig\lexer($twig)); + $this->template_path = $this->test_path . '/templates'; $this->ext_template_path = 'tests/extension/ext/vendor4/bar/styles/all/template'; - $this->template = new \phpbb\template\twig\twig($path_helper, $config, $this->user, new \phpbb\template\context(), $this->extension_manager); $this->template->set_custom_style('all', array($this->template_path, $this->ext_template_path)); } } -- cgit v1.2.1 From 5d3f0a9abbfe9678a9b5b480d1bbdfae69384018 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Sat, 22 Nov 2014 00:13:13 +0100 Subject: [ticket/13359] Add phpbb\template\twig\environment to template constructor PHPBB3-13359 --- tests/template/template_includecss_test.php | 30 ++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) (limited to 'tests/template') diff --git a/tests/template/template_includecss_test.php b/tests/template/template_includecss_test.php index 49bd9dec8b..a8db74c3f1 100644 --- a/tests/template/template_includecss_test.php +++ b/tests/template/template_includecss_test.php @@ -15,6 +15,12 @@ require_once dirname(__FILE__) . '/template_test_case_with_tree.php'; class phpbb_template_template_includecss_test extends phpbb_template_template_test_case_with_tree { + /** @var \phpbb\path_helper */ + protected $phpbb_path_helper; + + /** @var string */ + protected $parent_template_path; + protected function setup_engine(array $new_config = array()) { global $phpbb_root_path, $phpEx, $user; @@ -34,11 +40,32 @@ class phpbb_template_template_includecss_test extends phpbb_template_template_te $this->template_path = $this->test_path . '/templates'; $this->parent_template_path = $this->test_path . '/parent_templates'; + $container = new phpbb_mock_container_builder(); + $cache_path = $phpbb_root_path . 'cache/twig'; + $context = new \phpbb\template\context(); + $loader = new \phpbb\template\twig\loader(''); + $twig = new \phpbb\template\twig\environment( + $config, + $this->phpbb_path_helper, + $container, + $cache_path, + null, + $loader, + array( + 'cache' => false, + 'debug' => false, + 'auto_reload' => true, + 'autoescape' => false, + ) + ); $this->template = new phpbb\template\twig\twig( $this->phpbb_path_helper, $config, $user, - new phpbb\template\context(), + $context, + $twig, + $cache_path, + array(new \phpbb\template\twig\extension($context, $this->user)), new phpbb_mock_extension_manager( dirname(__FILE__) . '/', array( @@ -50,6 +77,7 @@ class phpbb_template_template_includecss_test extends phpbb_template_template_te ) ) ); + $container->set('template.twig.lexer', new \phpbb\template\twig\lexer($twig)); $this->template->set_custom_style('tests', array($this->template_path, $this->parent_template_path)); } -- cgit v1.2.1 From 26713063045117b2221ad9373d09267dcae8637f Mon Sep 17 00:00:00 2001 From: Matt Friedman Date: Thu, 29 Jan 2015 01:41:52 -0800 Subject: [ticket/10388] Update tests PHPBB3-10388 --- tests/template/template_test.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests/template') diff --git a/tests/template/template_test.php b/tests/template/template_test.php index 0bbfe3848d..bb6b7300cb 100644 --- a/tests/template/template_test.php +++ b/tests/template/template_test.php @@ -286,7 +286,7 @@ class phpbb_template_template_test extends phpbb_template_template_test_case array(), array(), array(), - "Value'\n1 O'Clock\nValue\'\n1 O\'Clock", + "Value'\n1 O'Clock\nValue\\x27\n1\\x20O\\x27Clock", array('VARIABLE' => "Value'", '1_VARIABLE' => "1 O'Clock"), ), array( -- cgit v1.2.1 From f4b42c961f5729b0bbadca8a897410f890228364 Mon Sep 17 00:00:00 2001 From: Nicofuma Date: Tue, 3 Feb 2015 12:41:31 +0100 Subject: [ticket/13139] Fix tests PHPBB3-13139 --- tests/template/template_includecss_test.php | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) (limited to 'tests/template') diff --git a/tests/template/template_includecss_test.php b/tests/template/template_includecss_test.php index a8db74c3f1..96980e17c6 100644 --- a/tests/template/template_includecss_test.php +++ b/tests/template/template_includecss_test.php @@ -83,13 +83,6 @@ class phpbb_template_template_includecss_test extends phpbb_template_template_te public function template_data() { - $url_base = explode('/', dirname(__FILE__)); - foreach ($url_base as &$dir) - { - $dir = rawurlencode($dir); - } - $url_base = implode('/', $url_base); - return array( /* array( @@ -107,11 +100,11 @@ class phpbb_template_template_includecss_test extends phpbb_template_template_te ), array( array('TEST' => 3), - '', + '', ), array( array('TEST' => 4), - '', + '', ), ); } -- cgit v1.2.1 From cf39cfc5939f9407082f8f5c1f876ea0ee607a45 Mon Sep 17 00:00:00 2001 From: Tristan Darricau Date: Tue, 7 Oct 2014 20:51:08 +0200 Subject: [ticket/13132] Twig: Add loops content to the root context PHPBB3-13132 --- tests/template/template_test.php | 149 ++++++++++++++++++++- tests/template/templates/loop_advanced_twig.html | 19 +++ tests/template/templates/loop_expressions.html | 4 +- .../template/templates/loop_expressions_twig.html | 11 ++ tests/template/templates/loop_include1_twig.html | 1 + tests/template/templates/loop_include_twig.html | 4 + tests/template/templates/loop_nested2_twig.html | 6 + .../loop_nested_deep_multilevel_ref_twig.html | 13 ++ .../templates/loop_nested_include1_twig.html | 5 + .../templates/loop_nested_include_twig.html | 4 + .../templates/loop_nested_multilevel_ref_twig.html | 10 ++ tests/template/templates/loop_nested_twig.html | 6 + tests/template/templates/loop_reuse_twig.html | 6 + tests/template/templates/loop_size_twig.html | 39 ++++++ tests/template/templates/loop_twig.html | 21 +++ tests/template/templates/loop_underscore_twig.html | 21 +++ tests/template/templates/loop_vars_twig.html | 13 ++ 17 files changed, 329 insertions(+), 3 deletions(-) create mode 100644 tests/template/templates/loop_advanced_twig.html create mode 100644 tests/template/templates/loop_expressions_twig.html create mode 100644 tests/template/templates/loop_include1_twig.html create mode 100644 tests/template/templates/loop_include_twig.html create mode 100644 tests/template/templates/loop_nested2_twig.html create mode 100644 tests/template/templates/loop_nested_deep_multilevel_ref_twig.html create mode 100644 tests/template/templates/loop_nested_include1_twig.html create mode 100644 tests/template/templates/loop_nested_include_twig.html create mode 100644 tests/template/templates/loop_nested_multilevel_ref_twig.html create mode 100644 tests/template/templates/loop_nested_twig.html create mode 100644 tests/template/templates/loop_reuse_twig.html create mode 100644 tests/template/templates/loop_size_twig.html create mode 100644 tests/template/templates/loop_twig.html create mode 100644 tests/template/templates/loop_underscore_twig.html create mode 100644 tests/template/templates/loop_vars_twig.html (limited to 'tests/template') diff --git a/tests/template/template_test.php b/tests/template/template_test.php index bb6b7300cb..b67b49bd35 100644 --- a/tests/template/template_test.php +++ b/tests/template/template_test.php @@ -129,6 +129,34 @@ class phpbb_template_template_test extends phpbb_template_template_test_case array(), "loop\nloop\nloop\nloop\nloop#0-block#0\nloop#0-block#1\nloop#1-block#0\nloop#1-block#1", ), + array( + 'loop_twig.html', + array(), + array(), + array(), + "noloop\nnoloop", + ), + array( + 'loop_twig.html', + array(), + array('test_loop' => array(array())), + array(), + "loop\nloop", + ), + array( + 'loop_twig.html', + array(), + array('test_loop' => array(array(), array()), 'test_loop.block' => array(array())), + array(), + "loop\nloop\nloop\nloop", + ), + array( + 'loop_twig.html', + array(), + array('test_loop' => array(array(), array()), 'test_loop.block' => array(array()), 'block' => array(array(), array())), + array(), + "loop\nloop\nloop\nloop\nloop#0-block#0\nloop#0-block#1\nloop#1-block#0\nloop#1-block#1", + ), array( 'loop_vars.html', array(), @@ -150,6 +178,27 @@ class phpbb_template_template_test extends phpbb_template_template_test_case array(), "first\n0 - a\nx - b\nset\n1 - a\ny - b\nset\nlast\n0 - c\n1 - c\nlast inner", ), + array( + 'loop_vars_twig.html', + array(), + array('test_loop' => array(array('VARIABLE' => 'x'))), + array(), + "first\n0 - a\nx - b\nset\nlast", + ), + array( + 'loop_vars_twig.html', + array(), + array('test_loop' => array(array('VARIABLE' => 'x'), array('VARIABLE' => 'y'))), + array(), + "first\n0 - a\nx - b\nset\n1 - a\ny - b\nset\nlast", + ), + array( + 'loop_vars_twig.html', + array(), + array('test_loop' => array(array('VARIABLE' => 'x'), array('VARIABLE' => 'y')), 'test_loop.inner' => array(array(), array())), + array(), + "first\n0 - a\nx - b\nset\n1 - a\ny - b\nset\nlast\n0 - c\n1 - c\nlast inner", + ), array( 'loop_advanced.html', array(), @@ -157,6 +206,13 @@ class phpbb_template_template_test extends phpbb_template_template_test_case array(), "101234561\nx\n101234561\nx\n101234561\nx\n1234561\nx\n1\nx\n101\nx\n234\nx\n10\nx\n561\nx\n561", ), + array( + 'loop_advanced_twig.html', + array(), + array('test_loop' => array(array(), array(), array(), array(), array(), array(), array())), + array(), + "101234561\nx\n101234561\nx\n101234561\nx\n1234561\nx\n1\nx\n101\nx\n234\nx\n10\nx\n561\nx\n561", + ), array( 'loop_nested2.html', array(), @@ -164,6 +220,13 @@ class phpbb_template_template_test extends phpbb_template_template_test_case array(), "o0o1m01m11", ), + array( + 'loop_nested2_twig.html', + array(), + array('outer' => array(array(), array()), 'outer.middle' => array(array(), array())), + array(), + "o0o1m01m11", + ), array( 'define.html', array(), @@ -243,6 +306,13 @@ class phpbb_template_template_test extends phpbb_template_template_test_case array('test_loop'), '', ), + array( + 'loop_vars_twig.html', + array(), + array('test_loop' => array(array('VARIABLE' => 'x'), array('VARIABLE' => 'y')), 'test_loop.inner' => array(array(), array())), + array('test_loop'), + '', + ), array( 'include_define_variable.html', array('VARIABLE' => 'variable.html'), @@ -274,6 +344,15 @@ class phpbb_template_template_test extends phpbb_template_template_test_case array(), "noloop\nnoloop", ), + array( + // Just like a regular loop but the name begins + // with an underscore + 'loop_underscore_twig.html', + array(), + array(), + array(), + "noloop\nnoloop", + ), array( 'lang.html', array(), @@ -296,6 +375,13 @@ class phpbb_template_template_test extends phpbb_template_template_test_case array(), "top-level content", ), + array( + 'loop_nested_multilevel_ref_twig.html', + array(), + array(), + array(), + "top-level content", + ), array( 'loop_nested_multilevel_ref.html', array(), @@ -303,6 +389,13 @@ class phpbb_template_template_test extends phpbb_template_template_test_case array(), "top-level content\nouter x\nouter y\ninner z\nfirst row\n\ninner zz", ), + array( + 'loop_nested_multilevel_ref_twig.html', + array(), + array('outer' => array(array('VARIABLE' => 'x'), array('VARIABLE' => 'y')), 'outer.inner' => array(array('VARIABLE' => 'z'), array('VARIABLE' => 'zz'))), + array(), + "top-level content\nouter x\nouter y\ninner z\nfirst row\n\ninner zz", + ), array( 'loop_nested_deep_multilevel_ref.html', array(), @@ -310,6 +403,13 @@ class phpbb_template_template_test extends phpbb_template_template_test_case array(), "top-level content\nouter\nmiddle\ninner z\nfirst row of 2 in inner\n\ninner zz", ), + array( + 'loop_nested_deep_multilevel_ref_twig.html', + array(), + array('outer' => array(array()), 'outer.middle' => array(array()), 'outer.middle.inner' => array(array('VARIABLE' => 'z'), array('VARIABLE' => 'zz'))), + array(), + "top-level content\nouter\nmiddle\ninner z\nfirst row of 2 in inner\n\ninner zz", + ), array( 'loop_size.html', array(), @@ -317,6 +417,13 @@ class phpbb_template_template_test extends phpbb_template_template_test_case array(), "nonexistent = 0\n! nonexistent\n\nempty = 0\n! empty\nloop\n\nin loop", ), + array( + 'loop_size_twig.html', + array(), + array('test_loop' => array(array()), 'empty_loop' => array()), + array(), + "nonexistent = 0\n! nonexistent\n\nempty = 0\n! empty\nloop\n\nin loop", + ), array( 'loop_include.html', array(), @@ -324,6 +431,13 @@ class phpbb_template_template_test extends phpbb_template_template_test_case array(), "barbarbar1bar1", ), + array( + 'loop_include_twig.html', + array(), + array('test_loop' => array(array('foo' => 'bar'), array('foo' => 'bar1'))), + array(), + "barbarbar1bar1", + ), array( 'loop_nested_include.html', array(), @@ -335,6 +449,17 @@ class phpbb_template_template_test extends phpbb_template_template_test_case "[bar|[bar|]][bar1|[bar1|[bar1|works]]]", array(), ), + array( + 'loop_nested_include_twig.html', + array(), + array( + 'test_loop' => array(array('foo' => 'bar'), array('foo' => 'bar1')), + 'test_loop.inner' => array(array('myinner' => 'works')), + ), + array(), + "[bar|[bar|]][bar1|[bar1|[bar1|works]]]", + array(), + ), /* Does not pass with the current implementation. array( 'loop_reuse.html', @@ -343,8 +468,15 @@ class phpbb_template_template_test extends phpbb_template_template_test_case array(), // Not entirely sure what should be outputted but the current output of "a" is most certainly wrong "a\nb\nc\nd", + ),*/ + array( + 'loop_reuse_twig.html', + array(), + array('one' => array(array('VAR' => 'a'), array('VAR' => 'b')), 'one.one' => array(array('VAR' => 'c'), array('VAR' => 'd'))), + array(), + // Not entirely sure what should be outputted but the current output of "a" is most certainly wrong + "a\nb\nc\nd", ), - */ array( 'twig.html', array('VARIABLE' => 'FOObar',), @@ -359,6 +491,21 @@ class phpbb_template_template_test extends phpbb_template_template_test_case array(), 'inner_value', ), + // Disable: needs Twig 1.14.2 + /*array( + 'loop_expressions.html', + array('loop' => array(array(),array(),array(),array(),array(),array()),), + array(), + array(), + 'yesnonoyesnonoyesnoyesnonoyes', + ), + array( + 'loop_expressions_twig.html', + array('loop' => array(array(),array(),array(),array(),array(),array()),), + array(), + array(), + 'yesnonoyesnonoyesnoyesnonoyes', + ),*/ ); } diff --git a/tests/template/templates/loop_advanced_twig.html b/tests/template/templates/loop_advanced_twig.html new file mode 100644 index 0000000000..fd9fcae045 --- /dev/null +++ b/tests/template/templates/loop_advanced_twig.html @@ -0,0 +1,19 @@ +{% for test_loop_inner in test_loop %}{{ test_loop_inner.S_FIRST_ROW }}{{ test_loop_inner.S_ROW_COUNT }}{{ test_loop_inner.S_LAST_ROW }}{% endfor %} +x +{% for test_loop_inner in test_loop|subset(0) %}{{ test_loop_inner.S_FIRST_ROW }}{{ test_loop_inner.S_ROW_COUNT }}{{ test_loop_inner.S_LAST_ROW }}{% endfor %} +x +{% for test_loop_inner in test_loop|subset(0,-1) %}{{ test_loop_inner.S_FIRST_ROW }}{{ test_loop_inner.S_ROW_COUNT }}{{ test_loop_inner.S_LAST_ROW }}{% endfor %} +x +{% for test_loop_inner in test_loop|subset(1) %}{{ test_loop_inner.S_FIRST_ROW }}{{ test_loop_inner.S_ROW_COUNT }}{{ test_loop_inner.S_LAST_ROW }}{% endfor %} +x +{% for test_loop_inner in test_loop|subset(1,1) %}{{ test_loop_inner.S_FIRST_ROW }}{{ test_loop_inner.S_ROW_COUNT }}{{ test_loop_inner.S_LAST_ROW }}{% endfor %} +x +{% for test_loop_inner in test_loop|subset(0,1) %}{{ test_loop_inner.S_FIRST_ROW }}{{ test_loop_inner.S_ROW_COUNT }}{{ test_loop_inner.S_LAST_ROW }}{% endfor %} +x +{% for test_loop_inner in test_loop|subset(2,4) %}{{ test_loop_inner.S_FIRST_ROW }}{{ test_loop_inner.S_ROW_COUNT }}{{ test_loop_inner.S_LAST_ROW }}{% endfor %} +x +{% for test_loop_inner in test_loop|subset(0,-7) %}{{ test_loop_inner.S_FIRST_ROW }}{{ test_loop_inner.S_ROW_COUNT }}{{ test_loop_inner.S_LAST_ROW }}{% endfor %} +x +{% for test_loop_inner in test_loop|subset(-2,6) %}{{ test_loop_inner.S_FIRST_ROW }}{{ test_loop_inner.S_ROW_COUNT }}{{ test_loop_inner.S_LAST_ROW }}{% endfor %} +x +{% for test_loop_inner in test_loop|subset(-2,-1) %}{{ test_loop_inner.S_FIRST_ROW }}{{ test_loop_inner.S_ROW_COUNT }}{{ test_loop_inner.S_LAST_ROW }}{% endfor %} diff --git a/tests/template/templates/loop_expressions.html b/tests/template/templates/loop_expressions.html index 6bff53f388..278bce1eca 100644 --- a/tests/template/templates/loop_expressions.html +++ b/tests/template/templates/loop_expressions.html @@ -1,11 +1,11 @@ -onoff +onoff -onoff +onoff diff --git a/tests/template/templates/loop_expressions_twig.html b/tests/template/templates/loop_expressions_twig.html new file mode 100644 index 0000000000..61a36c51e4 --- /dev/null +++ b/tests/template/templates/loop_expressions_twig.html @@ -0,0 +1,11 @@ +{% for loop_inner in loop %} + +{% if loop_inner.S_ROW_NUM is divisible by 4 %}on{% else %}off{% endif %} + +{% endfor %} + +{% for loop_inner in loop %} + +{% if loop_inner.S_ROW_NUM is divisible by 3 %}on{% else %}off{% endif %} + +{% endfor %} diff --git a/tests/template/templates/loop_include1_twig.html b/tests/template/templates/loop_include1_twig.html new file mode 100644 index 0000000000..2ff9f61b02 --- /dev/null +++ b/tests/template/templates/loop_include1_twig.html @@ -0,0 +1 @@ +{{ test_loop_inner.foo }} diff --git a/tests/template/templates/loop_include_twig.html b/tests/template/templates/loop_include_twig.html new file mode 100644 index 0000000000..1a534e2dbc --- /dev/null +++ b/tests/template/templates/loop_include_twig.html @@ -0,0 +1,4 @@ +{% for test_loop_inner in test_loop %} + {{ test_loop_inner.foo }} + {% INCLUDE 'loop_include1_twig.html' %} +{% endfor %} diff --git a/tests/template/templates/loop_nested2_twig.html b/tests/template/templates/loop_nested2_twig.html new file mode 100644 index 0000000000..cf802dc69f --- /dev/null +++ b/tests/template/templates/loop_nested2_twig.html @@ -0,0 +1,6 @@ +{% for outer_inner in outer %} + o{{ outer_inner.S_ROW_COUNT }} + {% for middle in outer_inner.middle %} + m{{ middle.S_ROW_COUNT }}{{ outer_inner.S_ROW_COUNT }} + {% endfor %} +{% endfor %} diff --git a/tests/template/templates/loop_nested_deep_multilevel_ref_twig.html b/tests/template/templates/loop_nested_deep_multilevel_ref_twig.html new file mode 100644 index 0000000000..9bc68e6e2e --- /dev/null +++ b/tests/template/templates/loop_nested_deep_multilevel_ref_twig.html @@ -0,0 +1,13 @@ +top-level content +{% for outer_inner in outer %} + outer + {% for middle in outer_inner.middle %} + {{ middle.S_BLOCK_NAME }} + {% for inner in middle.inner %} + inner {{ inner.VARIABLE }} + {% if inner.S_FIRST_ROW %} + first row of {{ inner.S_NUM_ROWS }} in {{ inner.S_BLOCK_NAME }} + {% endif %} + {% endfor %} + {% endfor %} +{% endfor %} diff --git a/tests/template/templates/loop_nested_include1_twig.html b/tests/template/templates/loop_nested_include1_twig.html new file mode 100644 index 0000000000..4c2ebb5f15 --- /dev/null +++ b/tests/template/templates/loop_nested_include1_twig.html @@ -0,0 +1,5 @@ +[{{ test_loop_inner.foo }}| +{% for inner in test_loop_inner.inner %} + [{{ test_loop_inner.foo }}| + {{ inner.myinner }}] +{% endfor %}] diff --git a/tests/template/templates/loop_nested_include_twig.html b/tests/template/templates/loop_nested_include_twig.html new file mode 100644 index 0000000000..c92ac922d1 --- /dev/null +++ b/tests/template/templates/loop_nested_include_twig.html @@ -0,0 +1,4 @@ +{% for test_loop_inner in test_loop %} + [{{ test_loop_inner.foo }} + |{% INCLUDE 'loop_nested_include1_twig.html' %}] +{% endfor %} diff --git a/tests/template/templates/loop_nested_multilevel_ref_twig.html b/tests/template/templates/loop_nested_multilevel_ref_twig.html new file mode 100644 index 0000000000..336a57d0bc --- /dev/null +++ b/tests/template/templates/loop_nested_multilevel_ref_twig.html @@ -0,0 +1,10 @@ +top-level content +{% for outer_inner in outer %} + outer {{ outer_inner.VARIABLE }} + {% for inner in outer_inner.inner %} + inner {{ inner.VARIABLE }} + {% if inner.S_FIRST_ROW %} + first row + {% endif %} + {% endfor %} +{% endfor %} diff --git a/tests/template/templates/loop_nested_twig.html b/tests/template/templates/loop_nested_twig.html new file mode 100644 index 0000000000..b294226b3a --- /dev/null +++ b/tests/template/templates/loop_nested_twig.html @@ -0,0 +1,6 @@ +{% for outer_inner in outer %} +outer - {{ outer_inner.S_ROW_COUNT }}{% if outer_inner.VARIABLE %} - {{ outer_inner.VARIABLE }}{% endif %}{% if TEST_MORE %}[{{ outer_inner.S_BLOCK_NAME }}|{{ outer_inner.S_NUM_ROWS }}]{% endif %} +{% for middle in outer_inner.middle %} +middle - {{ middle.S_ROW_COUNT }}{% if middle.VARIABLE %} - {{ middle.VARIABLE }}{% endif %}{% if TEST_MORE %}[{{ middle.S_BLOCK_NAME }}|{{ middle.S_NUM_ROWS }}]{% endif %} +{% endfor %} +{% endfor %} diff --git a/tests/template/templates/loop_reuse_twig.html b/tests/template/templates/loop_reuse_twig.html new file mode 100644 index 0000000000..67452a737f --- /dev/null +++ b/tests/template/templates/loop_reuse_twig.html @@ -0,0 +1,6 @@ +{% for one_inner in one %} + {{ one_inner.VAR }} + {% for one_one_inner in one_inner.one %} + {{ one_one_inner.VAR }} + {% endfor %} +{% endfor %} diff --git a/tests/template/templates/loop_size_twig.html b/tests/template/templates/loop_size_twig.html new file mode 100644 index 0000000000..f6d2571e11 --- /dev/null +++ b/tests/template/templates/loop_size_twig.html @@ -0,0 +1,39 @@ +{% if nonexistent_loop|length %} +nonexistent +{% endif %} + +{% if nonexistent_loop|length == 0 %} +nonexistent = 0 +{% endif %} + +{% if ! nonexistent_loop|length %} +! nonexistent +{% endif %} + +{% if empty_loop|length %} +empty +{% endif %} + +{% if empty_loop|length == 0 %} +empty = 0 +{% endif %} + +{% if ! empty_loop|length %} +! empty +{% endif %} + +{% if test_loop|length %} +loop +{% endif %} + +{% if test_loop|length == 0 %} +loop = 0 +{% endif %} + +{% if ! test_loop|length %} +! loop +{% endif %} + +{% for test_loop_inner in test_loop %} +in loop +{% endfor %} diff --git a/tests/template/templates/loop_twig.html b/tests/template/templates/loop_twig.html new file mode 100644 index 0000000000..fb24f331b3 --- /dev/null +++ b/tests/template/templates/loop_twig.html @@ -0,0 +1,21 @@ +{% for test_loop_inner in test_loop %} +loop +{% else %} +noloop +{% endfor %} + +{% if test_loop|length %} +loop +{% else %} +noloop +{% endif %} + +{% if test_loop|length == 2 %} +loop +{% endif %} + +{% for test_loop_inner in test_loop %} +{% for block_inner in block %} +loop#{{ test_loop_inner.S_ROW_COUNT }}-block#{{ block_inner.S_ROW_COUNT }} +{% endfor %} +{% endfor %} diff --git a/tests/template/templates/loop_underscore_twig.html b/tests/template/templates/loop_underscore_twig.html new file mode 100644 index 0000000000..44b095c882 --- /dev/null +++ b/tests/template/templates/loop_underscore_twig.html @@ -0,0 +1,21 @@ +{% for _underscore_loop_inner in _underscore_loop %} +loop +{% else %} +noloop +{% endfor %} + +{% if _underscore_loop|length %} +loop +{% else %} +noloop +{% endif %} + +{% if _underscore_loop|length == 2 %} +loop +{% endif %} + +{% for _underscore_loop_inner in _underscore_loop %} +{% for block_inner in block %} +loop#{{ loop.S_ROW_COUNT }}-block#{{ block_inner.S_ROW_COUNT }} +{% endfor %} +{% endfor %} diff --git a/tests/template/templates/loop_vars_twig.html b/tests/template/templates/loop_vars_twig.html new file mode 100644 index 0000000000..af6c63d8e3 --- /dev/null +++ b/tests/template/templates/loop_vars_twig.html @@ -0,0 +1,13 @@ +{% for test_loop_inner in test_loop %} +{% if test_loop_inner.S_FIRST_ROW %}first{% endif %} +{{ test_loop_inner.S_ROW_NUM }} - a +{{ test_loop_inner.VARIABLE }} - b +{% if test_loop_inner.VARIABLE %}set{% endif %} +{% if test_loop_inner.S_LAST_ROW %} +last +{% endif %} +{% for inner_inner in test_loop_inner.inner %} +{{ inner_inner.S_ROW_NUM }} - c +{% if inner_inner.S_LAST_ROW and inner_inner.S_ROW_COUNT and inner_inner.S_NUM_ROWS %}last inner{% endif %} +{% endfor %} +{% endfor %} -- cgit v1.2.1 From 54753e926df28b686937394bc675130647893639 Mon Sep 17 00:00:00 2001 From: Nicofuma Date: Thu, 5 Mar 2015 21:53:48 +0100 Subject: [ticket/13132] Enable twig expressions tests PHPBB3-13132 --- tests/template/template_test.php | 18 ++++++++++++------ tests/template/templates/loop_expressions.html | 4 ++-- tests/template/templates/loop_expressions_twig.html | 4 ++-- tests/template/templates/loop_expressions_twig2.html | 11 +++++++++++ 4 files changed, 27 insertions(+), 10 deletions(-) create mode 100644 tests/template/templates/loop_expressions_twig2.html (limited to 'tests/template') diff --git a/tests/template/template_test.php b/tests/template/template_test.php index b67b49bd35..33dc4ca551 100644 --- a/tests/template/template_test.php +++ b/tests/template/template_test.php @@ -491,21 +491,27 @@ class phpbb_template_template_test extends phpbb_template_template_test_case array(), 'inner_value', ), - // Disable: needs Twig 1.14.2 - /*array( + array( 'loop_expressions.html', - array('loop' => array(array(),array(),array(),array(),array(),array()),), array(), + array('loop' => array(array(),array(),array(),array(),array(),array()),), array(), - 'yesnonoyesnonoyesnoyesnonoyes', + 'yesnononoyesnoyesnonoyesnono', ), array( 'loop_expressions_twig.html', + array(), + array('loop' => array(array(),array(),array(),array(),array(),array()),), + array(), + 'yesnononoyesnoyesnonoyesnono', + ), + array( + 'loop_expressions_twig2.html', array('loop' => array(array(),array(),array(),array(),array(),array()),), array(), array(), - 'yesnonoyesnonoyesnoyesnonoyes', - ),*/ + 'yesnononoyesnoyesnonoyesnono', + ), ); } diff --git a/tests/template/templates/loop_expressions.html b/tests/template/templates/loop_expressions.html index 278bce1eca..ddb9fd52fa 100644 --- a/tests/template/templates/loop_expressions.html +++ b/tests/template/templates/loop_expressions.html @@ -1,11 +1,11 @@ -onoff +yesno -onoff +yesno diff --git a/tests/template/templates/loop_expressions_twig.html b/tests/template/templates/loop_expressions_twig.html index 61a36c51e4..5ca8cc3601 100644 --- a/tests/template/templates/loop_expressions_twig.html +++ b/tests/template/templates/loop_expressions_twig.html @@ -1,11 +1,11 @@ {% for loop_inner in loop %} -{% if loop_inner.S_ROW_NUM is divisible by 4 %}on{% else %}off{% endif %} +{% if loop_inner.S_ROW_NUM is divisible by(4) %}yes{% else %}no{% endif %} {% endfor %} {% for loop_inner in loop %} -{% if loop_inner.S_ROW_NUM is divisible by 3 %}on{% else %}off{% endif %} +{% if loop_inner.S_ROW_NUM is divisible by(3) %}yes{% else %}no{% endif %} {% endfor %} diff --git a/tests/template/templates/loop_expressions_twig2.html b/tests/template/templates/loop_expressions_twig2.html new file mode 100644 index 0000000000..16159ead4c --- /dev/null +++ b/tests/template/templates/loop_expressions_twig2.html @@ -0,0 +1,11 @@ +{% for loop_inner in loop %} + +{% if loop.index0 is divisible by(4) %}yes{% else %}no{% endif %} + +{% endfor %} + +{% for loop_inner in loop %} + +{% if loop.index0 is divisible by(3) %}yes{% else %}no{% endif %} + +{% endfor %} -- cgit v1.2.1 From 4bdef6fd21a5dcab455b0cd1ee2652de606929c3 Mon Sep 17 00:00:00 2001 From: MateBartus Date: Thu, 12 Mar 2015 00:25:00 +0100 Subject: [ticket/13697] Moving filesystem related functions to filesystem service * Moving filesystem service to \phpbb\filesystem namespace * Wraping Symfony's Filesystem component * Moving filesystem related functions from includes/functions.php into \phpbb\filesystem\filesystem Functions moved (and deprecated): - phpbb_chmod - phpbb_is_writable - phpbb_is_absolute - phpbb_own_realpath - phpbb_realpath * Adding interface for filesystem service PHPBB3-13697 --- tests/template/includephp_test.php | 3 ++- tests/template/template_allfolder_test.php | 4 ++-- tests/template/template_events_test.php | 4 ++-- tests/template/template_includecss_test.php | 4 ++-- tests/template/template_test_case.php | 8 ++++++-- tests/template/template_test_case_with_tree.php | 4 ++-- 6 files changed, 16 insertions(+), 11 deletions(-) (limited to 'tests/template') diff --git a/tests/template/includephp_test.php b/tests/template/includephp_test.php index fdddbef4f2..722e10e42d 100644 --- a/tests/template/includephp_test.php +++ b/tests/template/includephp_test.php @@ -39,8 +39,9 @@ class phpbb_template_includephp_test extends phpbb_template_template_test_case { global $phpbb_root_path; + $filesystem = new \phpbb\filesystem\filesystem(); $path_to_php = str_replace('\\', '/', dirname(__FILE__)) . '/templates/_dummy_include.php.inc'; - $this->assertTrue(phpbb_is_absolute($path_to_php)); + $this->assertTrue($filesystem->is_absolute_path($path_to_php)); $template_text = "Path is absolute.\n"; $cache_dir = $phpbb_root_path . 'cache/'; diff --git a/tests/template/template_allfolder_test.php b/tests/template/template_allfolder_test.php index e87688a57c..f739a78d84 100644 --- a/tests/template/template_allfolder_test.php +++ b/tests/template/template_allfolder_test.php @@ -34,7 +34,7 @@ class phpbb_template_allfolder_test extends phpbb_template_template_test_case new \phpbb\symfony_request( new phpbb_mock_request() ), - new \phpbb\filesystem(), + new \phpbb\filesystem\filesystem(), $this->getMock('\phpbb\request\request'), $phpbb_root_path, $phpEx @@ -54,7 +54,7 @@ class phpbb_template_allfolder_test extends phpbb_template_template_test_case $container = new phpbb_mock_container_builder(); $cache_path = $phpbb_root_path . 'cache/twig'; $context = new \phpbb\template\context(); - $loader = new \phpbb\template\twig\loader(''); + $loader = new \phpbb\template\twig\loader(new \phpbb\filesystem\filesystem(), ''); $twig = new \phpbb\template\twig\environment( $config, $path_helper, diff --git a/tests/template/template_events_test.php b/tests/template/template_events_test.php index e8ffea8d11..6d1b7253e3 100644 --- a/tests/template/template_events_test.php +++ b/tests/template/template_events_test.php @@ -142,7 +142,7 @@ Zeta test event in all', new \phpbb\symfony_request( new phpbb_mock_request() ), - new \phpbb\filesystem(), + new \phpbb\filesystem\filesystem(), $this->getMock('\phpbb\request\request'), $phpbb_root_path, $phpEx @@ -151,7 +151,7 @@ Zeta test event in all', $container = new phpbb_mock_container_builder(); $cache_path = $phpbb_root_path . 'cache/twig'; $context = new \phpbb\template\context(); - $loader = new \phpbb\template\twig\loader(''); + $loader = new \phpbb\template\twig\loader(new \phpbb\filesystem\filesystem(), ''); $twig = new \phpbb\template\twig\environment( $config, $path_helper, diff --git a/tests/template/template_includecss_test.php b/tests/template/template_includecss_test.php index 96980e17c6..7a73d1f888 100644 --- a/tests/template/template_includecss_test.php +++ b/tests/template/template_includecss_test.php @@ -32,7 +32,7 @@ class phpbb_template_template_includecss_test extends phpbb_template_template_te new \phpbb\symfony_request( new phpbb_mock_request() ), - new \phpbb\filesystem(), + new \phpbb\filesystem\filesystem(), $this->getMock('\phpbb\request\request'), $phpbb_root_path, $phpEx @@ -43,7 +43,7 @@ class phpbb_template_template_includecss_test extends phpbb_template_template_te $container = new phpbb_mock_container_builder(); $cache_path = $phpbb_root_path . 'cache/twig'; $context = new \phpbb\template\context(); - $loader = new \phpbb\template\twig\loader(''); + $loader = new \phpbb\template\twig\loader(new \phpbb\filesystem\filesystem(), ''); $twig = new \phpbb\template\twig\environment( $config, $this->phpbb_path_helper, diff --git a/tests/template/template_test_case.php b/tests/template/template_test_case.php index f9ea8cfaba..29ff669efc 100644 --- a/tests/template/template_test_case.php +++ b/tests/template/template_test_case.php @@ -71,7 +71,7 @@ class phpbb_template_template_test_case extends phpbb_test_case new \phpbb\symfony_request( new phpbb_mock_request() ), - new \phpbb\filesystem(), + new \phpbb\filesystem\filesystem(), $this->getMock('\phpbb\request\request'), $phpbb_root_path, $phpEx @@ -82,7 +82,7 @@ class phpbb_template_template_test_case extends phpbb_test_case $container = new phpbb_mock_container_builder(); $cache_path = $phpbb_root_path . 'cache/twig'; $context = new \phpbb\template\context(); - $loader = new \phpbb\template\twig\loader(''); + $loader = new \phpbb\template\twig\loader(new \phpbb\filesystem\filesystem(), ''); $twig = new \phpbb\template\twig\environment( $config, $path_helper, @@ -108,6 +108,10 @@ class phpbb_template_template_test_case extends phpbb_test_case $this->setup_engine(); $this->template->clear_cache(); + + global $phpbb_filesystem; + + $phpbb_filesystem = new \phpbb\filesystem\filesystem(); } protected function tearDown() diff --git a/tests/template/template_test_case_with_tree.php b/tests/template/template_test_case_with_tree.php index c634e2051a..eab83f379a 100644 --- a/tests/template/template_test_case_with_tree.php +++ b/tests/template/template_test_case_with_tree.php @@ -26,7 +26,7 @@ class phpbb_template_template_test_case_with_tree extends phpbb_template_templat new \phpbb\symfony_request( new phpbb_mock_request() ), - new \phpbb\filesystem(), + new \phpbb\filesystem\filesystem(), $this->getMock('\phpbb\request\request'), $phpbb_root_path, $phpEx @@ -38,7 +38,7 @@ class phpbb_template_template_test_case_with_tree extends phpbb_template_templat $container = new phpbb_mock_container_builder(); $cache_path = $phpbb_root_path . 'cache/twig'; $context = new \phpbb\template\context(); - $loader = new \phpbb\template\twig\loader(''); + $loader = new \phpbb\template\twig\loader(new \phpbb\filesystem\filesystem(), ''); $twig = new \phpbb\template\twig\environment( $config, $this->phpbb_path_helper, -- cgit v1.2.1 From 179a4700221aa49071b07d638c44b9326c7a14a8 Mon Sep 17 00:00:00 2001 From: MateBartus Date: Tue, 14 Apr 2015 02:31:23 +0200 Subject: [ticket/13762] Moving language related functionality into a separate class PHPBB3-13762 --- tests/template/template_allfolder_test.php | 5 ++++- tests/template/template_test_case.php | 22 ++++++++++++++++++++-- 2 files changed, 24 insertions(+), 3 deletions(-) (limited to 'tests/template') diff --git a/tests/template/template_allfolder_test.php b/tests/template/template_allfolder_test.php index f739a78d84..63f35bc758 100644 --- a/tests/template/template_allfolder_test.php +++ b/tests/template/template_allfolder_test.php @@ -28,7 +28,10 @@ class phpbb_template_allfolder_test extends phpbb_template_template_test_case $defaults = $this->config_defaults(); $config = new \phpbb\config\config(array_merge($defaults, $new_config)); - $this->user = new \phpbb\user('\phpbb\datetime'); + $lang_loader = new \phpbb\language\language_file_loader($phpbb_root_path, $phpEx); + $lang = new \phpbb\language\language($lang_loader); + $user = new \phpbb\user($lang, '\phpbb\datetime'); + $this->user = $user; $path_helper = new \phpbb\path_helper( new \phpbb\symfony_request( diff --git a/tests/template/template_test_case.php b/tests/template/template_test_case.php index 29ff669efc..7e2020ba09 100644 --- a/tests/template/template_test_case.php +++ b/tests/template/template_test_case.php @@ -15,6 +15,7 @@ require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php'; class phpbb_template_template_test_case extends phpbb_test_case { + protected $lang; protected $template; protected $template_path; protected $user; @@ -24,6 +25,17 @@ class phpbb_template_template_test_case extends phpbb_test_case // Keep the contents of the cache for debugging? const PRESERVE_CACHE = true; + static protected $language_reflection_lang; + + static public function setUpBeforeClass() + { + parent::setUpBeforeClass(); + + $reflection = new ReflectionClass('\phpbb\language\language'); + self::$language_reflection_lang = $reflection->getProperty('lang'); + self::$language_reflection_lang->setAccessible(true); + } + protected function display($handle) { ob_start(); @@ -65,7 +77,10 @@ class phpbb_template_template_test_case extends phpbb_test_case $defaults = $this->config_defaults(); $config = new \phpbb\config\config(array_merge($defaults, $new_config)); - $this->user = new \phpbb\user('\phpbb\datetime'); + $lang_loader = new \phpbb\language\language_file_loader($phpbb_root_path, $phpEx); + $this->lang = $lang = new \phpbb\language\language($lang_loader); + $user = new \phpbb\user($lang, '\phpbb\datetime'); + $this->user = $user; $path_helper = new \phpbb\path_helper( new \phpbb\symfony_request( @@ -145,7 +160,10 @@ class phpbb_template_template_test_case extends phpbb_test_case { foreach ($lang_vars as $name => $value) { - $this->user->lang[$name] = $value; + self::$language_reflection_lang->setValue($this->lang, array_merge( + self::$language_reflection_lang->getValue($this->lang), + array($name => $value) + )); } } -- cgit v1.2.1 From 321ed2a3dd10231a09dec18a85a783a73ba12ddf Mon Sep 17 00:00:00 2001 From: Nicofuma Date: Sun, 22 Feb 2015 22:43:53 +0100 Subject: [ticket/13638] Add tests PHPBB3-13638 --- tests/template/asset_test.php | 49 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 tests/template/asset_test.php (limited to 'tests/template') diff --git a/tests/template/asset_test.php b/tests/template/asset_test.php new file mode 100644 index 0000000000..f84ea2e3ee --- /dev/null +++ b/tests/template/asset_test.php @@ -0,0 +1,49 @@ + +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file. +* +*/ + +use phpbb\template\asset; + +class phpbb_template_asset_test extends phpbb_test_case +{ + public function set_path_data() + { + return array( + // array(phpbb_root_path, given path, expected path), + array('.', 'foo/bar', 'foo/bar'), + array('../', 'foo/bar', 'foo/bar'), + array('./phpBB/', 'foo/bar', 'foo/bar'), + array('../', __DIR__ . '/foo/bar', '../phpbb/tests/template/foo/bar'), + array('./', __DIR__ . '/foo/bar', './tests/template/foo/bar'), + array('./phpBB/', __DIR__ . '/foo/bar', 'tests/template/foo/bar'), + ); + } + + /** + * @dataProvider set_path_data + */ + public function test_set_path($phpbb_root_path, $path, $expected) + { + $path_helper = $this->getMockBuilder('\phpbb\path_helper') + ->disableOriginalConstructor() + ->setMethods(array()) + ->getMock(); + + $path_helper->method('get_phpbb_root_path') + ->willReturn($phpbb_root_path); + + $asset = new asset('', $path_helper); + + $asset->set_path($path, true); + $this->assertEquals($expected, $asset->get_path()); + } +} -- cgit v1.2.1 From 51376a43919cba7a5037edb7cc31f18b5950437b Mon Sep 17 00:00:00 2001 From: Nicofuma Date: Mon, 4 May 2015 23:50:16 +0200 Subject: [ticket/13638] Inject $filesystem in \phpbb\template\asset PHPBB3-13638 --- tests/template/asset_test.php | 2 +- tests/template/template_allfolder_test.php | 5 ++++- tests/template/template_events_test.php | 3 +++ tests/template/template_includecss_test.php | 5 ++++- tests/template/template_test_case.php | 5 ++++- tests/template/template_test_case_with_tree.php | 5 ++++- 6 files changed, 20 insertions(+), 5 deletions(-) (limited to 'tests/template') diff --git a/tests/template/asset_test.php b/tests/template/asset_test.php index f84ea2e3ee..f6ce0fe241 100644 --- a/tests/template/asset_test.php +++ b/tests/template/asset_test.php @@ -41,7 +41,7 @@ class phpbb_template_asset_test extends phpbb_test_case $path_helper->method('get_phpbb_root_path') ->willReturn($phpbb_root_path); - $asset = new asset('', $path_helper); + $asset = new asset('', $path_helper, new phpbb\filesystem\filesystem()); $asset->set_path($path, true); $this->assertEquals($expected, $asset->get_path()); diff --git a/tests/template/template_allfolder_test.php b/tests/template/template_allfolder_test.php index 63f35bc758..14a8e9d463 100644 --- a/tests/template/template_allfolder_test.php +++ b/tests/template/template_allfolder_test.php @@ -33,11 +33,13 @@ class phpbb_template_allfolder_test extends phpbb_template_template_test_case $user = new \phpbb\user($lang, '\phpbb\datetime'); $this->user = $user; + $filesystem = new \phpbb\filesystem\filesystem(); + $path_helper = new \phpbb\path_helper( new \phpbb\symfony_request( new phpbb_mock_request() ), - new \phpbb\filesystem\filesystem(), + $filesystem, $this->getMock('\phpbb\request\request'), $phpbb_root_path, $phpEx @@ -60,6 +62,7 @@ class phpbb_template_allfolder_test extends phpbb_template_template_test_case $loader = new \phpbb\template\twig\loader(new \phpbb\filesystem\filesystem(), ''); $twig = new \phpbb\template\twig\environment( $config, + $filesystem, $path_helper, $container, $cache_path, diff --git a/tests/template/template_events_test.php b/tests/template/template_events_test.php index 6d1b7253e3..285e82188b 100644 --- a/tests/template/template_events_test.php +++ b/tests/template/template_events_test.php @@ -138,6 +138,8 @@ Zeta test event in all', $this->extension_manager = new phpbb_mock_filesystem_extension_manager( dirname(__FILE__) . "/datasets/$dataset/" ); + + $filesystem = new \phpbb\filesystem\filesystem(); $path_helper = new \phpbb\path_helper( new \phpbb\symfony_request( new phpbb_mock_request() @@ -154,6 +156,7 @@ Zeta test event in all', $loader = new \phpbb\template\twig\loader(new \phpbb\filesystem\filesystem(), ''); $twig = new \phpbb\template\twig\environment( $config, + $filesystem, $path_helper, $container, $cache_path, diff --git a/tests/template/template_includecss_test.php b/tests/template/template_includecss_test.php index 7a73d1f888..8c398d992b 100644 --- a/tests/template/template_includecss_test.php +++ b/tests/template/template_includecss_test.php @@ -28,11 +28,13 @@ class phpbb_template_template_includecss_test extends phpbb_template_template_te $defaults = $this->config_defaults(); $config = new \phpbb\config\config(array_merge($defaults, $new_config)); + $filesystem = new \phpbb\filesystem\filesystem(); + $this->phpbb_path_helper = new \phpbb\path_helper( new \phpbb\symfony_request( new phpbb_mock_request() ), - new \phpbb\filesystem\filesystem(), + $filesystem, $this->getMock('\phpbb\request\request'), $phpbb_root_path, $phpEx @@ -46,6 +48,7 @@ class phpbb_template_template_includecss_test extends phpbb_template_template_te $loader = new \phpbb\template\twig\loader(new \phpbb\filesystem\filesystem(), ''); $twig = new \phpbb\template\twig\environment( $config, + $filesystem, $this->phpbb_path_helper, $container, $cache_path, diff --git a/tests/template/template_test_case.php b/tests/template/template_test_case.php index 7e2020ba09..b1826571af 100644 --- a/tests/template/template_test_case.php +++ b/tests/template/template_test_case.php @@ -82,11 +82,13 @@ class phpbb_template_template_test_case extends phpbb_test_case $user = new \phpbb\user($lang, '\phpbb\datetime'); $this->user = $user; + $filesystem = new \phpbb\filesystem\filesystem(); + $path_helper = new \phpbb\path_helper( new \phpbb\symfony_request( new phpbb_mock_request() ), - new \phpbb\filesystem\filesystem(), + $filesystem, $this->getMock('\phpbb\request\request'), $phpbb_root_path, $phpEx @@ -100,6 +102,7 @@ class phpbb_template_template_test_case extends phpbb_test_case $loader = new \phpbb\template\twig\loader(new \phpbb\filesystem\filesystem(), ''); $twig = new \phpbb\template\twig\environment( $config, + $filesystem, $path_helper, $container, $cache_path, diff --git a/tests/template/template_test_case_with_tree.php b/tests/template/template_test_case_with_tree.php index eab83f379a..d0c49006fd 100644 --- a/tests/template/template_test_case_with_tree.php +++ b/tests/template/template_test_case_with_tree.php @@ -22,11 +22,13 @@ class phpbb_template_template_test_case_with_tree extends phpbb_template_templat $defaults = $this->config_defaults(); $config = new \phpbb\config\config(array_merge($defaults, $new_config)); + $filesystem = new \phpbb\filesystem\filesystem(); + $this->phpbb_path_helper = new \phpbb\path_helper( new \phpbb\symfony_request( new phpbb_mock_request() ), - new \phpbb\filesystem\filesystem(), + $filesystem, $this->getMock('\phpbb\request\request'), $phpbb_root_path, $phpEx @@ -41,6 +43,7 @@ class phpbb_template_template_test_case_with_tree extends phpbb_template_templat $loader = new \phpbb\template\twig\loader(new \phpbb\filesystem\filesystem(), ''); $twig = new \phpbb\template\twig\environment( $config, + $filesystem, $this->phpbb_path_helper, $container, $cache_path, -- cgit v1.2.1 From 7b301e22f32e9209bb4e3ea17a5637a84a4ef908 Mon Sep 17 00:00:00 2001 From: MateBartus Date: Fri, 1 May 2015 19:04:21 +0200 Subject: [ticket/13804] Make template's user dependency optional PHPBB3-13804 --- tests/template/template_allfolder_test.php | 2 +- tests/template/template_events_test.php | 2 +- tests/template/template_includecss_test.php | 2 +- tests/template/template_test_case.php | 2 +- tests/template/template_test_case_with_tree.php | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) (limited to 'tests/template') diff --git a/tests/template/template_allfolder_test.php b/tests/template/template_allfolder_test.php index 14a8e9d463..9a0f1f512e 100644 --- a/tests/template/template_allfolder_test.php +++ b/tests/template/template_allfolder_test.php @@ -75,7 +75,7 @@ class phpbb_template_allfolder_test extends phpbb_template_template_test_case 'autoescape' => false, ) ); - $this->template = new \phpbb\template\twig\twig($path_helper, $config, $this->user, $context, $twig, $cache_path, array(new \phpbb\template\twig\extension($context, $this->user)), $this->extension_manager); + $this->template = new \phpbb\template\twig\twig($path_helper, $config, $context, $twig, $cache_path, $this->user, array(new \phpbb\template\twig\extension($context, $this->user)), $this->extension_manager); $container->set('template.twig.lexer', new \phpbb\template\twig\lexer($twig)); $this->template_path = $this->test_path . '/templates'; diff --git a/tests/template/template_events_test.php b/tests/template/template_events_test.php index 285e82188b..54e08652a1 100644 --- a/tests/template/template_events_test.php +++ b/tests/template/template_events_test.php @@ -169,7 +169,7 @@ Zeta test event in all', 'autoescape' => false, ) ); - $this->template = new \phpbb\template\twig\twig($path_helper, $config, $user, $context, $twig, $cache_path, array(new \phpbb\template\twig\extension($context, $this->user)), $this->extension_manager); + $this->template = new \phpbb\template\twig\twig($path_helper, $config, $context, $twig, $cache_path, $this->user, array(new \phpbb\template\twig\extension($context, $this->user)), $this->extension_manager); $container->set('template.twig.lexer', new \phpbb\template\twig\lexer($twig)); $this->template->set_custom_style(((!empty($style_names)) ? $style_names : 'silver'), array($this->template_path)); diff --git a/tests/template/template_includecss_test.php b/tests/template/template_includecss_test.php index 8c398d992b..062fc9493b 100644 --- a/tests/template/template_includecss_test.php +++ b/tests/template/template_includecss_test.php @@ -64,10 +64,10 @@ class phpbb_template_template_includecss_test extends phpbb_template_template_te $this->template = new phpbb\template\twig\twig( $this->phpbb_path_helper, $config, - $user, $context, $twig, $cache_path, + $this->user, array(new \phpbb\template\twig\extension($context, $this->user)), new phpbb_mock_extension_manager( dirname(__FILE__) . '/', diff --git a/tests/template/template_test_case.php b/tests/template/template_test_case.php index b1826571af..62eea0d361 100644 --- a/tests/template/template_test_case.php +++ b/tests/template/template_test_case.php @@ -115,7 +115,7 @@ class phpbb_template_template_test_case extends phpbb_test_case 'autoescape' => false, ) ); - $this->template = new phpbb\template\twig\twig($path_helper, $config, $user, $context, $twig, $cache_path, array(new \phpbb\template\twig\extension($context, $this->user))); + $this->template = new phpbb\template\twig\twig($path_helper, $config, $context, $twig, $cache_path, $this->user, array(new \phpbb\template\twig\extension($context, $this->user))); $container->set('template.twig.lexer', new \phpbb\template\twig\lexer($twig)); $this->template->set_custom_style('tests', $this->template_path); } diff --git a/tests/template/template_test_case_with_tree.php b/tests/template/template_test_case_with_tree.php index d0c49006fd..bf5de6b85e 100644 --- a/tests/template/template_test_case_with_tree.php +++ b/tests/template/template_test_case_with_tree.php @@ -56,7 +56,7 @@ class phpbb_template_template_test_case_with_tree extends phpbb_template_templat 'autoescape' => false, ) ); - $this->template = new phpbb\template\twig\twig($this->phpbb_path_helper, $config, $user, $context, $twig, $cache_path, array(new \phpbb\template\twig\extension($context, $this->user))); + $this->template = new phpbb\template\twig\twig($this->phpbb_path_helper, $config, $context, $twig, $cache_path, $this->user, array(new \phpbb\template\twig\extension($context, $this->user))); $container->set('template.twig.lexer', new \phpbb\template\twig\lexer($twig)); $this->template->set_custom_style('tests', array($this->template_path, $this->parent_template_path)); } -- cgit v1.2.1 From 737affcbb2f2e4f7ee5d8182a4e8cac599265ef4 Mon Sep 17 00:00:00 2001 From: Nicofuma Date: Thu, 14 May 2015 16:33:39 +0200 Subject: [ticket/13839] Don't be dependent on the phpBB root directory name in tests PHPBB3-13839 --- tests/template/asset_test.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests/template') diff --git a/tests/template/asset_test.php b/tests/template/asset_test.php index f6ce0fe241..3d2fdd8959 100644 --- a/tests/template/asset_test.php +++ b/tests/template/asset_test.php @@ -22,7 +22,7 @@ class phpbb_template_asset_test extends phpbb_test_case array('.', 'foo/bar', 'foo/bar'), array('../', 'foo/bar', 'foo/bar'), array('./phpBB/', 'foo/bar', 'foo/bar'), - array('../', __DIR__ . '/foo/bar', '../phpbb/tests/template/foo/bar'), + array('../', __DIR__ . '/foo/bar', '../' . basename(dirname(dirname(__DIR__))) . '/tests/template/foo/bar'), array('./', __DIR__ . '/foo/bar', './tests/template/foo/bar'), array('./phpBB/', __DIR__ . '/foo/bar', 'tests/template/foo/bar'), ); -- cgit v1.2.1 From 80f91da9b9ab7f4c2d66ba5632802a3a5dfa489f Mon Sep 17 00:00:00 2001 From: Matt Friedman Date: Wed, 8 Jul 2015 15:11:10 -0700 Subject: [ticket/13995] Fix errors in tests from merge conflict PHPBB3-13995 --- tests/template/template_includecss_test.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'tests/template') diff --git a/tests/template/template_includecss_test.php b/tests/template/template_includecss_test.php index ea851e3568..ac62e820ae 100644 --- a/tests/template/template_includecss_test.php +++ b/tests/template/template_includecss_test.php @@ -103,11 +103,11 @@ class phpbb_template_template_includecss_test extends phpbb_template_template_te ), array( array('TEST' => 3), - '', + '', ), array( array('TEST' => 4), - '', + '', ), ); } -- cgit v1.2.1 From 99ace63e62fddc934eded20afc6a7aebbc05e13b Mon Sep 17 00:00:00 2001 From: Tristan Darricau Date: Sun, 7 Feb 2016 12:49:00 +0100 Subject: [ticket/14457] Don't set CSS to JS and JS to CSS PHPBB3-14457 --- tests/template/template_test_case.php | 1 + 1 file changed, 1 insertion(+) (limited to 'tests/template') diff --git a/tests/template/template_test_case.php b/tests/template/template_test_case.php index 62eea0d361..3c97d30edc 100644 --- a/tests/template/template_test_case.php +++ b/tests/template/template_test_case.php @@ -172,6 +172,7 @@ class phpbb_template_template_test_case extends phpbb_test_case $expected = str_replace(array("\n", "\r", "\t"), '', $expected); $output = str_replace(array("\n", "\r", "\t"), '', $this->display('test')); + $this->assertEquals($expected, $output, "Testing $file"); } } -- cgit v1.2.1 From 14e8113fcf01be7dbdb080458fcbf4e75668cc1a Mon Sep 17 00:00:00 2001 From: Matt Friedman Date: Thu, 31 Mar 2016 11:06:47 -0700 Subject: [ticket/14576] Move common required files to bootstrap PHPBB3-14576 --- tests/template/template_parser_test.php | 1 - tests/template/template_test.php | 1 - tests/template/template_test_case.php | 2 -- 3 files changed, 4 deletions(-) (limited to 'tests/template') diff --git a/tests/template/template_parser_test.php b/tests/template/template_parser_test.php index d32fe78391..938b1bc8b8 100644 --- a/tests/template/template_parser_test.php +++ b/tests/template/template_parser_test.php @@ -11,7 +11,6 @@ * */ -require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php'; require_once dirname(__FILE__) . '/template_test_case.php'; class phpbb_template_template_parser_test extends phpbb_template_template_test_case diff --git a/tests/template/template_test.php b/tests/template/template_test.php index 33dc4ca551..63e7cb869a 100644 --- a/tests/template/template_test.php +++ b/tests/template/template_test.php @@ -11,7 +11,6 @@ * */ -require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php'; require_once dirname(__FILE__) . '/template_test_case.php'; class phpbb_template_template_test extends phpbb_template_template_test_case diff --git a/tests/template/template_test_case.php b/tests/template/template_test_case.php index 3c97d30edc..cda0623dcb 100644 --- a/tests/template/template_test_case.php +++ b/tests/template/template_test_case.php @@ -11,8 +11,6 @@ * */ -require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php'; - class phpbb_template_template_test_case extends phpbb_test_case { protected $lang; -- cgit v1.2.1 From 663e3bc64238668ec139b53ccfb2f82a1d306601 Mon Sep 17 00:00:00 2001 From: Tristan Darricau Date: Wed, 23 Mar 2016 21:59:40 +0100 Subject: [ticket/13616] Updates direct call to twig environment constructor PHPBB3-13616 --- tests/template/template_allfolder_test.php | 3 +-- tests/template/template_events_test.php | 3 +-- tests/template/template_includecss_test.php | 3 +-- tests/template/template_test_case.php | 3 +-- tests/template/template_test_case_with_tree.php | 3 +-- 5 files changed, 5 insertions(+), 10 deletions(-) (limited to 'tests/template') diff --git a/tests/template/template_allfolder_test.php b/tests/template/template_allfolder_test.php index 9a0f1f512e..9a0a42fabd 100644 --- a/tests/template/template_allfolder_test.php +++ b/tests/template/template_allfolder_test.php @@ -64,7 +64,6 @@ class phpbb_template_allfolder_test extends phpbb_template_template_test_case $config, $filesystem, $path_helper, - $container, $cache_path, $this->extension_manager, $loader, @@ -76,7 +75,7 @@ class phpbb_template_allfolder_test extends phpbb_template_template_test_case ) ); $this->template = new \phpbb\template\twig\twig($path_helper, $config, $context, $twig, $cache_path, $this->user, array(new \phpbb\template\twig\extension($context, $this->user)), $this->extension_manager); - $container->set('template.twig.lexer', new \phpbb\template\twig\lexer($twig)); + $twig->setLexer(new \phpbb\template\twig\lexer($twig)); $this->template_path = $this->test_path . '/templates'; $this->ext_template_path = 'tests/extension/ext/vendor4/bar/styles/all/template'; diff --git a/tests/template/template_events_test.php b/tests/template/template_events_test.php index 54e08652a1..e245c90aee 100644 --- a/tests/template/template_events_test.php +++ b/tests/template/template_events_test.php @@ -158,7 +158,6 @@ Zeta test event in all', $config, $filesystem, $path_helper, - $container, $cache_path, $this->extension_manager, $loader, @@ -170,7 +169,7 @@ Zeta test event in all', ) ); $this->template = new \phpbb\template\twig\twig($path_helper, $config, $context, $twig, $cache_path, $this->user, array(new \phpbb\template\twig\extension($context, $this->user)), $this->extension_manager); - $container->set('template.twig.lexer', new \phpbb\template\twig\lexer($twig)); + $twig->setLexer(new \phpbb\template\twig\lexer($twig)); $this->template->set_custom_style(((!empty($style_names)) ? $style_names : 'silver'), array($this->template_path)); } diff --git a/tests/template/template_includecss_test.php b/tests/template/template_includecss_test.php index ac62e820ae..764652c9c2 100644 --- a/tests/template/template_includecss_test.php +++ b/tests/template/template_includecss_test.php @@ -50,7 +50,6 @@ class phpbb_template_template_includecss_test extends phpbb_template_template_te $config, $filesystem, $this->phpbb_path_helper, - $container, $cache_path, null, $loader, @@ -80,7 +79,7 @@ class phpbb_template_template_includecss_test extends phpbb_template_template_te ) ) ); - $container->set('template.twig.lexer', new \phpbb\template\twig\lexer($twig)); + $twig->setLexer(new \phpbb\template\twig\lexer($twig)); $this->template->set_custom_style('tests', array($this->template_path, $this->parent_template_path)); } diff --git a/tests/template/template_test_case.php b/tests/template/template_test_case.php index cda0623dcb..e52d3b76dd 100644 --- a/tests/template/template_test_case.php +++ b/tests/template/template_test_case.php @@ -102,7 +102,6 @@ class phpbb_template_template_test_case extends phpbb_test_case $config, $filesystem, $path_helper, - $container, $cache_path, null, $loader, @@ -114,7 +113,7 @@ class phpbb_template_template_test_case extends phpbb_test_case ) ); $this->template = new phpbb\template\twig\twig($path_helper, $config, $context, $twig, $cache_path, $this->user, array(new \phpbb\template\twig\extension($context, $this->user))); - $container->set('template.twig.lexer', new \phpbb\template\twig\lexer($twig)); + $twig->setLexer(new \phpbb\template\twig\lexer($twig)); $this->template->set_custom_style('tests', $this->template_path); } diff --git a/tests/template/template_test_case_with_tree.php b/tests/template/template_test_case_with_tree.php index bf5de6b85e..ff35d16120 100644 --- a/tests/template/template_test_case_with_tree.php +++ b/tests/template/template_test_case_with_tree.php @@ -45,7 +45,6 @@ class phpbb_template_template_test_case_with_tree extends phpbb_template_templat $config, $filesystem, $this->phpbb_path_helper, - $container, $cache_path, null, $loader, @@ -57,7 +56,7 @@ class phpbb_template_template_test_case_with_tree extends phpbb_template_templat ) ); $this->template = new phpbb\template\twig\twig($this->phpbb_path_helper, $config, $context, $twig, $cache_path, $this->user, array(new \phpbb\template\twig\extension($context, $this->user))); - $container->set('template.twig.lexer', new \phpbb\template\twig\lexer($twig)); + $twig->setLexer(new \phpbb\template\twig\lexer($twig)); $this->template->set_custom_style('tests', array($this->template_path, $this->parent_template_path)); } } -- cgit v1.2.1 From c40642b8274c9afa39af6b34cd831bed8b960b83 Mon Sep 17 00:00:00 2001 From: javiexin Date: Sat, 7 Jan 2017 19:57:22 +0100 Subject: [ticket/14943] Fix template loop access by index Allows inserting elements in a loop specified as 'outer[3].inner'. This was coded, but malfunctioning. Name incorrectly set on insert. Added tests. PHPBB3-14943 --- tests/template/template_test.php | 121 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 119 insertions(+), 2 deletions(-) (limited to 'tests/template') diff --git a/tests/template/template_test.php b/tests/template/template_test.php index 0bbfe3848d..92de5d3fac 100644 --- a/tests/template/template_test.php +++ b/tests/template/template_test.php @@ -528,22 +528,139 @@ EOT ), array( 'outer', + array('VARIABLE' => 'changed'), + 0, + 'change', + << 'changed'), + array('S_ROW_NUM' => 2), + 'change', + << 'before'), + false, + 'insert', + << 'after'), + true, + 'insert', + << 'pos #1'), + 1, + 'insert', + << 'changed'), 0, 'change', << 'changed'), + array('S_ROW_NUM' => 1), + 'change', + << Date: Sat, 7 Jan 2017 20:12:32 +0100 Subject: [ticket/14943] Fix template loop access by index Allows inserting elements in a loop specified as 'outer[3].inner'. This was coded, but malfunctioning. Name incorrectly set on insert. Added more tests. PHPBB3-14943 --- tests/template/template_test.php | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'tests/template') diff --git a/tests/template/template_test.php b/tests/template/template_test.php index 92de5d3fac..7231f71511 100644 --- a/tests/template/template_test.php +++ b/tests/template/template_test.php @@ -718,6 +718,16 @@ EOT $expect = 'outer - 0[outer|4]outer - 1[outer|4]middle - 0[middle|1]outer - 2 - test[outer|4]middle - 0[middle|2]middle - 1[middle|2]outer - 3[outer|4]middle - 0[middle|3]middle - 1[middle|3]middle - 2[middle|3]'; $this->assertEquals($expect, str_replace(array("\n", "\r", "\t"), '', $this->display('test')), 'Ensuring S_NUM_ROWS is correct after modification'); + + $this->template->alter_block_array('outer.middle', array()); + + $expect = 'outer - 0[outer|4]outer - 1[outer|4]middle - 0[middle|1]outer - 2 - test[outer|4]middle - 0[middle|2]middle - 1[middle|2]outer - 3[outer|4]middle - 0[middle|4]middle - 1[middle|4]middle - 2[middle|4]middle - 3[middle|4]'; + $this->assertEquals($expect, str_replace(array("\n", "\r", "\t"), '', $this->display('test')), 'Ensuring S_NUM_ROWS is correct after insertion at middle level'); + + $this->template->alter_block_array('outer.middle', array('VARIABLE' => 'test'), 2, 'change'); + + $expect = 'outer - 0[outer|4]outer - 1[outer|4]middle - 0[middle|1]outer - 2 - test[outer|4]middle - 0[middle|2]middle - 1[middle|2]outer - 3[outer|4]middle - 0[middle|4]middle - 1[middle|4]middle - 2 - test[middle|4]middle - 3[middle|4]'; + $this->assertEquals($expect, str_replace(array("\n", "\r", "\t"), '', $this->display('test')), 'Ensuring S_NUM_ROWS is correct after modification at middle level'); } public function assign_block_vars_array_data() -- cgit v1.2.1 From 20c03cccdde2302412d1e14adda370e7eb57b8e8 Mon Sep 17 00:00:00 2001 From: javiexin Date: Sun, 8 Jan 2017 00:00:47 +0100 Subject: [ticket/14944] Add possibility to search for template loop indexes by key Adds a new function to the template interface, and implements it in the context class. The function returns the ordinal index for a specified key, with the same structure that the key for alter_block_array. Reuses same code. Remove unneeded references, do nothing for int keys. Check out of bounds or wrong blockname errors. Added tests. PHPBB3-14944 --- tests/template/template_test.php | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) (limited to 'tests/template') diff --git a/tests/template/template_test.php b/tests/template/template_test.php index 0bbfe3848d..33fa4b63a0 100644 --- a/tests/template/template_test.php +++ b/tests/template/template_test.php @@ -603,6 +603,43 @@ EOT $this->assertEquals($expect, str_replace(array("\n", "\r", "\t"), '', $this->display('test')), 'Ensuring S_NUM_ROWS is correct after modification'); } + public function test_find_key_index() + { + $this->template->set_filenames(array('test' => 'loop_nested.html')); + + $this->template->assign_var('TEST_MORE', true); + + // @todo Change this + $this->template->assign_block_vars('outer', array('VARIABLE' => 'zero')); + $this->template->assign_block_vars('outer', array('VARIABLE' => 'one')); + $this->template->assign_block_vars('outer.middle', array('VARIABLE' => '1A')); + $this->template->assign_block_vars('outer', array('VARIABLE' => 'two')); + $this->template->assign_block_vars('outer.middle', array('VARIABLE' => '2A')); + $this->template->assign_block_vars('outer.middle', array('VARIABLE' => '2B')); + $this->template->assign_block_vars('outer', array('VARIABLE' => 'three')); + $this->template->assign_block_vars('outer.middle', array('VARIABLE' => '3A')); + $this->template->assign_block_vars('outer.middle', array('VARIABLE' => '3B')); + $this->template->assign_block_vars('outer.middle', array('VARIABLE' => '3C')); + + $expect = 'outer - 0 - zero[outer|4]outer - 1 - one[outer|4]middle - 0 - 1A[middle|1]outer - 2 - two[outer|4]middle - 0 - 2A[middle|2]middle - 1 - 2B[middle|2]outer - 3 - three[outer|4]middle - 0 - 3A[middle|3]middle - 1 - 3B[middle|3]middle - 2 - 3C[middle|3]'; + $this->assertEquals($expect, str_replace(array("\n", "\r", "\t"), '', $this->display('test')), 'Ensuring template is built correctly before modification'); + + $this->template->find_key_index('outer', false); + + $this->assertEquals(0, $this->template->find_key_index('outer', false), 'Find index at the beginning of outer loop'); + $this->assertEquals(1, $this->template->find_key_index('outer', 1), 'Find index by index in outer loop'); + $this->assertEquals(2, $this->template->find_key_index('outer', array('VARIABLE' => 'two')), 'Find index by key in outer loop'); + $this->assertEquals(3, $this->template->find_key_index('outer', true), 'Find index at the end of outer loop'); + $this->assertEquals(false, $this->template->find_key_index('outer', 7), 'Find index out of bounds of outer loop'); + + $this->assertEquals(false, $this->template->find_key_index('outer[0].middle', false), 'Find index at the beginning of middle loop, no middle block'); + $this->assertEquals(false, $this->template->find_key_index('outer[1].middle', 1), 'Find index by index in inner loop, out of bounds'); + $this->assertEquals(1, $this->template->find_key_index('outer[2].middle', array('VARIABLE' => '2B')), 'Find index by key in middle loop'); + $this->assertEquals(2, $this->template->find_key_index('outer.middle', true), 'Find index at the end of middle loop'); + + $this->assertEquals(false, $this->template->find_key_index('outer.wrong'), 'Wrong middle block name'); + $this->assertEquals(false, $this->template->find_key_index('wrong.middle'), 'Wrong outer block name'); + } public function assign_block_vars_array_data() { return array( -- cgit v1.2.1 From 849fd9df7d9b2e449801e14ef54584fc8e063d43 Mon Sep 17 00:00:00 2001 From: javiexin Date: Sat, 28 Jan 2017 21:34:08 +0100 Subject: [ticket/14944] Add possibility to search for template loop indexes by key Adds a new function to the template interface, and implements it in the context class. The function returns the ordinal index for a specified key, with the same structure that the key for alter_block_array. Reuses same code. Remove unneeded references, do nothing for int keys. Check out of bounds or wrong blockname errors. Added tests. Remove default parameter value. PHPBB3-14944 --- tests/template/template_test.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'tests/template') diff --git a/tests/template/template_test.php b/tests/template/template_test.php index 33fa4b63a0..997da80246 100644 --- a/tests/template/template_test.php +++ b/tests/template/template_test.php @@ -637,8 +637,8 @@ EOT $this->assertEquals(1, $this->template->find_key_index('outer[2].middle', array('VARIABLE' => '2B')), 'Find index by key in middle loop'); $this->assertEquals(2, $this->template->find_key_index('outer.middle', true), 'Find index at the end of middle loop'); - $this->assertEquals(false, $this->template->find_key_index('outer.wrong'), 'Wrong middle block name'); - $this->assertEquals(false, $this->template->find_key_index('wrong.middle'), 'Wrong outer block name'); + $this->assertEquals(false, $this->template->find_key_index('outer.wrong', true), 'Wrong middle block name'); + $this->assertEquals(false, $this->template->find_key_index('wrong.middle', false), 'Wrong outer block name'); } public function assign_block_vars_array_data() { -- cgit v1.2.1