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/template_test.php') 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 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 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 148 insertions(+), 1 deletion(-) (limited to 'tests/template/template_test.php') 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', + ),*/ ); } -- 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 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) (limited to 'tests/template/template_test.php') 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', + ), ); } -- 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_test.php | 1 - 1 file changed, 1 deletion(-) (limited to 'tests/template/template_test.php') 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 -- cgit v1.2.1 From 9b2b9dd9de8d413f3f3b947b53e1a2a1e33dc477 Mon Sep 17 00:00:00 2001 From: javiexin Date: Sat, 7 Jan 2017 22:47:26 +0100 Subject: [ticket/14950] Add possibility to delete a template block Adds a new mode to alter_block_array to allow for the deletion of a certain block of template variables. The selection method is the same as for the other modes for alter_block_array. The passed in vararray is ignored, and an out of bounds index is considered an error. Added tests for the new function. PHPBB3-14950 --- tests/template/template_test.php | 42 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) (limited to 'tests/template/template_test.php') diff --git a/tests/template/template_test.php b/tests/template/template_test.php index 0bbfe3848d..d253651564 100644 --- a/tests/template/template_test.php +++ b/tests/template/template_test.php @@ -603,6 +603,48 @@ EOT $this->assertEquals($expect, str_replace(array("\n", "\r", "\t"), '', $this->display('test')), 'Ensuring S_NUM_ROWS is correct after modification'); } + public function test_delete_alter_block_array() + { + $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->alter_block_array('outer', array(), true, 'delete'); + + $expect = 'outer - 0 - one[outer|3]middle - 0 - 1A[middle|1]outer - 1 - two[outer|3]middle - 0 - 2A[middle|2]middle - 1 - 2B[middle|2]outer - 2 - three[outer|3]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')), 'Deleting at the beginning of outer loop'); + + $this->template->alter_block_array('outer[0].middle', array(), false, 'delete'); + + $expect = 'outer - 0 - one[outer|3]outer - 1 - two[outer|3]middle - 0 - 2A[middle|2]middle - 1 - 2B[middle|2]outer - 2 - three[outer|3]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')), 'Deleting at the end of first middle loop, delete complete loop'); + + $this->template->alter_block_array('outer', array(), 1, 'delete'); + + $expect = 'outer - 0 - one[outer|2]outer - 1 - three[outer|2]middle - 0 - 3A[middle|2]middle - 1 - 3C[middle|2]'; + $this->assertEquals($expect, str_replace(array("\n", "\r", "\t"), '', $this->display('test')), 'Deleting by index at top level'); + + $this->template->alter_block_array('outer', array(), 4, 'delete'); + + $expect = 'outer - 0 - one[outer|2]outer - 1 - three[outer|2]middle - 0 - 3A[middle|2]middle - 1 - 3C[middle|2]'; + $this->assertEquals($expect, str_replace(array("\n", "\r", "\t"), '', $this->display('test')), 'Deleting by index out of bounds, ignored'); + } + public function assign_block_vars_array_data() { return array( -- cgit v1.2.1 From 696724ac1b102d67aa765ebba7c898b0da3e8ba8 Mon Sep 17 00:00:00 2001 From: javiexin Date: Sun, 8 Jan 2017 00:59:26 +0100 Subject: [ticket/14950] Add possibility to delete a template block Adds a new mode to alter_block_array to allow for the deletion of a certain block of template variables. The selection method is the same as for the other modes for alter_block_array. The passed in vararray is ignored, and an out of bounds index is considered an error. Added tests for the new function, fixed. PHPBB3-14950 --- tests/template/template_test.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'tests/template/template_test.php') diff --git a/tests/template/template_test.php b/tests/template/template_test.php index d253651564..2d27a5b56a 100644 --- a/tests/template/template_test.php +++ b/tests/template/template_test.php @@ -624,12 +624,12 @@ EOT $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->alter_block_array('outer', array(), true, 'delete'); + $this->template->alter_block_array('outer', array(), false, 'delete'); $expect = 'outer - 0 - one[outer|3]middle - 0 - 1A[middle|1]outer - 1 - two[outer|3]middle - 0 - 2A[middle|2]middle - 1 - 2B[middle|2]outer - 2 - three[outer|3]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')), 'Deleting at the beginning of outer loop'); - $this->template->alter_block_array('outer[0].middle', array(), false, 'delete'); + $this->template->alter_block_array('outer[0].middle', array(), true, 'delete'); $expect = 'outer - 0 - one[outer|3]outer - 1 - two[outer|3]middle - 0 - 2A[middle|2]middle - 1 - 2B[middle|2]outer - 2 - three[outer|3]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')), 'Deleting at the end of first middle loop, delete complete loop'); -- cgit v1.2.1 From 7f8dd6b007393482b7f9e3316a6756d0c3953e11 Mon Sep 17 00:00:00 2001 From: javiexin Date: Sun, 8 Jan 2017 01:19:22 +0100 Subject: [ticket/14950] Add possibility to delete a template block Adds a new mode to alter_block_array to allow for the deletion of a certain block of template variables. The selection method is the same as for the other modes for alter_block_array. The passed in vararray is ignored, and an out of bounds index is considered an error. Added tests for the new function, fixed. PHPBB3-14950 --- tests/template/template_test.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'tests/template/template_test.php') diff --git a/tests/template/template_test.php b/tests/template/template_test.php index 2d27a5b56a..3bc2f66ef0 100644 --- a/tests/template/template_test.php +++ b/tests/template/template_test.php @@ -636,9 +636,14 @@ EOT $this->template->alter_block_array('outer', array(), 1, 'delete'); - $expect = 'outer - 0 - one[outer|2]outer - 1 - three[outer|2]middle - 0 - 3A[middle|2]middle - 1 - 3C[middle|2]'; + $expect = 'outer - 0 - one[outer|2]outer - 1 - three[outer|3]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')), 'Deleting by index at top level'); + $this->template->alter_block_array('outer.middle', array(), 1, 'delete'); + + $expect = 'outer - 0 - one[outer|2]outer - 1 - three[outer|2]middle - 0 - 3A[middle|2]middle - 1 - 3C[middle|2]'; + $this->assertEquals($expect, str_replace(array("\n", "\r", "\t"), '', $this->display('test')), 'Deleting by index at middle level'); + $this->template->alter_block_array('outer', array(), 4, 'delete'); $expect = 'outer - 0 - one[outer|2]outer - 1 - three[outer|2]middle - 0 - 3A[middle|2]middle - 1 - 3C[middle|2]'; -- cgit v1.2.1 From 988865fd0a1d213a441777b3c613265365fe651a Mon Sep 17 00:00:00 2001 From: javiexin Date: Sun, 8 Jan 2017 01:35:18 +0100 Subject: [ticket/14950] Add possibility to delete a template block Adds a new mode to alter_block_array to allow for the deletion of a certain block of template variables. The selection method is the same as for the other modes for alter_block_array. The passed in vararray is ignored, and an out of bounds index is considered an error. Added tests for the new function, fixed. PHPBB3-14950 --- tests/template/template_test.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests/template/template_test.php') diff --git a/tests/template/template_test.php b/tests/template/template_test.php index 3bc2f66ef0..c03da6e646 100644 --- a/tests/template/template_test.php +++ b/tests/template/template_test.php @@ -636,7 +636,7 @@ EOT $this->template->alter_block_array('outer', array(), 1, 'delete'); - $expect = 'outer - 0 - one[outer|2]outer - 1 - three[outer|3]middle - 0 - 3A[middle|3]middle - 1 - 3B[middle|3]middle - 2 - 3C[middle|3]'; + $expect = 'outer - 0 - one[outer|2]outer - 1 - three[outer|2]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')), 'Deleting by index at top level'); $this->template->alter_block_array('outer.middle', array(), 1, 'delete'); -- cgit v1.2.1 From 60d6667eb4c5ad8a02d67dea62bc2d5b9553f958 Mon Sep 17 00:00:00 2001 From: javiexin Date: Sun, 21 May 2017 18:18:59 +0200 Subject: [ticket/15068] Add template vars retrieval from the template object Added tests. PHPBB3-15068 --- tests/template/template_test.php | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) (limited to 'tests/template/template_test.php') diff --git a/tests/template/template_test.php b/tests/template/template_test.php index 0bbfe3848d..ad36954049 100644 --- a/tests/template/template_test.php +++ b/tests/template/template_test.php @@ -445,6 +445,37 @@ class phpbb_template_template_test extends phpbb_template_template_test_case $this->assertEquals($expecting, $this->display('append_var')); } + public function test_retrieve_data() + { + $this->template->set_filenames(array('test' => 'loop_nested.html')); + + $this->template->assign_var('TEST_MORE', false); + + // @todo Change this + $this->template->assign_vars(array('ONE' => true, 'TWO' => 'two', 'THREE' => 3)); + $this->template->assign_block_vars('outer', array('POSITION' => 'O1')); + $this->template->assign_block_vars('outer.middle', array('POSITION' => 'O1M1')); + $this->template->assign_block_vars('outer', array('POSITION' => 'O2')); + $this->template->assign_block_vars('outer.middle', array('POSITION' => 'O2M1')); + $this->template->assign_block_vars('outer.middle', array('POSITION' => 'O2M2')); + $this->template->assign_block_vars('outer', array('POSITION' => 'O3')); + $this->template->assign_block_vars('outer.middle', array('POSITION' => 'O3M1')); + $this->template->assign_block_vars('outer.middle', array('POSITION' => 'O3M2', 'ONE' => true, 'TWO' => 'two', 'THREE' => 3)); + $this->template->assign_block_vars('outer.middle', array('POSITION' => 'O3M3')); + + $expect = 'outer - 0middle - 0outer - 1middle - 0middle - 1outer - 2middle - 0middle - 1middle - 2'; + $this->assertEquals($expect, str_replace(array("\n", "\r", "\t"), '', $this->display('test')), 'Ensuring template is built correctly before modification'); + + $this->assertEquals(true, $this->template->retrieve_var('ONE'), 'Retrieve a single value from the template'); + $this->assertEquals(null, $this->template->retrieve_var('FOUR'), 'Retrieve a non_existent value from the template'); + $this->assertEquals(array('TWO' => 'two', 'THREE' => 3, 'FOUR' => null), $this->template->retrieve_vars(array('TWO','THREE', 'FOUR')), 'Retrieve several variables from the template'); + + $this->assertEquals(array('POSITION' => 'O3', 'SIZE' => null), $this->template->retrieve_block_vars('outer', array('POSITION', 'SIZE')), 'Retrieve vars from a block in the template'); + $this->assertEquals(array('POSITION' => 'O2M1'), $this->template->retrieve_block_vars('outer[1].middle[0]', array('POSITION')), 'Retrieve single var from a nested indexed block in the template'); + $this->assertEquals(array('S_ROW_NUM' => 2), $this->template->retrieve_block_vars('outer.middle', array('S_ROW_NUM')), 'Retrieve automatic var from a block in the template'); + $this->assertEquals(array('POSITION' => 'O3M2', 'ONE' => true, 'TWO' => 'two', 'THREE' => 3), $this->template->retrieve_block_vars('outer[2].middle[1]', array()), 'Retrieve all vars from a block in the template'); + } + public function test_php() { global $phpbb_root_path; -- cgit v1.2.1 From bf882826e48d4f29ca4c48ecb7d65cbdf459d5fb Mon Sep 17 00:00:00 2001 From: javiexin Date: Sun, 21 May 2017 14:57:40 +0200 Subject: [ticket/14994] Refactor template->assign_block_var Refactor assign_block_var to use the same block selection mechanism as is used in alter_block_array. This allows creating new blocks at any position in the template structure, not only on the last block. Allows selecting a block as outer[2].middle. Added tests. PHPBB3-14994 --- tests/template/template_test.php | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) (limited to 'tests/template/template_test.php') diff --git a/tests/template/template_test.php b/tests/template/template_test.php index 9f2124418d..0f761abc76 100644 --- a/tests/template/template_test.php +++ b/tests/template/template_test.php @@ -998,6 +998,46 @@ EOT $this->assertEquals($expect, str_replace(array("\n", "\r", "\t"), '', $this->display('test')), 'Deleting by index out of bounds, ignored'); } + public function test_indexed_assign_block_vars() + { + $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()); + $this->template->assign_block_vars('outer.middle', array()); + $this->template->assign_block_vars('outer', array()); + $this->template->assign_block_vars('outer.middle', array()); + $this->template->assign_block_vars('outer.middle', array()); + $this->template->assign_block_vars('outer', array()); + $this->template->assign_block_vars('outer.middle', array()); + $this->template->assign_block_vars('outer.middle', array()); + $this->template->assign_block_vars('outer.middle', array()); + + $expect = 'outer - 0[outer|3]middle - 0[middle|1]outer - 1[outer|3]middle - 0[middle|2]middle - 1[middle|2]outer - 2[outer|3]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 template is built correctly before modification'); + + $this->template->assign_block_vars('outer[0].middle', array('VARIABLE' => 'test')); + + $expect = 'outer - 0[outer|3]middle - 0[middle|2]middle - 1 - test[middle|2]outer - 1[outer|3]middle - 0[middle|2]middle - 1[middle|2]outer - 2[outer|3]middle - 0[middle|3]middle - 1[middle|3]middle - 2[middle|3]'; + $this->assertEquals($expect, str_replace(array("\n", "\r", "\t"), '', $this->display('test')), 'Inserting at the first outer block'); + + $this->template->assign_block_vars('outer[1].middle[0].inner', array()); + + $expect = 'outer - 0[outer|3]middle - 0[middle|2]middle - 1 - test[middle|2]outer - 1[outer|3]middle - 0[middle|2]inner - 0[inner|1]middle - 1[middle|2]outer - 2[outer|3]middle - 0[middle|3]middle - 1[middle|3]middle - 2[middle|3]'; + $this->assertEquals($expect, str_replace(array("\n", "\r", "\t"), '', $this->display('test')), 'Creating an inner block at the first middle block in the second outer block'); + + $this->template->assign_block_vars('outer[1].middle[0].inner', array()); + + $expect = 'outer - 0[outer|3]middle - 0[middle|2]middle - 1 - test[middle|2]outer - 1[outer|3]middle - 0[middle|2]inner - 0[inner|2]inner - 1[inner|2]middle - 1[middle|2]outer - 2[outer|3]middle - 0[middle|3]middle - 1[middle|3]middle - 2[middle|3]'; + $this->assertEquals($expect, str_replace(array("\n", "\r", "\t"), '', $this->display('test')), 'Inserting another inner block in the same place'); + + $this->template->assign_block_vars('outer.middle[1].inner', array('VARIABLE' => 'test')); + + $expect = 'outer - 0[outer|3]middle - 0[middle|2]middle - 1 - test[middle|2]outer - 1[outer|3]middle - 0[middle|2]inner - 0[inner|2]inner - 1[inner|2]middle - 1[middle|2]outer - 2[outer|3]middle - 0[middle|3]middle - 1[middle|3]inner - 0 - test[inner|1]middle - 2[middle|3]'; + $this->assertEquals($expect, str_replace(array("\n", "\r", "\t"), '', $this->display('test')), 'Inserting another inner block in the same place'); + } public function assign_block_vars_array_data() { -- cgit v1.2.1 From c20d84ce1702b1ea69bcc2ffbb2435225021c7a1 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Tue, 21 Aug 2018 21:25:33 +0200 Subject: [ticket/15746] Adjust tests after twig update PHPBB3-15746 --- tests/template/template_test.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests/template/template_test.php') diff --git a/tests/template/template_test.php b/tests/template/template_test.php index 0f761abc76..727f35e9d2 100644 --- a/tests/template/template_test.php +++ b/tests/template/template_test.php @@ -364,7 +364,7 @@ class phpbb_template_template_test extends phpbb_template_template_test_case array(), array(), array(), - "Value'\n1 O'Clock\nValue\\x27\n1\\x20O\\x27Clock", + "Value'\n1 O'Clock\nValue\\u0027\n1\\u0020O\\u0027Clock", array('VARIABLE' => "Value'", '1_VARIABLE' => "1 O'Clock"), ), array( -- cgit v1.2.1