aboutsummaryrefslogtreecommitdiffstats
path: root/tests/template/template_test_case.php
diff options
context:
space:
mode:
Diffstat (limited to 'tests/template/template_test_case.php')
-rw-r--r--tests/template/template_test_case.php55
1 files changed, 49 insertions, 6 deletions
diff --git a/tests/template/template_test_case.php b/tests/template/template_test_case.php
index 1250397401..e52d3b76dd 100644
--- a/tests/template/template_test_case.php
+++ b/tests/template/template_test_case.php
@@ -11,10 +11,9 @@
*
*/
-require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php';
-
class phpbb_template_template_test_case extends phpbb_test_case
{
+ protected $lang;
protected $template;
protected $template_path;
protected $user;
@@ -24,6 +23,17 @@ class phpbb_template_template_test_case extends phpbb_test_case
// Keep the contents of the cache for debugging?
const PRESERVE_CACHE = true;
+ static protected $language_reflection_lang;
+
+ static public function setUpBeforeClass()
+ {
+ parent::setUpBeforeClass();
+
+ $reflection = new ReflectionClass('\phpbb\language\language');
+ self::$language_reflection_lang = $reflection->getProperty('lang');
+ self::$language_reflection_lang->setAccessible(true);
+ }
+
protected function display($handle)
{
ob_start();
@@ -65,20 +75,45 @@ class phpbb_template_template_test_case extends phpbb_test_case
$defaults = $this->config_defaults();
$config = new \phpbb\config\config(array_merge($defaults, $new_config));
- $this->user = new \phpbb\user('\phpbb\datetime');
+ $lang_loader = new \phpbb\language\language_file_loader($phpbb_root_path, $phpEx);
+ $this->lang = $lang = new \phpbb\language\language($lang_loader);
+ $user = new \phpbb\user($lang, '\phpbb\datetime');
+ $this->user = $user;
+
+ $filesystem = new \phpbb\filesystem\filesystem();
$path_helper = new \phpbb\path_helper(
new \phpbb\symfony_request(
new phpbb_mock_request()
),
- new \phpbb\filesystem(),
+ $filesystem,
$this->getMock('\phpbb\request\request'),
$phpbb_root_path,
$phpEx
);
$this->template_path = $this->test_path . '/templates';
- $this->template = new \phpbb\template\twig\twig($path_helper, $config, $this->user, new \phpbb\template\context());
+
+ $container = new phpbb_mock_container_builder();
+ $cache_path = $phpbb_root_path . 'cache/twig';
+ $context = new \phpbb\template\context();
+ $loader = new \phpbb\template\twig\loader(new \phpbb\filesystem\filesystem(), '');
+ $twig = new \phpbb\template\twig\environment(
+ $config,
+ $filesystem,
+ $path_helper,
+ $cache_path,
+ null,
+ $loader,
+ array(
+ 'cache' => false,
+ 'debug' => false,
+ 'auto_reload' => true,
+ '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)));
+ $twig->setLexer(new \phpbb\template\twig\lexer($twig));
$this->template->set_custom_style('tests', $this->template_path);
}
@@ -88,6 +123,10 @@ class phpbb_template_template_test_case extends phpbb_test_case
$this->setup_engine();
$this->template->clear_cache();
+
+ global $phpbb_filesystem;
+
+ $phpbb_filesystem = new \phpbb\filesystem\filesystem();
}
protected function tearDown()
@@ -121,12 +160,16 @@ class phpbb_template_template_test_case extends phpbb_test_case
{
foreach ($lang_vars as $name => $value)
{
- $this->user->lang[$name] = $value;
+ self::$language_reflection_lang->setValue($this->lang, array_merge(
+ self::$language_reflection_lang->getValue($this->lang),
+ array($name => $value)
+ ));
}
}
$expected = str_replace(array("\n", "\r", "\t"), '', $expected);
$output = str_replace(array("\n", "\r", "\t"), '', $this->display('test'));
+
$this->assertEquals($expected, $output, "Testing $file");
}
}