From 7efddcef5411c4dd386f9dbcb3c117a15093a36f Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Thu, 7 Oct 2021 20:08:31 +0200 Subject: [PATCH 1/5] [ticket/13508] Add include_js twig tag as replacement for INCLUDEJS PHPBB3-13508 --- phpBB/phpbb/template/twig/extension.php | 1 + .../template/twig/tokenparser/include_js.php | 32 +++++++++++++++++++ 2 files changed, 33 insertions(+) create mode 100644 phpBB/phpbb/template/twig/tokenparser/include_js.php diff --git a/phpBB/phpbb/template/twig/extension.php b/phpBB/phpbb/template/twig/extension.php index 968a9c9d3e..6bce7c791f 100644 --- a/phpBB/phpbb/template/twig/extension.php +++ b/phpBB/phpbb/template/twig/extension.php @@ -60,6 +60,7 @@ class extension extends \Twig\Extension\AbstractExtension return array( new \phpbb\template\twig\tokenparser\defineparser, new \phpbb\template\twig\tokenparser\includeparser, + new \phpbb\template\twig\tokenparser\include_js, new \phpbb\template\twig\tokenparser\includejs, new \phpbb\template\twig\tokenparser\includecss, new \phpbb\template\twig\tokenparser\event($this->environment), diff --git a/phpBB/phpbb/template/twig/tokenparser/include_js.php b/phpBB/phpbb/template/twig/tokenparser/include_js.php new file mode 100644 index 0000000000..861ed1d209 --- /dev/null +++ b/phpBB/phpbb/template/twig/tokenparser/include_js.php @@ -0,0 +1,32 @@ + +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file. +* +*/ + +namespace phpbb\template\twig\tokenparser; + +use Twig\Error\SyntaxError; +use Twig\Node\Node; +use Twig\Token; +use Twig\TokenParser\AbstractTokenParser; + +class include_js extends includejs +{ + /** + * Gets the tag name associated with this token parser. + * + * @return string The tag name + */ + public function getTag(): string + { + return 'include_js'; + } +} From 02e5a7afc49558b0925378dce825e8f8dae84ddd Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Thu, 7 Oct 2021 21:19:35 +0200 Subject: [PATCH 2/5] [ticket/13508] Add include_css() and fix include_js() code linting issues PHPBB3-13508 --- phpBB/phpbb/template/twig/extension.php | 1 + .../template/twig/tokenparser/include_css.php | 27 ++++++++++++++ .../template/twig/tokenparser/include_js.php | 5 --- tests/template/templates/include_css.html | 10 ++++++ tests/template/templates/include_js.html | 36 +++++++++++++++++++ 5 files changed, 74 insertions(+), 5 deletions(-) create mode 100644 phpBB/phpbb/template/twig/tokenparser/include_css.php create mode 100644 tests/template/templates/include_css.html create mode 100644 tests/template/templates/include_js.html diff --git a/phpBB/phpbb/template/twig/extension.php b/phpBB/phpbb/template/twig/extension.php index 6bce7c791f..4b4771c8aa 100644 --- a/phpBB/phpbb/template/twig/extension.php +++ b/phpBB/phpbb/template/twig/extension.php @@ -62,6 +62,7 @@ class extension extends \Twig\Extension\AbstractExtension new \phpbb\template\twig\tokenparser\includeparser, new \phpbb\template\twig\tokenparser\include_js, new \phpbb\template\twig\tokenparser\includejs, + new \phpbb\template\twig\tokenparser\include_css, new \phpbb\template\twig\tokenparser\includecss, new \phpbb\template\twig\tokenparser\event($this->environment), new \phpbb\template\twig\tokenparser\includephp($this->environment), diff --git a/phpBB/phpbb/template/twig/tokenparser/include_css.php b/phpBB/phpbb/template/twig/tokenparser/include_css.php new file mode 100644 index 0000000000..353fb26c9c --- /dev/null +++ b/phpBB/phpbb/template/twig/tokenparser/include_css.php @@ -0,0 +1,27 @@ + +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file. +* +*/ + +namespace phpbb\template\twig\tokenparser; + +class include_css extends includecss +{ + /** + * Gets the tag name associated with this token parser. + * + * @return string The tag name + */ + public function getTag(): string + { + return 'include_css'; + } +} diff --git a/phpBB/phpbb/template/twig/tokenparser/include_js.php b/phpBB/phpbb/template/twig/tokenparser/include_js.php index 861ed1d209..5b57fb4d6f 100644 --- a/phpBB/phpbb/template/twig/tokenparser/include_js.php +++ b/phpBB/phpbb/template/twig/tokenparser/include_js.php @@ -13,11 +13,6 @@ namespace phpbb\template\twig\tokenparser; -use Twig\Error\SyntaxError; -use Twig\Node\Node; -use Twig\Token; -use Twig\TokenParser\AbstractTokenParser; - class include_js extends includejs { /** diff --git a/tests/template/templates/include_css.html b/tests/template/templates/include_css.html new file mode 100644 index 0000000000..23e3c426d7 --- /dev/null +++ b/tests/template/templates/include_css.html @@ -0,0 +1,10 @@ + + + + + + + + + +{$STYLESHEETS} diff --git a/tests/template/templates/include_js.html b/tests/template/templates/include_js.html new file mode 100644 index 0000000000..0bcdf1a815 --- /dev/null +++ b/tests/template/templates/include_js.html @@ -0,0 +1,36 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +{$SCRIPTS} From 97034e07769867905538260ded062401bf379e2c Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Thu, 7 Oct 2021 21:20:09 +0200 Subject: [PATCH 3/5] [ticket/13508] Add tests for include_js() and include_css() twig tokens PHPBB3-13508 --- tests/template/template_includecss_test.php | 14 +++++ tests/template/template_includejs_test.php | 14 +++++ tests/template/templates/include_css.html | 18 +++--- tests/template/templates/include_js.html | 70 ++++++++++----------- 4 files changed, 72 insertions(+), 44 deletions(-) diff --git a/tests/template/template_includecss_test.php b/tests/template/template_includecss_test.php index e6429b8c4f..57b31a840f 100644 --- a/tests/template/template_includecss_test.php +++ b/tests/template/template_includecss_test.php @@ -125,4 +125,18 @@ class phpbb_template_template_includecss_test extends phpbb_template_template_te // Run test $this->run_template('includecss.html', array(), array(), array(), $expected); } + + /** + * @dataProvider template_data + */ + public function test_include_css_compilation($vars, $expected) + { + // Reset the engine state + $this->setup_engine(array('assets_version' => 1)); + + $this->template->assign_vars($vars); + + // Run test + $this->run_template('include_css.html', array(), array(), array(), $expected); + } } diff --git a/tests/template/template_includejs_test.php b/tests/template/template_includejs_test.php index 7580d4b32d..035be4da0b 100644 --- a/tests/template/template_includejs_test.php +++ b/tests/template/template_includejs_test.php @@ -106,4 +106,18 @@ class phpbb_template_template_includejs_test extends phpbb_template_template_tes // Run test $this->run_template('includejs.html', array_merge(array('PARENT' => 'parent_only.js', 'SUBDIR' => 'subdir', 'EXT' => 'js'), $vars), array(), array(), $expected); } + + /** + * @dataProvider template_data + */ + public function test_include_js_compilation($vars, $expected) + { + // Reset the engine state + $this->setup_engine(array('assets_version' => 1)); + + $this->template->assign_vars($vars); + + // Run test + $this->run_template('include_js.html', array_merge(array('PARENT' => 'parent_only.js', 'SUBDIR' => 'subdir', 'EXT' => 'js'), $vars), array(), array(), $expected); + } } diff --git a/tests/template/templates/include_css.html b/tests/template/templates/include_css.html index 23e3c426d7..a8f644e406 100644 --- a/tests/template/templates/include_css.html +++ b/tests/template/templates/include_css.html @@ -1,10 +1,10 @@ - - - - - - - - - +{% if TEST === 1 %} + {% include_css('child_only.css') %} +{% elseif TEST === 2 %} + {% include_css('parent_only.css') %} +{% elseif TEST === 3 %} + {% include_css('@include_css/test.css') %} +{% elseif TEST === 4 %} + {% include_css('@include_css/child_only.css') %} +{% endif %} {$STYLESHEETS} diff --git a/tests/template/templates/include_js.html b/tests/template/templates/include_js.html index 0bcdf1a815..96ed42ebc7 100644 --- a/tests/template/templates/include_js.html +++ b/tests/template/templates/include_js.html @@ -1,36 +1,36 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +{% if TEST === 1 %} + {% include_js('parent_and_child.js') %} +{% elseif TEST === 2 %} + {% include_js('parent_and_child.js?assets_version=0') %} +{% elseif TEST === 3 %} + {% include_js('parent_and_child.js?test=1&assets_version=0') %} +{% elseif TEST === 4 %} + {% include_js('parent_and_child.js?test=1&assets_version=0') %} +{% elseif TEST === 6 %} + {% include_js(PARENT) %} +{% elseif TEST === 7 %} + {% set test_var = 'child_only.js' %} + {% include_js(test_var) %} +{% elseif TEST === 8 %} + {% include_js('subdir/' ~ PARENT) %} +{% elseif TEST === 9 %} + {% include_js(SUBDIR ~ '/subsubdir/' ~ PARENT) %} +{% elseif TEST === 10 %} + {% include_js(SUBDIR ~ '/parent_only.' ~ EXT) %} +{% elseif TEST === 11 %} + {% set test_var = 'child_only.js?test1=1&test2=2#test3' %} + {% include_js(test_var) %} +{% elseif TEST === 12 %} + {% include_js('parent_only.js?test1=1&test2=2#test3') %} +{% elseif TEST === 14 %} + {% include_js('parent_only.js?test1="#test3') %} +{% elseif TEST === 15 %} + {% include_js('http://phpbb.com/b.js?c=d#f') %} +{% elseif TEST === 16 %} + {% include_js('http://phpbb.com/b.js?c=d&assets_version=2#f') %} +{% elseif TEST === 17 %} + {% include_js('//phpbb.com/b.js') %} +{% elseif TEST === 18 %} + {% include_js('parent_and_child.js?test=1&test2=0') %} +{% endif %} {$SCRIPTS} From 056fb494b10098804c1bcbf533841ea5b28d55b0 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Sun, 17 Oct 2021 13:20:22 +0200 Subject: [PATCH 4/5] [ticket/13508] Switch back to current include format PHPBB3-13508 --- phpBB/phpbb/template/twig/extension.php | 2 -- .../template/twig/tokenparser/include_css.php | 27 ---------------- .../template/twig/tokenparser/include_js.php | 27 ---------------- tests/template/templates/include_css.html | 8 ++--- tests/template/templates/include_js.html | 32 +++++++++---------- 5 files changed, 20 insertions(+), 76 deletions(-) delete mode 100644 phpBB/phpbb/template/twig/tokenparser/include_css.php delete mode 100644 phpBB/phpbb/template/twig/tokenparser/include_js.php diff --git a/phpBB/phpbb/template/twig/extension.php b/phpBB/phpbb/template/twig/extension.php index 4b4771c8aa..968a9c9d3e 100644 --- a/phpBB/phpbb/template/twig/extension.php +++ b/phpBB/phpbb/template/twig/extension.php @@ -60,9 +60,7 @@ class extension extends \Twig\Extension\AbstractExtension return array( new \phpbb\template\twig\tokenparser\defineparser, new \phpbb\template\twig\tokenparser\includeparser, - new \phpbb\template\twig\tokenparser\include_js, new \phpbb\template\twig\tokenparser\includejs, - new \phpbb\template\twig\tokenparser\include_css, new \phpbb\template\twig\tokenparser\includecss, new \phpbb\template\twig\tokenparser\event($this->environment), new \phpbb\template\twig\tokenparser\includephp($this->environment), diff --git a/phpBB/phpbb/template/twig/tokenparser/include_css.php b/phpBB/phpbb/template/twig/tokenparser/include_css.php deleted file mode 100644 index 353fb26c9c..0000000000 --- a/phpBB/phpbb/template/twig/tokenparser/include_css.php +++ /dev/null @@ -1,27 +0,0 @@ - -* @license GNU General Public License, version 2 (GPL-2.0) -* -* For full copyright and license information, please see -* the docs/CREDITS.txt file. -* -*/ - -namespace phpbb\template\twig\tokenparser; - -class include_css extends includecss -{ - /** - * Gets the tag name associated with this token parser. - * - * @return string The tag name - */ - public function getTag(): string - { - return 'include_css'; - } -} diff --git a/phpBB/phpbb/template/twig/tokenparser/include_js.php b/phpBB/phpbb/template/twig/tokenparser/include_js.php deleted file mode 100644 index 5b57fb4d6f..0000000000 --- a/phpBB/phpbb/template/twig/tokenparser/include_js.php +++ /dev/null @@ -1,27 +0,0 @@ - -* @license GNU General Public License, version 2 (GPL-2.0) -* -* For full copyright and license information, please see -* the docs/CREDITS.txt file. -* -*/ - -namespace phpbb\template\twig\tokenparser; - -class include_js extends includejs -{ - /** - * Gets the tag name associated with this token parser. - * - * @return string The tag name - */ - public function getTag(): string - { - return 'include_js'; - } -} diff --git a/tests/template/templates/include_css.html b/tests/template/templates/include_css.html index a8f644e406..935633d573 100644 --- a/tests/template/templates/include_css.html +++ b/tests/template/templates/include_css.html @@ -1,10 +1,10 @@ {% if TEST === 1 %} - {% include_css('child_only.css') %} + {% INCLUDECSS('child_only.css') %} {% elseif TEST === 2 %} - {% include_css('parent_only.css') %} + {% INCLUDECSS('parent_only.css') %} {% elseif TEST === 3 %} - {% include_css('@include_css/test.css') %} + {% INCLUDECSS('@include_css/test.css') %} {% elseif TEST === 4 %} - {% include_css('@include_css/child_only.css') %} + {% INCLUDECSS('@include_css/child_only.css') %} {% endif %} {$STYLESHEETS} diff --git a/tests/template/templates/include_js.html b/tests/template/templates/include_js.html index 96ed42ebc7..dcf29bf0d1 100644 --- a/tests/template/templates/include_js.html +++ b/tests/template/templates/include_js.html @@ -1,36 +1,36 @@ {% if TEST === 1 %} - {% include_js('parent_and_child.js') %} + {% INCLUDEJS('parent_and_child.js') %} {% elseif TEST === 2 %} - {% include_js('parent_and_child.js?assets_version=0') %} + {% INCLUDEJS('parent_and_child.js?assets_version=0') %} {% elseif TEST === 3 %} - {% include_js('parent_and_child.js?test=1&assets_version=0') %} + {% INCLUDEJS('parent_and_child.js?test=1&assets_version=0') %} {% elseif TEST === 4 %} - {% include_js('parent_and_child.js?test=1&assets_version=0') %} + {% INCLUDEJS('parent_and_child.js?test=1&assets_version=0') %} {% elseif TEST === 6 %} - {% include_js(PARENT) %} + {% INCLUDEJS(PARENT) %} {% elseif TEST === 7 %} {% set test_var = 'child_only.js' %} - {% include_js(test_var) %} + {% INCLUDEJS(test_var) %} {% elseif TEST === 8 %} - {% include_js('subdir/' ~ PARENT) %} + {% INCLUDEJS('subdir/' ~ PARENT) %} {% elseif TEST === 9 %} - {% include_js(SUBDIR ~ '/subsubdir/' ~ PARENT) %} + {% INCLUDEJS(SUBDIR ~ '/subsubdir/' ~ PARENT) %} {% elseif TEST === 10 %} - {% include_js(SUBDIR ~ '/parent_only.' ~ EXT) %} + {% INCLUDEJS(SUBDIR ~ '/parent_only.' ~ EXT) %} {% elseif TEST === 11 %} {% set test_var = 'child_only.js?test1=1&test2=2#test3' %} - {% include_js(test_var) %} + {% INCLUDEJS(test_var) %} {% elseif TEST === 12 %} - {% include_js('parent_only.js?test1=1&test2=2#test3') %} + {% INCLUDEJS('parent_only.js?test1=1&test2=2#test3') %} {% elseif TEST === 14 %} - {% include_js('parent_only.js?test1="#test3') %} + {% INCLUDEJS('parent_only.js?test1="#test3') %} {% elseif TEST === 15 %} - {% include_js('http://phpbb.com/b.js?c=d#f') %} + {% INCLUDEJS('http://phpbb.com/b.js?c=d#f') %} {% elseif TEST === 16 %} - {% include_js('http://phpbb.com/b.js?c=d&assets_version=2#f') %} + {% INCLUDEJS('http://phpbb.com/b.js?c=d&assets_version=2#f') %} {% elseif TEST === 17 %} - {% include_js('//phpbb.com/b.js') %} + {% INCLUDEJS('//phpbb.com/b.js') %} {% elseif TEST === 18 %} - {% include_js('parent_and_child.js?test=1&test2=0') %} + {% INCLUDEJS('parent_and_child.js?test=1&test2=0') %} {% endif %} {$SCRIPTS} From 4d966d17623c080ceec395644e5a898c457f4c2a Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Sun, 17 Oct 2021 13:21:35 +0200 Subject: [PATCH 5/5] [ticket/13508] Rename test files to fit in with current naming PHPBB3-13508 --- tests/template/template_includecss_test.php | 2 +- tests/template/template_includejs_test.php | 2 +- .../templates/{include_css.html => includecss_twig.html} | 0 .../template/templates/{include_js.html => includejs_twig.html} | 0 4 files changed, 2 insertions(+), 2 deletions(-) rename tests/template/templates/{include_css.html => includecss_twig.html} (100%) rename tests/template/templates/{include_js.html => includejs_twig.html} (100%) diff --git a/tests/template/template_includecss_test.php b/tests/template/template_includecss_test.php index 57b31a840f..bdd32411ad 100644 --- a/tests/template/template_includecss_test.php +++ b/tests/template/template_includecss_test.php @@ -137,6 +137,6 @@ class phpbb_template_template_includecss_test extends phpbb_template_template_te $this->template->assign_vars($vars); // Run test - $this->run_template('include_css.html', array(), array(), array(), $expected); + $this->run_template('includecss_twig.html', array(), array(), array(), $expected); } } diff --git a/tests/template/template_includejs_test.php b/tests/template/template_includejs_test.php index 035be4da0b..9886ced6ad 100644 --- a/tests/template/template_includejs_test.php +++ b/tests/template/template_includejs_test.php @@ -118,6 +118,6 @@ class phpbb_template_template_includejs_test extends phpbb_template_template_tes $this->template->assign_vars($vars); // Run test - $this->run_template('include_js.html', array_merge(array('PARENT' => 'parent_only.js', 'SUBDIR' => 'subdir', 'EXT' => 'js'), $vars), array(), array(), $expected); + $this->run_template('includejs_twig.html', array_merge(array('PARENT' => 'parent_only.js', 'SUBDIR' => 'subdir', 'EXT' => 'js'), $vars), array(), array(), $expected); } } diff --git a/tests/template/templates/include_css.html b/tests/template/templates/includecss_twig.html similarity index 100% rename from tests/template/templates/include_css.html rename to tests/template/templates/includecss_twig.html diff --git a/tests/template/templates/include_js.html b/tests/template/templates/includejs_twig.html similarity index 100% rename from tests/template/templates/include_js.html rename to tests/template/templates/includejs_twig.html