aboutsummaryrefslogtreecommitdiffstats
path: root/tests/template/template_test.php
diff options
context:
space:
mode:
authorjaviexin <javiexin@gmail.com>2017-05-21 14:57:40 +0200
committerMarc Alexander <admin@m-a-styles.de>2017-11-01 12:29:47 +0100
commitbf882826e48d4f29ca4c48ecb7d65cbdf459d5fb (patch)
tree4de143053424317af4f4d53f3d52872def286ad6 /tests/template/template_test.php
parente32324c72a33b9ef5baf5233a88963bc13066f8e (diff)
downloadforums-bf882826e48d4f29ca4c48ecb7d65cbdf459d5fb.tar
forums-bf882826e48d4f29ca4c48ecb7d65cbdf459d5fb.tar.gz
forums-bf882826e48d4f29ca4c48ecb7d65cbdf459d5fb.tar.bz2
forums-bf882826e48d4f29ca4c48ecb7d65cbdf459d5fb.tar.xz
forums-bf882826e48d4f29ca4c48ecb7d65cbdf459d5fb.zip
[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
Diffstat (limited to 'tests/template/template_test.php')
-rw-r--r--tests/template/template_test.php40
1 files changed, 40 insertions, 0 deletions
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()
{