aboutsummaryrefslogtreecommitdiffstats
path: root/tests/template
diff options
context:
space:
mode:
authorjaviexin <javiexin@gmail.com>2017-05-21 18:18:59 +0200
committerjaviexin <javiexin@gmail.com>2017-05-21 18:18:59 +0200
commit60d6667eb4c5ad8a02d67dea62bc2d5b9553f958 (patch)
tree2b039860457d5fa7ab546b8b19c50e730e2a4654 /tests/template
parent96a90d3f81c1fcce3834ee72b7d1b9f76aa9354c (diff)
downloadforums-60d6667eb4c5ad8a02d67dea62bc2d5b9553f958.tar
forums-60d6667eb4c5ad8a02d67dea62bc2d5b9553f958.tar.gz
forums-60d6667eb4c5ad8a02d67dea62bc2d5b9553f958.tar.bz2
forums-60d6667eb4c5ad8a02d67dea62bc2d5b9553f958.tar.xz
forums-60d6667eb4c5ad8a02d67dea62bc2d5b9553f958.zip
[ticket/15068] Add template vars retrieval from the template object
Added tests. PHPBB3-15068
Diffstat (limited to 'tests/template')
-rw-r--r--tests/template/template_test.php31
1 files changed, 31 insertions, 0 deletions
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;