diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/all_tests.php | 6 | ||||
-rw-r--r-- | tests/bbcode/all_tests.php | 44 | ||||
-rw-r--r-- | tests/bbcode/parser_test.php | 31 | ||||
-rw-r--r-- | tests/class_loader/all_tests.php | 41 | ||||
-rw-r--r-- | tests/class_loader/cache_mock.php | 29 | ||||
-rw-r--r-- | tests/class_loader/class_loader_test.php | 65 | ||||
-rw-r--r-- | tests/class_loader/includes/class_name.php | 6 | ||||
-rw-r--r-- | tests/class_loader/includes/dir/class_name.php | 6 | ||||
-rw-r--r-- | tests/class_loader/includes/dir/subdir/class_name.php | 6 | ||||
-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 | 10 | ||||
-rw-r--r-- | tests/template/templates/includephp.html | 2 | ||||
-rw-r--r-- | tests/template/templates/loop_expressions.html | 11 |
14 files changed, 404 insertions, 12 deletions
diff --git a/tests/all_tests.php b/tests/all_tests.php index 7894d688ee..4eee950860 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'); @@ -17,10 +15,12 @@ if (!defined('PHPUnit_MAIN_METHOD')) require_once 'test_framework/framework.php'; require_once 'PHPUnit/TextUI/TestRunner.php'; +require_once 'class_loader/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'; +#require_once 'bbcode/all_tests.php'; require_once 'text_processing/all_tests.php'; require_once 'dbal/all_tests.php'; require_once 'regex/all_tests.php'; @@ -39,10 +39,12 @@ class phpbb_all_tests { $suite = new PHPUnit_Framework_TestSuite('phpBB'); + $suite->addTest(phpbb_class_loader_all_tests::suite()); $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()); +# $suite->addTest(phpbb_bbcode_all_tests::suite()); $suite->addTest(phpbb_text_processing_all_tests::suite()); $suite->addTest(phpbb_dbal_all_tests::suite()); $suite->addTest(phpbb_regex_all_tests::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/class_loader/all_tests.php b/tests/class_loader/all_tests.php new file mode 100644 index 0000000000..451a1b02c2 --- /dev/null +++ b/tests/class_loader/all_tests.php @@ -0,0 +1,41 @@ +<?php +/** +* +* @package testing +* @copyright (c) 2008 phpBB Group +* @license http://opensource.org/licenses/gpl-license.php GNU Public License +* +*/ + +if (!defined('PHPUnit_MAIN_METHOD')) +{ + define('PHPUnit_MAIN_METHOD', 'phpbb_class_loader_all_tests::main'); +} + +require_once 'test_framework/framework.php'; +require_once 'PHPUnit/TextUI/TestRunner.php'; + +require_once 'class_loader/class_loader_test.php'; + +class phpbb_class_loader_all_tests +{ + public static function main() + { + PHPUnit_TextUI_TestRunner::run(self::suite()); + } + + public static function suite() + { + $suite = new PHPUnit_Framework_TestSuite('phpBB Class Loader'); + + $suite->addTestSuite('phpbb_class_loader_test'); + + return $suite; + } +} + +if (PHPUnit_MAIN_METHOD == 'phpbb_class_loader_all_tests::main') +{ + phpbb_class_loader_all_tests::main(); +} + diff --git a/tests/class_loader/cache_mock.php b/tests/class_loader/cache_mock.php new file mode 100644 index 0000000000..c8069fa9cc --- /dev/null +++ b/tests/class_loader/cache_mock.php @@ -0,0 +1,29 @@ +<?php +/** +* +* @package testing +* @version $Id$ +* @copyright (c) 2008 phpBB Group +* @license http://opensource.org/licenses/gpl-license.php GNU Public License +* +*/ + +class phpbb_cache_mock +{ + private $variables = array(); + + function get($var_name) + { + if (isset($this->variables[$var_name])) + { + return $this->variables[$var_name]; + } + + return false; + } + + function put($var_name, $value) + { + $this->variables[$var_name] = $value; + } +}
\ No newline at end of file diff --git a/tests/class_loader/class_loader_test.php b/tests/class_loader/class_loader_test.php new file mode 100644 index 0000000000..37c11657c4 --- /dev/null +++ b/tests/class_loader/class_loader_test.php @@ -0,0 +1,65 @@ +<?php +/** +* +* @package testing +* @version $Id$ +* @copyright (c) 2008 phpBB Group +* @license http://opensource.org/licenses/gpl-license.php GNU Public License +* +*/ + +require_once 'test_framework/framework.php'; +require_once 'class_loader/cache_mock.php'; + +require_once '../phpBB/includes/class_loader.php'; + + +class phpbb_class_loader_test extends PHPUnit_Framework_TestCase +{ + public function test_resolve_path() + { + $prefix = 'class_loader/'; + $class_loader = new phpbb_class_loader($prefix); + + $prefix .= 'includes/'; + + $this->assertEquals( + $prefix . 'class_name.php', + $class_loader->resolve_path('phpbb_class_name'), + 'Top level class' + ); + $this->assertEquals( + $prefix . 'dir/class_name.php', + $class_loader->resolve_path('phpbb_dir_class_name'), + 'Class in a directory' + ); + $this->assertEquals( + $prefix . 'dir/subdir/class_name.php', + $class_loader->resolve_path('phpbb_dir_subdir_class_name'), + 'Class in a sub-directory' + ); + } + + public function test_resolve_cached() + { + $cache = new phpbb_cache_mock; + $cache->put('class_loader', array('phpbb_a_cached_name' => 'a/cached_name')); + + $prefix = 'class_loader/'; + $class_loader = new phpbb_class_loader($prefix, '.php', $cache); + + $prefix .= 'includes/'; + + $this->assertEquals( + $prefix . 'dir/class_name.php', + $class_loader->resolve_path('phpbb_dir_class_name'), + 'Class in a directory' + ); + + $this->assertEquals( + $prefix . 'a/cached_name.php', + $class_loader->resolve_path('phpbb_a_cached_name'), + 'Class in a directory' + ); + } +} diff --git a/tests/class_loader/includes/class_name.php b/tests/class_loader/includes/class_name.php new file mode 100644 index 0000000000..e941173cdd --- /dev/null +++ b/tests/class_loader/includes/class_name.php @@ -0,0 +1,6 @@ +<?php + +class phpbb_class_name +{ +} + diff --git a/tests/class_loader/includes/dir/class_name.php b/tests/class_loader/includes/dir/class_name.php new file mode 100644 index 0000000000..0675aa8fc5 --- /dev/null +++ b/tests/class_loader/includes/dir/class_name.php @@ -0,0 +1,6 @@ +<?php + +class phpbb_dir_class_name +{ +} + diff --git a/tests/class_loader/includes/dir/subdir/class_name.php b/tests/class_loader/includes/dir/subdir/class_name.php new file mode 100644 index 0000000000..7321a609cc --- /dev/null +++ b/tests/class_loader/includes/dir/subdir/class_name.php @@ -0,0 +1,6 @@ +<?php + +class phpbb_dir_subdir_class_name +{ +} + 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 145fe8de61..9436ab2d98 100644 --- a/tests/template/template.php +++ b/tests/template/template.php @@ -17,20 +17,12 @@ class phpbb_template_template_test extends phpbb_test_case private $template_path; // Keep the contents of the cache for debugging? - const PRESERVE_CACHE = true; + const PRESERVE_CACHE = false; private function display($handle) { - // allow the templates to throw notices - $error_level = error_reporting(); - error_reporting($error_level & ~E_NOTICE); - ob_start(); $this->assertTrue($this->template->display($handle, false)); - - // reset error level - error_reporting($error_level); - return self::trim_template_result(ob_get_clean()); } 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 --> |