diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/all_tests.php | 4 | ||||
-rw-r--r-- | tests/bbcode/all_tests.php | 44 | ||||
-rw-r--r-- | tests/bbcode/parser_test.php | 31 | ||||
-rw-r--r-- | tests/request/request_class.php | 74 | ||||
-rw-r--r-- | tests/request/request_var.php | 85 | ||||
-rw-r--r-- | tests/template/template.php | 88 | ||||
-rw-r--r-- | tests/template/templates/includephp.html | 2 | ||||
-rw-r--r-- | tests/template/templates/loop_expressions.html | 11 |
8 files changed, 336 insertions, 3 deletions
diff --git a/tests/all_tests.php b/tests/all_tests.php index 1ed6126e80..a9421067ff 100644 --- a/tests/all_tests.php +++ b/tests/all_tests.php @@ -7,8 +7,6 @@ * */ -error_reporting(E_ALL); - if (!defined('PHPUnit_MAIN_METHOD')) { define('PHPUnit_MAIN_METHOD', 'phpbb_all_tests::main'); @@ -21,6 +19,7 @@ require_once 'utf/all_tests.php'; require_once 'request/all_tests.php'; require_once 'security/all_tests.php'; require_once 'template/all_tests.php'; +#require_once 'bbcode/all_tests.php'; require_once 'text_processing/all_tests.php'; // exclude the test directory from code coverage reports @@ -41,6 +40,7 @@ class phpbb_all_tests $suite->addTest(phpbb_request_all_tests::suite()); $suite->addTest(phpbb_security_all_tests::suite()); $suite->addTest(phpbb_template_all_tests::suite()); +# $suite->addTest(phpbb_bbcode_all_tests::suite()); $suite->addTest(phpbb_text_processing_all_tests::suite()); return $suite; diff --git a/tests/bbcode/all_tests.php b/tests/bbcode/all_tests.php new file mode 100644 index 0000000000..f4200fd0a9 --- /dev/null +++ b/tests/bbcode/all_tests.php @@ -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_bbcode_all_tests::main'); +} + +require_once 'test_framework/framework.php'; +require_once 'PHPUnit/TextUI/TestRunner.php'; + +require_once 'bbcode/parser_test.php'; + +class phpbb_bbcode_all_tests +{ + public static function main() + { + PHPUnit_TextUI_TestRunner::run(self::suite()); + } + + public static function suite() + { + $suite = new PHPUnit_Framework_TestSuite('phpBB Formatted Text / BBCode'); + + $suite->addTestSuite('phpbb_bbcode_parser_test'); + + return $suite; + } +} + +if (PHPUnit_MAIN_METHOD == 'phpbb_bbcode_all_tests::main') +{ + phpbb_bbcode_all_tests::main(); +} +?>
\ No newline at end of file diff --git a/tests/bbcode/parser_test.php b/tests/bbcode/parser_test.php new file mode 100644 index 0000000000..729fe93fc2 --- /dev/null +++ b/tests/bbcode/parser_test.php @@ -0,0 +1,31 @@ +<?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); + +require_once 'test_framework/framework.php'; +require_once '../phpBB/includes/bbcode/bbcode_parser_base.php'; +require_once '../phpBB/includes/bbcode/bbcode_parser.php'; + +class phpbb_bbcode_parser_test extends PHPUnit_Framework_TestCase +{ + public function test_both_passes() + { + $parser = new phpbb_bbcode_parser(); + + $result = $parser->first_pass('[i]Italic [u]underlined text[/u][/i]'); + $result = $parser->second_pass($result); + + $expected = '<span style="font-style: italic">Italic <span style="text-decoration: underline">underlined text</span></span>'; + + $this->assertEquals($expected, $result, 'Simple nested BBCode first+second pass'); + } +} +?>
\ No newline at end of file diff --git a/tests/request/request_class.php b/tests/request/request_class.php new file mode 100644 index 0000000000..e8c2154bab --- /dev/null +++ b/tests/request/request_class.php @@ -0,0 +1,74 @@ +<?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); + +require_once 'test_framework/framework.php'; + +require_once '../phpBB/includes/functions.php'; + +class phpbb_request_request_class_test extends phpbb_test_case +{ + protected function setUp() + { + $_POST['test'] = 1; + $_GET['test'] = 2; + $_COOKIE['test'] = 3; + $_REQUEST['test'] = 3; + + // reread data from super globals + request::reset(); + } + + public function test_toggle_super_globals() + { + // toggle super globals + request::disable_super_globals(); + request::enable_super_globals(); + + $this->assertEquals(1, $_POST['test'], 'Checking $_POST toggling via request::dis/enable_super_globals'); + $this->assertEquals(2, $_GET['test'], 'Checking $_GET toggling via request::dis/enable_super_globals'); + $this->assertEquals(3, $_COOKIE['test'], 'Checking $_COOKIE toggling via request::dis/enable_super_globals'); + $this->assertEquals(3, $_REQUEST['test'], 'Checking $_REQUEST toggling via request::dis/enable_super_globals'); + + $_POST['x'] = 2; + $this->assertEquals($_POST, $GLOBALS['_POST'], 'Checking whether $_POST can still be accessed via $GLOBALS[\'_POST\']'); + } + + /** + * Checks that directly accessing $_POST will trigger + * an error. + */ + public function test_disable_post_super_global() + { + request::disable_super_globals(); + + $this->setExpectedTriggerError(E_USER_ERROR); + $_POST['test'] = 3; + } + + public function test_is_set_post() + { + $_GET['unset'] = ''; + request::reset(); + + $this->assertTrue(request::is_set_post('test')); + $this->assertFalse(request::is_set_post('unset')); + } + + /** + * Makes sure super globals work properly after these tests + */ + protected function tearDown() + { + request::enable_super_globals(); + request::reset(); + } +}
\ No newline at end of file diff --git a/tests/request/request_var.php b/tests/request/request_var.php index b1dacef3fd..0f24d77034 100644 --- a/tests/request/request_var.php +++ b/tests/request/request_var.php @@ -73,6 +73,45 @@ class phpbb_request_request_var_test extends phpbb_test_case unset($_GET[$var], $_POST[$var], $_REQUEST[$var], $_COOKIE[$var]); } + /** + * @dataProvider deep_access + * Only possible with 3.1.x (later) + public function test_deep_multi_dim_array_access($path, $default, $expected) + { + $this->unset_variables('var'); + + $_REQUEST['var'] = array( + 0 => array( + 'b' => array( + true => array( + 5 => 'c', + 6 => 'd', + ), + ), + ), + 2 => array( + 3 => array( + false => 5, + ), + ), + ); + + $result = request_var($path, $default); + $this->assertEquals($expected, $result, 'Testing deep access to multidimensional input arrays: ' . $path); + } + + public static function deep_access() + { + return array( + // array(path, default, expected result) + array(array('var', 0, 'b', true, 5), '', 'c'), + array(array('var', 0, 'b', true, 6), '', 'd'), + array(array('var', 2, 3, false), 0, 5), + array(array('var', 0, 'b', true), array(0 => ''), array(5 => 'c', 6 => 'd')), + ); + } +*/ + public static function request_variables() { return array( @@ -173,6 +212,52 @@ class phpbb_request_request_var_test extends phpbb_test_case 'abc' => array() ) ), + /* 3-dimensional (not supported atm! + array( + // input: + array( + 0 => array(0 => array(3, '4', 'ab'), 1 => array()), + 1 => array(array(3, 4)), + ), + // default: + array(0 => array(0 => array(0))), + false, + // expected: + array( + 0 => array(0 => array(3, 4, 0), 1 => array()), + 1 => array(array(3, 4)) + ) + ), + array( + // input: + array( + 'ü' => array(array('c' => 'd')), + 'ä' => array(4 => array('a' => 2, 'ö' => 3)), + ), + // default: + array('' => array(0 => array('' => 0))), + false, + // expected: + array( + '??' => array(4 => array('a' => 2, '??' => 3)), + ) + ), + array( + // input: + array( + 'ü' => array(array('c' => 'd')), + 'ä' => array(4 => array('a' => 2, 'ö' => 3)), + ), + // default: + array('' => array(0 => array('' => 0))), + true, + // expected: + array( + 'ü' => array(array('c' => 0)), + 'ä' => array(4 => array('a' => 2, 'ö' => 3)), + ) + ), + */ ); } diff --git a/tests/template/template.php b/tests/template/template.php index df12f92046..e3ea532383 100644 --- a/tests/template/template.php +++ b/tests/template/template.php @@ -2,6 +2,10 @@ /** * * @package testing +<<<<<<< HEAD +* @version $Id$ +======= +>>>>>>> develop-olympus * @copyright (c) 2008 phpBB Group * @license http://opensource.org/licenses/gpl-license.php GNU Public License * @@ -17,6 +21,14 @@ class phpbb_template_template_test extends phpbb_test_case private $template_path; // Keep the contents of the cache for debugging? +<<<<<<< HEAD + const PRESERVE_CACHE = false; + + private function display($handle) + { + ob_start(); + $this->assertTrue($this->template->display($handle, false)); +======= const PRESERVE_CACHE = true; private function display($handle) @@ -31,6 +43,7 @@ class phpbb_template_template_test extends phpbb_test_case // reset error level error_reporting($error_level); +>>>>>>> develop-olympus return self::trim_template_result(ob_get_clean()); } @@ -119,7 +132,11 @@ class phpbb_template_template_test extends phpbb_test_case array('S_VALUE' => true), array(), array(), +<<<<<<< HEAD + '1', +======= "1\n0", +>>>>>>> develop-olympus ), array( 'if.html', @@ -161,15 +178,24 @@ class phpbb_template_template_test extends phpbb_test_case array(), array('loop' => array(array(), array()), 'loop.block' => array(array()), 'block' => array(array(), array())), array(), +<<<<<<< HEAD + "loop\nloop\nloop\nloop\n\nloop#0-block#0\nloop#0-block#1\nloop#1-block#0\nloop#1-block#1", +======= "loop\nloop\nloop\nloop\nloop#0-block#0\nloop#0-block#1\nloop#1-block#0\nloop#1-block#1", +>>>>>>> develop-olympus ), array( 'loop_vars.html', array(), array('loop' => array(array('VARIABLE' => 'x'))), array(), +<<<<<<< HEAD + "first\n0\n0\n1\nx\nset\nlast", + ), +======= "first\n0\nx\nset\nlast", ),/* no nested top level loops +>>>>>>> develop-olympus array( 'loop_vars.html', array(), @@ -183,34 +209,54 @@ class phpbb_template_template_test extends phpbb_test_case array('loop' => array(array('VARIABLE' => 'x'), array('VARIABLE' => 'y')), 'loop.inner' => array(array(), array())), array(), "first\n0\n0\n2\nx\nset\n1\n1\n2\ny\nset\nlast\n0\n\n1\nlast inner\ninner loop", +<<<<<<< HEAD + ), +======= ),*/ +>>>>>>> develop-olympus array( 'loop_advanced.html', array(), array('loop' => array(array(), array(), array(), array(), array(), array(), array())), array(), +<<<<<<< HEAD + "101234561\n101234561\n101234561\n1234561\n1\n101\n234\n10\n561\n561", +======= "101234561\nx\n101234561\nx\n101234561\nx\n1234561\nx\n1\nx\n101\nx\n234\nx\n10\nx\n561\nx\n561", +>>>>>>> develop-olympus ), array( 'define.html', array(), array('loop' => array(array(), array(), array(), array(), array(), array(), array()), 'test' => array(array()), 'test.deep' => array(array()), 'test.deep.defines' => array(array())), array(), +<<<<<<< HEAD + "xyz\nabc\n\n00\n11\n22\n33\n44\n55\n66\n\n144\n144", +======= "xyz\nabc", +>>>>>>> develop-olympus ), array( 'expressions.html', array(), array(), array(), +<<<<<<< HEAD + trim(str_repeat("pass\n", 40)), +======= trim(str_repeat("pass", 39)), +>>>>>>> develop-olympus ), array( 'php.html', array(), array(), array(), +<<<<<<< HEAD + '<!-- echo "test"; -->', +======= '', +>>>>>>> develop-olympus ), array( 'include.html', @@ -225,14 +271,29 @@ class phpbb_template_template_test extends phpbb_test_case array('loop' => array(array('VARIABLE' => 'x'), array('VARIABLE' => 'y')), 'loop.inner' => array(array(), array())), array('loop'), '', +<<<<<<< HEAD + ), +======= ),/* no top level nested loops +>>>>>>> develop-olympus array( 'loop_vars.html', array(), array('loop' => array(array('VARIABLE' => 'x'), array('VARIABLE' => 'y')), 'loop.inner' => array(array(), array())), array('loop.inner'), "first\n0\n0\n2\nx\nset\n1\n1\n2\ny\nset\nlast", +<<<<<<< HEAD + ), + array( + 'loop_expressions.html', + array(), + array('loop' => array(array(), array(), array(), array(), array(), array(), array(), array(), array(), array(), array(), array())), + array(), + "on\non\non\non\noff\noff\noff\noff\non\non\non\non\n\noff\noff\noff\non\non\non\noff\noff\noff\non\non\non", + ), +======= ),*/ +>>>>>>> develop-olympus array( 'lang.html', array(), @@ -346,7 +407,10 @@ class phpbb_template_template_test extends phpbb_test_case /** * @dataProvider template_data +<<<<<<< HEAD +======= */ +>>>>>>> develop-olympus public function test_assign_display($file, array $vars, array $block_vars, array $destroy, $expected) { $this->template->set_filenames(array( @@ -388,12 +452,20 @@ class phpbb_template_template_test extends phpbb_test_case $GLOBALS['config']['tpl_allow_php'] = false; } +<<<<<<< HEAD +*/ +/* + public function test_includephp() + { + phpbb::$config['tpl_allow_php'] = true; +======= public function test_includephp() { $this->markTestIncomplete('Include PHP test file paths are broken'); $GLOBALS['config']['tpl_allow_php'] = true; +>>>>>>> develop-olympus $cache_file = $this->template->cachepath . 'includephp.html.' . PHP_EXT; @@ -407,9 +479,15 @@ class phpbb_template_template_test extends phpbb_test_case chdir($cwd); +<<<<<<< HEAD + phpbb::$config['tpl_allow_php'] = false; + } +*/ +======= $GLOBALS['config']['tpl_allow_php'] = false; } +>>>>>>> develop-olympus public static function alter_block_array_data() { return array( @@ -643,11 +721,16 @@ EOT /** * @dataProvider alter_block_array_data +<<<<<<< HEAD + public function test_alter_block_array($alter_block, array $vararray, $key, $mode, $expect, $description) + { +======= */ public function test_alter_block_array($alter_block, array $vararray, $key, $mode, $expect, $description) { $this->markTestIncomplete('Alter Block Test is broken'); +>>>>>>> develop-olympus $this->template->set_filenames(array('test' => 'loop_nested.html')); // @todo Change this @@ -667,5 +750,10 @@ EOT $this->template->alter_block_array($alter_block, $vararray, $key, $mode); $this->assertEquals($expect, $this->display('test'), $description); } +<<<<<<< HEAD + */ +} +======= } +>>>>>>> develop-olympus diff --git a/tests/template/templates/includephp.html b/tests/template/templates/includephp.html index 3e13fa33fa..42c78b9377 100644 --- a/tests/template/templates/includephp.html +++ b/tests/template/templates/includephp.html @@ -1 +1 @@ -<!-- INCLUDEPHP ../templates/_dummy_include.php --> +<!-- INCLUDEPHP _dummy_include.php --> diff --git a/tests/template/templates/loop_expressions.html b/tests/template/templates/loop_expressions.html new file mode 100644 index 0000000000..6bff53f388 --- /dev/null +++ b/tests/template/templates/loop_expressions.html @@ -0,0 +1,11 @@ +<!-- BEGIN loop --> + +<!-- IF loop.S_ROW_NUM is even by 4 -->on<!-- ELSE -->off<!-- ENDIF --> + +<!-- END loop --> + +<!-- BEGIN loop --> + +<!-- IF loop.S_ROW_NUM is odd by 3 -->on<!-- ELSE -->off<!-- ENDIF --> + +<!-- END loop --> |