diff options
Diffstat (limited to 'tests')
42 files changed, 2341 insertions, 51 deletions
diff --git a/tests/bbcode/parser_test.php b/tests/bbcode/parser_test.php new file mode 100644 index 0000000000..9423383938 --- /dev/null +++ b/tests/bbcode/parser_test.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 +* +*/ + +// require_once dirname(__FILE__) . '/../../phpBB/includes/bbcode/bbcode_parser_base.php'; +// require_once dirname(__FILE__) . '/../../phpBB/includes/bbcode/bbcode_parser.php'; + +class phpbb_bbcode_parser_test extends PHPUnit_Framework_TestCase +{ + public function test_both_passes() + { + $this->markTestIncomplete('New bbcode parser has not been backported from feature/ascraeus-experiment yet.'); + + $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'); + } +} diff --git a/tests/bootstrap.php b/tests/bootstrap.php index 6f3c93a374..b7c3534cde 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -30,6 +30,10 @@ else } require_once $phpbb_root_path . 'includes/constants.php'; +require_once $phpbb_root_path . 'includes/class_loader.' . $phpEx; + +$class_loader = new phpbb_class_loader($phpbb_root_path, '.php'); +$class_loader->register(); require_once 'test_framework/phpbb_test_case_helpers.php'; require_once 'test_framework/phpbb_test_case.php'; diff --git a/tests/cache/cache_test.php b/tests/cache/cache_test.php new file mode 100644 index 0000000000..b127c507f0 --- /dev/null +++ b/tests/cache/cache_test.php @@ -0,0 +1,70 @@ +<?php +/** +* +* @package testing +* @copyright (c) 2010 phpBB Group +* @license http://opensource.org/licenses/gpl-license.php GNU Public License +* +*/ + +require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php'; + +class phpbb_cache_test extends phpbb_test_case +{ + private $cache_dir; + + public function __construct() + { + $this->cache_dir = dirname(__FILE__) . '/../tmp/cache/'; + } + + protected function setUp() + { + if (file_exists($this->cache_dir)) + { + // cache directory possibly left after aborted + // or failed run earlier + $this->remove_cache_dir(); + } + $this->create_cache_dir(); + } + + protected function tearDown() + { + if (file_exists($this->cache_dir)) + { + $this->remove_cache_dir(); + } + } + + private function create_cache_dir() + { + $this->get_test_case_helpers()->makedirs($this->cache_dir); + } + + private function remove_cache_dir() + { + $iterator = new DirectoryIterator($this->cache_dir); + foreach ($iterator as $file) + { + if ($file != '.' && $file != '..') + { + unlink($this->cache_dir . '/' . $file); + } + } + rmdir($this->cache_dir); + } + + public function test_cache_driver_file() + { + $driver = new phpbb_cache_driver_file($this->cache_dir); + $driver->put('test_key', 'test_value'); + $driver->save(); + + $this->assertEquals( + 'test_value', + $driver->get('test_key'), + 'File ACM put and get' + ); + } +} diff --git a/tests/class_loader/class_loader_test.php b/tests/class_loader/class_loader_test.php new file mode 100644 index 0000000000..0c7fe3f97a --- /dev/null +++ b/tests/class_loader/class_loader_test.php @@ -0,0 +1,86 @@ +<?php +/** +* +* @package testing +* @copyright (c) 2011 phpBB Group +* @license http://opensource.org/licenses/gpl-license.php GNU Public License +* +*/ + +require_once dirname(__FILE__) . '/../mock/cache.php'; + +class phpbb_class_loader_test extends PHPUnit_Framework_TestCase +{ + public function setUp() + { + global $class_loader; + $class_loader->unregister(); + } + + public function tearDown() + { + global $class_loader; + $class_loader->register(); + } + + public function test_resolve_path() + { + $prefix = dirname(__FILE__) . '/'; + $class_loader = new phpbb_class_loader($prefix); + + $prefix .= 'includes/'; + + $this->assertEquals( + '', + $class_loader->resolve_path('phpbb_dir'), + 'Class with same name as a directory is unloadable' + ); + + $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' + ); + $this->assertEquals( + $prefix . 'dir2/dir2.php', + $class_loader->resolve_path('phpbb_dir2'), + 'Class with name of dir within dir (short class name)' + ); + } + + public function test_resolve_cached() + { + $cacheMap = array('class_loader' => array('phpbb_a_cached_name' => 'a/cached_name')); + $cache = new phpbb_mock_cache($cacheMap); + + $prefix = dirname(__FILE__) . '/'; + $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' + ); + + $cacheMap['class_loader']['phpbb_dir_class_name'] = 'dir/class_name'; + $cache->check($this, $cacheMap); + } +} 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.php b/tests/class_loader/includes/dir.php new file mode 100644 index 0000000000..1c8930d8e7 --- /dev/null +++ b/tests/class_loader/includes/dir.php @@ -0,0 +1,6 @@ +<?php + +class phpbb_dir +{ +} + 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/class_loader/includes/dir2/dir2.php b/tests/class_loader/includes/dir2/dir2.php new file mode 100644 index 0000000000..01cf4086ff --- /dev/null +++ b/tests/class_loader/includes/dir2/dir2.php @@ -0,0 +1,6 @@ +<?php + +class phpbb_dir2 +{ +} + diff --git a/tests/config/config_test.php b/tests/config/config_test.php new file mode 100644 index 0000000000..73a365c847 --- /dev/null +++ b/tests/config/config_test.php @@ -0,0 +1,112 @@ +<?php +/** +* +* @package testing +* @copyright (c) 2010 phpBB Group +* @license http://opensource.org/licenses/gpl-license.php GNU Public License +* +*/ + +class phpbb_config_test extends phpbb_test_case +{ + public function test_offset_exists() + { + $config = new phpbb_config(array('foo' => 'bar')); + + $this->assertTrue(isset($config['foo'])); + $this->assertFalse(isset($config['foobar'])); + } + + public function test_offset_get() + { + $config = new phpbb_config(array('foo' => 'bar')); + $this->assertEquals('bar', $config['foo']); + } + + public function test_offset_get_missing() + { + $config = new phpbb_config(array()); + $this->assertEquals('', $config['foo']); + } + + public function test_offset_set() + { + $config = new phpbb_config(array()); + $config['foo'] = 'x'; + $this->assertEquals('x', $config['foo']); + } + + public function test_offset_unset_fails() + { + $this->setExpectedTriggerError(E_USER_ERROR); + $config = new phpbb_config(array('foo' => 'x')); + unset($config['foo']); + } + + public function test_count() + { + $config = new phpbb_config(array('foo' => 'bar')); + $this->assertEquals(1, count($config)); + } + + public function test_iterate() + { + $vars = array('foo' => '23', 'bar' => '42'); + $config = new phpbb_config($vars); + + $count = 0; + foreach ($config as $key => $value) + { + $this->assertTrue(isset($vars[$key])); + $this->assertEquals($vars[$key], $value); + + $count++; + } + + $this->assertEquals(count($vars), $count); + } + + public function test_set_overwrite() + { + $config = new phpbb_config(array('foo' => 'x')); + $config->set('foo', 'bar'); + $this->assertEquals('bar', $config['foo']); + } + + public function test_set_new() + { + $config = new phpbb_config(array()); + $config->set('foo', 'bar'); + $this->assertEquals('bar', $config['foo']); + } + + public function test_set_atomic_overwrite() + { + $config = new phpbb_config(array('foo' => 'bar')); + $this->assertTrue($config->set_atomic('foo', 'bar', '23')); + $this->assertEquals('23', $config['foo']); + } + + public function test_set_atomic_new() + { + $config = new phpbb_config(array()); + $this->assertTrue($config->set_atomic('foo', false, '23')); + $this->assertEquals('23', $config['foo']); + } + + public function test_set_atomic_failure() + { + $config = new phpbb_config(array('foo' => 'bar')); + $this->assertFalse($config->set_atomic('foo', 'wrong', '23')); + $this->assertEquals('bar', $config['foo']); + } + + public function test_increment() + { + $config = new phpbb_config(array('foo' => '23')); + $config->increment('foo', 3); + $this->assertEquals(26, $config['foo']); + $config->increment('foo', 1); + $this->assertEquals(27, $config['foo']); + } +} diff --git a/tests/config/db_test.php b/tests/config/db_test.php new file mode 100644 index 0000000000..e0d5252f19 --- /dev/null +++ b/tests/config/db_test.php @@ -0,0 +1,128 @@ +<?php +/** +* +* @package testing +* @copyright (c) 2010 phpBB Group +* @license http://opensource.org/licenses/gpl-license.php GNU Public License +* +*/ + +require_once dirname(__FILE__) . '/../mock/cache.php'; + +class phpbb_config_db_test extends phpbb_database_test_case +{ + private $cache; + private $db; + private $config; + + public function getDataSet() + { + return $this->createXMLDataSet(dirname(__FILE__) . '/fixtures/config.xml'); + } + + public function setUp() + { + parent::setUp(); + + $this->cache = new phpbb_mock_cache; + $this->db = $this->new_dbal(); + $this->config = new phpbb_config_db($this->db, $this->cache, 'phpbb_config'); + } + + public function test_load_config() + { + $this->assertEquals('23', $this->config['foo']); + $this->assertEquals('42', $this->config['bar']); + } + + public function test_load_cached() + { + $cache = new phpbb_mock_cache(array('config' => array('x' => 'y'))); + $this->config = new phpbb_config_db($this->db, $cache, 'phpbb_config'); + + $this->assertTrue(!isset($this->config['foo'])); + $this->assertEquals('42', $this->config['bar']); + + $this->assertEquals('y', $this->config['x']); + } + + public function test_offset_set() + { + $this->config['foo'] = 'x'; // temporary set + $this->assertEquals('x', $this->config['foo']); + + $config2 = new phpbb_config_db($this->db, $this->cache, 'phpbb_config'); + $this->assertEquals('23', $config2['foo']); + } + + public function test_set_overwrite() + { + $this->config->set('foo', '17'); + $this->assertEquals('17', $this->config['foo']); + + // re-read config and populate cache + $config2 = new phpbb_config_db($this->db, $this->cache, 'phpbb_config'); + $this->cache->checkVar($this, 'config', array('foo' => '17')); + } + + public function test_set_overwrite_uncached() + { + $this->config->set('bar', '17', false); + + // re-read config and populate cache + $config2 = new phpbb_config_db($this->db, $this->cache, 'phpbb_config'); + $this->cache->checkVar($this, 'config', array('foo' => '23')); + } + + public function test_set_new() + { + $this->config->set('foobar', '5'); + $this->assertEquals('5', $this->config['foobar']); + + // re-read config and populate cache + $config2 = new phpbb_config_db($this->db, $this->cache, 'phpbb_config'); + $this->cache->checkVar($this, 'config', array('foo' => '23', 'foobar' => '5')); + } + + public function test_set_new_uncached() + { + $this->config->set('foobar', '5', false); + $this->assertEquals('5', $this->config['foobar']); + + // re-read config and populate cache + $config2 = new phpbb_config_db($this->db, $this->cache, 'phpbb_config'); + $this->cache->checkVar($this, 'config', array('foo' => '23')); + } + + public function test_set_atomic_overwrite() + { + $this->assertTrue($this->config->set_atomic('foo', '23', '17')); + $this->assertEquals('17', $this->config['foo']); + } + + public function test_set_atomic_new() + { + $this->assertTrue($this->config->set_atomic('foobar', false, '5')); + $this->assertEquals('5', $this->config['foobar']); + } + + public function test_set_atomic_failure() + { + $this->assertFalse($this->config->set_atomic('foo', 'wrong', '17')); + $this->assertEquals('23', $this->config['foo']); + } + + public function test_increment() + { + $this->config->increment('foo', 3); + $this->assertEquals(26, $this->config['foo']); + $this->config->increment('foo', 1); + $this->assertEquals(27, $this->config['foo']); + } + + public function test_increment_new() + { + $this->config->increment('foobar', 3); + $this->assertEquals(3, $this->config['foobar']);; + } +} diff --git a/tests/config/fixtures/config.xml b/tests/config/fixtures/config.xml new file mode 100644 index 0000000000..9d395b685c --- /dev/null +++ b/tests/config/fixtures/config.xml @@ -0,0 +1,18 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<dataset> + <table name="phpbb_config"> + <column>config_name</column> + <column>config_value</column> + <column>is_dynamic</column> + <row> + <value>foo</value> + <value>23</value> + <value>0</value> + </row> + <row> + <value>bar</value> + <value>42</value> + <value>1</value> + </row> + </table> +</dataset> diff --git a/tests/cron/manager_test.php b/tests/cron/manager_test.php new file mode 100644 index 0000000000..65d8360fbb --- /dev/null +++ b/tests/cron/manager_test.php @@ -0,0 +1,83 @@ +<?php +/** +* +* @package testing +* @copyright (c) 2010 phpBB Group +* @license http://opensource.org/licenses/gpl-license.php GNU Public License +* +*/ + +require_once dirname(__FILE__) . '/../mock/cache.php'; +require_once dirname(__FILE__) . '/task/testmod/dummy_task.php'; +require_once dirname(__FILE__) . '/task/testmod/second_dummy_task.php'; +require_once dirname(__FILE__) . '/task2/testmod/simple_ready.php'; +require_once dirname(__FILE__) . '/task2/testmod/simple_not_runnable.php'; +require_once dirname(__FILE__) . '/task2/testmod/simple_should_not_run.php'; + +class phpbb_cron_manager_test extends PHPUnit_Framework_TestCase +{ + public function setUp() + { + $this->manager = new phpbb_cron_manager(dirname(__FILE__) . '/task/', 'php'); + $this->task_name = 'phpbb_cron_task_testmod_dummy_task'; + } + + public function test_manager_finds_shipped_tasks() + { + $tasks = $this->manager->find_cron_task_names(); + $this->assertEquals(2, sizeof($tasks)); + } + + public function test_manager_finds_shipped_task_by_name() + { + $task = $this->manager->find_task($this->task_name); + $this->assertInstanceOf('phpbb_cron_task_wrapper', $task); + $this->assertEquals($this->task_name, $task->get_name()); + } + + public function test_manager_instantiates_task_by_name() + { + $task = $this->manager->instantiate_task($this->task_name, array()); + $this->assertInstanceOf('phpbb_cron_task_wrapper', $task); + $this->assertEquals($this->task_name, $task->get_name()); + } + + public function test_manager_finds_all_ready_tasks() + { + $tasks = $this->manager->find_all_ready_tasks(); + $this->assertEquals(2, sizeof($tasks)); + } + + public function test_manager_finds_one_ready_task() + { + $task = $this->manager->find_one_ready_task(); + $this->assertInstanceOf('phpbb_cron_task_wrapper', $task); + } + + public function test_manager_finds_all_ready_tasks_cached() + { + $cache = new phpbb_mock_cache(array('_cron_tasks' => array($this->task_name))); + $manager = new phpbb_cron_manager(dirname(__FILE__) . '/../../phpBB/', 'php', $cache); + + $tasks = $manager->find_all_ready_tasks(); + $this->assertEquals(1, sizeof($tasks)); + } + + public function test_manager_finds_only_ready_tasks() + { + $manager = new phpbb_cron_manager(dirname(__FILE__) . '/task2/', 'php'); + $tasks = $manager->find_all_ready_tasks(); + $task_names = $this->tasks_to_names($tasks); + $this->assertEquals(array('phpbb_cron_task_testmod_simple_ready'), $task_names); + } + + private function tasks_to_names($tasks) + { + $names = array(); + foreach ($tasks as $task) + { + $names[] = get_class($task->task); + } + return $names; + } +} diff --git a/tests/cron/task/testmod/dummy_task.php b/tests/cron/task/testmod/dummy_task.php new file mode 100644 index 0000000000..5941157589 --- /dev/null +++ b/tests/cron/task/testmod/dummy_task.php @@ -0,0 +1,23 @@ +<?php +/** +* +* @package testing +* @copyright (c) 2010 phpBB Group +* @license http://opensource.org/licenses/gpl-license.php GNU Public License +* +*/ + +class phpbb_cron_task_testmod_dummy_task extends phpbb_cron_task_base +{ + public static $was_run = 0; + + public function run() + { + self::$was_run++; + } + + public function should_run() + { + return true; + } +} diff --git a/tests/cron/task/testmod/second_dummy_task.php b/tests/cron/task/testmod/second_dummy_task.php new file mode 100644 index 0000000000..7118b2ebe7 --- /dev/null +++ b/tests/cron/task/testmod/second_dummy_task.php @@ -0,0 +1,23 @@ +<?php +/** +* +* @package testing +* @copyright (c) 2010 phpBB Group +* @license http://opensource.org/licenses/gpl-license.php GNU Public License +* +*/ + +class phpbb_cron_task_testmod_second_dummy_task extends phpbb_cron_task_base +{ + public static $was_run = 0; + + public function run() + { + self::$was_run++; + } + + public function should_run() + { + return true; + } +} diff --git a/tests/cron/task2/testmod/simple_not_runnable.php b/tests/cron/task2/testmod/simple_not_runnable.php new file mode 100644 index 0000000000..54869fa1cc --- /dev/null +++ b/tests/cron/task2/testmod/simple_not_runnable.php @@ -0,0 +1,13 @@ +<?php + +class phpbb_cron_task_testmod_simple_not_runnable extends phpbb_cron_task_base +{ + public function run() + { + } + + public function is_runnable() + { + return false; + } +} diff --git a/tests/cron/task2/testmod/simple_ready.php b/tests/cron/task2/testmod/simple_ready.php new file mode 100644 index 0000000000..e407441e90 --- /dev/null +++ b/tests/cron/task2/testmod/simple_ready.php @@ -0,0 +1,8 @@ +<?php + +class phpbb_cron_task_testmod_simple_ready extends phpbb_cron_task_base +{ + public function run() + { + } +} diff --git a/tests/cron/task2/testmod/simple_should_not_run.php b/tests/cron/task2/testmod/simple_should_not_run.php new file mode 100644 index 0000000000..14ba4cdbd3 --- /dev/null +++ b/tests/cron/task2/testmod/simple_should_not_run.php @@ -0,0 +1,13 @@ +<?php + +class phpbb_cron_task_testmod_simple_should_not_run extends phpbb_cron_task_base +{ + public function run() + { + } + + public function should_run() + { + return false; + } +} diff --git a/tests/download/http_byte_range_test.php b/tests/download/http_byte_range_test.php new file mode 100644 index 0000000000..ba2caee192 --- /dev/null +++ b/tests/download/http_byte_range_test.php @@ -0,0 +1,61 @@ +<?php +/** +* +* @package testing +* @copyright (c) 2010 phpBB Group +* @license http://opensource.org/licenses/gpl-license.php GNU Public License +* +*/ + +require_once dirname(__FILE__) . '/../../phpBB/includes/functions_download.php'; + +class phpbb_download_http_byte_range_test extends phpbb_test_case +{ + public function test_find_range_request() + { + // Missing 'bytes=' prefix + $_SERVER['HTTP_RANGE'] = 'bztes='; + $this->assertEquals(false, phpbb_find_range_request()); + unset($_SERVER['HTTP_RANGE']); + + $_ENV['HTTP_RANGE'] = 'bztes='; + $this->assertEquals(false, phpbb_find_range_request()); + unset($_ENV['HTTP_RANGE']); + + $_SERVER['HTTP_RANGE'] = 'bytes=0-0,123-125'; + $this->assertEquals(array('0-0', '123-125'), phpbb_find_range_request()); + unset($_SERVER['HTTP_RANGE']); + } + + /** + * @dataProvider parse_range_request_data() + */ + public function test_parse_range_request($request_array, $filesize, $expected) + { + $this->assertEquals($expected, phpbb_parse_range_request($request_array, $filesize)); + } + + public function parse_range_request_data() + { + return array( + // Does not read until the end of file. + array( + array('3-4'), + 10, + false, + ), + + // Valid request, handle second range. + array( + array('0-0', '120-125'), + 125, + array( + 'byte_pos_start' => 120, + 'byte_pos_end' => 124, + 'bytes_requested' => 5, + 'bytes_total' => 125, + ) + ), + ); + } +} diff --git a/tests/functions_acp/build_cfg_template_test.php b/tests/functions_acp/build_cfg_template_test.php new file mode 100644 index 0000000000..7bf85a3532 --- /dev/null +++ b/tests/functions_acp/build_cfg_template_test.php @@ -0,0 +1,192 @@ +<?php +/** +* +* @package testing +* @copyright (c) 2010 phpBB Group +* @license http://opensource.org/licenses/gpl-license.php GNU Public License +* +*/ + +require_once dirname(__FILE__) . '/../mock/lang.php'; +require_once dirname(__FILE__) . '/../../phpBB/includes/functions_acp.php'; + +class phpbb_functions_acp_build_cfg_template_test extends phpbb_test_case +{ + public function build_cfg_template_text_data() + { + return array( + array( + array('text', 20, 255), + 'key_name', + array('config_key_name' => '1'), + 'config_key_name', + array(), + '<input id="key_name" type="text" size="20" maxlength="255" name="config[config_key_name]" value="1" />', + ), + array( + array('password', 20, 128), + 'key_name', + array('config_key_name' => '2'), + 'config_key_name', + array(), + '<input id="key_name" type="password" size="20" maxlength="128" name="config[config_key_name]" value="2" />', + ), + array( + array('text', 0, 255), + 'key_name', + array('config_key_name' => '3'), + 'config_key_name', + array(), + '<input id="key_name" type="text" maxlength="255" name="config[config_key_name]" value="3" />', + ), + ); + } + + /** + * @dataProvider build_cfg_template_text_data + */ + public function test_build_cfg_template_text($tpl_type, $key, $new, $config_key, $vars, $expected) + { + global $user; + + $user->lang = new phpbb_mock_lang(); + + $this->assertEquals($expected, build_cfg_template($tpl_type, $key, $new, $config_key, $vars)); + } + + public function build_cfg_template_dimension_data() + { + return array( + array( + array('dimension', 20, 255), + 'key_name', + array('config_key_name_width' => 10, 'config_key_name_height' => 20), + 'config_key_name', + array(), + '<input id="key_name" type="text" size="20" maxlength="255" name="config[config_key_name_width]" value="10" /> x <input type="text" size="20" maxlength="255" name="config[config_key_name_height]" value="20" />', + ), + array( + array('dimension', 0, 255), + 'key_name', + array('config_key_name_width' => 10, 'config_key_name_height' => 20), + 'config_key_name', + array(), + '<input id="key_name" type="text" maxlength="255" name="config[config_key_name_width]" value="10" /> x <input type="text" maxlength="255" name="config[config_key_name_height]" value="20" />', + ), + ); + } + + /** + * @dataProvider build_cfg_template_dimension_data + */ + public function test_build_cfg_template_dimension($tpl_type, $key, $new, $config_key, $vars, $expected) + { + global $user; + + $user->lang = new phpbb_mock_lang(); + + $this->assertEquals($expected, build_cfg_template($tpl_type, $key, $new, $config_key, $vars)); + } + + public function build_cfg_template_textarea_data() + { + return array( + array( + array('textarea', 5, 30), + 'key_name', + array('config_key_name' => 'phpBB'), + 'config_key_name', + array(), + '<textarea id="key_name" name="config[config_key_name]" rows="5" cols="30">phpBB</textarea>', + ), + ); + } + + /** + * @dataProvider build_cfg_template_textarea_data + */ + public function test_build_cfg_template_textarea($tpl_type, $key, $new, $config_key, $vars, $expected) + { + global $user; + + $user->lang = new phpbb_mock_lang(); + + $this->assertEquals($expected, build_cfg_template($tpl_type, $key, $new, $config_key, $vars)); + } + + public function build_cfg_template_radio_data() + { + return array( + array( + array('radio', 'enabled_disabled'), + 'key_name', + array('config_key_name' => '0'), + 'config_key_name', + array(), + '<label><input type="radio" id="key_name" name="config[config_key_name]" value="1" class="radio" /> ENABLED</label><label><input type="radio" name="config[config_key_name]" value="0" checked="checked" class="radio" /> DISABLED</label>', + ), + array( + array('radio', 'enabled_disabled'), + 'key_name', + array('config_key_name' => '1'), + 'config_key_name', + array(), + '<label><input type="radio" id="key_name" name="config[config_key_name]" value="1" checked="checked" class="radio" /> ENABLED</label><label><input type="radio" name="config[config_key_name]" value="0" class="radio" /> DISABLED</label>', + ), + array( + array('radio', 'yes_no'), + 'key_name', + array('config_key_name' => '0'), + 'config_key_name', + array(), + '<label><input type="radio" id="key_name" name="config[config_key_name]" value="1" class="radio" /> YES</label><label><input type="radio" name="config[config_key_name]" value="0" checked="checked" class="radio" /> NO</label>', + ), + array( + array('radio', 'yes_no'), + 'key_name', + array('config_key_name' => '1'), + 'config_key_name', + array(), + '<label><input type="radio" id="key_name" name="config[config_key_name]" value="1" checked="checked" class="radio" /> YES</label><label><input type="radio" name="config[config_key_name]" value="0" class="radio" /> NO</label>', + ), + ); + } + + /** + * @dataProvider build_cfg_template_radio_data + */ + public function test_build_cfg_template_radio($tpl_type, $key, $new, $config_key, $vars, $expected) + { + global $user; + + $user->lang = new phpbb_mock_lang(); + + $this->assertEquals($expected, build_cfg_template($tpl_type, $key, $new, $config_key, $vars)); + } + + public function build_cfg_template_append_data() + { + return array( + array( + array('textarea', 5, 30), + 'key_name', + array('config_key_name' => 'phpBB'), + 'config_key_name', + array('append' => 'Bertie is cool!'), + '<textarea id="key_name" name="config[config_key_name]" rows="5" cols="30">phpBB</textarea>Bertie is cool!', + ), + ); + } + + /** + * @dataProvider build_cfg_template_append_data + */ + public function test_build_cfg_template_append($tpl_type, $key, $new, $config_key, $vars, $expected) + { + global $user; + + $user->lang = new phpbb_mock_lang(); + + $this->assertEquals($expected, build_cfg_template($tpl_type, $key, $new, $config_key, $vars)); + } +} diff --git a/tests/functions_acp/build_select_test.php b/tests/functions_acp/build_select_test.php new file mode 100644 index 0000000000..7079e69f12 --- /dev/null +++ b/tests/functions_acp/build_select_test.php @@ -0,0 +1,56 @@ +<?php +/** +* +* @package testing +* @copyright (c) 2010 phpBB Group +* @license http://opensource.org/licenses/gpl-license.php GNU Public License +* +*/ + +require_once dirname(__FILE__) . '/../mock/lang.php'; +require_once dirname(__FILE__) . '/../../phpBB/includes/functions_acp.php'; + +class phpbb_functions_acp_built_select_test extends phpbb_test_case +{ + public function build_select_data() + { + return array( + array( + array( + 'test' => 'TEST', + 'second' => 'SEC_OPTION', + ), + false, + '<option value="test">TEST</option><option value="second">SEC_OPTION</option>', + ), + array( + array( + 'test' => 'TEST', + 'second' => 'SEC_OPTION', + ), + 'test', + '<option value="test" selected="selected">TEST</option><option value="second">SEC_OPTION</option>', + ), + array( + array( + 'test' => 'TEST', + 'second' => 'SEC_OPTION', + ), + 'second', + '<option value="test">TEST</option><option value="second" selected="selected">SEC_OPTION</option>', + ), + ); + } + + /** + * @dataProvider build_select_data + */ + public function test_build_select($option_ary, $option_default, $expected) + { + global $user; + + $user->lang = new phpbb_mock_lang(); + + $this->assertEquals($expected, build_select($option_ary, $option_default)); + } +} diff --git a/tests/functions_acp/h_radio_test.php b/tests/functions_acp/h_radio_test.php new file mode 100644 index 0000000000..18cb5d031e --- /dev/null +++ b/tests/functions_acp/h_radio_test.php @@ -0,0 +1,121 @@ +<?php +/** +* +* @package testing +* @copyright (c) 2010 phpBB Group +* @license http://opensource.org/licenses/gpl-license.php GNU Public License +* +*/ + +require_once dirname(__FILE__) . '/../mock/lang.php'; +require_once dirname(__FILE__) . '/../../phpBB/includes/functions_acp.php'; + +class phpbb_functions_acp_h_radio_test extends phpbb_test_case +{ + public function h_radio_data() + { + return array( + array( + 'test_name', + array( + 'test' => 'TEST', + 'second' => 'SEC_OPTION', + ), + false, + false, + false, + '<label><input type="radio" name="test_name" value="test" class="radio" /> TEST</label><label><input type="radio" name="test_name" value="second" class="radio" /> SEC_OPTION</label>', + ), + array( + 'test_name', + array( + 'test' => 'TEST', + 'second' => 'SEC_OPTION', + ), + 'test', + false, + false, + '<label><input type="radio" name="test_name" value="test" checked="checked" class="radio" /> TEST</label><label><input type="radio" name="test_name" value="second" class="radio" /> SEC_OPTION</label>', + ), + array( + 'test_name', + array( + 'test' => 'TEST', + 'second' => 'SEC_OPTION', + ), + false, + 'test_id', + false, + '<label><input type="radio" name="test_name" id="test_id" value="test" class="radio" /> TEST</label><label><input type="radio" name="test_name" value="second" class="radio" /> SEC_OPTION</label>', + ), + array( + 'test_name', + array( + 'test' => 'TEST', + 'second' => 'SEC_OPTION', + ), + 'test', + 'test_id', + false, + '<label><input type="radio" name="test_name" id="test_id" value="test" checked="checked" class="radio" /> TEST</label><label><input type="radio" name="test_name" value="second" class="radio" /> SEC_OPTION</label>', + ), + + array( + 'test_name', + array( + 'test' => 'TEST', + 'second' => 'SEC_OPTION', + ), + false, + false, + 'k', + '<label><input type="radio" name="test_name" value="test" accesskey="k" class="radio" /> TEST</label><label><input type="radio" name="test_name" value="second" accesskey="k" class="radio" /> SEC_OPTION</label>', + ), + array( + 'test_name', + array( + 'test' => 'TEST', + 'second' => 'SEC_OPTION', + ), + 'test', + false, + 'k', + '<label><input type="radio" name="test_name" value="test" checked="checked" accesskey="k" class="radio" /> TEST</label><label><input type="radio" name="test_name" value="second" accesskey="k" class="radio" /> SEC_OPTION</label>', + ), + array( + 'test_name', + array( + 'test' => 'TEST', + 'second' => 'SEC_OPTION', + ), + false, + 'test_id', + 'k', + '<label><input type="radio" name="test_name" id="test_id" value="test" accesskey="k" class="radio" /> TEST</label><label><input type="radio" name="test_name" value="second" accesskey="k" class="radio" /> SEC_OPTION</label>', + ), + array( + 'test_name', + array( + 'test' => 'TEST', + 'second' => 'SEC_OPTION', + ), + 'test', + 'test_id', + 'k', + '<label><input type="radio" name="test_name" id="test_id" value="test" checked="checked" accesskey="k" class="radio" /> TEST</label><label><input type="radio" name="test_name" value="second" accesskey="k" class="radio" /> SEC_OPTION</label>', + ), + ); + } + + /** + * @dataProvider h_radio_data + */ + public function test_h_radio($name, $input_ary, $input_default, $id, $key, $expected) + { + global $user; + + $user->lang = new phpbb_mock_lang(); + + $this->assertEquals($expected, h_radio($name, $input_ary, $input_default, $id, $key)); + } +} diff --git a/tests/functions_acp/validate_config_vars_test.php b/tests/functions_acp/validate_config_vars_test.php new file mode 100644 index 0000000000..aa63bc38df --- /dev/null +++ b/tests/functions_acp/validate_config_vars_test.php @@ -0,0 +1,151 @@ +<?php +/** +* +* @package testing +* @copyright (c) 2010 phpBB Group +* @license http://opensource.org/licenses/gpl-license.php GNU Public License +* +*/ + +require_once dirname(__FILE__) . '/../mock/lang.php'; +require_once dirname(__FILE__) . '/../../phpBB/includes/functions_acp.php'; + +class phpbb_functions_acp_validate_config_vars_test extends phpbb_test_case +{ + /** + * Helper function which returns a string in a given length. + */ + static public function return_string($length) + { + $string = ''; + for ($i = 0; $i < $length; $i++) + { + $string .= 'a'; + } + return $string; + } + + /** + * Data sets that don't throw an error. + */ + public function validate_config_vars_fit_data() + { + return array( + array( + array( + 'test_bool' => array('lang' => 'TEST_BOOL', 'validate' => 'bool'), + 'test_string' => array('lang' => 'TEST_STRING', 'validate' => 'string'), + 'test_string_128' => array('lang' => 'TEST_STRING_128', 'validate' => 'string:128'), + 'test_string_32_64' => array('lang' => 'TEST_STRING_32_64', 'validate' => 'string:32:64'), + 'test_int' => array('lang' => 'TEST_INT', 'validate' => 'int'), + 'test_int_32' => array('lang' => 'TEST_INT', 'validate' => 'int:32'), + 'test_int_32_64' => array('lang' => 'TEST_INT', 'validate' => 'int:32:64'), + 'test_lang' => array('lang' => 'TEST_LANG', 'validate' => 'lang'), + /* + 'test_sp' => array('lang' => 'TEST_SP', 'validate' => 'script_path'), + 'test_rpath' => array('lang' => 'TEST_RPATH', 'validate' => 'rpath'), + 'test_rwpath' => array('lang' => 'TEST_RWPATH', 'validate' => 'rwpath'), + 'test_path' => array('lang' => 'TEST_PATH', 'validate' => 'path'), + 'test_wpath' => array('lang' => 'TEST_WPATH', 'validate' => 'wpath'), + */ + ), + array( + 'test_bool' => true, + 'test_string' => self::return_string(255), + 'test_string_128' => self::return_string(128), + 'test_string_32_64' => self::return_string(48), + 'test_int' => 128, + 'test_int_32' => 32, + 'test_int_32_64' => 48, + 'test_lang' => 'en', + ), + ), + ); + } + + /** + * @dataProvider validate_config_vars_fit_data + */ + public function test_validate_config_vars_fit($test_data, $cfg_array) + { + global $user; + + $user->lang = new phpbb_mock_lang(); + + $phpbb_error = array(); + validate_config_vars($test_data, $cfg_array, $phpbb_error); + + $this->assertEquals(array(), $phpbb_error); + } + + /** + * Data sets that throw the error. + */ + public function validate_config_vars_error_data() + { + return array( + array( + array('test_string_32_64' => array('lang' => 'TEST_STRING_32_64', 'validate' => 'string:32:64')), + array('test_string_32_64' => self::return_string(20)), + array('SETTING_TOO_SHORT'), + ), + array( + array('test_string' => array('lang' => 'TEST_STRING', 'validate' => 'string')), + array('test_string' => self::return_string(256)), + array('SETTING_TOO_LONG'), + ), + array( + array('test_string_32_64' => array('lang' => 'TEST_STRING_32_64', 'validate' => 'string:32:64')), + array('test_string_32_64' => self::return_string(65)), + array('SETTING_TOO_LONG'), + ), + + array( + array('test_int_32' => array('lang' => 'TEST_INT', 'validate' => 'int:32')), + array('test_int_32' => 31), + array('SETTING_TOO_LOW'), + ), + array( + array('test_int_32_64' => array('lang' => 'TEST_INT', 'validate' => 'int:32:64')), + array('test_int_32_64' => 31), + array('SETTING_TOO_LOW'), + ), + array( + array('test_int_32_64' => array('lang' => 'TEST_INT', 'validate' => 'int:32:64')), + array('test_int_32_64' => 65), + array('SETTING_TOO_BIG'), + ), + array( + array( + 'test_int_min' => array('lang' => 'TEST_INT_MIN', 'validate' => 'int:32:64'), + 'test_int_max' => array('lang' => 'TEST_INT_MAX', 'validate' => 'int:32:64'), + ), + array( + 'test_int_min' => 52, + 'test_int_max' => 48, + ), + array('SETTING_TOO_LOW'), + ), + array( + array('test_lang' => array('lang' => 'TEST_LANG', 'validate' => 'lang')), + array('test_lang' => 'this_is_no_language'), + array('WRONG_DATA_LANG'), + ), + ); + } + + /** + * @dataProvider validate_config_vars_error_data + */ + public function test_validate_config_vars_error($test_data, $cfg_array, $expected) + { + global $user; + + $user->lang = new phpbb_mock_lang(); + + $phpbb_error = array(); + validate_config_vars($test_data, $cfg_array, $phpbb_error); + + $this->assertEquals($expected, $phpbb_error); + } +} diff --git a/tests/functions_acp/validate_range_test.php b/tests/functions_acp/validate_range_test.php new file mode 100644 index 0000000000..a9c9612ad7 --- /dev/null +++ b/tests/functions_acp/validate_range_test.php @@ -0,0 +1,179 @@ +<?php +/** +* +* @package testing +* @copyright (c) 2010 phpBB Group +* @license http://opensource.org/licenses/gpl-license.php GNU Public License +* +*/ + +require_once dirname(__FILE__) . '/../mock/lang.php'; +require_once dirname(__FILE__) . '/../../phpBB/includes/functions_acp.php'; + +class phpbb_functions_acp_validate_range_test extends phpbb_test_case +{ + /** + * Helper function which returns a string in a given length. + */ + static public function return_string($length) + { + $string = ''; + for ($i = 0; $i < $length; $i++) + { + $string .= 'a'; + } + return $string; + } + + /** + * Data sets that don't throw an error. + */ + public function validate_range_data_fit() + { + return array( + array(array(array('column_type' => 'BOOL', 'lang' => 'TEST', 'value' => 0))), + array(array(array('column_type' => 'BOOL', 'lang' => 'TEST', 'value' => 1))), + + array(array(array('column_type' => 'USINT', 'lang' => 'TEST', 'value' => 0))), + array(array(array('column_type' => 'USINT', 'lang' => 'TEST', 'value' => 65535))), + array(array(array('column_type' => 'USINT:32:128', 'lang' => 'TEST', 'value' => 35))), + + array(array(array('column_type' => 'UINT', 'lang' => 'TEST', 'value' => 0))), + array(array(array('column_type' => 'UINT', 'lang' => 'TEST', 'value' => (int) 0x7fffffff))), + array(array(array('column_type' => 'UINT:32:128', 'lang' => 'TEST', 'value' => 35))), + + array(array(array('column_type' => 'INT', 'lang' => 'TEST', 'value' => (int) -2147483648))), + array(array(array('column_type' => 'INT', 'lang' => 'TEST', 'value' => (int) 0x7fffffff))), + array(array(array('column_type' => 'INT:-32:128', 'lang' => 'TEST', 'value' => -28))), + array(array(array('column_type' => 'INT:-32:128', 'lang' => 'TEST', 'value' => 35))), + + array(array(array('column_type' => 'TINT', 'lang' => 'TEST', 'value' => -128))), + array(array(array('column_type' => 'TINT', 'lang' => 'TEST', 'value' => 127))), + array(array(array('column_type' => 'TINT:-32:64', 'lang' => 'TEST', 'value' => -16))), + array(array(array('column_type' => 'TINT:-32:64', 'lang' => 'TEST', 'value' => 16))), + + array(array(array('column_type' => 'VCHAR', 'lang' => 'TEST', 'value' => ''))), + array(array(array('column_type' => 'VCHAR', 'lang' => 'TEST', 'value' => self::return_string(255)))), + array(array(array('column_type' => 'VCHAR:128', 'lang' => 'TEST', 'value' => self::return_string(128)))), + ); + } + + /** + * @dataProvider validate_range_data_fit + */ + public function test_validate_range_fit($test_data) + { + global $user; + + $user->lang = new phpbb_mock_lang(); + + $phpbb_error = array(); + validate_range($test_data, $phpbb_error); + + $this->assertEquals(array(), $phpbb_error); + } + + /** + * Data sets that throw the SETTING_TOO_LOW-error. + */ + public function validate_range_data_too_low() + { + return array( + array(array(array('column_type' => 'BOOL', 'lang' => 'TEST', 'value' => -1))), + + array(array(array('column_type' => 'USINT', 'lang' => 'TEST', 'value' => -1))), + array(array(array('column_type' => 'USINT:32:128', 'lang' => 'TEST', 'value' => 31))), + + array(array(array('column_type' => 'UINT', 'lang' => 'TEST', 'value' => -1))), + array(array(array('column_type' => 'UINT:32:128', 'lang' => 'TEST', 'value' => 31))), + + array(array(array('column_type' => 'INT', 'lang' => 'TEST', 'value' => ((int) -2147483648) - 1))), + array(array(array('column_type' => 'INT:32:128', 'lang' => 'TEST', 'value' => 31))), + array(array(array('column_type' => 'INT:-32:128', 'lang' => 'TEST', 'value' => -33))), + + array(array(array('column_type' => 'TINT', 'lang' => 'TEST', 'value' => -129))), + array(array(array('column_type' => 'TINT:32:64', 'lang' => 'TEST', 'value' => 31))), + array(array(array('column_type' => 'TINT:-32:64', 'lang' => 'TEST', 'value' => -33))), + ); + } + + /** + * @dataProvider validate_range_data_too_low + */ + public function test_validate_range_too_low($test_data) + { + global $user; + + $user->lang = new phpbb_mock_lang(); + + $phpbb_error = array(); + validate_range($test_data, $phpbb_error); + + $this->assertEquals(array('SETTING_TOO_LOW'), $phpbb_error); + } + + /** + * Data sets that throw the SETTING_TOO_BIG-error. + */ + public function validate_range_data_too_big() + { + return array( + array(array(array('column_type' => 'BOOL', 'lang' => 'TEST', 'value' => 2))), + + array(array(array('column_type' => 'USINT', 'lang' => 'TEST', 'value' => 65536))), + array(array(array('column_type' => 'USINT:32:128', 'lang' => 'TEST', 'value' => 129))), + + array(array(array('column_type' => 'UINT', 'lang' => 'TEST', 'value' => ((int) 0x7fffffff) + 1))), + array(array(array('column_type' => 'UINT:32:128', 'lang' => 'TEST', 'value' => 129))), + + array(array(array('column_type' => 'INT', 'lang' => 'TEST', 'value' => ((int) 0x7fffffff) + 1))), + array(array(array('column_type' => 'INT:-32:-16', 'lang' => 'TEST', 'value' => -15))), + array(array(array('column_type' => 'INT:-32:128', 'lang' => 'TEST', 'value' => 129))), + + array(array(array('column_type' => 'TINT', 'lang' => 'TEST', 'value' => 128))), + array(array(array('column_type' => 'TINT:-32:-16', 'lang' => 'TEST', 'value' => -15))), + array(array(array('column_type' => 'TINT:-32:64', 'lang' => 'TEST', 'value' => 65))), + ); + } + + /** + * @dataProvider validate_range_data_too_big + */ + public function test_validate_range_too_big($test_data) + { + global $user; + + $user->lang = new phpbb_mock_lang(); + + $phpbb_error = array(); + validate_range($test_data, $phpbb_error); + + $this->assertEquals(array('SETTING_TOO_BIG'), $phpbb_error); + } + + /** + * Data sets that throw the SETTING_TOO_LONG-error. + */ + public function validate_range_data_too_long() + { + return array( + array(array(array('column_type' => 'VCHAR', 'lang' => 'TEST', 'value' => self::return_string(256)))), + array(array(array('column_type' => 'VCHAR:128', 'lang' => 'TEST', 'value' => self::return_string(129)))), + ); + } + + /** + * @dataProvider validate_range_data_too_long + */ + public function test_validate_range_too_long($test_data) + { + global $user; + + $user->lang = new phpbb_mock_lang(); + + $phpbb_error = array(); + validate_range($test_data, $phpbb_error); + + $this->assertEquals(array('SETTING_TOO_LONG'), $phpbb_error); + } +} diff --git a/tests/group_positions/fixtures/group_positions.xml b/tests/group_positions/fixtures/group_positions.xml new file mode 100644 index 0000000000..55b1c2e08d --- /dev/null +++ b/tests/group_positions/fixtures/group_positions.xml @@ -0,0 +1,23 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<dataset> + <table name="phpbb_groups"> + <column>group_id</column> + <column>group_teampage</column> + <column>group_legend</column> + <row> + <value>1</value> + <value>0</value> + <value>0</value> + </row> + <row> + <value>2</value> + <value>1</value> + <value>0</value> + </row> + <row> + <value>3</value> + <value>2</value> + <value>1</value> + </row> + </table> +</dataset> diff --git a/tests/group_positions/group_positions_test.php b/tests/group_positions/group_positions_test.php new file mode 100644 index 0000000000..b68f205b37 --- /dev/null +++ b/tests/group_positions/group_positions_test.php @@ -0,0 +1,287 @@ +<?php +/** +* +* @package testing +* @copyright (c) 2011 phpBB Group +* @license http://opensource.org/licenses/gpl-license.php GNU Public License +* +*/ + + +class phpbb_group_positions_test extends phpbb_database_test_case +{ + public function getDataSet() + { + return $this->createXMLDataSet(dirname(__FILE__) . '/fixtures/group_positions.xml'); + } + + public static function get_group_value_data() + { + return array( + array('teampage', 1, 0), + array('teampage', 2, 1), + array('legend', 1, 0), + array('legend', 3, 1), + ); + } + + /** + * @dataProvider get_group_value_data + */ + public function test_get_group_value($field, $group_id, $expected) + { + global $db; + + $db = $this->new_dbal(); + + $test_class = new phpbb_group_positions($db, $field); + $this->assertEquals($expected, $test_class->get_group_value($group_id)); + } + + public static function get_group_count_data() + { + return array( + array('teampage', 2), + array('legend', 1), + ); + } + + /** + * @dataProvider get_group_count_data + */ + public function test_get_group_count($field, $expected) + { + global $db; + + $db = $this->new_dbal(); + + $test_class = new phpbb_group_positions($db, $field); + $this->assertEquals($expected, $test_class->get_group_count()); + } + + public static function add_group_data() + { + return array( + array('teampage', 1, array( + array('group_id' => 1, 'group_teampage' => 3, 'group_legend' => 0), + array('group_id' => 2, 'group_teampage' => 1, 'group_legend' => 0), + array('group_id' => 3, 'group_teampage' => 2, 'group_legend' => 1), + )), + array('teampage', 2, array( + array('group_id' => 1, 'group_teampage' => 0, 'group_legend' => 0), + array('group_id' => 2, 'group_teampage' => 1, 'group_legend' => 0), + array('group_id' => 3, 'group_teampage' => 2, 'group_legend' => 1), + )), + ); + } + + /** + * @dataProvider add_group_data + */ + public function test_add_group($field, $group_id, $expected) + { + global $db; + + $db = $this->new_dbal(); + $test_class = new phpbb_group_positions($db, $field); + $test_class->add_group($group_id); + + $result = $db->sql_query('SELECT group_id, group_teampage, group_legend + FROM ' . GROUPS_TABLE . ' + ORDER BY group_id ASC'); + + $this->assertEquals($expected, $db->sql_fetchrowset($result)); + } + + public static function delete_group_data() + { + return array( + array('teampage', 1, false, array( + array('group_id' => 1, 'group_teampage' => 0, 'group_legend' => 0), + array('group_id' => 2, 'group_teampage' => 1, 'group_legend' => 0), + array('group_id' => 3, 'group_teampage' => 2, 'group_legend' => 1), + )), + array('teampage', 2, false, array( + array('group_id' => 1, 'group_teampage' => 0, 'group_legend' => 0), + array('group_id' => 2, 'group_teampage' => 0, 'group_legend' => 0), + array('group_id' => 3, 'group_teampage' => 1, 'group_legend' => 1), + )), + array('teampage', 3, false, array( + array('group_id' => 1, 'group_teampage' => 0, 'group_legend' => 0), + array('group_id' => 2, 'group_teampage' => 1, 'group_legend' => 0), + array('group_id' => 3, 'group_teampage' => 0, 'group_legend' => 1), + )), + array('teampage', 1, true, array( + array('group_id' => 1, 'group_teampage' => 0, 'group_legend' => 0), + array('group_id' => 2, 'group_teampage' => 1, 'group_legend' => 0), + array('group_id' => 3, 'group_teampage' => 2, 'group_legend' => 1), + )), + array('teampage', 2, true, array( + array('group_id' => 1, 'group_teampage' => 0, 'group_legend' => 0), + array('group_id' => 2, 'group_teampage' => 1, 'group_legend' => 0), + array('group_id' => 3, 'group_teampage' => 1, 'group_legend' => 1), + )), + array('teampage', 3, true, array( + array('group_id' => 1, 'group_teampage' => 0, 'group_legend' => 0), + array('group_id' => 2, 'group_teampage' => 1, 'group_legend' => 0), + array('group_id' => 3, 'group_teampage' => 2, 'group_legend' => 1), + )), + ); + } + + /** + * @dataProvider delete_group_data + */ + public function test_delete_group($field, $group_id, $skip_group, $expected) + { + global $db; + + $db = $this->new_dbal(); + $test_class = new phpbb_group_positions($db, $field); + $test_class->delete_group($group_id, $skip_group); + + $result = $db->sql_query('SELECT group_id, group_teampage, group_legend + FROM ' . GROUPS_TABLE . ' + ORDER BY group_id ASC'); + + $this->assertEquals($expected, $db->sql_fetchrowset($result)); + } + + public static function move_up_data() + { + return array( + array('teampage', 1, array( + array('group_id' => 1, 'group_teampage' => 0, 'group_legend' => 0), + array('group_id' => 2, 'group_teampage' => 1, 'group_legend' => 0), + array('group_id' => 3, 'group_teampage' => 2, 'group_legend' => 1), + )), + array('teampage', 2, array( + array('group_id' => 1, 'group_teampage' => 0, 'group_legend' => 0), + array('group_id' => 2, 'group_teampage' => 1, 'group_legend' => 0), + array('group_id' => 3, 'group_teampage' => 2, 'group_legend' => 1), + )), + array('teampage', 3, array( + array('group_id' => 1, 'group_teampage' => 0, 'group_legend' => 0), + array('group_id' => 2, 'group_teampage' => 2, 'group_legend' => 0), + array('group_id' => 3, 'group_teampage' => 1, 'group_legend' => 1), + )), + ); + } + + /** + * @dataProvider move_up_data + */ + public function test_move_up($field, $group_id, $expected) + { + global $db; + + $db = $this->new_dbal(); + $test_class = new phpbb_group_positions($db, $field); + $test_class->move_up($group_id); + + $result = $db->sql_query('SELECT group_id, group_teampage, group_legend + FROM ' . GROUPS_TABLE . ' + ORDER BY group_id ASC'); + + $this->assertEquals($expected, $db->sql_fetchrowset($result)); + } + + public static function move_down_data() + { + return array( + array('teampage', 1, array( + array('group_id' => 1, 'group_teampage' => 0, 'group_legend' => 0), + array('group_id' => 2, 'group_teampage' => 1, 'group_legend' => 0), + array('group_id' => 3, 'group_teampage' => 2, 'group_legend' => 1), + )), + array('teampage', 2, array( + array('group_id' => 1, 'group_teampage' => 0, 'group_legend' => 0), + array('group_id' => 2, 'group_teampage' => 2, 'group_legend' => 0), + array('group_id' => 3, 'group_teampage' => 1, 'group_legend' => 1), + )), + array('teampage', 3, array( + array('group_id' => 1, 'group_teampage' => 0, 'group_legend' => 0), + array('group_id' => 2, 'group_teampage' => 1, 'group_legend' => 0), + array('group_id' => 3, 'group_teampage' => 2, 'group_legend' => 1), + )), + ); + } + + /** + * @dataProvider move_down_data + */ + public function test_move_down($field, $group_id, $expected) + { + global $db; + + $db = $this->new_dbal(); + $test_class = new phpbb_group_positions($db, $field); + $test_class->move_down($group_id); + + $result = $db->sql_query('SELECT group_id, group_teampage, group_legend + FROM ' . GROUPS_TABLE . ' + ORDER BY group_id ASC'); + + $this->assertEquals($expected, $db->sql_fetchrowset($result)); + } + + public static function move_data() + { + return array( + array('teampage', 1, 1, array( + array('group_id' => 1, 'group_teampage' => 0, 'group_legend' => 0), + array('group_id' => 2, 'group_teampage' => 1, 'group_legend' => 0), + array('group_id' => 3, 'group_teampage' => 2, 'group_legend' => 1), + )), + array('teampage', 1, -1, array( + array('group_id' => 1, 'group_teampage' => 0, 'group_legend' => 0), + array('group_id' => 2, 'group_teampage' => 1, 'group_legend' => 0), + array('group_id' => 3, 'group_teampage' => 2, 'group_legend' => 1), + )), + array('teampage', 3, 3, array( + array('group_id' => 1, 'group_teampage' => 0, 'group_legend' => 0), + array('group_id' => 2, 'group_teampage' => 2, 'group_legend' => 0), + array('group_id' => 3, 'group_teampage' => 1, 'group_legend' => 1), + )), + array('teampage', 2, 0, array( + array('group_id' => 1, 'group_teampage' => 0, 'group_legend' => 0), + array('group_id' => 2, 'group_teampage' => 1, 'group_legend' => 0), + array('group_id' => 3, 'group_teampage' => 2, 'group_legend' => 1), + )), + array('teampage', 2, -1, array( + array('group_id' => 1, 'group_teampage' => 0, 'group_legend' => 0), + array('group_id' => 2, 'group_teampage' => 2, 'group_legend' => 0), + array('group_id' => 3, 'group_teampage' => 1, 'group_legend' => 1), + )), + array('teampage', 2, -3, array( + array('group_id' => 1, 'group_teampage' => 0, 'group_legend' => 0), + array('group_id' => 2, 'group_teampage' => 2, 'group_legend' => 0), + array('group_id' => 3, 'group_teampage' => 1, 'group_legend' => 1), + )), + array('teampage', 3, -1, array( + array('group_id' => 1, 'group_teampage' => 0, 'group_legend' => 0), + array('group_id' => 2, 'group_teampage' => 1, 'group_legend' => 0), + array('group_id' => 3, 'group_teampage' => 2, 'group_legend' => 1), + )), + ); + } + + /** + * @dataProvider move_data + */ + public function test_move($field, $group_id, $increment, $expected) + { + global $db; + + $db = $this->new_dbal(); + $test_class = new phpbb_group_positions($db, $field); + $test_class->move($group_id, $increment); + + $result = $db->sql_query('SELECT group_id, group_teampage, group_legend + FROM ' . GROUPS_TABLE . ' + ORDER BY group_id ASC'); + + $this->assertEquals($expected, $db->sql_fetchrowset($result)); + } +} + diff --git a/tests/lock/db_test.php b/tests/lock/db_test.php new file mode 100644 index 0000000000..ed15423314 --- /dev/null +++ b/tests/lock/db_test.php @@ -0,0 +1,83 @@ +<?php +/** +* +* @package testing +* @copyright (c) 2010 phpBB Group +* @license http://opensource.org/licenses/gpl-license.php GNU Public License +* +*/ + +require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php'; + +class phpbb_lock_db_test extends phpbb_database_test_case +{ + private $db; + private $config; + private $lock; + + public function getDataSet() + { + return $this->createXMLDataSet(dirname(__FILE__).'/fixtures/config.xml'); + } + + public function setUp() + { + global $db, $config; + + $db = $this->db = $this->new_dbal(); + $config = $this->config = new phpbb_config(array('rand_seed' => '', 'rand_seed_last_update' => '0')); + set_config(null, null, null, $this->config); + $this->lock = new phpbb_lock_db('test_lock', $this->config, $this->db); + } + + public function test_new_lock() + { + $this->assertTrue($this->lock->acquire()); + $this->assertTrue(isset($this->config['test_lock']), 'Lock was created'); + + $lock2 = new phpbb_lock_db('test_lock', $this->config, $this->db); + $this->assertFalse($lock2->acquire()); + + $this->lock->release(); + $this->assertEquals('0', $this->config['test_lock'], 'Lock was released'); + } + + public function test_expire_lock() + { + $lock = new phpbb_lock_db('foo_lock', $this->config, $this->db); + $this->assertTrue($lock->acquire()); + } + + public function test_double_lock() + { + $this->assertTrue($this->lock->acquire()); + $this->assertTrue(isset($this->config['test_lock']), 'Lock was created'); + + $value = $this->config['test_lock']; + + $this->assertFalse($this->lock->acquire()); + $this->assertEquals($value, $this->config['test_lock'], 'Second lock failed'); + + $this->lock->release(); + $this->assertEquals('0', $this->config['test_lock'], 'Lock was released'); + } + + public function test_double_unlock() + { + $this->assertTrue($this->lock->acquire()); + $this->assertFalse(empty($this->config['test_lock']), 'First lock is acquired'); + + $this->lock->release(); + $this->assertEquals('0', $this->config['test_lock'], 'First lock is released'); + + $lock2 = new phpbb_lock_db('test_lock', $this->config, $this->db); + $this->assertTrue($lock2->acquire()); + $this->assertFalse(empty($this->config['test_lock']), 'Second lock is acquired'); + + $this->lock->release(); + $this->assertFalse(empty($this->config['test_lock']), 'Double release of first lock is ignored'); + + $lock2->release(); + $this->assertEquals('0', $this->config['test_lock'], 'Second lock is released'); + } +} diff --git a/tests/lock/fixtures/config.xml b/tests/lock/fixtures/config.xml new file mode 100644 index 0000000000..f36c8b929a --- /dev/null +++ b/tests/lock/fixtures/config.xml @@ -0,0 +1,13 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<dataset> + <table name="phpbb_config"> + <column>config_name</column> + <column>config_value</column> + <column>is_dynamic</column> + <row> + <value>foo_lock</value> + <value>1 abcd</value> + <value>1</value> + </row> + </table> +</dataset> diff --git a/tests/mock/cache.php b/tests/mock/cache.php index 11e525ff79..d3f9b8ad5a 100644 --- a/tests/mock/cache.php +++ b/tests/mock/cache.php @@ -2,21 +2,18 @@ /** * * @package testing -* @copyright (c) 2008 phpBB Group +* @copyright (c) 2011 phpBB Group * @license http://opensource.org/licenses/gpl-license.php GNU Public License * */ -class phpbb_mock_cache +class phpbb_mock_cache implements phpbb_cache_driver_interface { + protected $data; + public function __construct($data = array()) { $this->data = $data; - - if (!isset($this->data['_bots'])) - { - $this->data['_bots'] = array(); - } } public function get($var_name) @@ -34,25 +31,17 @@ class phpbb_mock_cache $this->data[$var_name] = $var; } - /** - * Obtain active bots - */ - public function obtain_bots() - { - return $this->data['_bots']; - } - - public function set_bots($bots) - { - $this->data['_bots'] = $bots; - } - public function checkVar(PHPUnit_Framework_Assert $test, $var_name, $data) { $test->assertTrue(isset($this->data[$var_name])); $test->assertEquals($data, $this->data[$var_name]); } + public function checkVarUnset(PHPUnit_Framework_Assert $test, $var_name) + { + $test->assertFalse(isset($this->data[$var_name])); + } + public function check(PHPUnit_Framework_Assert $test, $data, $ignore_db_info = true) { $cache_data = $this->data; @@ -69,5 +58,53 @@ class phpbb_mock_cache $test->assertEquals($data, $cache_data); } -} + function load() + { + } + function unload() + { + } + function save() + { + } + function tidy() + { + } + function purge() + { + } + function destroy($var_name, $table = '') + { + unset($this->data[$var_name]); + } + public function _exists($var_name) + { + } + public function sql_load($query) + { + } + public function sql_save($query, &$query_result, $ttl) + { + } + public function sql_exists($query_id) + { + } + public function sql_fetchrow($query_id) + { + } + public function sql_fetchfield($query_id, $field) + { + } + public function sql_rowseek($rownum, $query_id) + { + } + public function sql_freeresult($query_id) + { + } + + public function obtain_bots() + { + return isset($this->data['_bots']) ? $this->data['_bots'] : array(); + } +} diff --git a/tests/mock/lang.php b/tests/mock/lang.php new file mode 100644 index 0000000000..17a39629c1 --- /dev/null +++ b/tests/mock/lang.php @@ -0,0 +1,33 @@ +<?php +/** +* +* @package testing +* @copyright (c) 2010 phpBB Group +* @license http://opensource.org/licenses/gpl-license.php GNU Public License +* +*/ + +/** +* phpbb_mock_lang +* mock a user with some language-keys specified +*/ +class phpbb_mock_lang implements ArrayAccess +{ + public function offsetExists($offset) + { + return true; + } + + public function offsetGet($offset) + { + return $offset; + } + + public function offsetSet($offset, $value) + { + } + + public function offsetUnset($offset) + { + } +} diff --git a/tests/mock/request.php b/tests/mock/request.php new file mode 100644 index 0000000000..da4015e78b --- /dev/null +++ b/tests/mock/request.php @@ -0,0 +1,46 @@ +<?php +/** +* +* @package testing +* @copyright (c) 2011 phpBB Group +* @license http://opensource.org/licenses/gpl-license.php GNU Public License +* +*/ + +class phpbb_mock_request implements phpbb_request_interface +{ + protected $data; + + public function __construct($get = array(), $post = array(), $cookie = array(), $request = false) + { + $this->data[phpbb_request_interface::GET] = $get; + $this->data[phpbb_request_interface::POST] = $post; + $this->data[phpbb_request_interface::COOKIE] = $cookie; + $this->data[phpbb_request_interface::REQUEST] = ($request === false) ? $post + $get : $request; + } + + public function overwrite($var_name, $value, $super_global = phpbb_request_interface::REQUEST) + { + $this->data[$super_global][$var_name] = $value; + } + + public function variable($var_name, $default, $multibyte = false, $super_global = phpbb_request_interface::REQUEST) + { + return isset($this->data[$super_global][$var_name]) ? $this->data[$super_global][$var_name] : $default; + } + + public function is_set_post($name) + { + return $this->is_set($name, phpbb_request_interface::POST); + } + + public function is_set($var, $super_global = phpbb_request_interface::REQUEST) + { + return isset($this->data[$super_global][$var]); + } + + public function variable_names($super_global = phpbb_request_interface::REQUEST) + { + return array_keys($this->data[$super_global]); + } +} diff --git a/tests/network/inet_ntop_pton_test.php b/tests/network/inet_ntop_pton_test.php new file mode 100644 index 0000000000..d3332f20c0 --- /dev/null +++ b/tests/network/inet_ntop_pton_test.php @@ -0,0 +1,54 @@ +<?php +/** +* +* @package testing +* @copyright (c) 2010 phpBB Group +* @license http://opensource.org/licenses/gpl-license.php GNU Public License +* +*/ + +require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php'; + +class phpbb_network_inet_ntop_pton_test extends phpbb_test_case +{ + public function data_provider() + { + return array( + array('127.0.0.1', '7f000001'), + array('192.232.131.223', 'c0e883df'), + array('13.1.68.3', '0d014403'), + array('129.144.52.38', '81903426'), + + array('2001:280:0:10::5', '20010280000000100000000000000005'), + array('fe80::200:4cff:fefe:172f', 'fe8000000000000002004cfffefe172f'), + + array('::', '00000000000000000000000000000000'), + array('::1', '00000000000000000000000000000001'), + array('1::', '00010000000000000000000000000000'), + + array('1:1:0:0:1::', '00010001000000000001000000000000'), + + array('0:2:3:4:5:6:7:8', '00000002000300040005000600070008'), + array('1:2:0:4:5:6:7:8', '00010002000000040005000600070008'), + array('1:2:3:4:5:6:7:0', '00010002000300040005000600070000'), + + array('2001:0:0:1::1', '20010000000000010000000000000001'), + ); + } + + /** + * @dataProvider data_provider + */ + public function test_inet_ntop($address, $hex) + { + $this->assertEquals($address, phpbb_inet_ntop(pack('H*', $hex))); + } + + /** + * @dataProvider data_provider + */ + public function test_inet_pton($address, $hex) + { + $this->assertEquals($hex, bin2hex(phpbb_inet_pton($address))); + } +} diff --git a/tests/network/ip_normalise_test.php b/tests/network/ip_normalise_test.php new file mode 100644 index 0000000000..dce0774d85 --- /dev/null +++ b/tests/network/ip_normalise_test.php @@ -0,0 +1,64 @@ +<?php +/** +* +* @package testing +* @copyright (c) 2010 phpBB Group +* @license http://opensource.org/licenses/gpl-license.php GNU Public License +* +*/ + +require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php'; + +class phpbb_network_ip_normalise_test extends phpbb_test_case +{ + public function data_provider() + { + return array( + // From: A Recommendation for IPv6 Address Text Representation + // http://tools.ietf.org/html/draft-ietf-6man-text-addr-representation-07 + + // Section 4: A Recommendation for IPv6 Text Representation + // Section 4.1: Handling Leading Zeros in a 16 Bit Field + array('2001:0db8::0001', '2001:db8::1'), + + // Section 4.2: "::" Usage + // Section 4.2.1: Shorten As Much As Possible + array('2001:db8::0:1', '2001:db8::1'), + + // Section 4.2.2: Handling One 16 Bit 0 Field + array('2001:db8::1:1:1:1:1', '2001:db8:0:1:1:1:1:1'), + + // Section 4.2.3: Choice in Placement of "::" + array('2001:db8:0:0:1:0:0:1', '2001:db8::1:0:0:1'), + + // Section 4.3: Lower Case + array('2001:DB8::1', '2001:db8::1'), + + // Section 5: Text Representation of Special Addresses + // We want to show IPv4-mapped addresses as plain IPv4 addresses, though. + array('::ffff:192.168.0.1', '192.168.0.1'), + array('0000::0000:ffff:c000:0280', '192.0.2.128'), + + // IPv6 addresses with the last 32-bit written in dotted-quad notation + // should be converted to hex-only IPv6 addresses. + array('2001:db8::192.0.2.128', '2001:db8::c000:280'), + + // Any string not passing the IPv4 or IPv6 regular expression + // is supposed to result in false being returned. + // Valid and invalid IP addresses are tested in + // tests/regex/ipv4.php and tests/regex/ipv6.php. + array('', false), + array('192.168.1.256', false), + array('::ffff:192.168.255.256', false), + array('::1111:2222:3333:4444:5555:6666::', false), + ); + } + + /** + * @dataProvider data_provider + */ + public function test_ip_normalise($ip_address, $expected) + { + $this->assertEquals($expected, phpbb_ip_normalise($ip_address)); + } +} diff --git a/tests/request/deactivated_super_global_test.php b/tests/request/deactivated_super_global_test.php new file mode 100644 index 0000000000..995f93443d --- /dev/null +++ b/tests/request/deactivated_super_global_test.php @@ -0,0 +1,22 @@ +<?php +/** +* +* @package testing +* @version $Id$ +* @copyright (c) 2009 phpBB Group +* @license http://opensource.org/licenses/gpl-license.php GNU Public License +* +*/ + +class phpbb_deactivated_super_global_test extends phpbb_test_case +{ + /** + * Checks that on write access the correct error is thrown + */ + public function test_write_triggers_error() + { + $this->setExpectedTriggerError(E_USER_ERROR); + $obj = new phpbb_request_deactivated_super_global($this->getMock('phpbb_request_interface'), 'obj', phpbb_request_interface::POST); + $obj->offsetSet(0, 0); + } +} diff --git a/tests/request/request_test.php b/tests/request/request_test.php new file mode 100644 index 0000000000..203c9fd880 --- /dev/null +++ b/tests/request/request_test.php @@ -0,0 +1,77 @@ +<?php +/** +* +* @package testing +* @version $Id$ +* @copyright (c) 2009 phpBB Group +* @license http://opensource.org/licenses/gpl-license.php GNU Public License +* +*/ + +class phpbb_request_test extends phpbb_test_case +{ + private $type_cast_helper; + private $request; + + protected function setUp() + { + // populate super globals + $_POST['test'] = 1; + $_GET['test'] = 2; + $_COOKIE['test'] = 3; + $_REQUEST['test'] = 3; + $_GET['unset'] = ''; + + $this->type_cast_helper = $this->getMock('phpbb_request_type_cast_helper_interface'); + + $this->request = new phpbb_request($this->type_cast_helper); + } + + public function test_toggle_super_globals() + { + $this->assertTrue($this->request->super_globals_disabled(), 'Superglobals were not disabled'); + + $this->request->enable_super_globals(); + + $this->assertFalse($this->request->super_globals_disabled(), 'Superglobals were not enabled'); + + $this->assertEquals(1, $_POST['test'], 'Checking $_POST after enable_super_globals'); + $this->assertEquals(2, $_GET['test'], 'Checking $_GET after enable_super_globals'); + $this->assertEquals(3, $_COOKIE['test'], 'Checking $_COOKIE after enable_super_globals'); + $this->assertEquals(3, $_REQUEST['test'], 'Checking $_REQUEST after 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() + { + $this->setExpectedTriggerError(E_USER_ERROR); + $_POST['test'] = 3; + } + + public function test_is_set_post() + { + $this->assertTrue($this->request->is_set_post('test')); + $this->assertFalse($this->request->is_set_post('unset')); + } + + public function test_variable_names() + { + $expected = array('test', 'unset'); + $result = $this->request->variable_names(); + $this->assertEquals($expected, $result); + } + + /** + * Makes sure super globals work properly after these tests + */ + protected function tearDown() + { + $this->request->enable_super_globals(); + } +} diff --git a/tests/request/request_var_test.php b/tests/request/request_var_test.php index fa17b1909f..7a45ef2fee 100644 --- a/tests/request/request_var_test.php +++ b/tests/request/request_var_test.php @@ -10,9 +10,18 @@ require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php'; require_once dirname(__FILE__) . '/../../phpBB/includes/utf/utf_tools.php'; -class phpbb_request_request_var_test extends phpbb_test_case +class phpbb_request_var_test extends phpbb_test_case { /** + * Makes sure request_var has its standard behaviour. + */ + protected function setUp() + { + parent::setUp(); + request_var(false, false, false, false, false); + } + + /** * @dataProvider request_variables */ public function test_post($variable_value, $default, $multibyte, $expected) @@ -73,6 +82,47 @@ 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'); + + // cannot set $_REQUEST directly because in phpbb_request implementation + // $_REQUEST = $_POST + $_GET + $_POST['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 +223,50 @@ class phpbb_request_request_var_test extends phpbb_test_case 'abc' => array() ) ), + 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/request/type_cast_helper_test.php b/tests/request/type_cast_helper_test.php new file mode 100644 index 0000000000..06cf2e1bf6 --- /dev/null +++ b/tests/request/type_cast_helper_test.php @@ -0,0 +1,51 @@ +<?php +/** +* +* @package testing +* @version $Id$ +* @copyright (c) 2009 phpBB Group +* @license http://opensource.org/licenses/gpl-license.php GNU Public License +* +*/ + +require_once dirname(__FILE__) . '/../../phpBB/includes/utf/utf_tools.php'; + +class phpbb_type_cast_helper_test extends phpbb_test_case +{ + private $type_cast_helper; + + protected function setUp() + { + $this->type_cast_helper = new phpbb_request_type_cast_helper(); + } + + public function test_addslashes_recursively() + { + $data = array('some"string' => array('that"' => 'really"', 'needs"' => '"escaping')); + $expected = array('some\\"string' => array('that\\"' => 'really\\"', 'needs\\"' => '\\"escaping')); + + $this->type_cast_helper->addslashes_recursively($data); + + $this->assertEquals($expected, $data); + } + + public function test_simple_recursive_set_var() + { + $data = 'eviL<3'; + $expected = 'eviL<3'; + + $this->type_cast_helper->recursive_set_var($data, '', true); + + $this->assertEquals($expected, $data); + } + + public function test_nested_recursive_set_var() + { + $data = array('eviL<3'); + $expected = array('eviL<3'); + + $this->type_cast_helper->recursive_set_var($data, array(0 => ''), true); + + $this->assertEquals($expected, $data); + } +} diff --git a/tests/security/redirect_test.php b/tests/security/redirect_test.php index 70ba8527b1..76347d309f 100644 --- a/tests/security/redirect_test.php +++ b/tests/security/redirect_test.php @@ -30,7 +30,7 @@ class phpbb_security_redirect_test extends phpbb_security_test_base protected function setUp() { parent::setUp(); - + $GLOBALS['config'] = array( 'force_server_vars' => '0', ); @@ -57,4 +57,3 @@ class phpbb_security_redirect_test extends phpbb_security_test_base } } } - diff --git a/tests/session/testable_factory.php b/tests/session/testable_factory.php index f3ef19a257..2b6a1683d3 100644 --- a/tests/session/testable_factory.php +++ b/tests/session/testable_factory.php @@ -7,6 +7,7 @@ * */ +require_once dirname(__FILE__) . '/../mock/request.php'; require_once dirname(__FILE__) . '/../mock/session_testable.php'; /** @@ -24,6 +25,7 @@ class phpbb_session_testable_factory protected $config; protected $cache; + protected $request; /** * Initialises the factory with a set of default config and cache values. @@ -66,15 +68,23 @@ class phpbb_session_testable_factory public function get_session(dbal $dbal) { // set up all the global variables used by session - global $SID, $_SID, $db, $config, $cache; + global $SID, $_SID, $db, $config, $cache, $request; + + $request = $this->request = new phpbb_mock_request( + array(), + array(), + $this->cookies + ); + request_var(null, null, null, null, $request); + + $config = $this->config = new phpbb_config($this->get_config_data()); + set_config(null, null, null, $config); - $config = $this->config = $this->get_config_data(); $db = $dbal; $cache = $this->cache = new phpbb_mock_cache($this->get_cache_data()); $SID = $_SID = null; - $_COOKIE = $this->cookies; $_SERVER = $this->server_data; $session = new phpbb_mock_session_testable; diff --git a/tests/template/template_test.php b/tests/template/template_test.php index 33c82d53ad..62f94f7d32 100644 --- a/tests/template/template_test.php +++ b/tests/template/template_test.php @@ -16,34 +16,13 @@ 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(); - - try - { - $this->assertTrue($this->template->display($handle, false)); - } - catch (Exception $exception) - { - // reset the error level even when an error occured - // PHPUnit turns trigger_error into exceptions as well - error_reporting($error_level); - ob_end_clean(); - throw $exception; - } - - $result = self::trim_template_result(ob_get_clean()); - - // reset error level - error_reporting($error_level); - return $result; + $this->assertTrue($this->template->display($handle, false)); + return self::trim_template_result(ob_get_clean()); } private static function trim_template_result($result) @@ -60,6 +39,8 @@ class phpbb_template_template_test extends phpbb_test_case protected function setUp() { + $this->markTestIncomplete("template::display raises notices."); + // Test the engine can be used $this->setup_engine(); 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 --> diff --git a/tests/test_framework/phpbb_test_case_helpers.php b/tests/test_framework/phpbb_test_case_helpers.php index 0acdce32e0..697dc93501 100644 --- a/tests/test_framework/phpbb_test_case_helpers.php +++ b/tests/test_framework/phpbb_test_case_helpers.php @@ -41,4 +41,9 @@ class phpbb_test_case_helpers $this->expectedTriggerError = true; $this->test_case->setExpectedException($exceptionName, (string) $message, $errno); } + + public function makedirs($path) + { + mkdir($path, 0777, true); + } } |