aboutsummaryrefslogtreecommitdiffstats
path: root/tests/template
diff options
context:
space:
mode:
Diffstat (limited to 'tests/template')
-rw-r--r--tests/template/context_test.php4
-rw-r--r--tests/template/extension_test.php258
-rw-r--r--tests/template/template_allfolder_test.php4
-rw-r--r--tests/template/template_events_test.php4
-rw-r--r--tests/template/template_includecss_test.php4
-rw-r--r--tests/template/template_test.php4
-rw-r--r--tests/template/template_test_case.php8
-rw-r--r--tests/template/template_test_case_with_tree.php4
-rw-r--r--tests/template/templates/avatar_user.html1
-rw-r--r--tests/template/templates/expressions.html2
-rw-r--r--tests/template/templates/extension_config_test.html1
-rw-r--r--tests/template/templates/extension_username_test.html1
12 files changed, 278 insertions, 17 deletions
diff --git a/tests/template/context_test.php b/tests/template/context_test.php
index 52ce6c8fde..a1be672f51 100644
--- a/tests/template/context_test.php
+++ b/tests/template/context_test.php
@@ -14,7 +14,7 @@
class context_test extends phpbb_test_case
{
protected $context;
- protected function setUp()
+ protected function setUp(): void
{
$this->context = new \phpbb\template\context();
@@ -31,7 +31,7 @@ class context_test extends phpbb_test_case
'SUBFOO' => 'subfoo' . $j,
'SUBBAR' => 'subbar' . $j,
));
-
+
for ($k = 0; $k < 10; $k++)
{
$this->context->assign_block_vars('block' . $i . '.subblock.subsubblock', array(
diff --git a/tests/template/extension_test.php b/tests/template/extension_test.php
new file mode 100644
index 0000000000..d633001060
--- /dev/null
+++ b/tests/template/extension_test.php
@@ -0,0 +1,258 @@
+<?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.
+ *
+ */
+
+require_once dirname(__FILE__) . '/template_test_case.php';
+
+class phpbb_template_extension_test extends phpbb_template_template_test_case
+{
+ protected function setup_engine(array $new_config = array())
+ {
+ global $config, $phpbb_container, $phpbb_dispatcher, $phpbb_root_path, $phpEx;
+
+ $defaults = $this->config_defaults();
+ $defaults = array_merge($defaults, [
+ 'allow_avatar' => true,
+ 'allow_avatar_upload' => true,
+ ]);
+ $config = new \phpbb\config\config(array_merge($defaults, $new_config));
+ $lang_loader = new \phpbb\language\language_file_loader($phpbb_root_path, $phpEx);
+ $this->lang = $lang = new \phpbb\language\language($lang_loader);
+ $this->user = new \phpbb\user($lang, '\phpbb\datetime');
+
+ global $auth, $request, $symfony_request, $user;
+ $user = new phpbb_mock_user();
+ $user->optionset('user_id', 2);
+ $auth = $this->getMockBuilder('phpbb\auth\auth')
+ ->disableOriginalConstructor()
+ ->setMethods(['acl_get'])
+ ->getMock();
+ $auth->method('acl_get')
+ ->willReturn(true);
+
+ $filesystem = new \phpbb\filesystem\filesystem();
+ $request = new phpbb_mock_request;
+ $symfony_request = new \phpbb\symfony_request(
+ $request
+ );
+ $phpbb_path_helper = new \phpbb\path_helper(
+ $symfony_request,
+ $filesystem,
+ $request,
+ $phpbb_root_path,
+ $phpEx
+ );
+
+ $phpbb_dispatcher = new phpbb_mock_event_dispatcher();
+ $phpbb_container = new phpbb_mock_container_builder();
+ $files = new phpbb\files\factory($phpbb_container);
+ $upload_avatar_driver = new phpbb\avatar\driver\upload($config, $phpbb_root_path, $phpEx, $filesystem, $phpbb_path_helper, $phpbb_dispatcher, $files);
+ $upload_avatar_driver->set_name('avatar.driver.upload');
+ $phpbb_container->set('avatar.manager', new \phpbb\avatar\manager($config, $phpbb_dispatcher, [
+ $upload_avatar_driver,
+ ]));
+ $phpbb_container->set('path_helper', $phpbb_path_helper);
+
+ $class = new ReflectionClass('\phpbb\avatar\manager');
+ $enabled_drivers = $class->getProperty('enabled_drivers');
+ $enabled_drivers->setAccessible(true);
+ $enabled_drivers->setValue(false);
+
+ $this->template_path = $this->test_path . '/templates';
+
+ $cache_path = $phpbb_root_path . 'cache/twig';
+ $context = new \phpbb\template\context();
+ $loader = new \phpbb\template\twig\loader($filesystem);
+ $twig = new \phpbb\template\twig\environment(
+ $config,
+ $filesystem,
+ $phpbb_path_helper,
+ $cache_path,
+ null,
+ $loader,
+ new \phpbb\event\dispatcher($phpbb_container),
+ array(
+ 'cache' => false,
+ 'debug' => false,
+ 'auto_reload' => true,
+ 'autoescape' => false,
+ )
+ );
+ $this->template = new phpbb\template\twig\twig(
+ $phpbb_path_helper,
+ $config,
+ $context,
+ $twig,
+ $cache_path,
+ $this->user,
+ [
+ new \phpbb\template\twig\extension($context, $twig, $this->lang),
+ new \phpbb\template\twig\extension\avatar(),
+ new \phpbb\template\twig\extension\config($config),
+ new \phpbb\template\twig\extension\username(),
+ ]
+ );
+ $twig->setLexer(new \phpbb\template\twig\lexer($twig));
+ $this->template->set_custom_style('tests', $this->template_path);
+ }
+
+ public function data_template_extensions()
+ {
+ return [
+ [
+ 'avatar_user.html',
+ [
+ 'row' => [
+ 'user_avatar' => 'great_avatar.png',
+ 'user_avatar_type' => 'avatar.driver.upload',
+ 'user_avatar_width' => 90,
+ 'user_avatar_height' => 90,
+ ],
+ 'alt' => 'foo'
+ ],
+ [],
+ [],
+ '<img class="avatar" src="phpBB/download/file.php?avatar=great_avatar.png" width="90" height="90" alt="foo" />',
+ []
+ ],
+ [
+ 'avatar_user.html',
+ [
+ 'row' => [
+ 'user_avatar' => 'great_avatar.png',
+ 'user_avatar_type' => 'avatar.driver.upload',
+ 'user_avatar_width' => 90,
+ 'user_avatar_height' => 90,
+ ],
+ 'alt' => 'foo',
+ 'ignore_config' => true,
+ 'lazy' => true,
+ ],
+ [],
+ [],
+ '<img class="avatar" src="phpBB/styles//theme/images/no_avatar.gif" data-src="phpBB/download/file.php?avatar=great_avatar.png" width="90" height="90" alt="foo" />',
+ []
+ ],
+ [
+ 'avatar_user.html',
+ [
+ 'row' => [
+ 'user_avatar' => 'foo@bar.com',
+ 'user_avatar_type' => 'avatar.driver.gravatar',
+ 'user_avatar_width' => 90,
+ 'user_avatar_height' => 90,
+ ],
+ 'alt' => 'foo'
+ ],
+ [],
+ [],
+ '',
+ []
+ ],
+ [
+ 'extension_username_test.html',
+ [
+ 'mode' => 'profile',
+ 'user_id' => 2,
+ 'username' => 'admin',
+ 'user_colour' => 'abcdef',
+ 'guest_username' => 'lol',
+ ],
+ [],
+ [],
+ 'phpBB/memberlist.php?mode=viewprofile&amp;u=2',
+ []
+ ],
+ [
+ 'extension_username_test.html',
+ [
+ 'mode' => 'profile',
+ 'user_id' => 2,
+ 'username' => 'admin',
+ 'user_colour' => 'abcdef',
+ 'guest_username' => 'lol',
+ 'custom_profile_url' => 'http://lol.bar',
+ ],
+ [],
+ [],
+ 'http://lol.bar&amp;u=2',
+ []
+ ],
+ [
+ 'extension_username_test.html',
+ [
+ 'mode' => 'full',
+ 'user_id' => 2,
+ 'username' => 'admin',
+ 'user_colour' => 'abcdef',
+ 'guest_username' => 'lol',
+ ],
+ [],
+ [],
+ '<a href="phpBB/memberlist.php?mode=viewprofile&amp;u=2" style="color: #abcdef;" class="username-coloured">admin</a>',
+ []
+ ],
+ [
+ 'extension_username_test.html',
+ [
+ 'mode' => 'no_profile',
+ 'user_id' => 2,
+ 'username' => 'admin',
+ 'user_colour' => 'abcdef',
+ 'guest_username' => 'lol',
+ ],
+ [],
+ [],
+ '<span style="color: #abcdef;" class="username-coloured">admin</span>',
+ []
+ ],
+ [
+ 'extension_config_test.html',
+ [
+ 'config_name' => 'allow_avatar',
+ ],
+ [],
+ [],
+ '1',
+ []
+ ],
+ [
+ 'extension_config_test.html',
+ [
+ 'config_name' => 'does not exist',
+ ],
+ [],
+ [],
+ '',
+ []
+ ],
+ [
+ 'extension_config_test.html',
+ [
+ 'config_name' => 'tpl_allow_php',
+ ],
+ [],
+ [],
+ '',
+ []
+ ],
+ ];
+ }
+
+ /**
+ * @dataProvider data_template_extensions
+ */
+ public function test_get_user_avatar($file, $vars, $block_vars, $destroy_array, $expected, $lang_vars = [])
+ {
+ $this->run_template($file, $vars, $block_vars, $destroy_array, $expected, $lang_vars);
+ }
+}
diff --git a/tests/template/template_allfolder_test.php b/tests/template/template_allfolder_test.php
index 63a6ef08ea..a9a8ecc287 100644
--- a/tests/template/template_allfolder_test.php
+++ b/tests/template/template_allfolder_test.php
@@ -40,7 +40,7 @@ class phpbb_template_allfolder_test extends phpbb_template_template_test_case
new phpbb_mock_request()
),
$filesystem,
- $this->getMock('\phpbb\request\request'),
+ $this->createMock('\phpbb\request\request'),
$phpbb_root_path,
$phpEx
);
@@ -75,7 +75,7 @@ class phpbb_template_allfolder_test extends phpbb_template_template_test_case
'autoescape' => false,
)
);
- $this->template = new \phpbb\template\twig\twig($path_helper, $config, $context, $twig, $cache_path, $this->user, array(new \phpbb\template\twig\extension($context, $this->user)), $this->extension_manager);
+ $this->template = new \phpbb\template\twig\twig($path_helper, $config, $context, $twig, $cache_path, $this->user, array(new \phpbb\template\twig\extension($context, $twig, $this->user)), $this->extension_manager);
$twig->setLexer(new \phpbb\template\twig\lexer($twig));
$this->template_path = $this->test_path . '/templates';
diff --git a/tests/template/template_events_test.php b/tests/template/template_events_test.php
index 3a93c91e11..9243390937 100644
--- a/tests/template/template_events_test.php
+++ b/tests/template/template_events_test.php
@@ -145,7 +145,7 @@ Zeta test event in all',
new phpbb_mock_request()
),
new \phpbb\filesystem\filesystem(),
- $this->getMock('\phpbb\request\request'),
+ $this->createMock('\phpbb\request\request'),
$phpbb_root_path,
$phpEx
);
@@ -169,7 +169,7 @@ Zeta test event in all',
'autoescape' => false,
)
);
- $this->template = new \phpbb\template\twig\twig($path_helper, $config, $context, $twig, $cache_path, $this->user, array(new \phpbb\template\twig\extension($context, $this->user)), $this->extension_manager);
+ $this->template = new \phpbb\template\twig\twig($path_helper, $config, $context, $twig, $cache_path, $this->user, array(new \phpbb\template\twig\extension($context, $twig, $this->user)), $this->extension_manager);
$twig->setLexer(new \phpbb\template\twig\lexer($twig));
$this->template->set_custom_style(((!empty($style_names)) ? $style_names : 'silver'), array($this->template_path));
diff --git a/tests/template/template_includecss_test.php b/tests/template/template_includecss_test.php
index 4eb30eda1e..5f9875a556 100644
--- a/tests/template/template_includecss_test.php
+++ b/tests/template/template_includecss_test.php
@@ -35,7 +35,7 @@ class phpbb_template_template_includecss_test extends phpbb_template_template_te
new phpbb_mock_request()
),
$filesystem,
- $this->getMock('\phpbb\request\request'),
+ $this->createMock('\phpbb\request\request'),
$phpbb_root_path,
$phpEx
);
@@ -68,7 +68,7 @@ class phpbb_template_template_includecss_test extends phpbb_template_template_te
$twig,
$cache_path,
$this->user,
- array(new \phpbb\template\twig\extension($context, $this->user)),
+ array(new \phpbb\template\twig\extension($context, $twig, $this->user)),
new phpbb_mock_extension_manager(
dirname(__FILE__) . '/',
array(
diff --git a/tests/template/template_test.php b/tests/template/template_test.php
index 727f35e9d2..01c132e032 100644
--- a/tests/template/template_test.php
+++ b/tests/template/template_test.php
@@ -521,7 +521,7 @@ class phpbb_template_template_test extends phpbb_template_template_test_case
$this->template->set_filenames(array('test' => $filename));
$this->assertFileNotExists($this->template_path . '/' . $filename, 'Testing missing file, file cannot exist');
- $this->setExpectedException('Twig_Error_Loader');
+ $this->expectException('Twig_Error_Loader');
$this->display('test');
}
@@ -529,7 +529,7 @@ class phpbb_template_template_test extends phpbb_template_template_test_case
public function test_invalid_handle()
{
- $this->setExpectedException('Twig_Error_Loader');
+ $this->expectException('Twig_Error_Loader');
$this->display('test');
}
diff --git a/tests/template/template_test_case.php b/tests/template/template_test_case.php
index 8adbafb1b2..0389088ec8 100644
--- a/tests/template/template_test_case.php
+++ b/tests/template/template_test_case.php
@@ -87,7 +87,7 @@ class phpbb_template_template_test_case extends phpbb_test_case
new phpbb_mock_request()
),
$filesystem,
- $this->getMock('\phpbb\request\request'),
+ $this->createMock('\phpbb\request\request'),
$phpbb_root_path,
$phpEx
);
@@ -113,12 +113,12 @@ class phpbb_template_template_test_case extends phpbb_test_case
'autoescape' => false,
)
);
- $this->template = new phpbb\template\twig\twig($path_helper, $config, $context, $twig, $cache_path, $this->user, array(new \phpbb\template\twig\extension($context, $this->user)));
+ $this->template = new phpbb\template\twig\twig($path_helper, $config, $context, $twig, $cache_path, $this->user, array(new \phpbb\template\twig\extension($context, $twig, $this->user)));
$twig->setLexer(new \phpbb\template\twig\lexer($twig));
$this->template->set_custom_style('tests', $this->template_path);
}
- protected function setUp()
+ protected function setUp(): void
{
// Test the engine can be used
$this->setup_engine();
@@ -130,7 +130,7 @@ class phpbb_template_template_test_case extends phpbb_test_case
$phpbb_filesystem = new \phpbb\filesystem\filesystem();
}
- protected function tearDown()
+ protected function tearDown(): void
{
if ($this->template)
{
diff --git a/tests/template/template_test_case_with_tree.php b/tests/template/template_test_case_with_tree.php
index 75e3918f44..c0238b6f03 100644
--- a/tests/template/template_test_case_with_tree.php
+++ b/tests/template/template_test_case_with_tree.php
@@ -29,7 +29,7 @@ class phpbb_template_template_test_case_with_tree extends phpbb_template_templat
new phpbb_mock_request()
),
$filesystem,
- $this->getMock('\phpbb\request\request'),
+ $this->createMock('\phpbb\request\request'),
$phpbb_root_path,
$phpEx
);
@@ -56,7 +56,7 @@ class phpbb_template_template_test_case_with_tree extends phpbb_template_templat
'autoescape' => false,
)
);
- $this->template = new phpbb\template\twig\twig($this->phpbb_path_helper, $config, $context, $twig, $cache_path, $this->user, array(new \phpbb\template\twig\extension($context, $this->user)));
+ $this->template = new phpbb\template\twig\twig($this->phpbb_path_helper, $config, $context, $twig, $cache_path, $this->user, array(new \phpbb\template\twig\extension($context, $twig, $this->user)));
$twig->setLexer(new \phpbb\template\twig\lexer($twig));
$this->template->set_custom_style('tests', array($this->template_path, $this->parent_template_path));
}
diff --git a/tests/template/templates/avatar_user.html b/tests/template/templates/avatar_user.html
new file mode 100644
index 0000000000..bd0b960611
--- /dev/null
+++ b/tests/template/templates/avatar_user.html
@@ -0,0 +1 @@
+{{ avatar('user', row, alt, ignore_config, lazy) }}
diff --git a/tests/template/templates/expressions.html b/tests/template/templates/expressions.html
index e1283f165f..17a5b8d265 100644
--- a/tests/template/templates/expressions.html
+++ b/tests/template/templates/expressions.html
@@ -3,7 +3,7 @@
<!-- IF not 390 is even -->fail<!-- ELSE -->pass<!-- ENDIF -->
<!-- IF 9 is odd -->pass<!-- ELSE -->fail<!-- ENDIF -->
<!-- IF 32 is odd -->fail<!-- ELSE -->pass<!-- ENDIF -->
-<!-- IF 32 is div by 16 -->pass<!-- ELSE -->fail<!-- ENDIF -->
+<!-- IF 32 is divisible by(16) -->pass<!-- ELSE -->fail<!-- ENDIF -->
<!-- IF 10 is not even -->fail<!-- ELSE -->pass<!-- ENDIF -->
<!-- IF 24 == 24 -->pass<!-- ELSE -->fail<!-- ENDIF -->
<!-- IF 24 eq 24 -->pass<!-- ELSE -->fail<!-- ENDIF -->
diff --git a/tests/template/templates/extension_config_test.html b/tests/template/templates/extension_config_test.html
new file mode 100644
index 0000000000..0f12ab2672
--- /dev/null
+++ b/tests/template/templates/extension_config_test.html
@@ -0,0 +1 @@
+{{ config(config_name) }}
diff --git a/tests/template/templates/extension_username_test.html b/tests/template/templates/extension_username_test.html
new file mode 100644
index 0000000000..a78bf0df62
--- /dev/null
+++ b/tests/template/templates/extension_username_test.html
@@ -0,0 +1 @@
+{{ username(mode, user_id, username, user_colour, guest_username, custom_profile_url) }}