aboutsummaryrefslogtreecommitdiffstats
path: root/tests/template
diff options
context:
space:
mode:
authorJakub Senko <jakubsenko@gmail.com>2018-06-18 11:20:18 +0200
committerJakub Senko <jakubsenko@gmail.com>2018-07-07 15:46:24 +0200
commitb5daa91650aa482bbe5fce75761804259ee4eb94 (patch)
tree81d1651b89bae224895ca3a4d3647901f704e8d5 /tests/template
parent02cbb864a5b6df62e978a69c368c8ec5ca35d8a3 (diff)
downloadforums-b5daa91650aa482bbe5fce75761804259ee4eb94.tar
forums-b5daa91650aa482bbe5fce75761804259ee4eb94.tar.gz
forums-b5daa91650aa482bbe5fce75761804259ee4eb94.tar.bz2
forums-b5daa91650aa482bbe5fce75761804259ee4eb94.tar.xz
forums-b5daa91650aa482bbe5fce75761804259ee4eb94.zip
[ticket/15659] Fix retrieve_block_vars()
PHPBB3-15659
Diffstat (limited to 'tests/template')
-rw-r--r--tests/template/context_test.php96
1 files changed, 96 insertions, 0 deletions
diff --git a/tests/template/context_test.php b/tests/template/context_test.php
new file mode 100644
index 0000000000..52ce6c8fde
--- /dev/null
+++ b/tests/template/context_test.php
@@ -0,0 +1,96 @@
+<?php
+/**
+*
+* This file is part of the phpBB Forum Software package.
+*
+* @copyright (c) phpBB Limited <https://www.phpbb.com>
+* @license GNU General Public License, version 2 (GPL-2.0)
+*
+* For full copyright and license information, please see
+* the docs/CREDITS.txt file.
+*
+*/
+
+class context_test extends phpbb_test_case
+{
+ protected $context;
+ protected function setUp()
+ {
+ $this->context = new \phpbb\template\context();
+
+ for ($i = 0; $i < 10; $i++)
+ {
+ $this->context->assign_block_vars('block' . $i, array(
+ 'FOO' . $i => 'foo' . $i,
+ 'BAR' . $i => 'bar' . $i,
+ ));
+
+ for ($j = 0; $j < 10; $j++)
+ {
+ $this->context->assign_block_vars('block' . $i . '.subblock', array(
+ 'SUBFOO' => 'subfoo' . $j,
+ 'SUBBAR' => 'subbar' . $j,
+ ));
+
+ for ($k = 0; $k < 10; $k++)
+ {
+ $this->context->assign_block_vars('block' . $i . '.subblock.subsubblock', array(
+ 'SUBSUBFOO' => 'subsubfoo' . $k,
+ 'SUBSUBBAR' => 'subsubbar' . $k,
+ ));
+ }
+ }
+ }
+ }
+
+ public function retrieve_block_vars_data()
+ {
+ return array(
+ array('foo', array(), array()), // non-existent top-level block
+ array('block1.foo', array(), array()), // non-existent sub-level block
+ array('block1', array(), array( // top-level block, all vars
+ 'FOO1' => 'foo1',
+ 'BAR1' => 'bar1',
+ )),
+ array('block1', array('FOO1'), array( // top-level block, one var
+ 'FOO1' => 'foo1',
+ )),
+ array('block2.subblock', array(), array( // sub-level block, all vars
+ 'SUBFOO' => 'subfoo9',
+ 'SUBBAR' => 'subbar9',
+ )),
+ array('block2.subblock', array('SUBBAR'), array( // sub-level block, one var
+ 'SUBBAR' => 'subbar9',
+ )),
+ array('block2.subblock.subsubblock', array(), array( // sub-sub-level block, all vars
+ 'SUBSUBFOO' => 'subsubfoo9',
+ 'SUBSUBBAR' => 'subsubbar9',
+ )),
+ array('block2.subblock.subsubblock', array('SUBSUBBAR'), array( // sub-sub-level block, one var
+ 'SUBSUBBAR' => 'subsubbar9',
+ )),
+ array('block3.subblock[2]', array(), array( // sub-level, exact index, all vars
+ 'SUBFOO' => 'subfoo2',
+ 'SUBBAR' => 'subbar2',
+ )),
+ array('block3.subblock[2]', array('SUBBAR'), array( // sub-level, exact index, one var
+ 'SUBBAR' => 'subbar2',
+ )),
+ array('block3.subblock[3].subsubblock[5]', array(), array( // sub-sub-level, exact index, all vars
+ 'SUBSUBFOO' => 'subsubfoo5',
+ 'SUBSUBBAR' => 'subsubbar5',
+ )),
+ array('block3.subblock[4].subsubblock[6]', array('SUBSUBFOO'), array( // sub-sub-level, exact index, one var
+ 'SUBSUBFOO' => 'subsubfoo6',
+ )),
+ );
+ }
+
+ /**
+ * @dataProvider retrieve_block_vars_data
+ */
+ public function test_retrieve_block_vars($blockname, $vararray, $result)
+ {
+ $this->assertEquals($result, $this->context->retrieve_block_vars($blockname, $vararray));
+ }
+}