mirror of
https://github.com/phpbb/phpbb.git
synced 2025-06-07 20:08:53 +00:00
Initial template tests, a bit hackish currently, excuse the rushed nature of this commit got to catch a train :)
git-svn-id: file:///svn/phpbb/trunk@9020 89ea8834-ac86-4346-8a33-228a782c2dd0
This commit is contained in:
parent
baf8d571e3
commit
69cfb5b821
10 changed files with 330 additions and 0 deletions
|
@ -22,6 +22,7 @@ require_once 'bbcode/all_tests.php';
|
|||
require_once 'utf/all_tests.php';
|
||||
require_once 'request/all_tests.php';
|
||||
require_once 'security/all_tests.php';
|
||||
require_once 'template/all_tests.php';
|
||||
|
||||
// exclude the test directory from code coverage reports
|
||||
PHPUnit_Util_Filter::addDirectoryToFilter('./');
|
||||
|
@ -41,6 +42,7 @@ class phpbb_all_tests
|
|||
$suite->addTest(phpbb_utf_all_tests::suite());
|
||||
$suite->addTest(phpbb_request_all_tests::suite());
|
||||
$suite->addTest(phpbb_security_all_tests::suite());
|
||||
$suite->addTest(phpbb_template_all_tests::suite());
|
||||
|
||||
return $suite;
|
||||
}
|
||||
|
|
44
tests/template/all_tests.php
Normal file
44
tests/template/all_tests.php
Normal file
|
@ -0,0 +1,44 @@
|
|||
<?php
|
||||
/**
|
||||
*
|
||||
* @package testing
|
||||
* @version $Id$
|
||||
* @copyright (c) 2008 phpBB Group
|
||||
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
|
||||
*
|
||||
*/
|
||||
|
||||
define('IN_PHPBB', true);
|
||||
|
||||
if (!defined('PHPUnit_MAIN_METHOD'))
|
||||
{
|
||||
define('PHPUnit_MAIN_METHOD', 'phpbb_template_all_tests::main');
|
||||
}
|
||||
|
||||
require_once 'PHPUnit/Framework.php';
|
||||
require_once 'PHPUnit/TextUI/TestRunner.php';
|
||||
|
||||
require_once 'template/template.php';
|
||||
|
||||
class phpbb_template_all_tests
|
||||
{
|
||||
public static function main()
|
||||
{
|
||||
PHPUnit_TextUI_TestRunner::run(self::suite());
|
||||
}
|
||||
|
||||
public static function suite()
|
||||
{
|
||||
$suite = new PHPUnit_Framework_TestSuite('phpBB Template Engine');
|
||||
|
||||
$suite->addTestSuite('phpbb_template_template_test');
|
||||
|
||||
return $suite;
|
||||
}
|
||||
}
|
||||
|
||||
if (PHPUnit_MAIN_METHOD == 'phpbb_template_all_tests::main')
|
||||
{
|
||||
phpbb_template_all_tests::main();
|
||||
}
|
||||
?>
|
144
tests/template/template.php
Normal file
144
tests/template/template.php
Normal file
|
@ -0,0 +1,144 @@
|
|||
<?php
|
||||
/**
|
||||
*
|
||||
* @package testing
|
||||
* @version $Id$
|
||||
* @copyright (c) 2008 phpBB Group
|
||||
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
|
||||
*
|
||||
*/
|
||||
|
||||
define('IN_PHPBB', true);
|
||||
define('PHP_EXT', 'php');
|
||||
define('PHPBB_ROOT_PATH', '../phpBB/');
|
||||
|
||||
require_once 'PHPUnit/Framework.php';
|
||||
|
||||
require_once '../phpBB/includes/constants.php';
|
||||
require_once '../phpBB/includes/functions.php';
|
||||
require_once '../phpBB/includes/template.php';
|
||||
|
||||
$config = array(
|
||||
'load_tplcompile' => true
|
||||
);
|
||||
|
||||
class phpbb_template_template_test extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
private $template;
|
||||
|
||||
private function display($handle)
|
||||
{
|
||||
ob_start();
|
||||
$this->assertTrue($this->template->display($handle, false));
|
||||
$contents = str_replace("\n\n", "\n", implode("\n", array_map('trim', explode("\n", trim(ob_get_contents())))));
|
||||
ob_end_clean();
|
||||
|
||||
return $contents;
|
||||
}
|
||||
|
||||
private function setup_engine()
|
||||
{
|
||||
$this->template = new template;
|
||||
$this->template->set_custom_template(dirname(__FILE__) . '/templates/', 'tests');
|
||||
}
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public static function template_data()
|
||||
{
|
||||
return array(
|
||||
/*
|
||||
array(
|
||||
'', // File
|
||||
array(), // vars
|
||||
array(), // block vars
|
||||
'', // Expected result
|
||||
),
|
||||
*/
|
||||
array(
|
||||
'variable.html',
|
||||
array('VARIABLE' => 'value'),
|
||||
array(),
|
||||
'value',
|
||||
),
|
||||
array(
|
||||
'if.html',
|
||||
array(),
|
||||
array(),
|
||||
'0',
|
||||
),
|
||||
array(
|
||||
'if.html',
|
||||
array('S_VALUE' => true),
|
||||
array(),
|
||||
'1',
|
||||
),
|
||||
array(
|
||||
'loop.html',
|
||||
array(),
|
||||
array(),
|
||||
"noloop\nnoloop",
|
||||
),
|
||||
array(
|
||||
'loop.html',
|
||||
array(),
|
||||
array('loop' => array(array())),
|
||||
"loop\nloop",
|
||||
),
|
||||
array(
|
||||
'loop.html',
|
||||
array(),
|
||||
array('loop' => array(array(), array())),
|
||||
"loop\nloop\nloop",
|
||||
),
|
||||
array(
|
||||
'loop_vars.html',
|
||||
array(),
|
||||
array('loop' => array(array('VARIABLE' => 'x'))),
|
||||
"first\n0\nx\nlast",
|
||||
),
|
||||
array(
|
||||
'loop_vars.html',
|
||||
array(),
|
||||
array('loop' => array(array('VARIABLE' => 'x'), array('VARIABLE' => 'y'))),
|
||||
"first\n0\nx\n1\ny\nlast",
|
||||
),
|
||||
array(
|
||||
'define.html',
|
||||
array(),
|
||||
array(),
|
||||
"xyz\nabc",
|
||||
),
|
||||
array(
|
||||
'expressions.html',
|
||||
array(),
|
||||
array(),
|
||||
trim(str_repeat("pass\n", 38)),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider template_data
|
||||
*/
|
||||
public function test_template($file, array $vars, array $block_vars, $expected)
|
||||
{
|
||||
$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.html");
|
||||
}
|
||||
}
|
||||
?>
|
18
tests/template/templates/basic.html
Normal file
18
tests/template/templates/basic.html
Normal file
|
@ -0,0 +1,18 @@
|
|||
<!-- IF S_FALSE -->
|
||||
fail
|
||||
<!-- ENDIF -->
|
||||
<!-- IF S_TRUE -->
|
||||
pass
|
||||
<!-- ENDIF -->
|
||||
<!-- IF S_FALSE -->
|
||||
fail
|
||||
<!-- ELSEIF S_FALSE and not S_TRUE -->
|
||||
fail
|
||||
<!-- ELSE -->
|
||||
pass
|
||||
<!-- ENDIF -->
|
||||
<!-- BEGIN empty -->
|
||||
fail
|
||||
<!-- BEGINELSE -->
|
||||
pass
|
||||
<!-- END empty -->
|
11
tests/template/templates/define.html
Normal file
11
tests/template/templates/define.html
Normal file
|
@ -0,0 +1,11 @@
|
|||
<!-- DEFINE $VALUE = 'xyz' -->
|
||||
|
||||
{$VALUE}
|
||||
|
||||
<!-- DEFINE $VALUE = 'abc' -->
|
||||
|
||||
{$VALUE}
|
||||
|
||||
<!-- UNDEFINE $VALUE -->
|
||||
|
||||
{$VALUE}
|
85
tests/template/templates/expressions.html
Normal file
85
tests/template/templates/expressions.html
Normal file
|
@ -0,0 +1,85 @@
|
|||
<!-- IF 10 is even -->pass<!-- ELSE -->fail<!-- ENDIF -->
|
||||
|
||||
<!-- IF 9 is even -->fail<!-- ELSE -->pass<!-- ENDIF -->
|
||||
|
||||
<!-- 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 24 == 24 -->pass<!-- ELSE -->fail<!-- ENDIF -->
|
||||
|
||||
<!-- IF 24 eq 24 -->pass<!-- ELSE -->fail<!-- ENDIF -->
|
||||
|
||||
<!-- IF ((((((24 == 24)))))) -->pass<!-- ELSE -->fail<!-- ENDIF -->
|
||||
|
||||
|
||||
<!-- IF 24 != 20 -->pass<!-- ELSE -->fail<!-- ENDIF -->
|
||||
|
||||
<!-- IF 24 <> 20 -->pass<!-- ELSE -->fail<!-- ENDIF -->
|
||||
|
||||
<!-- IF 24 ne 20 -->pass<!-- ELSE -->fail<!-- ENDIF -->
|
||||
|
||||
<!-- IF 24 neq 20 -->pass<!-- ELSE -->fail<!-- ENDIF -->
|
||||
|
||||
|
||||
<!-- IF 10 lt 20 -->pass<!-- ELSE -->fail<!-- ENDIF -->
|
||||
|
||||
<!-- IF 10 < 20 -->pass<!-- ELSE -->fail<!-- ENDIF -->
|
||||
|
||||
|
||||
<!-- IF 10 le 20 -->pass<!-- ELSE -->fail<!-- ENDIF -->
|
||||
|
||||
<!-- IF 10 lte 20 -->pass<!-- ELSE -->fail<!-- ENDIF -->
|
||||
|
||||
<!-- IF 10 <= 20 -->pass<!-- ELSE -->fail<!-- ENDIF -->
|
||||
|
||||
<!-- IF 20 le 20 -->pass<!-- ELSE -->fail<!-- ENDIF -->
|
||||
|
||||
<!-- IF 20 lte 20 -->pass<!-- ELSE -->fail<!-- ENDIF -->
|
||||
|
||||
<!-- IF 20 <= 20 -->pass<!-- ELSE -->fail<!-- ENDIF -->
|
||||
|
||||
|
||||
<!-- IF 9 gt 1 -->pass<!-- ELSE -->fail<!-- ENDIF -->
|
||||
|
||||
<!-- IF 9 > 1 -->pass<!-- ELSE -->fail<!-- ENDIF -->
|
||||
|
||||
|
||||
<!-- IF 9 >= 1 -->pass<!-- ELSE -->fail<!-- ENDIF -->
|
||||
|
||||
<!-- IF 9 gte 1 -->pass<!-- ELSE -->fail<!-- ENDIF -->
|
||||
|
||||
<!-- IF 9 ge 1 -->pass<!-- ELSE -->fail<!-- ENDIF -->
|
||||
|
||||
<!-- IF 9 >= 9 -->pass<!-- ELSE -->fail<!-- ENDIF -->
|
||||
|
||||
<!-- IF 9 gte 9 -->pass<!-- ELSE -->fail<!-- ENDIF -->
|
||||
|
||||
<!-- IF 9 ge 9 -->pass<!-- ELSE -->fail<!-- ENDIF -->
|
||||
|
||||
|
||||
<!-- IF true && (10 > 4) -->pass<!-- ELSE -->fail<!-- ENDIF -->
|
||||
|
||||
<!-- IF true and (10 > 4) -->pass<!-- ELSE -->fail<!-- ENDIF -->
|
||||
|
||||
|
||||
<!-- IF false || true -->pass<!-- ELSE -->fail<!-- ENDIF -->
|
||||
|
||||
<!-- IF false or true -->pass<!-- ELSE -->fail<!-- ENDIF -->
|
||||
|
||||
|
||||
<!-- IF !false -->pass<!-- ELSE -->fail<!-- ENDIF -->
|
||||
|
||||
<!-- IF !! true -->pass<!-- ELSE -->fail<!-- ENDIF -->
|
||||
|
||||
<!-- IF not false -->pass<!-- ELSE -->fail<!-- ENDIF -->
|
||||
|
||||
<!-- IF not not not false -->pass<!-- ELSE -->fail<!-- ENDIF -->
|
||||
|
||||
|
||||
<!-- IF 6 % 4 == 2 -->pass<!-- ELSE -->fail<!-- ENDIF -->
|
||||
|
||||
<!-- IF 24 mod 12 == 0 -->pass<!-- ELSE -->fail<!-- ENDIF -->
|
5
tests/template/templates/if.html
Normal file
5
tests/template/templates/if.html
Normal file
|
@ -0,0 +1,5 @@
|
|||
<!-- IF S_VALUE -->
|
||||
1
|
||||
<!-- ELSE -->
|
||||
0
|
||||
<!-- ENDIF -->
|
11
tests/template/templates/loop.html
Normal file
11
tests/template/templates/loop.html
Normal file
|
@ -0,0 +1,11 @@
|
|||
<!-- BEGIN loop -->
|
||||
loop
|
||||
<!-- BEGINELSE -->
|
||||
noloop
|
||||
<!-- END loop -->
|
||||
|
||||
<!-- IF .loop -->
|
||||
loop
|
||||
<!-- ELSE -->
|
||||
noloop
|
||||
<!-- ENDIF -->
|
9
tests/template/templates/loop_vars.html
Normal file
9
tests/template/templates/loop_vars.html
Normal file
|
@ -0,0 +1,9 @@
|
|||
<!-- BEGIN loop -->
|
||||
<!-- IF loop.S_FIRST_ROW -->first<!-- ENDIF -->
|
||||
|
||||
{loop.S_ROW_COUNT}
|
||||
|
||||
{loop.VARIABLE}
|
||||
|
||||
<!-- IF loop.S_LAST_ROW -->last<!-- ENDIF -->
|
||||
<!-- END loop -->
|
1
tests/template/templates/variable.html
Normal file
1
tests/template/templates/variable.html
Normal file
|
@ -0,0 +1 @@
|
|||
{VARIABLE}
|
Loading…
Add table
Reference in a new issue