aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorOleg Pudeyev <oleg@bsdpower.com>2012-03-07 18:20:49 -0500
committerOleg Pudeyev <oleg@bsdpower.com>2012-03-07 18:20:49 -0500
commit65e711cbb0314dea5895308d1558453d222240e2 (patch)
tree755d4d8300219eaf40734794acb65672b3990061
parent74dfea22a1eca116d27cd8f41e228f8f69584d92 (diff)
parentebdd03872a9759532805b0319931bb3381ac790f (diff)
downloadforums-65e711cbb0314dea5895308d1558453d222240e2.tar
forums-65e711cbb0314dea5895308d1558453d222240e2.tar.gz
forums-65e711cbb0314dea5895308d1558453d222240e2.tar.bz2
forums-65e711cbb0314dea5895308d1558453d222240e2.tar.xz
forums-65e711cbb0314dea5895308d1558453d222240e2.zip
Merge remote-tracking branch 'cyberalien/feature/append_var' into develop
* cyberalien/feature/append_var: [feature/append_var] Adding test case [feature/append_var] Adding append_var template class function
-rw-r--r--phpBB/includes/template/context.php19
-rw-r--r--phpBB/includes/template/template.php17
-rw-r--r--tests/template/template_test.php36
3 files changed, 70 insertions, 2 deletions
diff --git a/phpBB/includes/template/context.php b/phpBB/includes/template/context.php
index 65a3531bc5..ec09da1cf3 100644
--- a/phpBB/includes/template/context.php
+++ b/phpBB/includes/template/context.php
@@ -53,7 +53,9 @@ class phpbb_template_context
}
/**
- * Assign a single variable to a single key
+ * Assign a single scalar value to a single key.
+ *
+ * Value can be a string, an integer or a boolean.
*
* @param string $varname Variable name
* @param string $varval Value to assign to variable
@@ -66,6 +68,21 @@ class phpbb_template_context
}
/**
+ * Append text to the string value stored in a key.
+ *
+ * Text is appended using the string concatenation operator (.).
+ *
+ * @param string $varname Variable name
+ * @param string $varval Value to append to variable
+ */
+ public function append_var($varname, $varval)
+ {
+ $this->rootref[$varname] = (isset($this->rootref[$varname]) ? $this->rootref[$varname] : '') . $varval;
+
+ return true;
+ }
+
+ /**
* Returns a reference to template data array.
*
* This function is public so that template renderer may invoke it.
diff --git a/phpBB/includes/template/template.php b/phpBB/includes/template/template.php
index 9297b759ac..bac5445511 100644
--- a/phpBB/includes/template/template.php
+++ b/phpBB/includes/template/template.php
@@ -378,7 +378,9 @@ class phpbb_template
}
/**
- * Assign a single variable to a single key
+ * Assign a single scalar value to a single key.
+ *
+ * Value can be a string, an integer or a boolean.
*
* @param string $varname Variable name
* @param string $varval Value to assign to variable
@@ -388,6 +390,19 @@ class phpbb_template
$this->context->assign_var($varname, $varval);
}
+ /**
+ * Append text to the string value stored in a key.
+ *
+ * Text is appended using the string concatenation operator (.).
+ *
+ * @param string $varname Variable name
+ * @param string $varval Value to append to variable
+ */
+ public function append_var($varname, $varval)
+ {
+ $this->context->append_var($varname, $varval);
+ }
+
// Docstring is copied from phpbb_template_context method with the same name.
/**
* Assign key variable pairs from an array to a specified block
diff --git a/tests/template/template_test.php b/tests/template/template_test.php
index 419c90bd2a..76b1af68d8 100644
--- a/tests/template/template_test.php
+++ b/tests/template/template_test.php
@@ -347,6 +347,42 @@ class phpbb_template_template_test extends phpbb_template_template_test_case
$this->assertEquals($expected, $this->display('container'), "Testing assign_display($file)");
}
+ public function test_append_var_without_assign_var()
+ {
+ $this->template->set_filenames(array(
+ 'append_var' => 'variable.html'
+ ));
+
+ $items = array('This ', 'is ', 'a ', 'test');
+ $expecting = implode('', $items);
+
+ foreach ($items as $word)
+ {
+ $this->template->append_var('VARIABLE', $word);
+ }
+
+ $this->assertEquals($expecting, $this->display('append_var'));
+ }
+
+ public function test_append_var_with_assign_var()
+ {
+ $this->template->set_filenames(array(
+ 'append_var' => 'variable.html'
+ ));
+
+ $start = 'This ';
+ $items = array('is ', 'a ', 'test');
+ $expecting = $start . implode('', $items);
+
+ $this->template->assign_var('VARIABLE', $start);
+ foreach ($items as $word)
+ {
+ $this->template->append_var('VARIABLE', $word);
+ }
+
+ $this->assertEquals($expecting, $this->display('append_var'));
+ }
+
public function test_php()
{
$this->setup_engine(array('tpl_allow_php' => true));