Refactor and fix :)

git-svn-id: file:///svn/phpbb/trunk@9093 89ea8834-ac86-4346-8a33-228a782c2dd0
This commit is contained in:
Chris Smith 2008-11-23 03:41:54 +00:00
parent f4c079a62b
commit ff22d7a368
3 changed files with 39 additions and 55 deletions

View file

@ -19,14 +19,6 @@ define('PHP_EXT', 'php');
require_once '../phpBB/includes/functions.php'; require_once '../phpBB/includes/functions.php';
require_once '../phpBB/includes/session.php'; require_once '../phpBB/includes/session.php';
if (!isset($config))
{
$config = array();
}
$config += array(
'force_server_vars' => 0,
);
class phpbb_security_redirect_test extends PHPUnit_Extensions_OutputTestCase class phpbb_security_redirect_test extends PHPUnit_Extensions_OutputTestCase
{ {
protected $error_triggered = false; protected $error_triggered = false;
@ -44,6 +36,13 @@ class phpbb_security_redirect_test extends PHPUnit_Extensions_OutputTestCase
); );
} }
protected function setUp()
{
$GLOBALS['config'] = array(
'force_server_vars' => 0,
);
}
/** /**
* Own error handler to catch trigger_error() calls within phpBB * Own error handler to catch trigger_error() calls within phpBB
*/ */

View file

@ -18,19 +18,9 @@ require_once '../phpBB/includes/constants.php';
require_once '../phpBB/includes/functions.php'; require_once '../phpBB/includes/functions.php';
require_once '../phpBB/includes/template.php'; require_once '../phpBB/includes/template.php';
if (!isset($config))
{
$config = array();
}
$config += array(
'load_tplcompile' => true
);
class phpbb_template_template_test extends PHPUnit_Framework_TestCase class phpbb_template_template_test extends PHPUnit_Framework_TestCase
{ {
private $template; private $template;
private static $ran_non_cached = false;
private function display($handle) private function display($handle)
{ {
ob_start(); ob_start();
@ -41,18 +31,10 @@ class phpbb_template_template_test extends PHPUnit_Framework_TestCase
return $contents; return $contents;
} }
private function setup_engine($clear_cache = false) private function setup_engine()
{ {
$this->template = new template; $this->template = new template;
$this->template->set_custom_template(dirname(__FILE__) . '/templates/', 'tests'); $this->template->set_custom_template(dirname(__FILE__) . '/templates/', 'tests');
if ($clear_cache)
{
foreach (glob($this->template->cachepath . '*') as $file)
{
unlink($file);
}
}
} }
protected function setUp() protected function setUp()
@ -64,6 +46,15 @@ class phpbb_template_template_test extends PHPUnit_Framework_TestCase
{ {
$this->markTestSkipped("Template cache directory is not writable."); $this->markTestSkipped("Template cache directory is not writable.");
} }
foreach (glob($this->template->cachepath . '*') as $file)
{
unlink($file);
}
$GLOBALS['config'] = array(
'load_tplcompile' => true
);
} }
/** /**
@ -155,40 +146,15 @@ class phpbb_template_template_test extends PHPUnit_Framework_TestCase
); );
} }
/**
* @dataProvider template_data
*/
public function test_template_no_cache($file, array $vars, array $block_vars, $expected)
{
$this->setup_engine(true);
$this->template->set_filenames(array('test' => $file));
$this->template->assign_vars($vars);
foreach ($block_vars as $block => $loops)
{
foreach ($loops as $_vars)
{
$this->template->assign_block_vars($block, $_vars);
}
}
$this->assertEquals($expected, $this->display('test'), "Testing $file");
self::$ran_non_cached = true;
}
/** /**
* @dataProvider template_data * @dataProvider template_data
*/ */
public function test_template($file, array $vars, array $block_vars, $expected) public function test_template($file, array $vars, array $block_vars, $expected)
{ {
if (!self::$ran_non_cached) $cache_file = $this->template->cachepath . str_replace('/', '.', $file) . '.' . PHP_EXT;
{
$this->fail('Non cached tests failed to run first'); $this->assertFileNotExists($cache_file);
return;
}
$this->setup_engine();
$this->template->set_filenames(array('test' => $file)); $this->template->set_filenames(array('test' => $file));
$this->template->assign_vars($vars); $this->template->assign_vars($vars);
@ -201,6 +167,24 @@ class phpbb_template_template_test extends PHPUnit_Framework_TestCase
} }
$this->assertEquals($expected, $this->display('test'), "Testing $file"); $this->assertEquals($expected, $this->display('test'), "Testing $file");
$this->assertFileExists($cache_file);
// Reset the engine state
$this->setup_engine();
$this->template->set_filenames(array('test' => $file));
$this->template->assign_vars($vars);
foreach ($block_vars as $block => $loops)
{
foreach ($loops as $_vars)
{
$this->template->assign_block_vars($block, $_vars);
}
}
$this->assertEquals($expected, $this->display('test'), "Testing $file");
$this->assertFileExists($cache_file);
} }
} }
?> ?>

View file

@ -0,0 +1 @@
<!-- INCLUDE variable.html -->