mirror of
https://github.com/phpbb/phpbb.git
synced 2025-07-26 11:58:53 +00:00
[feature/twig] Working on fixing tests
PHPBB3-11598
This commit is contained in:
parent
ff84aed0b2
commit
a1f957af84
5 changed files with 72 additions and 63 deletions
|
@ -160,7 +160,7 @@ class phpbb_style
|
||||||
$this->template->set_style_names($names, $appended_paths);
|
$this->template->set_style_names($names, $appended_paths);
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->template->cachepath = $this->phpbb_root_path . 'cache/tpl_' . str_replace('_', '-', $name) . '_';
|
//$this->template->cachepath = $this->phpbb_root_path . 'cache/tpl_' . str_replace('_', '-', $name) . '_';
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -130,4 +130,11 @@ interface phpbb_template
|
||||||
* @return bool false on error, true on success
|
* @return bool false on error, true on success
|
||||||
*/
|
*/
|
||||||
public function alter_block_array($blockname, array $vararray, $key = false, $mode = 'insert');
|
public function alter_block_array($blockname, array $vararray, $key = false, $mode = 'insert');
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Clear the cache
|
||||||
|
*
|
||||||
|
* @return phpbb_template
|
||||||
|
*/
|
||||||
|
public function clear_cache();
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,6 +32,8 @@ class phpbb_template_twig_node_begin extends Twig_Node
|
||||||
;
|
;
|
||||||
|
|
||||||
$compiler
|
$compiler
|
||||||
|
->write("if (!empty(\$parent['" . $this->getAttribute('beginName') . "'])) {\n")
|
||||||
|
->indent()
|
||||||
->write("foreach (\$parent['" . $this->getAttribute('beginName') . "'] as \$" . $this->getAttribute('beginName') . ") {\n")
|
->write("foreach (\$parent['" . $this->getAttribute('beginName') . "'] as \$" . $this->getAttribute('beginName') . ") {\n")
|
||||||
->indent()
|
->indent()
|
||||||
// Set up $context correctly so that Twig can get the correct data with $this->getAttribute
|
// Set up $context correctly so that Twig can get the correct data with $this->getAttribute
|
||||||
|
@ -43,6 +45,20 @@ class phpbb_template_twig_node_begin extends Twig_Node
|
||||||
|
|
||||||
$compiler->subcompile($this->getNode('body'));
|
$compiler->subcompile($this->getNode('body'));
|
||||||
|
|
||||||
|
$compiler
|
||||||
|
->outdent()
|
||||||
|
->write("}\n")
|
||||||
|
;
|
||||||
|
|
||||||
|
if (null !== $this->getNode('else')) {
|
||||||
|
$compiler
|
||||||
|
->write("} else {\n")
|
||||||
|
->indent()
|
||||||
|
->subcompile($this->getNode('else'))
|
||||||
|
->outdent()
|
||||||
|
;
|
||||||
|
}
|
||||||
|
|
||||||
$compiler
|
$compiler
|
||||||
->outdent()
|
->outdent()
|
||||||
->write("}\n")
|
->write("}\n")
|
||||||
|
|
|
@ -114,10 +114,6 @@ class phpbb_template_twig implements phpbb_template
|
||||||
// Initiate the loader, __main__ namespace paths will be setup later in set_style_names()
|
// Initiate the loader, __main__ namespace paths will be setup later in set_style_names()
|
||||||
$loader = new Twig_Loader_Filesystem('');
|
$loader = new Twig_Loader_Filesystem('');
|
||||||
|
|
||||||
// Add admin namespace
|
|
||||||
// @todo use phpbb_admin path
|
|
||||||
$loader->addPath($this->phpbb_root_path . 'adm/style/', 'admin');
|
|
||||||
|
|
||||||
$this->twig = new phpbb_template_twig_environment($loader, array(
|
$this->twig = new phpbb_template_twig_environment($loader, array(
|
||||||
'cache' => $this->cachepath,
|
'cache' => $this->cachepath,
|
||||||
'debug' => true, // @todo
|
'debug' => true, // @todo
|
||||||
|
@ -133,10 +129,7 @@ class phpbb_template_twig implements phpbb_template
|
||||||
|
|
||||||
// Clear previous cache files (while WIP)
|
// Clear previous cache files (while WIP)
|
||||||
// @todo remove
|
// @todo remove
|
||||||
if (is_dir($this->cachepath))
|
$this->clear_cache();
|
||||||
{
|
|
||||||
$this->twig->clearCacheFiles();
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->twig->addExtension(new phpbb_template_twig_extension);
|
$this->twig->addExtension(new phpbb_template_twig_extension);
|
||||||
|
|
||||||
|
@ -145,6 +138,21 @@ class phpbb_template_twig implements phpbb_template
|
||||||
$this->twig->setLexer($lexer);
|
$this->twig->setLexer($lexer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Clear the cache
|
||||||
|
*
|
||||||
|
* @return phpbb_template
|
||||||
|
*/
|
||||||
|
public function clear_cache()
|
||||||
|
{
|
||||||
|
if (is_dir($this->cachepath))
|
||||||
|
{
|
||||||
|
$this->twig->clearCacheFiles();
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the template filenames for handles.
|
* Sets the template filenames for handles.
|
||||||
*
|
*
|
||||||
|
@ -177,6 +185,10 @@ class phpbb_template_twig implements phpbb_template
|
||||||
{
|
{
|
||||||
$this->twig->getLoader()->setPaths($style_paths, 'core');
|
$this->twig->getLoader()->setPaths($style_paths, 'core');
|
||||||
|
|
||||||
|
// Add admin namespace
|
||||||
|
// @todo use phpbb_admin path
|
||||||
|
$loader->addPath($this->phpbb_root_path . 'adm/style/', 'admin');
|
||||||
|
|
||||||
// Add all namespaces for all extensions
|
// Add all namespaces for all extensions
|
||||||
if ($this->extension_manager instanceof phpbb_extension_manager)
|
if ($this->extension_manager instanceof phpbb_extension_manager)
|
||||||
{
|
{
|
||||||
|
@ -415,6 +427,8 @@ class phpbb_template_twig implements phpbb_template
|
||||||
$vars = array();
|
$vars = array();
|
||||||
|
|
||||||
// Work-around for now
|
// Work-around for now
|
||||||
|
if (!empty($this->user->lang))
|
||||||
|
{
|
||||||
foreach ($this->user->lang as $key => $value)
|
foreach ($this->user->lang as $key => $value)
|
||||||
{
|
{
|
||||||
if (!is_string($value))
|
if (!is_string($value))
|
||||||
|
@ -433,6 +447,7 @@ class phpbb_template_twig implements phpbb_template
|
||||||
'_phpbb_blocks' => $this->context->get_tpldata(),
|
'_phpbb_blocks' => $this->context->get_tpldata(),
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
}
|
||||||
|
|
||||||
// Must do this so that <!-- IF .blah --> works correctly
|
// Must do this so that <!-- IF .blah --> works correctly
|
||||||
// (only for the base loops, the rest are properly handled by the begin node)
|
// (only for the base loops, the rest are properly handled by the begin node)
|
||||||
|
|
|
@ -77,32 +77,15 @@ class phpbb_template_template_test_case extends phpbb_test_case
|
||||||
// Test the engine can be used
|
// Test the engine can be used
|
||||||
$this->setup_engine();
|
$this->setup_engine();
|
||||||
|
|
||||||
$template_cache_dir = dirname($this->template->cachepath);
|
$this->template->clear_cache();
|
||||||
if (!is_writable($template_cache_dir))
|
|
||||||
{
|
|
||||||
$this->markTestSkipped("Template cache directory ({$template_cache_dir}) is not writable.");
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach (glob($this->template->cachepath . '*') as $file)
|
|
||||||
{
|
|
||||||
unlink($file);
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->setup_engine();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function tearDown()
|
protected function tearDown()
|
||||||
{
|
{
|
||||||
if (is_object($this->template))
|
$this->template->clear_cache();
|
||||||
{
|
|
||||||
foreach (glob($this->template->cachepath . '*') as $file)
|
|
||||||
{
|
|
||||||
unlink($file);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function run_template($file, array $vars, array $block_vars, array $destroy, $expected, $cache_file)
|
protected function run_template($file, array $vars, array $block_vars, array $destroy, $expected)
|
||||||
{
|
{
|
||||||
$this->template->set_filenames(array('test' => $file));
|
$this->template->set_filenames(array('test' => $file));
|
||||||
$this->template->assign_vars($vars);
|
$this->template->assign_vars($vars);
|
||||||
|
@ -123,22 +106,10 @@ class phpbb_template_template_test_case extends phpbb_test_case
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
$this->assertEquals($expected, $this->display('test'), "Testing $file");
|
$this->assertEquals($expected, $this->display('test'), "Testing $file");
|
||||||
$this->assertFileExists($cache_file);
|
|
||||||
}
|
}
|
||||||
catch (ErrorException $e)
|
catch (ErrorException $e)
|
||||||
{
|
{
|
||||||
if (file_exists($cache_file))
|
|
||||||
{
|
|
||||||
copy($cache_file, str_replace('ctpl_', 'tests_ctpl_', $cache_file));
|
|
||||||
}
|
|
||||||
throw $e;
|
throw $e;
|
||||||
}
|
}
|
||||||
|
|
||||||
// For debugging.
|
|
||||||
// When testing eval path the cache file may not exist.
|
|
||||||
if (self::PRESERVE_CACHE && file_exists($cache_file))
|
|
||||||
{
|
|
||||||
copy($cache_file, str_replace('ctpl_', 'tests_ctpl_', $cache_file));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue