diff options
Diffstat (limited to 'tests')
166 files changed, 1762 insertions, 970 deletions
diff --git a/tests/RUNNING_TESTS.md b/tests/RUNNING_TESTS.md index f2688ab675..0778046141 100644 --- a/tests/RUNNING_TESTS.md +++ b/tests/RUNNING_TESTS.md @@ -57,7 +57,7 @@ found below. More information on configuration options can be found on the wiki (see below). <?php - $dbms = 'phpbb_db_driver_mysqli'; + $dbms = 'phpbb\db\driver\mysqli'; $dbhost = 'localhost'; $dbport = ''; $dbname = 'database'; diff --git a/tests/acp_board/auth_provider/invalid.php b/tests/acp_board/auth_provider/invalid.php index c12851afe6..acce3b7e2d 100644 --- a/tests/acp_board/auth_provider/invalid.php +++ b/tests/acp_board/auth_provider/invalid.php @@ -7,7 +7,9 @@ * */ -class phpbb_auth_provider_acp_board_invalid +namespace phpbb\auth\provider\acp; + +class board_invalid { } diff --git a/tests/acp_board/auth_provider/valid.php b/tests/acp_board/auth_provider/valid.php index 42b14cb0af..13ec1e3250 100644 --- a/tests/acp_board/auth_provider/valid.php +++ b/tests/acp_board/auth_provider/valid.php @@ -7,7 +7,9 @@ * */ -class phpbb_auth_provider_acp_board_valid extends phpbb_auth_provider_base +namespace phpbb\auth\provider\acp; + +class board_valid extends \phpbb\auth\provider\base { public function login($username, $password) { diff --git a/tests/acp_board/select_auth_method_test.php b/tests/acp_board/select_auth_method_test.php index 91aa5d1232..b943554564 100644 --- a/tests/acp_board/select_auth_method_test.php +++ b/tests/acp_board/select_auth_method_test.php @@ -31,8 +31,8 @@ class phpbb_acp_board_select_auth_method_test extends phpbb_test_case $phpbb_container = new phpbb_mock_container_builder(); $phpbb_container->set('auth.provider_collection', array( - 'auth.provider.acp_board_valid' => new phpbb_auth_provider_acp_board_valid, - 'auth.provider.acp_board_invalid' => new phpbb_auth_provider_acp_board_invalid, + 'auth.provider.acp_board_valid' => new phpbb\auth\provider\acp\board_valid, + 'auth.provider.acp_board_invalid' => new phpbb\auth\provider\acp\board_invalid, )); $this->acp_board = new acp_board(); diff --git a/tests/auth/fixtures/oauth_tokens.xml b/tests/auth/fixtures/oauth_tokens.xml new file mode 100644 index 0000000000..9bfb5a4422 --- /dev/null +++ b/tests/auth/fixtures/oauth_tokens.xml @@ -0,0 +1,10 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<dataset> + <table name="phpbb_oauth_tokens"> + <column>user_id</column> + <column>session_id</column> + <column>provider</column> + <column>oauth_token</column> + </table> +</dataset> + diff --git a/tests/auth/provider_apache_test.php b/tests/auth/provider_apache_test.php index 0ca6ef763e..e135a1f002 100644 --- a/tests/auth/provider_apache_test.php +++ b/tests/auth/provider_apache_test.php @@ -22,11 +22,11 @@ class phpbb_auth_provider_apache_test extends phpbb_database_test_case global $phpbb_root_path, $phpEx; $db = $this->new_dbal(); - $config = new phpbb_config(array()); - $this->request = $this->getMock('phpbb_request'); - $this->user = $this->getMock('phpbb_user'); + $config = new \phpbb\config\config(array()); + $this->request = $this->getMock('\phpbb\request\request'); + $this->user = $this->getMock('\phpbb\user'); - $this->provider = new phpbb_auth_provider_apache($db, $config, $this->request, $this->user, $phpbb_root_path, $phpEx); + $this->provider = new \phpbb\auth\provider\apache($db, $config, $this->request, $this->user, $phpbb_root_path, $phpEx); } public function getDataSet() @@ -43,7 +43,7 @@ class phpbb_auth_provider_apache_test extends phpbb_database_test_case $this->request->expects($this->once()) ->method('is_set') ->with('PHP_AUTH_USER', - phpbb_request_interface::SERVER) + \phpbb\request\request_interface::SERVER) ->will($this->returnValue(true)); $this->request->expects($this->once()) ->method('server') @@ -61,7 +61,7 @@ class phpbb_auth_provider_apache_test extends phpbb_database_test_case $this->request->expects($this->once()) ->method('is_set') ->with('PHP_AUTH_USER', - phpbb_request_interface::SERVER) + \phpbb\request\request_interface::SERVER) ->will($this->returnValue(true)); $this->request->expects($this->at(1)) ->method('server') @@ -93,7 +93,7 @@ class phpbb_auth_provider_apache_test extends phpbb_database_test_case $this->request->expects($this->once()) ->method('is_set') ->with('PHP_AUTH_USER', - phpbb_request_interface::SERVER) + \phpbb\request\request_interface::SERVER) ->will($this->returnValue(true)); $this->request->expects($this->at(1)) ->method('server') @@ -194,7 +194,7 @@ class phpbb_auth_provider_apache_test extends phpbb_database_test_case $this->request->expects($this->once()) ->method('is_set') ->with('PHP_AUTH_USER', - phpbb_request_interface::SERVER) + \phpbb\request\request_interface::SERVER) ->will($this->returnValue(true)); $this->request->expects($this->once()) ->method('server') diff --git a/tests/auth/provider_db_test.php b/tests/auth/provider_db_test.php index d876683f84..140a28cd3d 100644 --- a/tests/auth/provider_db_test.php +++ b/tests/auth/provider_db_test.php @@ -21,14 +21,14 @@ class phpbb_auth_provider_db_test extends phpbb_database_test_case global $phpbb_root_path, $phpEx; $db = $this->new_dbal(); - $config = new phpbb_config(array( + $config = new \phpbb\config\config(array( 'ip_login_limit_max' => 0, 'ip_login_limit_use_forwarded' => 0, 'max_login_attempts' => 0, )); - $request = $this->getMock('phpbb_request'); - $user = $this->getMock('phpbb_user'); - $provider = new phpbb_auth_provider_db($db, $config, $request, $user, $phpbb_root_path, $phpEx); + $request = $this->getMock('\phpbb\request\request'); + $user = $this->getMock('\phpbb\user'); + $provider = new \phpbb\auth\provider\db($db, $config, $request, $user, $phpbb_root_path, $phpEx); $expected = array( 'status' => LOGIN_SUCCESS, diff --git a/tests/auth/provider_oauth_token_storage_test.php b/tests/auth/provider_oauth_token_storage_test.php new file mode 100644 index 0000000000..fdc08833a3 --- /dev/null +++ b/tests/auth/provider_oauth_token_storage_test.php @@ -0,0 +1,207 @@ +<?php +/** +* +* @package testing +* @copyright (c) 2013 phpBB Group +* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 +* +*/ + +use OAuth\OAuth2\Token\StdOAuth2Token; + +class phpbb_auth_provider_oauth_token_storage_test extends phpbb_database_test_case +{ + protected $db; + protected $service_name; + protected $session_id; + protected $token_storage; + protected $token_storage_table; + protected $user; + + protected function setup() + { + parent::setUp(); + + global $phpbb_root_path, $phpEx; + + $this->db = $this->new_dbal(); + $this->user = $this->getMock('\phpbb\user'); + $this->service_name = 'auth.provider.oauth.service.testing'; + $this->token_storage_table = 'phpbb_oauth_tokens'; + + // Give the user a session_id that we will remember + $this->session_id = '12345'; + $this->user->data['session_id'] = $this->session_id; + + // Set the user id to anonymous + $this->user->data['user_id'] = ANONYMOUS; + + $this->token_storage = new \phpbb\auth\provider\oauth\token_storage($this->db, $this->user, $this->token_storage_table); + } + + public function getDataSet() + { + return $this->createXMLDataSet(dirname(__FILE__).'/fixtures/oauth_tokens.xml'); + } + + public static function retrieveAccessToken_data() + { + return array( + array(new StdOAuth2Token('access', 'refresh', StdOAuth2Token::EOL_NEVER_EXPIRES, array('extra' => 'param')), null), + array(null, 'OAuth\Common\Storage\Exception\TokenNotFoundException'), + ); + } + + /** + * @dataProvider retrieveAccessToken_data + */ + public function test_retrieveAccessToken($cache_token, $exception) + { + if ($cache_token) + { + $this->token_storage->storeAccessToken($this->service_name, $cache_token); + $token = $cache_token; + } + + $this->setExpectedException($exception); + + $stored_token = $this->token_storage->retrieveAccessToken($this->service_name); + $this->assertEquals($token, $stored_token); + } + + public function test_retrieveAccessToken_from_db() + { + $expected_token = new StdOAuth2Token('access', 'refresh', StdOAuth2Token::EOL_NEVER_EXPIRES); + + // Store a token in the database + $temp_storage = new \phpbb\auth\provider\oauth\token_storage($this->db, $this->user, $this->token_storage_table); + $temp_storage->storeAccessToken($this->service_name, $expected_token); + unset($temp_storage); + + // Test to see if the token can be retrieved + $stored_token = $this->token_storage->retrieveAccessToken($this->service_name); + $this->assertEquals($expected_token, $stored_token); + } + + /** + * @dataProvider retrieveAccessToken_data + */ + public function test_retrieve_access_token_by_session($cache_token, $exception) + { + if ($cache_token) + { + $this->token_storage->storeAccessToken($this->service_name, $cache_token); + $token = $cache_token; + } + + $this->setExpectedException($exception); + + $stored_token = $this->token_storage->retrieve_access_token_by_session($this->service_name); + $this->assertEquals($token, $stored_token); + } + + public function test_retrieve_access_token_by_session_from_db() + { + $expected_token = new StdOAuth2Token('access', 'refresh', StdOAuth2Token::EOL_NEVER_EXPIRES); + + // Store a token in the database + $temp_storage = new \phpbb\auth\provider\oauth\token_storage($this->db, $this->user, $this->token_storage_table); + $temp_storage->storeAccessToken($this->service_name, $expected_token); + unset($temp_storage); + + // Test to see if the token can be retrieved + $stored_token = $this->token_storage->retrieve_access_token_by_session($this->service_name); + $this->assertEquals($expected_token, $stored_token); + } + + public function test_storeAccessToken() + { + $token = new StdOAuth2Token('access', 'refresh', StdOAuth2Token::EOL_NEVER_EXPIRES, array('extra' => 'param') ); + $this->token_storage->storeAccessToken($this->service_name, $token); + + // Confirm that the token is cached + $extraParams = $this->token_storage->retrieveAccessToken($this->service_name)->getExtraParams(); + $this->assertEquals( 'param', $extraParams['extra'] ); + $this->assertEquals( 'access', $this->token_storage->retrieveAccessToken($this->service_name)->getAccessToken() ); + + $row = $this->get_token_row_by_session_id($this->session_id); + + // The token is serialized before stored in the database + $this->assertEquals($this->token_storage->json_encode_token($token), $row['oauth_token']); + } + + public static function hasAccessToken_data() + { + return array( + array(null, false), + array(new StdOAuth2Token('access', 'refresh', StdOAuth2Token::EOL_NEVER_EXPIRES, array('extra' => 'param') ), true), + ); + } + + /** + * @dataProvider hasAccessToken_data + */ + public function test_hasAccessToken($token, $expected) + { + if ($token) + { + $this->token_storage->storeAccessToken($this->service_name, $token); + } + + $has_access_token = $this->token_storage->hasAccessToken($this->service_name); + $this->assertEquals($expected, $has_access_token); + } + + /** + * @dataProvider hasAccessToken_data + */ + public function test_has_access_token_by_session($token, $expected) + { + if ($token) + { + $this->token_storage->storeAccessToken($this->service_name, $token); + } + + $has_access_token = $this->token_storage->has_access_token_by_session($this->service_name); + $this->assertEquals($expected, $has_access_token); + } + + public function test_clearToken() + { + $token = new StdOAuth2Token('access', 'refresh', StdOAuth2Token::EOL_NEVER_EXPIRES, array('extra' => 'param') ); + $this->token_storage->storeAccessToken($this->service_name, $token); + + $this->token_storage->clearToken($this->service_name); + + // Check that the database has been cleared + $row = $this->get_token_row_by_session_id($this->session_id); + $this->assertFalse($row); + + // Check that the token is no longer in memory + $this->assertFalse($this->token_storage->hasAccessToken($this->service_name)); + } + + public function test_set_user_id() + { + $token = new StdOAuth2Token('access', 'refresh', StdOAuth2Token::EOL_NEVER_EXPIRES, array('extra' => 'param') ); + $this->token_storage->storeAccessToken($this->service_name, $token); + + $new_user_id = ANONYMOUS + 1; + $this->token_storage->set_user_id($new_user_id); + + $row = $this->get_token_row_by_session_id($this->session_id); + $this->assertEquals($new_user_id, $row['user_id']); + } + + protected function get_token_row_by_session_id($session_id) + { + // Test that the token is stored in the database + $sql = 'SELECT * FROM phpbb_oauth_tokens + WHERE session_id = \'' . $this->db->sql_escape($session_id) . '\''; + $result = $this->db->sql_query($sql); + $row = $this->db->sql_fetchrow($result); + $this->db->sql_freeresult($result); + + return $row; + } +} diff --git a/tests/avatar/driver/barfoo.php b/tests/avatar/driver/barfoo.php index 0b701a4d70..11c100db36 100644 --- a/tests/avatar/driver/barfoo.php +++ b/tests/avatar/driver/barfoo.php @@ -1,6 +1,8 @@ <?php
-class phpbb_avatar_driver_barfoo extends phpbb_avatar_driver
+namespace phpbb\avatar\driver;
+
+class barfoo extends \phpbb\avatar\driver\driver
{
public function get_data($row)
{
diff --git a/tests/avatar/driver/foobar.php b/tests/avatar/driver/foobar.php index 995f35818b..a1e7bdf7cc 100644 --- a/tests/avatar/driver/foobar.php +++ b/tests/avatar/driver/foobar.php @@ -1,6 +1,8 @@ <?php
-class phpbb_avatar_driver_foobar extends phpbb_avatar_driver
+namespace phpbb\avatar\driver;
+
+class foobar extends \phpbb\avatar\driver\driver
{
public function get_data($row)
{
diff --git a/tests/avatar/manager_test.php b/tests/avatar/manager_test.php index 4ebe79c9cd..ba1fb04b33 100644 --- a/tests/avatar/manager_test.php +++ b/tests/avatar/manager_test.php @@ -22,17 +22,17 @@ class phpbb_avatar_manager_test extends PHPUnit_Framework_TestCase ->will($this->returnArgument(0)); // Prepare dependencies for avatar manager and driver - $config = new phpbb_config(array()); - $request = $this->getMock('phpbb_request'); - $cache = $this->getMock('phpbb_cache_driver_interface'); + $config = new \phpbb\config\config(array()); + $request = $this->getMock('\phpbb\request\request'); + $cache = $this->getMock('\phpbb\cache\driver\driver_interface'); // $this->avatar_foobar will be needed later on - $this->avatar_foobar = $this->getMock('phpbb_avatar_driver_foobar', array('get_name'), array($config, $phpbb_root_path, $phpEx, $cache)); + $this->avatar_foobar = $this->getMock('\phpbb\avatar\driver\foobar', array('get_name'), array($config, $phpbb_root_path, $phpEx, $cache)); $this->avatar_foobar->expects($this->any()) ->method('get_name') ->will($this->returnValue('avatar.driver.foobar')); // barfoo driver can't be mocked with constructor arguments - $this->avatar_barfoo = $this->getMock('phpbb_avatar_driver_barfoo', array('get_name')); + $this->avatar_barfoo = $this->getMock('\phpbb\avatar\driver\barfoo', array('get_name')); $this->avatar_barfoo->expects($this->any()) ->method('get_name') ->will($this->returnValue('avatar.driver.barfoo')); @@ -40,7 +40,7 @@ class phpbb_avatar_manager_test extends PHPUnit_Framework_TestCase foreach ($this->avatar_drivers() as $driver) { - $cur_avatar = $this->getMock('phpbb_avatar_driver_' . $driver, array('get_name'), array($config, $phpbb_root_path, $phpEx, $cache)); + $cur_avatar = $this->getMock('\phpbb\avatar\driver\\' . $driver, array('get_name'), array($config, $phpbb_root_path, $phpEx, $cache)); $cur_avatar->expects($this->any()) ->method('get_name') ->will($this->returnValue('avatar.driver.' . $driver)); @@ -52,7 +52,7 @@ class phpbb_avatar_manager_test extends PHPUnit_Framework_TestCase $config['allow_avatar_' . get_class($this->avatar_barfoo)] = false; // Set up avatar manager - $this->manager = new phpbb_avatar_manager($config, $avatar_drivers, $this->phpbb_container); + $this->manager = new \phpbb\avatar\manager($config, $avatar_drivers, $this->phpbb_container); } protected function avatar_drivers() @@ -203,7 +203,7 @@ class phpbb_avatar_manager_test extends PHPUnit_Framework_TestCase { $cleaned_row = array(); - $cleaned_row = phpbb_avatar_manager::clean_row($input); + $cleaned_row = \phpbb\avatar\manager::clean_row($input); foreach ($output as $key => $null) { $this->assertArrayHasKey($key, $cleaned_row); @@ -222,7 +222,7 @@ class phpbb_avatar_manager_test extends PHPUnit_Framework_TestCase public function test_localize_errors() { - $user = $this->getMock('phpbb_user'); + $user = $this->getMock('\phpbb\user'); $lang_array = array( array('FOOBAR_OFF', 'foobar_off'), array('FOOBAR_EXPLAIN', 'FOOBAR_EXPLAIN %s'), diff --git a/tests/bootstrap.php b/tests/bootstrap.php index 68cbb64c03..afb586435c 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -16,11 +16,11 @@ $table_prefix = 'phpbb_'; require_once $phpbb_root_path . 'includes/constants.php'; require_once $phpbb_root_path . 'phpbb/class_loader.' . $phpEx; -$phpbb_class_loader_mock = new phpbb_class_loader('phpbb_mock_', $phpbb_root_path . '../tests/mock/', "php"); +$phpbb_class_loader_mock = new \phpbb\class_loader('phpbb_mock_', $phpbb_root_path . '../tests/mock/', "php"); $phpbb_class_loader_mock->register(); -$phpbb_class_loader_ext = new phpbb_class_loader('phpbb_ext_', $phpbb_root_path . 'ext/', "php"); +$phpbb_class_loader_ext = new \phpbb\class_loader('\\', $phpbb_root_path . 'ext/', "php"); $phpbb_class_loader_ext->register(); -$phpbb_class_loader = new phpbb_class_loader('phpbb_', $phpbb_root_path . 'phpbb/', "php"); +$phpbb_class_loader = new \phpbb\class_loader('phpbb\\', $phpbb_root_path . 'phpbb/', "php"); $phpbb_class_loader->register(); require_once 'test_framework/phpbb_test_case_helpers.php'; diff --git a/tests/cache/apc_driver_test.php b/tests/cache/apc_driver_test.php index 3380762878..51f3ac24b6 100644 --- a/tests/cache/apc_driver_test.php +++ b/tests/cache/apc_driver_test.php @@ -30,7 +30,7 @@ class phpbb_cache_apc_driver_test extends phpbb_cache_common_test_case self::markTestSkipped('APC extension is not loaded'); } - $php_ini = new phpbb_php_ini; + $php_ini = new \phpbb\php\ini; if (!$php_ini->get_bool('apc.enabled')) { @@ -47,7 +47,7 @@ class phpbb_cache_apc_driver_test extends phpbb_cache_common_test_case { parent::setUp(); - $this->driver = new phpbb_cache_driver_apc; + $this->driver = new \phpbb\cache\driver\apc; $this->driver->purge(); } } diff --git a/tests/cache/common_test_case.php b/tests/cache/common_test_case.php index a5bc2bfda9..3fe10c63e1 100644 --- a/tests/cache/common_test_case.php +++ b/tests/cache/common_test_case.php @@ -65,9 +65,9 @@ abstract class phpbb_cache_common_test_case extends phpbb_database_test_case public function test_cache_sql() { global $db, $cache, $phpbb_root_path, $phpEx; - $config = new phpbb_config(array()); + $config = new phpbb\config\config(array()); $db = $this->new_dbal(); - $cache = new phpbb_cache_service($this->driver, $config, $db, $phpbb_root_path, $phpEx); + $cache = new \phpbb\cache\service($this->driver, $config, $db, $phpbb_root_path, $phpEx); $sql = "SELECT * FROM phpbb_config WHERE config_name = 'foo'"; diff --git a/tests/cache/file_driver_test.php b/tests/cache/file_driver_test.php index 745c6bb081..c0843e8ed9 100644 --- a/tests/cache/file_driver_test.php +++ b/tests/cache/file_driver_test.php @@ -36,7 +36,7 @@ class phpbb_cache_file_driver_test extends phpbb_cache_common_test_case } $this->create_cache_dir(); - $this->driver = new phpbb_cache_driver_file($this->cache_dir); + $this->driver = new \phpbb\cache\driver\file($this->cache_dir); } protected function tearDown() diff --git a/tests/cache/null_driver_test.php b/tests/cache/null_driver_test.php index 43a0cc806c..58e57f2b3a 100644 --- a/tests/cache/null_driver_test.php +++ b/tests/cache/null_driver_test.php @@ -20,7 +20,7 @@ class phpbb_cache_null_driver_test extends phpbb_database_test_case { parent::setUp(); - $this->driver = new phpbb_cache_driver_null; + $this->driver = new \phpbb\cache\driver\null; } public function test_get_put() @@ -48,9 +48,9 @@ class phpbb_cache_null_driver_test extends phpbb_database_test_case public function test_cache_sql() { global $db, $cache, $phpbb_root_path, $phpEx; - $config = new phpbb_config(array()); + $config = new phpbb\config\config(array()); $db = $this->new_dbal(); - $cache = new phpbb_cache_service($this->driver, $config, $db, $phpbb_root_path, $phpEx); + $cache = new \phpbb\cache\service($this->driver, $config, $db, $phpbb_root_path, $phpEx); $sql = "SELECT * FROM phpbb_config WHERE config_name = 'foo'"; diff --git a/tests/cache/redis_driver_test.php b/tests/cache/redis_driver_test.php index 1308519a18..3d954dc0db 100644 --- a/tests/cache/redis_driver_test.php +++ b/tests/cache/redis_driver_test.php @@ -43,7 +43,7 @@ class phpbb_cache_redis_driver_test extends phpbb_cache_common_test_case { parent::setUp(); - $this->driver = new phpbb_cache_driver_redis(self::$config['host'], self::$config['port']); + $this->driver = new \phpbb\cache\driver\redis(self::$config['host'], self::$config['port']); $this->driver->purge(); } } diff --git a/tests/class_loader/class_loader_test.php b/tests/class_loader/class_loader_test.php index 2b55c1ff8d..6e551f658a 100644 --- a/tests/class_loader/class_loader_test.php +++ b/tests/class_loader/class_loader_test.php @@ -30,74 +30,68 @@ class phpbb_class_loader_test extends PHPUnit_Framework_TestCase public function test_resolve_path() { $prefix = dirname(__FILE__) . '/'; - $class_loader = new phpbb_class_loader('phpbb_', $prefix . 'phpbb/'); + $class_loader = new \phpbb\class_loader('phpbb\\', $prefix . 'phpbb/'); $prefix .= 'phpbb/'; $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'), + $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_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_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)' + $class_loader->resolve_path('\\phpbb\\dir2\\dir2'), + 'Class with name of dir within dir' ); } public function test_resolve_cached() { $cache_map = array( - 'class_loader_phpbb_' => array('phpbb_a_cached_name' => 'a/cached_name'), - 'class_loader_phpbb_ext_' => array('phpbb_ext_foo' => 'foo'), + 'class_loader___phpbb__' => array('\\phpbb\\a\\cached_name' => 'a/cached_name'), + 'class_loader___' => array('\\phpbb\\ext\\foo' => 'foo'), ); $cache = new phpbb_mock_cache($cache_map); $prefix = dirname(__FILE__) . '/'; - $class_loader = new phpbb_class_loader('phpbb_', $prefix . 'phpbb/', 'php', $cache); - $class_loader_ext = new phpbb_class_loader('phpbb_ext_', $prefix . 'phpbb/', 'php', $cache); + $class_loader = new \phpbb\class_loader('phpbb\\', $prefix . 'phpbb/', 'php', $cache); + $class_loader_ext = new \phpbb\class_loader('\\', $prefix . 'phpbb/', 'php', $cache); $prefix .= 'phpbb/'; $this->assertEquals( $prefix . 'dir/class_name.php', - $class_loader->resolve_path('phpbb_dir_class_name'), + $class_loader->resolve_path('\\phpbb\\dir\\class_name'), 'Class in a directory' ); - $this->assertFalse($class_loader->resolve_path('phpbb_ext_foo')); - $this->assertFalse($class_loader_ext->resolve_path('phpbb_a_cached_name')); + $this->assertFalse($class_loader->resolve_path('\\phpbb\\ext\\foo')); + $this->assertFalse($class_loader_ext->resolve_path('\\phpbb\\a\\cached_name')); $this->assertEquals( $prefix . 'a/cached_name.php', - $class_loader->resolve_path('phpbb_a_cached_name'), + $class_loader->resolve_path('\\phpbb\\a\\cached_name'), 'Cached class found' ); $this->assertEquals( $prefix . 'foo.php', - $class_loader_ext->resolve_path('phpbb_ext_foo'), + $class_loader_ext->resolve_path('\\phpbb\\ext\\foo'), 'Cached class found in alternative loader' ); - $cache_map['class_loader_phpbb_']['phpbb_dir_class_name'] = 'dir/class_name'; + $cache_map['class_loader___phpbb__']['\\phpbb\\dir\\class_name'] = 'dir/class_name'; $cache->check($this, $cache_map); } } diff --git a/tests/class_loader/phpbb/class_name.php b/tests/class_loader/phpbb/class_name.php index e941173cdd..64a3fa646e 100644 --- a/tests/class_loader/phpbb/class_name.php +++ b/tests/class_loader/phpbb/class_name.php @@ -1,6 +1,8 @@ <?php -class phpbb_class_name +namespace phpbb; + +class class_name { } diff --git a/tests/class_loader/phpbb/dir.php b/tests/class_loader/phpbb/dir.php deleted file mode 100644 index 1c8930d8e7..0000000000 --- a/tests/class_loader/phpbb/dir.php +++ /dev/null @@ -1,6 +0,0 @@ -<?php - -class phpbb_dir -{ -} - diff --git a/tests/class_loader/phpbb/dir/class_name.php b/tests/class_loader/phpbb/dir/class_name.php index 0675aa8fc5..1cd39a1181 100644 --- a/tests/class_loader/phpbb/dir/class_name.php +++ b/tests/class_loader/phpbb/dir/class_name.php @@ -1,6 +1,8 @@ <?php -class phpbb_dir_class_name +namespace phpbb\dir; + +class class_name { } diff --git a/tests/class_loader/phpbb/dir/subdir/class_name.php b/tests/class_loader/phpbb/dir/subdir/class_name.php index 7321a609cc..89affbc847 100644 --- a/tests/class_loader/phpbb/dir/subdir/class_name.php +++ b/tests/class_loader/phpbb/dir/subdir/class_name.php @@ -1,6 +1,8 @@ <?php -class phpbb_dir_subdir_class_name +namespace phpbb\dir\subdir; + +class class_name { } diff --git a/tests/class_loader/phpbb/dir2/dir2.php b/tests/class_loader/phpbb/dir2/dir2.php index 01cf4086ff..b273511fcd 100644 --- a/tests/class_loader/phpbb/dir2/dir2.php +++ b/tests/class_loader/phpbb/dir2/dir2.php @@ -1,6 +1,8 @@ <?php -class phpbb_dir2 +namespace phpbb; + +class dir2 { } diff --git a/tests/config/config_test.php b/tests/config/config_test.php index 5845cc4590..5373fcef5f 100644 --- a/tests/config/config_test.php +++ b/tests/config/config_test.php @@ -11,7 +11,7 @@ class phpbb_config_test extends phpbb_test_case { public function test_offset_exists() { - $config = new phpbb_config(array('foo' => 'bar')); + $config = new \phpbb\config\config(array('foo' => 'bar')); $this->assertTrue(isset($config['foo'])); $this->assertFalse(isset($config['foobar'])); @@ -19,19 +19,19 @@ class phpbb_config_test extends phpbb_test_case public function test_offset_get() { - $config = new phpbb_config(array('foo' => 'bar')); + $config = new \phpbb\config\config(array('foo' => 'bar')); $this->assertEquals('bar', $config['foo']); } public function test_offset_get_missing() { - $config = new phpbb_config(array()); + $config = new \phpbb\config\config(array()); $this->assertEquals('', $config['foo']); } public function test_offset_set() { - $config = new phpbb_config(array()); + $config = new \phpbb\config\config(array()); $config['foo'] = 'x'; $this->assertEquals('x', $config['foo']); } @@ -39,20 +39,20 @@ class phpbb_config_test extends phpbb_test_case public function test_offset_unset_fails() { $this->setExpectedTriggerError(E_USER_ERROR); - $config = new phpbb_config(array('foo' => 'x')); + $config = new \phpbb\config\config(array('foo' => 'x')); unset($config['foo']); } public function test_count() { - $config = new phpbb_config(array('foo' => 'bar')); + $config = new \phpbb\config\config(array('foo' => 'bar')); $this->assertEquals(1, count($config)); } public function test_iterate() { $vars = array('foo' => '23', 'bar' => '42'); - $config = new phpbb_config($vars); + $config = new \phpbb\config\config($vars); $count = 0; foreach ($config as $key => $value) @@ -68,42 +68,42 @@ class phpbb_config_test extends phpbb_test_case public function test_set_overwrite() { - $config = new phpbb_config(array('foo' => 'x')); + $config = new \phpbb\config\config(array('foo' => 'x')); $config->set('foo', 'bar'); $this->assertEquals('bar', $config['foo']); } public function test_set_new() { - $config = new phpbb_config(array()); + $config = new \phpbb\config\config(array()); $config->set('foo', 'bar'); $this->assertEquals('bar', $config['foo']); } public function test_set_atomic_overwrite() { - $config = new phpbb_config(array('foo' => 'bar')); + $config = new \phpbb\config\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()); + $config = new \phpbb\config\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')); + $config = new \phpbb\config\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 = new \phpbb\config\config(array('foo' => '23')); $config->increment('foo', 3); $this->assertEquals(26, $config['foo']); $config->increment('foo', 1); @@ -112,7 +112,7 @@ class phpbb_config_test extends phpbb_test_case public function test_delete() { - $config = new phpbb_config(array('foo' => 'bar')); + $config = new \phpbb\config\config(array('foo' => 'bar')); $config->delete('foo'); $this->assertFalse(isset($config['foo'])); diff --git a/tests/config/db_test.php b/tests/config/db_test.php index 0b8f73d53a..dd1c88f707 100644 --- a/tests/config/db_test.php +++ b/tests/config/db_test.php @@ -24,7 +24,7 @@ class phpbb_config_db_test extends phpbb_database_test_case $this->cache = new phpbb_mock_cache; $this->db = $this->new_dbal(); - $this->config = new phpbb_config_db($this->db, $this->cache, 'phpbb_config'); + $this->config = new \phpbb\config\db($this->db, $this->cache, 'phpbb_config'); } public function test_load_config() @@ -36,7 +36,7 @@ class phpbb_config_db_test extends phpbb_database_test_case 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->config = new \phpbb\config\db($this->db, $cache, 'phpbb_config'); $this->assertTrue(!isset($this->config['foo'])); $this->assertEquals('42', $this->config['bar']); @@ -49,7 +49,7 @@ class phpbb_config_db_test extends phpbb_database_test_case $this->config['foo'] = 'x'; // temporary set $this->assertEquals('x', $this->config['foo']); - $config2 = new phpbb_config_db($this->db, $this->cache, 'phpbb_config'); + $config2 = new \phpbb\config\db($this->db, $this->cache, 'phpbb_config'); $this->assertEquals('23', $config2['foo']); } @@ -59,7 +59,7 @@ class phpbb_config_db_test extends phpbb_database_test_case $this->assertEquals('17', $this->config['foo']); // re-read config and populate cache - $config2 = new phpbb_config_db($this->db, $this->cache, 'phpbb_config'); + $config2 = new \phpbb\config\db($this->db, $this->cache, 'phpbb_config'); $this->cache->checkVar($this, 'config', array('foo' => '17')); } @@ -68,7 +68,7 @@ class phpbb_config_db_test extends phpbb_database_test_case $this->config->set('bar', '17', false); // re-read config and populate cache - $config2 = new phpbb_config_db($this->db, $this->cache, 'phpbb_config'); + $config2 = new \phpbb\config\db($this->db, $this->cache, 'phpbb_config'); $this->cache->checkVar($this, 'config', array('foo' => '23')); } @@ -78,7 +78,7 @@ class phpbb_config_db_test extends phpbb_database_test_case $this->assertEquals('5', $this->config['foobar']); // re-read config and populate cache - $config2 = new phpbb_config_db($this->db, $this->cache, 'phpbb_config'); + $config2 = new \phpbb\config\db($this->db, $this->cache, 'phpbb_config'); $this->cache->checkVar($this, 'config', array('foo' => '23', 'foobar' => '5')); } @@ -88,7 +88,7 @@ class phpbb_config_db_test extends phpbb_database_test_case $this->assertEquals('5', $this->config['foobar']); // re-read config and populate cache - $config2 = new phpbb_config_db($this->db, $this->cache, 'phpbb_config'); + $config2 = new \phpbb\config\db($this->db, $this->cache, 'phpbb_config'); $this->cache->checkVar($this, 'config', array('foo' => '23')); } @@ -133,7 +133,7 @@ class phpbb_config_db_test extends phpbb_database_test_case // re-read config and populate cache $cache2 = new phpbb_mock_cache; - $config2 = new phpbb_config_db($this->db, $cache2, 'phpbb_config'); + $config2 = new \phpbb\config\db($this->db, $cache2, 'phpbb_config'); $cache2->checkVarUnset($this, 'foo'); $this->assertFalse(isset($config2['foo'])); } @@ -145,7 +145,7 @@ class phpbb_config_db_test extends phpbb_database_test_case $this->config->delete('bar'); $this->cache->checkVarUnset($this, 'bar'); $this->assertFalse(isset($this->config['bar'])); - + $this->config->set('bar', 'new bar', false); $this->assertEquals('new bar', $this->config['bar']); } @@ -157,7 +157,7 @@ class phpbb_config_db_test extends phpbb_database_test_case $this->config->delete('foo'); $this->cache->checkVarUnset($this, 'foo'); $this->assertFalse(isset($this->config['foo'])); - + $this->config->set('foo', 'new foo', true); $this->assertEquals('new foo', $this->config['foo']); } diff --git a/tests/config/db_text_test.php b/tests/config/db_text_test.php index 4818bba8c9..354c0efacf 100644 --- a/tests/config/db_text_test.php +++ b/tests/config/db_text_test.php @@ -22,7 +22,7 @@ class phpbb_config_db_text_test extends phpbb_database_test_case parent::setUp(); $this->db = $this->new_dbal(); - $this->config_text = new phpbb_config_db_text($this->db, 'phpbb_config_text'); + $this->config_text = new \phpbb\config\db_text($this->db, 'phpbb_config_text'); } public function test_get() diff --git a/tests/content_visibility/delete_post_test.php b/tests/content_visibility/delete_post_test.php index 6234aac9ad..b2bdcb3b49 100644 --- a/tests/content_visibility/delete_post_test.php +++ b/tests/content_visibility/delete_post_test.php @@ -267,21 +267,21 @@ class phpbb_content_visibility_delete_post_test extends phpbb_database_test_case $config['search_type'] = 'phpbb_mock_search'; $cache = new phpbb_mock_cache; $db = $this->new_dbal(); - set_config_count(null, null, null, new phpbb_config(array('num_posts' => 3, 'num_topics' => 1))); + set_config_count(null, null, null, new \phpbb\config\config(array('num_posts' => 3, 'num_topics' => 1))); // Create auth mock - $auth = $this->getMock('phpbb_auth'); + $auth = $this->getMock('\phpbb\auth\auth'); $auth->expects($this->any()) ->method('acl_get') ->with($this->stringContains('_'), $this->anything()) ->will($this->returnValueMap(array( array('m_approve', 1, true), ))); - $user = $this->getMock('phpbb_user'); + $user = $this->getMock('\phpbb\user'); $phpbb_container = new phpbb_mock_container_builder(); $phpbb_container->set('notification_manager', new phpbb_mock_notification_manager()); - $phpbb_container->set('content.visibility', new phpbb_content_visibility($auth, $db, $user, $phpbb_root_path, $phpEx, FORUMS_TABLE, POSTS_TABLE, TOPICS_TABLE, USERS_TABLE)); + $phpbb_container->set('content.visibility', new \phpbb\content_visibility($auth, $db, $user, $phpbb_root_path, $phpEx, FORUMS_TABLE, POSTS_TABLE, TOPICS_TABLE, USERS_TABLE)); delete_post($forum_id, $topic_id, $post_id, $data, $is_soft, $reason); diff --git a/tests/content_visibility/get_forums_visibility_sql_test.php b/tests/content_visibility/get_forums_visibility_sql_test.php index aa44fa4013..22f210c406 100644 --- a/tests/content_visibility/get_forums_visibility_sql_test.php +++ b/tests/content_visibility/get_forums_visibility_sql_test.php @@ -125,13 +125,13 @@ class phpbb_content_visibility_get_forums_visibility_sql_test extends phpbb_data $db = $this->new_dbal(); // Create auth mock - $auth = $this->getMock('phpbb_auth'); + $auth = $this->getMock('\phpbb\auth\auth'); $auth->expects($this->any()) ->method('acl_getf') ->with($this->stringContains('_'), $this->anything()) ->will($this->returnValueMap($permissions)); - $user = $this->getMock('phpbb_user'); - $content_visibility = new phpbb_content_visibility($auth, $db, $user, $phpbb_root_path, $phpEx, FORUMS_TABLE, POSTS_TABLE, TOPICS_TABLE, USERS_TABLE); + $user = $this->getMock('\phpbb\user'); + $content_visibility = new \phpbb\content_visibility($auth, $db, $user, $phpbb_root_path, $phpEx, FORUMS_TABLE, POSTS_TABLE, TOPICS_TABLE, USERS_TABLE); $result = $db->sql_query('SELECT ' . $mode . '_id FROM ' . $table . ' diff --git a/tests/content_visibility/get_global_visibility_sql_test.php b/tests/content_visibility/get_global_visibility_sql_test.php index 0f019ffa50..9488a8c0b3 100644 --- a/tests/content_visibility/get_global_visibility_sql_test.php +++ b/tests/content_visibility/get_global_visibility_sql_test.php @@ -125,13 +125,13 @@ class phpbb_content_visibility_get_global_visibility_sql_test extends phpbb_data $db = $this->new_dbal(); // Create auth mock - $auth = $this->getMock('phpbb_auth'); + $auth = $this->getMock('\phpbb\auth\auth'); $auth->expects($this->any()) ->method('acl_getf') ->with($this->stringContains('_'), $this->anything()) ->will($this->returnValueMap($permissions)); - $user = $this->getMock('phpbb_user'); - $content_visibility = new phpbb_content_visibility($auth, $db, $user, $phpbb_root_path, $phpEx, FORUMS_TABLE, POSTS_TABLE, TOPICS_TABLE, USERS_TABLE); + $user = $this->getMock('\phpbb\user'); + $content_visibility = new \phpbb\content_visibility($auth, $db, $user, $phpbb_root_path, $phpEx, FORUMS_TABLE, POSTS_TABLE, TOPICS_TABLE, USERS_TABLE); $result = $db->sql_query('SELECT ' . $mode . '_id FROM ' . $table . ' diff --git a/tests/content_visibility/get_visibility_sql_test.php b/tests/content_visibility/get_visibility_sql_test.php index cc6c10c649..111e735650 100644 --- a/tests/content_visibility/get_visibility_sql_test.php +++ b/tests/content_visibility/get_visibility_sql_test.php @@ -72,13 +72,13 @@ class phpbb_content_visibility_get_visibility_sql_test extends phpbb_database_te $db = $this->new_dbal(); // Create auth mock - $auth = $this->getMock('phpbb_auth'); + $auth = $this->getMock('\phpbb\auth\auth'); $auth->expects($this->any()) ->method('acl_get') ->with($this->stringContains('_'), $this->anything()) ->will($this->returnValueMap($permissions)); - $user = $this->getMock('phpbb_user'); - $content_visibility = new phpbb_content_visibility($auth, $db, $user, $phpbb_root_path, $phpEx, FORUMS_TABLE, POSTS_TABLE, TOPICS_TABLE, USERS_TABLE); + $user = $this->getMock('\phpbb\user'); + $content_visibility = new \phpbb\content_visibility($auth, $db, $user, $phpbb_root_path, $phpEx, FORUMS_TABLE, POSTS_TABLE, TOPICS_TABLE, USERS_TABLE); $result = $db->sql_query('SELECT ' . $mode . '_id FROM ' . $table . ' diff --git a/tests/content_visibility/set_post_visibility_test.php b/tests/content_visibility/set_post_visibility_test.php index 81abf56c75..f81b83ff86 100644 --- a/tests/content_visibility/set_post_visibility_test.php +++ b/tests/content_visibility/set_post_visibility_test.php @@ -119,9 +119,9 @@ class phpbb_content_visibility_set_post_visibility_test extends phpbb_database_t $cache = new phpbb_mock_cache; $db = $this->new_dbal(); - $auth = $this->getMock('phpbb_auth'); - $user = $this->getMock('phpbb_user'); - $content_visibility = new phpbb_content_visibility($auth, $db, $user, $phpbb_root_path, $phpEx, FORUMS_TABLE, POSTS_TABLE, TOPICS_TABLE, USERS_TABLE); + $auth = $this->getMock('\phpbb\auth\auth'); + $user = $this->getMock('\phpbb\user'); + $content_visibility = new \phpbb\content_visibility($auth, $db, $user, $phpbb_root_path, $phpEx, FORUMS_TABLE, POSTS_TABLE, TOPICS_TABLE, USERS_TABLE); $content_visibility->set_post_visibility($visibility, $post_id, $topic_id, $forum_id, $user_id, $time, $reason, $is_starter, $is_latest); diff --git a/tests/content_visibility/set_topic_visibility_test.php b/tests/content_visibility/set_topic_visibility_test.php index 6b5d884a2b..92b1253a15 100644 --- a/tests/content_visibility/set_topic_visibility_test.php +++ b/tests/content_visibility/set_topic_visibility_test.php @@ -83,9 +83,9 @@ class phpbb_content_visibility_set_topic_visibility_test extends phpbb_database_ $cache = new phpbb_mock_cache; $db = $this->new_dbal(); - $auth = $this->getMock('phpbb_auth'); - $user = $this->getMock('phpbb_user'); - $content_visibility = new phpbb_content_visibility($auth, $db, $user, $phpbb_root_path, $phpEx, FORUMS_TABLE, POSTS_TABLE, TOPICS_TABLE, USERS_TABLE); + $auth = $this->getMock('\phpbb\auth\auth'); + $user = $this->getMock('\phpbb\user'); + $content_visibility = new \phpbb\content_visibility($auth, $db, $user, $phpbb_root_path, $phpEx, FORUMS_TABLE, POSTS_TABLE, TOPICS_TABLE, USERS_TABLE); $content_visibility->set_topic_visibility($visibility, $topic_id, $forum_id, $user_id, $time, $reason, $force_update_all); diff --git a/tests/controller/config/services.yml b/tests/controller/config/services.yml index f1bd047489..e4412af3d7 100644 --- a/tests/controller/config/services.yml +++ b/tests/controller/config/services.yml @@ -1,3 +1,3 @@ services: core_foo.controller: - class: phpbb_controller_foo + class: phpbb\controller\foo diff --git a/tests/controller/controller_test.php b/tests/controller/controller_test.php index dfc4f80469..10fced05a2 100644 --- a/tests/controller/controller_test.php +++ b/tests/controller/controller_test.php @@ -31,7 +31,7 @@ class phpbb_controller_controller_test extends phpbb_test_case public function test_provider() { - $provider = new phpbb_controller_provider; + $provider = new \phpbb\controller\provider; $routes = $provider ->import_paths_from_finder($this->extension_manager->get_finder()) ->find('./tests/controller/'); @@ -53,24 +53,24 @@ class phpbb_controller_controller_test extends phpbb_test_case // Autoloading classes within the tests folder does not work // so I'll include them manually. - if (!class_exists('phpbb_ext_foo_controller')) + if (!class_exists('foo\\controller')) { include(__DIR__.'/ext/foo/controller.php'); } - if (!class_exists('phpbb_controller_foo')) + if (!class_exists('phpbb\\controller\\foo')) { include(__DIR__.'/phpbb/controller/foo.php'); } - $resolver = new phpbb_controller_resolver(new phpbb_user, $container); + $resolver = new \phpbb\controller\resolver(new \phpbb\user, $container); $symfony_request = new Request(); $symfony_request->attributes->set('_controller', 'foo.controller:handle'); - $this->assertEquals($resolver->getController($symfony_request), array(new phpbb_ext_foo_controller, 'handle')); + $this->assertEquals($resolver->getController($symfony_request), array(new foo\controller, 'handle')); $symfony_request = new Request(); $symfony_request->attributes->set('_controller', 'core_foo.controller:bar'); - $this->assertEquals($resolver->getController($symfony_request), array(new phpbb_controller_foo, 'bar')); + $this->assertEquals($resolver->getController($symfony_request), array(new phpbb\controller\foo, 'bar')); } } diff --git a/tests/controller/ext/foo/config/services.yml b/tests/controller/ext/foo/config/services.yml index ce0e18c610..9ed67d5bc2 100644 --- a/tests/controller/ext/foo/config/services.yml +++ b/tests/controller/ext/foo/config/services.yml @@ -1,3 +1,3 @@ services: foo.controller: - class: phpbb_ext_foo_controller + class: foo\controller diff --git a/tests/controller/ext/foo/controller.php b/tests/controller/ext/foo/controller.php index cfc5c20622..ce2233b3c9 100644 --- a/tests/controller/ext/foo/controller.php +++ b/tests/controller/ext/foo/controller.php @@ -1,8 +1,10 @@ <?php +namespace foo; + use Symfony\Component\HttpFoundation\Response; -class phpbb_ext_foo_controller +class controller { /** * Handle method diff --git a/tests/controller/helper_url_test.php b/tests/controller/helper_url_test.php index 6686b77e8f..4ea177074f 100644 --- a/tests/controller/helper_url_test.php +++ b/tests/controller/helper_url_test.php @@ -12,50 +12,106 @@ require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php'; class phpbb_controller_helper_url_test extends phpbb_test_case { - public function helper_url_data() + public function helper_url_data_no_rewrite() { return array( - array('foo/bar?t=1&f=2', false, true, false, 'app.php?t=1&f=2&controller=foo/bar', 'parameters in url-argument'), - array('foo/bar', 't=1&f=2', true, false, 'app.php?controller=foo/bar&t=1&f=2', 'parameters in params-argument using amp'), - array('foo/bar', 't=1&f=2', false, false, 'app.php?controller=foo/bar&t=1&f=2', 'parameters in params-argument using &'), - array('foo/bar', array('t' => 1, 'f' => 2), true, false, 'app.php?controller=foo/bar&t=1&f=2', 'parameters in params-argument as array'), + array('foo/bar?t=1&f=2', false, true, false, 'app.php/foo/bar?t=1&f=2', 'parameters in url-argument'), + array('foo/bar', 't=1&f=2', true, false, 'app.php/foo/bar?t=1&f=2', 'parameters in params-argument using amp'), + array('foo/bar', 't=1&f=2', false, false, 'app.php/foo/bar?t=1&f=2', 'parameters in params-argument using &'), + array('foo/bar', array('t' => 1, 'f' => 2), true, false, 'app.php/foo/bar?t=1&f=2', 'parameters in params-argument as array'), // Custom sid parameter - array('foo/bar', 't=1&f=2', true, 'custom-sid', 'app.php?controller=foo/bar&t=1&f=2&sid=custom-sid', 'using session_id'), + array('foo/bar', 't=1&f=2', true, 'custom-sid', 'app.php/foo/bar?t=1&f=2&sid=custom-sid', 'using session_id'), // Testing anchors - array('foo/bar?t=1&f=2#anchor', false, true, false, 'app.php?t=1&f=2&controller=foo/bar#anchor', 'anchor in url-argument'), - array('foo/bar', 't=1&f=2#anchor', true, false, 'app.php?controller=foo/bar&t=1&f=2#anchor', 'anchor in params-argument'), - array('foo/bar', array('t' => 1, 'f' => 2, '#' => 'anchor'), true, false, 'app.php?controller=foo/bar&t=1&f=2#anchor', 'anchor in params-argument (array)'), + array('foo/bar?t=1&f=2#anchor', false, true, false, 'app.php/foo/bar?t=1&f=2#anchor', 'anchor in url-argument'), + array('foo/bar', 't=1&f=2#anchor', true, false, 'app.php/foo/bar?t=1&f=2#anchor', 'anchor in params-argument'), + array('foo/bar', array('t' => 1, 'f' => 2, '#' => 'anchor'), true, false, 'app.php/foo/bar?t=1&f=2#anchor', 'anchor in params-argument (array)'), // Anchors and custom sid - array('foo/bar?t=1&f=2#anchor', false, true, 'custom-sid', 'app.php?t=1&f=2&controller=foo/bar&sid=custom-sid#anchor', 'anchor in url-argument using session_id'), - array('foo/bar', 't=1&f=2#anchor', true, 'custom-sid', 'app.php?controller=foo/bar&t=1&f=2&sid=custom-sid#anchor', 'anchor in params-argument using session_id'), - array('foo/bar', array('t' => 1, 'f' => 2, '#' => 'anchor'), true, 'custom-sid', 'app.php?controller=foo/bar&t=1&f=2&sid=custom-sid#anchor', 'anchor in params-argument (array) using session_id'), + array('foo/bar?t=1&f=2#anchor', false, true, 'custom-sid', 'app.php/foo/bar?t=1&f=2&sid=custom-sid#anchor', 'anchor in url-argument using session_id'), + array('foo/bar', 't=1&f=2#anchor', true, 'custom-sid', 'app.php/foo/bar?t=1&f=2&sid=custom-sid#anchor', 'anchor in params-argument using session_id'), + array('foo/bar', array('t' => 1, 'f' => 2, '#' => 'anchor'), true, 'custom-sid', 'app.php/foo/bar?t=1&f=2&sid=custom-sid#anchor', 'anchor in params-argument (array) using session_id'), // Empty parameters should not append the & - array('foo/bar', false, true, false, 'app.php?controller=foo/bar', 'no params using bool false'), - array('foo/bar', '', true, false, 'app.php?controller=foo/bar', 'no params using empty string'), - array('foo/bar', array(), true, false, 'app.php?controller=foo/bar', 'no params using empty array'), + array('foo/bar', false, true, false, 'app.php/foo/bar', 'no params using bool false'), + array('foo/bar', '', true, false, 'app.php/foo/bar', 'no params using empty string'), + array('foo/bar', array(), true, false, 'app.php/foo/bar', 'no params using empty array'), ); } /** - * @dataProvider helper_url_data + * @dataProvider helper_url_data_no_rewrite() */ - public function test_helper_url($route, $params, $is_amp, $session_id, $expected, $description) + public function test_helper_url_no_rewrite($route, $params, $is_amp, $session_id, $expected, $description) { global $phpbb_dispatcher, $phpbb_root_path, $phpEx; $phpbb_dispatcher = new phpbb_mock_event_dispatcher; - $this->style_resource_locator = new phpbb_style_resource_locator(); - $this->user = $this->getMock('phpbb_user'); - $this->template = new phpbb_template_twig($phpbb_root_path, $phpEx, $config, $this->user, new phpbb_template_context()); - $this->style_resource_locator = new phpbb_style_resource_locator(); - $this->style_provider = new phpbb_style_path_provider(); - $this->style = new phpbb_style($phpbb_root_path, $phpEx, new phpbb_config(array()), $this->user, $this->style_resource_locator, $this->style_provider, $this->template); - - $helper = new phpbb_controller_helper($this->template, $this->user, '', 'php'); + $this->user = $this->getMock('\phpbb\user'); + $phpbb_filesystem = new \phpbb\filesystem( + new \phpbb\symfony_request( + new phpbb_mock_request() + ), + $phpbb_root_path, + $phpEx + ); + $this->template = new phpbb\template\twig\twig($phpbb_filesystem, $config, $this->user, new \phpbb\template\context()); + + // We don't use mod_rewrite in these tests + $config = new \phpbb\config\config(array('enable_mod_rewrite' => '0')); + $helper = new \phpbb\controller\helper($this->template, $this->user, $config, '', 'php'); + $this->assertEquals($helper->url($route, $params, $is_amp, $session_id), $expected); + } + + public function helper_url_data_with_rewrite() + { + return array( + array('foo/bar?t=1&f=2', false, true, false, 'foo/bar?t=1&f=2', 'parameters in url-argument'), + array('foo/bar', 't=1&f=2', true, false, 'foo/bar?t=1&f=2', 'parameters in params-argument using amp'), + array('foo/bar', 't=1&f=2', false, false, 'foo/bar?t=1&f=2', 'parameters in params-argument using &'), + array('foo/bar', array('t' => 1, 'f' => 2), true, false, 'foo/bar?t=1&f=2', 'parameters in params-argument as array'), + + // Custom sid parameter + array('foo/bar', 't=1&f=2', true, 'custom-sid', 'foo/bar?t=1&f=2&sid=custom-sid', 'using session_id'), + + // Testing anchors + array('foo/bar?t=1&f=2#anchor', false, true, false, 'foo/bar?t=1&f=2#anchor', 'anchor in url-argument'), + array('foo/bar', 't=1&f=2#anchor', true, false, 'foo/bar?t=1&f=2#anchor', 'anchor in params-argument'), + array('foo/bar', array('t' => 1, 'f' => 2, '#' => 'anchor'), true, false, 'foo/bar?t=1&f=2#anchor', 'anchor in params-argument (array)'), + + // Anchors and custom sid + array('foo/bar?t=1&f=2#anchor', false, true, 'custom-sid', 'foo/bar?t=1&f=2&sid=custom-sid#anchor', 'anchor in url-argument using session_id'), + array('foo/bar', 't=1&f=2#anchor', true, 'custom-sid', 'foo/bar?t=1&f=2&sid=custom-sid#anchor', 'anchor in params-argument using session_id'), + array('foo/bar', array('t' => 1, 'f' => 2, '#' => 'anchor'), true, 'custom-sid', 'foo/bar?t=1&f=2&sid=custom-sid#anchor', 'anchor in params-argument (array) using session_id'), + + // Empty parameters should not append the & + array('foo/bar', false, true, false, 'foo/bar', 'no params using bool false'), + array('foo/bar', '', true, false, 'foo/bar', 'no params using empty string'), + array('foo/bar', array(), true, false, 'foo/bar', 'no params using empty array'), + ); + } + + /** + * @dataProvider helper_url_data_with_rewrite() + */ + public function test_helper_url_with_rewrite($route, $params, $is_amp, $session_id, $expected, $description) + { + global $phpbb_dispatcher, $phpbb_root_path, $phpEx; + + $phpbb_dispatcher = new phpbb_mock_event_dispatcher; + $this->user = $this->getMock('\phpbb\user'); + $phpbb_filesystem = new \phpbb\filesystem( + new \phpbb\symfony_request( + new phpbb_mock_request() + ), + $phpbb_root_path, + $phpEx + ); + $this->template = new \phpbb\template\twig\twig($phpbb_filesystem, $config, $this->user, new \phpbb\template\context()); + + $config = new \phpbb\config\config(array('enable_mod_rewrite' => '1')); + $helper = new \phpbb\controller\helper($this->template, $this->user, $config, '', 'php'); $this->assertEquals($helper->url($route, $params, $is_amp, $session_id), $expected); } } diff --git a/tests/controller/phpbb/controller/foo.php b/tests/controller/phpbb/controller/foo.php index 04576e16c4..98669f428f 100644 --- a/tests/controller/phpbb/controller/foo.php +++ b/tests/controller/phpbb/controller/foo.php @@ -1,8 +1,10 @@ <?php +namespace phpbb\controller; + use Symfony\Component\HttpFoundation\Response; -class phpbb_controller_foo +class foo { /** * Bar method diff --git a/tests/cron/ext/testext/cron/dummy_task.php b/tests/cron/ext/testext/cron/dummy_task.php index 3e81db1895..8cdb6b09d5 100644 --- a/tests/cron/ext/testext/cron/dummy_task.php +++ b/tests/cron/ext/testext/cron/dummy_task.php @@ -7,7 +7,7 @@ * */ -class phpbb_ext_testext_cron_dummy_task extends phpbb_cron_task_base +class phpbb_ext_testext_cron_dummy_task extends \phpbb\cron\task\base { static public $was_run = 0; diff --git a/tests/cron/includes/cron/task/core/dummy_task.php b/tests/cron/includes/cron/task/core/dummy_task.php index c94455603f..c34684701b 100644 --- a/tests/cron/includes/cron/task/core/dummy_task.php +++ b/tests/cron/includes/cron/task/core/dummy_task.php @@ -7,7 +7,7 @@ * */ -class phpbb_cron_task_core_dummy_task extends phpbb_cron_task_base +class phpbb_cron_task_core_dummy_task extends \phpbb\cron\task\base { static public $was_run = 0; diff --git a/tests/cron/includes/cron/task/core/second_dummy_task.php b/tests/cron/includes/cron/task/core/second_dummy_task.php index 77ef6f70ed..1b212ab05d 100644 --- a/tests/cron/includes/cron/task/core/second_dummy_task.php +++ b/tests/cron/includes/cron/task/core/second_dummy_task.php @@ -7,7 +7,7 @@ * */ -class phpbb_cron_task_core_second_dummy_task extends phpbb_cron_task_base +class phpbb_cron_task_core_second_dummy_task extends \phpbb\cron\task\base { static public $was_run = 0; diff --git a/tests/cron/manager_test.php b/tests/cron/manager_test.php index 3c541be2a6..713f44c1e2 100644 --- a/tests/cron/manager_test.php +++ b/tests/cron/manager_test.php @@ -29,7 +29,7 @@ class phpbb_cron_manager_test extends PHPUnit_Framework_TestCase 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->assertInstanceOf('\phpbb\cron\task\wrapper', $task); $this->assertEquals($this->task_name, $task->get_name()); } @@ -42,7 +42,7 @@ class phpbb_cron_manager_test extends PHPUnit_Framework_TestCase public function test_manager_finds_one_ready_task() { $task = $this->manager->find_one_ready_task(); - $this->assertInstanceOf('phpbb_cron_task_wrapper', $task); + $this->assertInstanceOf('\phpbb\cron\task\wrapper', $task); } public function test_manager_finds_only_ready_tasks() @@ -71,6 +71,6 @@ class phpbb_cron_manager_test extends PHPUnit_Framework_TestCase { global $phpbb_root_path, $phpEx; - return new phpbb_cron_manager($tasks, $phpbb_root_path, $phpEx); + return new \phpbb\cron\manager($tasks, $phpbb_root_path, $phpEx); } } diff --git a/tests/cron/tasks/simple_not_runnable.php b/tests/cron/tasks/simple_not_runnable.php index 56d484eacd..4951b5b4b9 100644 --- a/tests/cron/tasks/simple_not_runnable.php +++ b/tests/cron/tasks/simple_not_runnable.php @@ -1,6 +1,6 @@ <?php -class phpbb_cron_task_core_simple_not_runnable extends phpbb_cron_task_base +class phpbb_cron_task_core_simple_not_runnable extends \phpbb\cron\task\base { public function get_name() { diff --git a/tests/cron/tasks/simple_ready.php b/tests/cron/tasks/simple_ready.php index 8aa0507406..245d9ba738 100644 --- a/tests/cron/tasks/simple_ready.php +++ b/tests/cron/tasks/simple_ready.php @@ -1,6 +1,6 @@ <?php -class phpbb_cron_task_core_simple_ready extends phpbb_cron_task_base +class phpbb_cron_task_core_simple_ready extends \phpbb\cron\task\base { public function get_name() { diff --git a/tests/cron/tasks/simple_should_not_run.php b/tests/cron/tasks/simple_should_not_run.php index 58f6df2616..7bd9df31b6 100644 --- a/tests/cron/tasks/simple_should_not_run.php +++ b/tests/cron/tasks/simple_should_not_run.php @@ -1,6 +1,6 @@ <?php -class phpbb_cron_task_core_simple_should_not_run extends phpbb_cron_task_base +class phpbb_cron_task_core_simple_should_not_run extends \phpbb\cron\task\base { public function get_name() { diff --git a/tests/datetime/from_format_test.php b/tests/datetime/from_format_test.php index 2d97672878..34f7f9ae44 100644 --- a/tests/datetime/from_format_test.php +++ b/tests/datetime/from_format_test.php @@ -35,7 +35,7 @@ class phpbb_datetime_from_format_test extends phpbb_test_case { global $user; - $user = new phpbb_user(); + $user = new \phpbb\user(); $user->timezone = new DateTimeZone($timezone); $user->lang['datetime'] = array( 'TODAY' => 'Today', diff --git a/tests/dbal/auto_increment_test.php b/tests/dbal/auto_increment_test.php index 077bfad933..2196292e83 100644 --- a/tests/dbal/auto_increment_test.php +++ b/tests/dbal/auto_increment_test.php @@ -26,7 +26,7 @@ class phpbb_dbal_auto_increment_test extends phpbb_database_test_case parent::setUp(); $this->db = $this->new_dbal(); - $this->tools = new phpbb_db_tools($this->db); + $this->tools = new \phpbb\db\tools($this->db); $this->table_data = array( 'COLUMNS' => array( diff --git a/tests/dbal/db_tools_test.php b/tests/dbal/db_tools_test.php index 7bdbc696e7..e25335165a 100644 --- a/tests/dbal/db_tools_test.php +++ b/tests/dbal/db_tools_test.php @@ -26,7 +26,7 @@ class phpbb_dbal_db_tools_test extends phpbb_database_test_case parent::setUp(); $this->db = $this->new_dbal(); - $this->tools = new phpbb_db_tools($this->db); + $this->tools = new \phpbb\db\tools($this->db); $this->table_data = array( 'COLUMNS' => array( @@ -254,7 +254,7 @@ class phpbb_dbal_db_tools_test extends phpbb_database_test_case public function test_peform_schema_changes_drop_tables() { - $db_tools = $this->getMock('phpbb_db_tools', array( + $db_tools = $this->getMock('\phpbb\db\tools', array( 'sql_table_exists', 'sql_table_drop', ), array(&$this->db)); @@ -280,7 +280,7 @@ class phpbb_dbal_db_tools_test extends phpbb_database_test_case public function test_peform_schema_changes_drop_columns() { - $db_tools = $this->getMock('phpbb_db_tools', array( + $db_tools = $this->getMock('\phpbb\db\tools', array( 'sql_column_exists', 'sql_column_remove', ), array(&$this->db)); diff --git a/tests/dbal/migration/dummy.php b/tests/dbal/migration/dummy.php index 0ac6e733a1..041c529855 100644 --- a/tests/dbal/migration/dummy.php +++ b/tests/dbal/migration/dummy.php @@ -7,7 +7,7 @@ * */ -class phpbb_dbal_migration_dummy extends phpbb_db_migration +class phpbb_dbal_migration_dummy extends \phpbb\db\migration\migration { static public function depends_on() { diff --git a/tests/dbal/migration/fail.php b/tests/dbal/migration/fail.php index f88d8169f5..d90972720d 100644 --- a/tests/dbal/migration/fail.php +++ b/tests/dbal/migration/fail.php @@ -7,7 +7,7 @@ * */ -class phpbb_dbal_migration_fail extends phpbb_db_migration +class phpbb_dbal_migration_fail extends \phpbb\db\migration\migration { function update_schema() { diff --git a/tests/dbal/migration/if.php b/tests/dbal/migration/if.php index 83fe21bd21..bbbda60ea3 100644 --- a/tests/dbal/migration/if.php +++ b/tests/dbal/migration/if.php @@ -7,7 +7,7 @@ * */ -class phpbb_dbal_migration_if extends phpbb_db_migration +class phpbb_dbal_migration_if extends \phpbb\db\migration\migration { function update_schema() { diff --git a/tests/dbal/migration/installed.php b/tests/dbal/migration/installed.php index 01829f7a99..4b86896d9c 100644 --- a/tests/dbal/migration/installed.php +++ b/tests/dbal/migration/installed.php @@ -7,7 +7,7 @@ * */ -class phpbb_dbal_migration_installed extends phpbb_db_migration +class phpbb_dbal_migration_installed extends \phpbb\db\migration\migration { function effectively_installed() { diff --git a/tests/dbal/migration/recall.php b/tests/dbal/migration/recall.php index 6c2f04bf08..041d12ad27 100644 --- a/tests/dbal/migration/recall.php +++ b/tests/dbal/migration/recall.php @@ -7,7 +7,7 @@ * */ -class phpbb_dbal_migration_recall extends phpbb_db_migration +class phpbb_dbal_migration_recall extends \phpbb\db\migration\migration { function update_schema() { diff --git a/tests/dbal/migration/revert.php b/tests/dbal/migration/revert.php index ac01987cd4..1882b20492 100644 --- a/tests/dbal/migration/revert.php +++ b/tests/dbal/migration/revert.php @@ -7,7 +7,7 @@ * */ -class phpbb_dbal_migration_revert extends phpbb_db_migration +class phpbb_dbal_migration_revert extends \phpbb\db\migration\migration { function update_schema() { diff --git a/tests/dbal/migration/revert_with_dependency.php b/tests/dbal/migration/revert_with_dependency.php index ca2c070e8c..0b09fb784d 100644 --- a/tests/dbal/migration/revert_with_dependency.php +++ b/tests/dbal/migration/revert_with_dependency.php @@ -7,7 +7,7 @@ * */ -class phpbb_dbal_migration_revert_with_dependency extends phpbb_db_migration +class phpbb_dbal_migration_revert_with_dependency extends \phpbb\db\migration\migration { static public function depends_on() { diff --git a/tests/dbal/migration/unfulfillable.php b/tests/dbal/migration/unfulfillable.php index 6d375e6880..a1cdef9a23 100644 --- a/tests/dbal/migration/unfulfillable.php +++ b/tests/dbal/migration/unfulfillable.php @@ -7,7 +7,7 @@ * */ -class phpbb_dbal_migration_unfulfillable extends phpbb_db_migration +class phpbb_dbal_migration_unfulfillable extends \phpbb\db\migration\migration { static public function depends_on() { diff --git a/tests/dbal/migrator_test.php b/tests/dbal/migrator_test.php index 9e55e4dd35..ef5d167fc2 100644 --- a/tests/dbal/migrator_test.php +++ b/tests/dbal/migrator_test.php @@ -33,15 +33,15 @@ class phpbb_dbal_migrator_test extends phpbb_database_test_case parent::setUp(); $this->db = $this->new_dbal(); - $this->db_tools = new phpbb_db_tools($this->db); + $this->db_tools = new \phpbb\db\tools($this->db); - $this->config = new phpbb_config_db($this->db, new phpbb_mock_cache, 'phpbb_config'); + $this->config = new \phpbb\config\db($this->db, new phpbb_mock_cache, 'phpbb_config'); $tools = array( - new phpbb_db_migration_tool_config($this->config), + new \phpbb\db\migration\tool\config($this->config), ); - $this->migrator = new phpbb_db_migrator( + $this->migrator = new \phpbb\db\migrator( $this->config, $this->db, $this->db_tools, @@ -55,11 +55,17 @@ class phpbb_dbal_migrator_test extends phpbb_database_test_case $container = new phpbb_mock_container_builder(); $container->set('migrator', $migrator); - $this->extension_manager = new phpbb_extension_manager( + $this->extension_manager = new \phpbb\extension\manager( $container, $this->db, $this->config, - new phpbb_filesystem(), + new phpbb\filesystem( + new phpbb\symfony_request( + new phpbb_mock_request() + ), + dirname(__FILE__) . '/../../phpBB/', + 'php' + ), 'phpbb_ext', dirname(__FILE__) . '/../../phpBB/', 'php', @@ -232,7 +238,7 @@ class phpbb_dbal_migrator_test extends phpbb_database_test_case $this->migrator->update(); } } - catch (phpbb_db_migration_exception $e) {} + catch (\phpbb\db\migration\exception $e) {} // Failure should have caused an automatic roll-back, so this should not exist. $this->assertFalse(isset($this->config['foobar3'])); diff --git a/tests/dbal/migrator_tool_config_test.php b/tests/dbal/migrator_tool_config_test.php index b82d1ef48d..a8d8966839 100644 --- a/tests/dbal/migrator_tool_config_test.php +++ b/tests/dbal/migrator_tool_config_test.php @@ -11,9 +11,9 @@ class phpbb_dbal_migrator_tool_config_test extends phpbb_test_case { public function setup() { - $this->config = new phpbb_config(array()); + $this->config = new \phpbb\config\config(array()); - $this->tool = new phpbb_db_migration_tool_config($this->config); + $this->tool = new \phpbb\db\migration\tool\config($this->config); parent::setup(); } diff --git a/tests/dbal/migrator_tool_module_test.php b/tests/dbal/migrator_tool_module_test.php index 828fb76c65..3c23891348 100644 --- a/tests/dbal/migrator_tool_module_test.php +++ b/tests/dbal/migrator_tool_module_test.php @@ -27,15 +27,15 @@ class phpbb_dbal_migrator_tool_module_test extends phpbb_database_test_case $skip_add_log = true; $db = $this->db = $this->new_dbal(); - $this->cache = new phpbb_cache_service(new phpbb_cache_driver_null(), new phpbb_config(array()), $this->db, $phpbb_root_path, $phpEx); - $user = $this->user = new phpbb_user(); + $this->cache = new \phpbb\cache\service(new \phpbb\cache\driver\null(), new \phpbb\config\config(array()), $this->db, $phpbb_root_path, $phpEx); + $user = $this->user = new \phpbb\user(); $cache = new phpbb_mock_cache; $phpbb_dispatcher = new phpbb_mock_event_dispatcher(); - $auth = $this->getMock('phpbb_auth'); - $phpbb_log = new phpbb_log($db, $user, $auth, $phpbb_dispatcher, $phpbb_root_path, 'adm/', $phpEx, LOG_TABLE); + $auth = $this->getMock('\phpbb\auth\auth'); + $phpbb_log = new \phpbb\log\log($db, $user, $auth, $phpbb_dispatcher, $phpbb_root_path, 'adm/', $phpEx, LOG_TABLE); - $this->tool = new phpbb_db_migration_tool_module($this->db, $this->cache, $this->user, $phpbb_root_path, $phpEx, 'phpbb_modules'); + $this->tool = new \phpbb\db\migration\tool\module($this->db, $this->cache, $this->user, $phpbb_root_path, $phpEx, 'phpbb_modules'); } public function exists_data() diff --git a/tests/dbal/migrator_tool_permission_test.php b/tests/dbal/migrator_tool_permission_test.php index 79d9db66da..1090b4726a 100644 --- a/tests/dbal/migrator_tool_permission_test.php +++ b/tests/dbal/migrator_tool_permission_test.php @@ -24,10 +24,10 @@ class phpbb_dbal_migrator_tool_permission_test extends phpbb_database_test_case parent::setup(); $db = $this->db = $this->new_dbal(); - $cache = $this->cache = new phpbb_cache_service(new phpbb_cache_driver_null(), new phpbb_config(array()), $this->db, $phpbb_root_path, $phpEx); - $this->auth = new phpbb_auth(); + $cache = $this->cache = new \phpbb\cache\service(new \phpbb\cache\driver\null(), new \phpbb\config\config(array()), $this->db, $phpbb_root_path, $phpEx); + $this->auth = new \phpbb\auth\auth(); - $this->tool = new phpbb_db_migration_tool_permission($this->db, $this->cache, $this->auth, $phpbb_root_path, $phpEx); + $this->tool = new \phpbb\db\migration\tool\permission($this->db, $this->cache, $this->auth, $phpbb_root_path, $phpEx); } public function exists_data() diff --git a/tests/dbal/sql_insert_buffer_test.php b/tests/dbal/sql_insert_buffer_test.php index 45339a6b50..a70eea4f7e 100644 --- a/tests/dbal/sql_insert_buffer_test.php +++ b/tests/dbal/sql_insert_buffer_test.php @@ -17,7 +17,7 @@ class phpbb_dbal_sql_insert_buffer_test extends phpbb_database_test_case parent::setUp(); $this->db = $this->new_dbal(); - $this->buffer = new phpbb_db_sql_insert_buffer($this->db, 'phpbb_config', 2); + $this->buffer = new \phpbb\db\sql_insert_buffer($this->db, 'phpbb_config', 2); $this->assert_config_count(2); } diff --git a/tests/dbal/write_test.php b/tests/dbal/write_test.php index 987161a831..c069d9a796 100644 --- a/tests/dbal/write_test.php +++ b/tests/dbal/write_test.php @@ -64,7 +64,7 @@ class phpbb_dbal_write_test extends phpbb_database_test_case FROM phpbb_config'; $result = $db->sql_query($sql); $rows = $db->sql_fetchrowset($result); - + $this->assertEquals(1, sizeof($rows)); $this->assertEquals('config2', $rows[0]['config_name']); diff --git a/tests/di/create_container_test.php b/tests/di/create_container_test.php index c570f19ebd..a3a1ad3597 100644 --- a/tests/di/create_container_test.php +++ b/tests/di/create_container_test.php @@ -7,66 +7,72 @@ * */ -require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php'; -require_once dirname(__FILE__) . '/../../phpBB/includes/functions_container.php'; - -class phpbb_di_container_test extends phpbb_test_case +namespace { - public function test_phpbb_create_container() - { - $phpbb_root_path = __DIR__ . '/../../phpBB/'; - $extensions = array( - new phpbb_di_extension_config(__DIR__ . '/fixtures/config.php'), - new phpbb_di_extension_core($phpbb_root_path . 'config'), - ); - $container = phpbb_create_container($extensions, $phpbb_root_path, 'php'); + require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php'; + require_once dirname(__FILE__) . '/../../phpBB/includes/functions_container.php'; + + class phpbb_di_container_test extends phpbb_test_case + { + public function test_phpbb_create_container() + { + $phpbb_root_path = __DIR__ . '/../../phpBB/'; + $extensions = array( + new \phpbb\di\extension\config(__DIR__ . '/fixtures/config.php'), + new \phpbb\di\extension\core($phpbb_root_path . 'config'), + ); + $container = phpbb_create_container($extensions, $phpbb_root_path, 'php'); - $this->assertInstanceOf('Symfony\Component\DependencyInjection\ContainerBuilder', $container); - } + $this->assertInstanceOf('Symfony\Component\DependencyInjection\ContainerBuilder', $container); + } - public function test_phpbb_create_install_container() - { - $phpbb_root_path = __DIR__ . '/../../phpBB/'; - $extensions = array( - new phpbb_di_extension_config(__DIR__ . '/fixtures/config.php'), - new phpbb_di_extension_core($phpbb_root_path . 'config'), - ); - $container = phpbb_create_install_container($phpbb_root_path, 'php'); + public function test_phpbb_create_install_container() + { + $phpbb_root_path = __DIR__ . '/../../phpBB/'; + $extensions = array( + new \phpbb\di\extension\config(__DIR__ . '/fixtures/config.php'), + new \phpbb\di\extension\core($phpbb_root_path . 'config'), + ); + $container = phpbb_create_install_container($phpbb_root_path, 'php'); - $this->assertInstanceOf('Symfony\Component\DependencyInjection\ContainerBuilder', $container); - $this->assertTrue($container->isFrozen()); - } + $this->assertInstanceOf('Symfony\Component\DependencyInjection\ContainerBuilder', $container); + $this->assertTrue($container->isFrozen()); + } - public function test_phpbb_create_compiled_container() - { - $phpbb_root_path = __DIR__ . '/../../phpBB/'; - $config_file = __DIR__ . '/fixtures/config.php'; - $extensions = array( - new phpbb_di_extension_config(__DIR__ . '/fixtures/config.php'), - new phpbb_di_extension_core($phpbb_root_path . 'config'), - ); - $container = phpbb_create_compiled_container($config_file, $extensions, array(), $phpbb_root_path, 'php'); + public function test_phpbb_create_compiled_container() + { + $phpbb_root_path = __DIR__ . '/../../phpBB/'; + $config_file = __DIR__ . '/fixtures/config.php'; + $extensions = array( + new \phpbb\di\extension\config(__DIR__ . '/fixtures/config.php'), + new \phpbb\di\extension\core($phpbb_root_path . 'config'), + ); + $container = phpbb_create_compiled_container($config_file, $extensions, array(), $phpbb_root_path, 'php'); - $this->assertInstanceOf('Symfony\Component\DependencyInjection\ContainerBuilder', $container); - $this->assertTrue($container->isFrozen()); - } + $this->assertInstanceOf('Symfony\Component\DependencyInjection\ContainerBuilder', $container); + $this->assertTrue($container->isFrozen()); + } + } } -class phpbb_db_driver_container_mock extends phpbb_db_driver +namespace phpbb\db\driver { - public function sql_connect() - { - } + class container_mock extends \phpbb\db\driver\driver + { + public function sql_connect() + { + } - public function sql_query() - { - } + public function sql_query() + { + } - public function sql_fetchrow() - { - } + public function sql_fetchrow() + { + } - public function sql_freeresult() - { - } + public function sql_freeresult() + { + } + } } diff --git a/tests/di/fixtures/config.php b/tests/di/fixtures/config.php index 5033d2dc9f..04e20f63d8 100644 --- a/tests/di/fixtures/config.php +++ b/tests/di/fixtures/config.php @@ -8,4 +8,4 @@ $dbname = 'phpbb'; $dbuser = 'root'; $dbpasswd = ''; $table_prefix = 'phpbb_'; -$acm_type = 'phpbb_cache_driver_null'; +$acm_type = '\phpbb\cache\driver\null'; diff --git a/tests/error_collector_test.php b/tests/error_collector_test.php index fceb8aa3d8..0804c64f6f 100644 --- a/tests/error_collector_test.php +++ b/tests/error_collector_test.php @@ -13,7 +13,7 @@ class phpbb_error_collector_test extends phpbb_test_case { public function test_collection() { - $collector = new phpbb_error_collector; + $collector = new \phpbb\error_collector; $collector->install(); // Cause a warning diff --git a/tests/event/dispatcher_test.php b/tests/event/dispatcher_test.php index 9b9203e06a..a76df90809 100644 --- a/tests/event/dispatcher_test.php +++ b/tests/event/dispatcher_test.php @@ -11,9 +11,9 @@ class phpbb_event_dispatcher_test extends phpbb_test_case { public function test_trigger_event() { - $dispatcher = new phpbb_event_dispatcher(new phpbb_mock_container_builder()); + $dispatcher = new \phpbb\event\dispatcher(new phpbb_mock_container_builder()); - $dispatcher->addListener('core.test_event', function (phpbb_event_data $event) { + $dispatcher->addListener('core.test_event', function (\phpbb\event\data $event) { $event['foo'] = $event['foo'] . '2'; $event['bar'] = $event['bar'] . '2'; }); diff --git a/tests/extension/ext/bar/ext.php b/tests/extension/ext/bar/ext.php index 5585edf9ac..22ff5e8077 100644 --- a/tests/extension/ext/bar/ext.php +++ b/tests/extension/ext/bar/ext.php @@ -1,6 +1,8 @@ <?php -class phpbb_ext_bar_ext extends phpbb_extension_base +namespace bar; + +class ext extends \phpbb\extension\base { static public $state; diff --git a/tests/extension/ext/bar/my/hidden_class.php b/tests/extension/ext/bar/my/hidden_class.php index 0261d7c59a..504c1873dc 100644 --- a/tests/extension/ext/bar/my/hidden_class.php +++ b/tests/extension/ext/bar/my/hidden_class.php @@ -1,5 +1,7 @@ <?php -class phpbb_ext_bar_my_hidden_class +namespace bar\my; + +class hidden_class { } diff --git a/tests/extension/ext/barfoo/acp/a_info.php b/tests/extension/ext/barfoo/acp/a_info.php index cd7e4e574b..ea07189f7a 100644 --- a/tests/extension/ext/barfoo/acp/a_info.php +++ b/tests/extension/ext/barfoo/acp/a_info.php @@ -1,11 +1,13 @@ <?php -class phpbb_ext_barfoo_acp_a_info +namespace barfoo\acp; + +class a_info { public function module() { return array( - 'filename' => 'phpbb_ext_barfoo_acp_a_module', + 'filename' => 'barfoo\\acp\\a_module', 'title' => 'Barfoo', 'version' => '3.1.0-dev', 'modes' => array( diff --git a/tests/extension/ext/barfoo/acp/a_module.php b/tests/extension/ext/barfoo/acp/a_module.php index 5bedb49645..0ae8775013 100644 --- a/tests/extension/ext/barfoo/acp/a_module.php +++ b/tests/extension/ext/barfoo/acp/a_module.php @@ -1,5 +1,7 @@ <?php -class phpbb_ext_barfoo_acp_a_module +namespace barfoo\acp; + +class a_module { } diff --git a/tests/extension/ext/barfoo/ext.php b/tests/extension/ext/barfoo/ext.php index 2e11ece8d1..1b7bb7ca5e 100644 --- a/tests/extension/ext/barfoo/ext.php +++ b/tests/extension/ext/barfoo/ext.php @@ -1,5 +1,7 @@ <?php -class phpbb_ext_barfoo_ext extends phpbb_extension_base +namespace barfoo; + +class ext extends \phpbb\extension\base { } diff --git a/tests/extension/ext/foo/a_class.php b/tests/extension/ext/foo/a_class.php index b7be1ad654..9db45a697f 100644 --- a/tests/extension/ext/foo/a_class.php +++ b/tests/extension/ext/foo/a_class.php @@ -1,5 +1,7 @@ <?php -class phpbb_ext_foo_a_class +namespace foo; + +class a_class { } diff --git a/tests/extension/ext/foo/acp/a_info.php b/tests/extension/ext/foo/acp/a_info.php index 3e9bbffaca..3b7d8cdd42 100644 --- a/tests/extension/ext/foo/acp/a_info.php +++ b/tests/extension/ext/foo/acp/a_info.php @@ -1,11 +1,13 @@ <?php -class phpbb_ext_foo_acp_a_info +namespace foo\acp; + +class a_info { public function module() { return array( - 'filename' => 'phpbb_ext_foo_acp_a_module', + 'filename' => 'foo\\acp\\a_module', 'title' => 'Foobar', 'version' => '3.1.0-dev', 'modes' => array( diff --git a/tests/extension/ext/foo/acp/a_module.php b/tests/extension/ext/foo/acp/a_module.php index 093b4b1ad7..7aa2351ab3 100644 --- a/tests/extension/ext/foo/acp/a_module.php +++ b/tests/extension/ext/foo/acp/a_module.php @@ -1,5 +1,7 @@ <?php -class phpbb_ext_foo_acp_a_module +namespace foo\acp; + +class a_module { } diff --git a/tests/extension/ext/foo/acp/fail_info.php b/tests/extension/ext/foo/acp/fail_info.php index 99aa09551e..01d29fc5eb 100644 --- a/tests/extension/ext/foo/acp/fail_info.php +++ b/tests/extension/ext/foo/acp/fail_info.php @@ -1,14 +1,17 @@ <?php + +namespace foo\acp; + /* * Due to the mismatch between the class name and the file name, this module * file shouldn't be found by the extension finder */ -class phpbb_ext_foo_acp_foo_info +class foo_info { public function module() { return array( - 'filename' => 'phpbb_ext_foo_acp_fail_module', + 'filename' => 'foo\acp\fail_module', 'title' => 'Foobar', 'version' => '3.1.0-dev', 'modes' => array( diff --git a/tests/extension/ext/foo/acp/fail_module.php b/tests/extension/ext/foo/acp/fail_module.php index a200d92d2f..8070929d3c 100644 --- a/tests/extension/ext/foo/acp/fail_module.php +++ b/tests/extension/ext/foo/acp/fail_module.php @@ -1,8 +1,11 @@ <?php + +namespace foo\acp; + /* * Due to the mismatch between the class name and the file name of the module * info file, this module's info file shouldn't be found */ -class phpbb_ext_foo_acp_fail_module +class fail_module { } diff --git a/tests/extension/ext/foo/b_class.php b/tests/extension/ext/foo/b_class.php index 4645266122..bb2a77c05e 100644 --- a/tests/extension/ext/foo/b_class.php +++ b/tests/extension/ext/foo/b_class.php @@ -1,5 +1,7 @@ <?php -class phpbb_ext_foo_b_class +namespace foo; + +class b_class { } diff --git a/tests/extension/ext/foo/ext.php b/tests/extension/ext/foo/ext.php index 60b3ad1f16..ac6098f2f1 100644 --- a/tests/extension/ext/foo/ext.php +++ b/tests/extension/ext/foo/ext.php @@ -1,6 +1,8 @@ <?php -class phpbb_ext_foo_ext extends phpbb_extension_base +namespace foo; + +class ext extends \phpbb\extension\base { static public $disabled; diff --git a/tests/extension/ext/foo/mcp/a_info.php b/tests/extension/ext/foo/mcp/a_info.php index 84a36b9134..9a896ce808 100644 --- a/tests/extension/ext/foo/mcp/a_info.php +++ b/tests/extension/ext/foo/mcp/a_info.php @@ -1,11 +1,13 @@ <?php -class phpbb_ext_foo_mcp_a_info +namespace foo\mcp; + +class a_info { public function module() { return array( - 'filename' => 'phpbb_ext_foo_mcp_a_module', + 'filename' => 'foo\\mcp\\a_module', 'title' => 'Foobar', 'version' => '3.1.0-dev', 'modes' => array( diff --git a/tests/extension/ext/foo/mcp/a_module.php b/tests/extension/ext/foo/mcp/a_module.php index 59d9f8cc6f..ca397e7004 100644 --- a/tests/extension/ext/foo/mcp/a_module.php +++ b/tests/extension/ext/foo/mcp/a_module.php @@ -1,5 +1,7 @@ <?php -class phpbb_ext_foo_mcp_a_module +namespace foo\mcp; + +class a_module { } diff --git a/tests/extension/ext/foo/sub/type/alternative.php b/tests/extension/ext/foo/sub/type/alternative.php index 2ea7353f4b..1eaf794609 100644 --- a/tests/extension/ext/foo/sub/type/alternative.php +++ b/tests/extension/ext/foo/sub/type/alternative.php @@ -1,5 +1,7 @@ <?php -class phpbb_ext_foo_sub_type_alternative +namespace foo\sub\type; + +class alternative { } diff --git a/tests/extension/ext/foo/type/alternative.php b/tests/extension/ext/foo/type/alternative.php index 404b66b965..8f753491ef 100644 --- a/tests/extension/ext/foo/type/alternative.php +++ b/tests/extension/ext/foo/type/alternative.php @@ -1,5 +1,7 @@ <?php -class phpbb_ext_foo_type_alternative +namespace foo\type; + +class alternative { } diff --git a/tests/extension/ext/foo/typewrong/error.php b/tests/extension/ext/foo/typewrong/error.php index ba22cfae9a..5020926043 100644 --- a/tests/extension/ext/foo/typewrong/error.php +++ b/tests/extension/ext/foo/typewrong/error.php @@ -1,5 +1,7 @@ <?php -class phpbb_ext_foo_typewrong_error +namespace foo\typewrong; + +class error { } diff --git a/tests/extension/ext/vendor/moo/ext.php b/tests/extension/ext/vendor/moo/ext.php index e0ac1a22cc..41ef570452 100644 --- a/tests/extension/ext/vendor/moo/ext.php +++ b/tests/extension/ext/vendor/moo/ext.php @@ -1,6 +1,8 @@ <?php -class phpbb_ext_vendor_moo_ext extends phpbb_extension_base +namespace vendor\moo; + +class ext extends \phpbb\extension\base { static public $purged; diff --git a/tests/extension/ext/vendor/moo/feature_class.php b/tests/extension/ext/vendor/moo/feature_class.php index c3bcc4451c..cb8bb3da56 100644 --- a/tests/extension/ext/vendor/moo/feature_class.php +++ b/tests/extension/ext/vendor/moo/feature_class.php @@ -1,5 +1,7 @@ <?php -class phpbb_ext_vendor_moo_feature_class +namespace vendor\moo; + +class feature_class { } diff --git a/tests/extension/finder_test.php b/tests/extension/finder_test.php index 3bf2c42573..8e6e71aaf8 100644 --- a/tests/extension/finder_test.php +++ b/tests/extension/finder_test.php @@ -43,10 +43,10 @@ class phpbb_extension_finder_test extends phpbb_test_case sort($classes); $this->assertEquals( array( - 'phpbb_default_implementation', - 'phpbb_ext_bar_my_hidden_class', - 'phpbb_ext_foo_a_class', - 'phpbb_ext_foo_b_class', + '\bar\my\hidden_class', + '\foo\a_class', + '\foo\b_class', + '\phpbb\default\implementation', ), $classes ); @@ -67,7 +67,7 @@ class phpbb_extension_finder_test extends phpbb_test_case public function test_prefix_get_directories() { $dirs = $this->finder - ->prefix('ty') + ->prefix('ty') ->get_directories(); sort($dirs); @@ -88,8 +88,8 @@ class phpbb_extension_finder_test extends phpbb_test_case sort($classes); $this->assertEquals( array( - 'phpbb_default_implementation', - 'phpbb_ext_bar_my_hidden_class', + '\bar\my\hidden_class', + '\phpbb\default\implementation', ), $classes ); @@ -105,9 +105,9 @@ class phpbb_extension_finder_test extends phpbb_test_case sort($classes); $this->assertEquals( array( - 'phpbb_default_implementation', - 'phpbb_ext_foo_sub_type_alternative', - 'phpbb_ext_foo_type_alternative', + '\foo\sub\type\alternative', + '\foo\type\alternative', + '\phpbb\default\implementation', ), $classes ); @@ -122,7 +122,7 @@ class phpbb_extension_finder_test extends phpbb_test_case sort($classes); $this->assertEquals( array( - 'phpbb_ext_foo_type_alternative', + '\foo\type\alternative', ), $classes ); @@ -137,7 +137,7 @@ class phpbb_extension_finder_test extends phpbb_test_case sort($classes); $this->assertEquals( array( - 'phpbb_ext_foo_sub_type_alternative', + '\foo\sub\type\alternative', ), $classes ); @@ -152,7 +152,7 @@ class phpbb_extension_finder_test extends phpbb_test_case sort($classes); $this->assertEquals( array( - 'phpbb_ext_foo_sub_type_alternative', + '\foo\sub\type\alternative', ), $classes ); @@ -168,8 +168,8 @@ class phpbb_extension_finder_test extends phpbb_test_case sort($classes); $this->assertEquals( array( - 'phpbb_ext_foo_type_alternative', - 'phpbb_ext_foo_type_dummy_empty', + '\foo\type\alternative', + '\foo\type\dummy\empty', ), $classes ); @@ -181,7 +181,7 @@ class phpbb_extension_finder_test extends phpbb_test_case public function test_get_classes_create_cache() { $cache = new phpbb_mock_cache; - $finder = new phpbb_extension_finder($this->extension_manager, new phpbb_filesystem(), dirname(__FILE__) . '/', $cache, 'php', '_custom_cache_name'); + $finder = new \phpbb\extension\finder($this->extension_manager, new \phpbb\filesystem(), dirname(__FILE__) . '/', $cache, 'php', '_custom_cache_name'); $files = $finder->suffix('_class.php')->get_files(); $expected_files = array( @@ -219,9 +219,9 @@ class phpbb_extension_finder_test extends phpbb_test_case 'is_dir' => false, ); - $finder = new phpbb_extension_finder( + $finder = new \phpbb\extension\finder( $this->extension_manager, - new phpbb_filesystem(), + new \phpbb\filesystem(), dirname(__FILE__) . '/', new phpbb_mock_cache(array( '_ext_finder' => array( diff --git a/tests/extension/manager_test.php b/tests/extension/manager_test.php index a23e5a18d9..c4a32f53ab 100644 --- a/tests/extension/manager_test.php +++ b/tests/extension/manager_test.php @@ -45,31 +45,31 @@ class phpbb_extension_manager_test extends phpbb_database_test_case public function test_enable() { - phpbb_ext_bar_ext::$state = 0; + bar\ext::$state = 0; $this->assertEquals(array('foo'), array_keys($this->extension_manager->all_enabled())); $this->extension_manager->enable('bar'); $this->assertEquals(array('bar', 'foo'), array_keys($this->extension_manager->all_enabled())); $this->assertEquals(array('bar', 'foo', 'vendor/moo'), array_keys($this->extension_manager->all_configured())); - $this->assertEquals(4, phpbb_ext_bar_ext::$state); + $this->assertEquals(4, bar\ext::$state); } public function test_disable() { - phpbb_ext_foo_ext::$disabled = false; + foo\ext::$disabled = false; $this->assertEquals(array('foo'), array_keys($this->extension_manager->all_enabled())); $this->extension_manager->disable('foo'); $this->assertEquals(array(), array_keys($this->extension_manager->all_enabled())); $this->assertEquals(array('foo', 'vendor/moo'), array_keys($this->extension_manager->all_configured())); - $this->assertTrue(phpbb_ext_foo_ext::$disabled); + $this->assertTrue(foo\ext::$disabled); } public function test_purge() { - phpbb_ext_vendor_moo_ext::$purged = false; + vendor\moo\ext::$purged = false; $this->assertEquals(array('foo'), array_keys($this->extension_manager->all_enabled())); $this->assertEquals(array('foo', 'vendor/moo'), array_keys($this->extension_manager->all_configured())); @@ -77,7 +77,7 @@ class phpbb_extension_manager_test extends phpbb_database_test_case $this->assertEquals(array('foo'), array_keys($this->extension_manager->all_enabled())); $this->assertEquals(array('foo'), array_keys($this->extension_manager->all_configured())); - $this->assertTrue(phpbb_ext_vendor_moo_ext::$purged); + $this->assertTrue(vendor\moo\ext::$purged); } public function test_enabled_no_cache() @@ -90,14 +90,14 @@ class phpbb_extension_manager_test extends phpbb_database_test_case protected function create_extension_manager($with_cache = true) { - $config = new phpbb_config(array()); + $config = new \phpbb\config\config(array()); $db = $this->new_dbal(); - $db_tools = new phpbb_db_tools($db); + $db_tools = new \phpbb\db\tools($db); $phpbb_root_path = __DIR__ . './../../phpBB/'; $php_ext = 'php'; $table_prefix = 'phpbb_'; - $migrator = new phpbb_db_migrator( + $migrator = new \phpbb\db\migrator( $config, $db, $db_tools, @@ -110,11 +110,17 @@ class phpbb_extension_manager_test extends phpbb_database_test_case $container = new phpbb_mock_container_builder(); $container->set('migrator', $migrator); - return new phpbb_extension_manager( + return new \phpbb\extension\manager( $container, $db, $config, - new phpbb_filesystem(), + new \phpbb\filesystem( + new \phpbb\symfony_request( + new phpbb_mock_request() + ), + $phpbb_root_path, + $php_ext + ), 'phpbb_ext', dirname(__FILE__) . '/', $php_ext, diff --git a/tests/extension/metadata_manager_test.php b/tests/extension/metadata_manager_test.php index e5bd29092e..2b27a1bae2 100644 --- a/tests/extension/metadata_manager_test.php +++ b/tests/extension/metadata_manager_test.php @@ -30,25 +30,30 @@ class phpbb_extension_metadata_manager_test extends phpbb_database_test_case parent::setUp(); $this->cache = new phpbb_mock_cache(); - $this->config = new phpbb_config(array( + $this->config = new \phpbb\config\config(array( 'version' => '3.1.0', )); $this->db = $this->new_dbal(); - $this->db_tools = new phpbb_db_tools($this->db); + $this->db_tools = new \phpbb\db\tools($this->db); $this->phpbb_root_path = dirname(__FILE__) . '/'; $this->phpEx = 'php'; - $this->user = new phpbb_user(); + $this->user = new \phpbb\user(); $this->table_prefix = 'phpbb_'; - $this->template = new phpbb_template_twig( - $this->phpbb_root_path, - $this->phpEx, + $this->template = new \phpbb\template\twig\twig( + new \phpbb\filesystem( + new \phpbb\symfony_request( + new phpbb_mock_request() + ), + $this->phpbb_root_path, + $this->phpEx + ), $this->config, $this->user, - new phpbb_template_context() + new \phpbb\template\context() ); - $this->migrator = new phpbb_db_migrator( + $this->migrator = new \phpbb\db\migrator( $this->config, $this->db, $this->db_tools, @@ -61,11 +66,17 @@ class phpbb_extension_metadata_manager_test extends phpbb_database_test_case $container = new phpbb_mock_container_builder(); $container->set('migrator', $migrator); - $this->extension_manager = new phpbb_extension_manager( + $this->extension_manager = new \phpbb\extension\manager( $container, $this->db, $this->config, - new phpbb_filesystem(), + new \phpbb\filesystem( + new \phpbb\symfony_request( + new phpbb_mock_request() + ), + $this->phpbb_root_path, + $this->phpEx + ), 'phpbb_ext', $this->phpbb_root_path, $this->phpEx, @@ -84,7 +95,7 @@ class phpbb_extension_metadata_manager_test extends phpbb_database_test_case { $manager->get_metadata(); } - catch(phpbb_extension_exception $e){} + catch(\phpbb\extension\exception $e){} $this->assertEquals((string) $e, 'The required file does not exist: ' . $this->phpbb_root_path . $this->extension_manager->get_extension_path($ext_name) . 'composer.json'); } @@ -100,7 +111,7 @@ class phpbb_extension_metadata_manager_test extends phpbb_database_test_case { $metadata = $manager->get_metadata(); } - catch(phpbb_extension_exception $e) + catch(\phpbb\extension\exception $e) { $this->fail($e); } @@ -123,7 +134,7 @@ class phpbb_extension_metadata_manager_test extends phpbb_database_test_case $this->fail('Exception not triggered'); } - catch(phpbb_extension_exception $e) + catch(\phpbb\extension\exception $e) { $this->assertEquals((string) $e, 'Required meta field \'name\' has not been set.'); } @@ -134,7 +145,7 @@ class phpbb_extension_metadata_manager_test extends phpbb_database_test_case $this->fail('Exception not triggered'); } - catch(phpbb_extension_exception $e) + catch(\phpbb\extension\exception $e) { $this->assertEquals((string) $e, 'Required meta field \'type\' has not been set.'); } @@ -145,7 +156,7 @@ class phpbb_extension_metadata_manager_test extends phpbb_database_test_case $this->fail('Exception not triggered'); } - catch(phpbb_extension_exception $e) + catch(\phpbb\extension\exception $e) { $this->assertEquals((string) $e, 'Required meta field \'licence\' has not been set.'); } @@ -156,7 +167,7 @@ class phpbb_extension_metadata_manager_test extends phpbb_database_test_case $this->fail('Exception not triggered'); } - catch(phpbb_extension_exception $e) + catch(\phpbb\extension\exception $e) { $this->assertEquals((string) $e, 'Required meta field \'version\' has not been set.'); } @@ -167,7 +178,7 @@ class phpbb_extension_metadata_manager_test extends phpbb_database_test_case $this->fail('Exception not triggered'); } - catch(phpbb_extension_exception $e) + catch(\phpbb\extension\exception $e) { $this->assertEquals((string) $e, 'Required meta field \'authors\' has not been set.'); } @@ -184,7 +195,7 @@ class phpbb_extension_metadata_manager_test extends phpbb_database_test_case $this->fail('Exception not triggered'); } - catch(phpbb_extension_exception $e) + catch(\phpbb\extension\exception $e) { $this->assertEquals((string) $e, 'Required meta field \'author name\' has not been set.'); } @@ -211,7 +222,7 @@ class phpbb_extension_metadata_manager_test extends phpbb_database_test_case $this->fail('Exception not triggered'); } - catch(phpbb_extension_exception $e) + catch(\phpbb\extension\exception $e) { $this->assertEquals((string) $e, 'Meta field \'name\' is invalid.'); } @@ -222,7 +233,7 @@ class phpbb_extension_metadata_manager_test extends phpbb_database_test_case $this->fail('Exception not triggered'); } - catch(phpbb_extension_exception $e) + catch(\phpbb\extension\exception $e) { $this->assertEquals((string) $e, 'Meta field \'type\' is invalid.'); } @@ -233,7 +244,7 @@ class phpbb_extension_metadata_manager_test extends phpbb_database_test_case $this->fail('Exception not triggered'); } - catch(phpbb_extension_exception $e) + catch(\phpbb\extension\exception $e) { $this->assertEquals((string) $e, 'Meta field \'licence\' is invalid.'); } @@ -244,7 +255,7 @@ class phpbb_extension_metadata_manager_test extends phpbb_database_test_case $this->fail('Exception not triggered'); } - catch(phpbb_extension_exception $e) + catch(\phpbb\extension\exception $e) { $this->assertEquals((string) $e, 'Meta field \'version\' is invalid.'); } @@ -268,7 +279,7 @@ class phpbb_extension_metadata_manager_test extends phpbb_database_test_case { $this->assertEquals(true, $manager->validate('enable')); } - catch(phpbb_extension_exception $e) + catch(\phpbb\extension\exception $e) { $this->fail($e); } @@ -293,7 +304,7 @@ class phpbb_extension_metadata_manager_test extends phpbb_database_test_case $this->assertEquals(false, $manager->validate_require_php()); $this->assertEquals(false, $manager->validate_require_phpbb()); } - catch(phpbb_extension_exception $e) + catch(\phpbb\extension\exception $e) { $this->fail($e); } @@ -312,7 +323,7 @@ class phpbb_extension_metadata_manager_test extends phpbb_database_test_case $this->assertEquals(true, $manager->validate_require_php()); $this->assertEquals(true, $manager->validate_require_phpbb()); } - catch(phpbb_extension_exception $e) + catch(\phpbb\extension\exception $e) { $this->fail($e); } @@ -331,7 +342,7 @@ class phpbb_extension_metadata_manager_test extends phpbb_database_test_case $this->assertEquals(false, $manager->validate_require_php()); $this->assertEquals(false, $manager->validate_require_phpbb()); } - catch(phpbb_extension_exception $e) + catch(\phpbb\extension\exception $e) { $this->fail($e); } @@ -350,7 +361,7 @@ class phpbb_extension_metadata_manager_test extends phpbb_database_test_case $this->assertEquals(false, $manager->validate_require_php()); $this->assertEquals(false, $manager->validate_require_phpbb()); } - catch(phpbb_extension_exception $e) + catch(\phpbb\extension\exception $e) { $this->fail($e); } @@ -369,7 +380,7 @@ class phpbb_extension_metadata_manager_test extends phpbb_database_test_case $this->assertEquals(true, $manager->validate_require_php()); $this->assertEquals(true, $manager->validate_require_phpbb()); } - catch(phpbb_extension_exception $e) + catch(\phpbb\extension\exception $e) { $this->fail($e); } @@ -388,7 +399,7 @@ class phpbb_extension_metadata_manager_test extends phpbb_database_test_case $this->assertEquals(true, $manager->validate_require_php()); $this->assertEquals(true, $manager->validate_require_phpbb()); } - catch(phpbb_extension_exception $e) + catch(\phpbb\extension\exception $e) { $this->fail($e); } @@ -407,7 +418,7 @@ class phpbb_extension_metadata_manager_test extends phpbb_database_test_case $this->assertEquals(true, $manager->validate_require_php()); $this->assertEquals(true, $manager->validate_require_phpbb()); } - catch(phpbb_extension_exception $e) + catch(\phpbb\extension\exception $e) { $this->fail($e); } diff --git a/tests/extension/modules_test.php b/tests/extension/modules_test.php index fe71747c5d..ef21c943c2 100644 --- a/tests/extension/modules_test.php +++ b/tests/extension/modules_test.php @@ -45,6 +45,8 @@ class phpbb_extension_modules_test extends phpbb_test_case { global $phpbb_root_path; +// $this->markTestIncomplete('Modules no speak namespace! Going to get rid of db modules altogether and fix this test after.'); + // Correctly set the root path for this test to this directory, so the classes can be found $phpbb_root_path = dirname(__FILE__) . '/'; @@ -52,8 +54,8 @@ class phpbb_extension_modules_test extends phpbb_test_case $this->acp_modules->module_class = 'acp'; $acp_modules = $this->acp_modules->get_module_infos(); $this->assertEquals(array( - 'phpbb_ext_foo_acp_a_module' => array( - 'filename' => 'phpbb_ext_foo_acp_a_module', + 'foo\\acp\\a_module' => array( + 'filename' => 'foo\\acp\\a_module', 'title' => 'Foobar', 'version' => '3.1.0-dev', 'modes' => array( @@ -74,8 +76,8 @@ class phpbb_extension_modules_test extends phpbb_test_case $this->acp_modules->module_class = 'mcp'; $acp_modules = $this->acp_modules->get_module_infos(); $this->assertEquals(array( - 'phpbb_ext_foo_mcp_a_module' => array( - 'filename' => 'phpbb_ext_foo_mcp_a_module', + 'foo\\mcp\\a_module' => array( + 'filename' => 'foo\\mcp\\a_module', 'title' => 'Foobar', 'version' => '3.1.0-dev', 'modes' => array( @@ -88,8 +90,8 @@ class phpbb_extension_modules_test extends phpbb_test_case $this->acp_modules->module_class = 'mcp'; $acp_modules = $this->acp_modules->get_module_infos('mcp_a_module'); $this->assertEquals(array( - 'phpbb_ext_foo_mcp_a_module' => array( - 'filename' => 'phpbb_ext_foo_mcp_a_module', + 'foo\\mcp\\a_module' => array( + 'filename' => 'foo\\mcp\\a_module', 'title' => 'Foobar', 'version' => '3.1.0-dev', 'modes' => array( @@ -102,8 +104,8 @@ class phpbb_extension_modules_test extends phpbb_test_case $this->acp_modules->module_class = ''; $acp_modules = $this->acp_modules->get_module_infos('mcp_a_module', 'mcp'); $this->assertEquals(array( - 'phpbb_ext_foo_mcp_a_module' => array( - 'filename' => 'phpbb_ext_foo_mcp_a_module', + 'foo\\mcp\\a_module' => array( + 'filename' => 'foo\\mcp\\a_module', 'title' => 'Foobar', 'version' => '3.1.0-dev', 'modes' => array( @@ -124,10 +126,10 @@ class phpbb_extension_modules_test extends phpbb_test_case // Get module info of specified extension module $this->acp_modules->module_class = 'acp'; - $acp_modules = $this->acp_modules->get_module_infos('phpbb_ext_foo_acp_a_module'); + $acp_modules = $this->acp_modules->get_module_infos('foo_acp_a_module'); $this->assertEquals(array( - 'phpbb_ext_foo_acp_a_module' => array ( - 'filename' => 'phpbb_ext_foo_acp_a_module', + 'foo\\acp\\a_module' => array ( + 'filename' => 'foo\\acp\\a_module', 'title' => 'Foobar', 'version' => '3.1.0-dev', 'modes' => array ( @@ -150,8 +152,8 @@ class phpbb_extension_modules_test extends phpbb_test_case $this->acp_modules->module_class = 'acp'; $acp_modules = $this->acp_modules->get_module_infos('', false, true); $this->assertEquals(array( - 'phpbb_ext_foo_acp_a_module' => array( - 'filename' => 'phpbb_ext_foo_acp_a_module', + 'foo\\acp\\a_module' => array( + 'filename' => 'foo\\acp\\a_module', 'title' => 'Foobar', 'version' => '3.1.0-dev', 'modes' => array( @@ -166,8 +168,8 @@ class phpbb_extension_modules_test extends phpbb_test_case 'test' => array('title' => 'Test', 'auth' => '', 'cat' => array('ACP_GENERAL')), ), ), - 'phpbb_ext_barfoo_acp_a_module' => array( - 'filename' => 'phpbb_ext_barfoo_acp_a_module', + 'barfoo\\acp\\a_module' => array( + 'filename' => 'barfoo\\acp\\a_module', 'title' => 'Barfoo', 'version' => '3.1.0-dev', 'modes' => array( @@ -177,10 +179,10 @@ class phpbb_extension_modules_test extends phpbb_test_case ), $acp_modules); // Specific module set to disabled extension - $acp_modules = $this->acp_modules->get_module_infos('phpbb_ext_barfoo_acp_a_module', 'acp', true); + $acp_modules = $this->acp_modules->get_module_infos('barfoo_acp_a_module', 'acp', true); $this->assertEquals(array( - 'phpbb_ext_barfoo_acp_a_module' => array( - 'filename' => 'phpbb_ext_barfoo_acp_a_module', + 'barfoo\\acp\\a_module' => array( + 'filename' => 'barfoo\\acp\\a_module', 'title' => 'Barfoo', 'version' => '3.1.0-dev', 'modes' => array( diff --git a/tests/extension/style_path_provider_test.php b/tests/extension/style_path_provider_test.php deleted file mode 100644 index e1021c20ac..0000000000 --- a/tests/extension/style_path_provider_test.php +++ /dev/null @@ -1,50 +0,0 @@ -<?php -/** -* -* @package testing -* @copyright (c) 2013 phpBB Group -* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 -* -*/ -require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php'; - -class phpbb_extension_style_path_provider_test extends phpbb_test_case -{ - protected $relative_root_path; - protected $root_path; - - public function setUp() - { - $this->relative_root_path = './'; - $this->root_path = dirname(__FILE__) . '/'; - } - - public function test_find() - { - $phpbb_style_path_provider = new phpbb_style_path_provider(); - $phpbb_style_path_provider->set_styles(array($this->relative_root_path . 'styles/prosilver')); - $phpbb_style_extension_path_provider = new phpbb_style_extension_path_provider(new phpbb_mock_extension_manager( - $this->root_path, - array( - 'foo' => array( - 'ext_name' => 'foo', - 'ext_active' => '1', - 'ext_path' => 'ext/foo/', - ), - 'bar' => array( - 'ext_name' => 'bar', - 'ext_active' => '1', - 'ext_path' => 'ext/bar/', - ), - )), $phpbb_style_path_provider, $this->relative_root_path); - - $this->assertEquals(array( - 'style' => array( - $this->relative_root_path . 'styles/prosilver', - ), - 'bar' => array( - $this->root_path . 'ext/bar/styles/prosilver', - ), - ), $phpbb_style_extension_path_provider->find()); - } -} diff --git a/tests/extension/subdir/style_path_provider_test.php b/tests/extension/subdir/style_path_provider_test.php deleted file mode 100644 index 1b5ce62e5f..0000000000 --- a/tests/extension/subdir/style_path_provider_test.php +++ /dev/null @@ -1,18 +0,0 @@ -<?php -/** -* -* @package testing -* @copyright (c) 2013 phpBB Group -* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 -* -*/ -require_once dirname(__FILE__) . '/../style_path_provider_test.php'; - -class phpbb_extension_subdir_style_path_provider_test extends phpbb_extension_style_path_provider_test -{ - public function setUp() - { - $this->relative_root_path = '../'; - $this->root_path = dirname(__FILE__) . '/../'; - } -} diff --git a/tests/filesystem/clean_path_test.php b/tests/filesystem/clean_path_test.php index 50951fc88c..5b9857ef2c 100644 --- a/tests/filesystem/clean_path_test.php +++ b/tests/filesystem/clean_path_test.php @@ -14,7 +14,13 @@ class phpbb_filesystem_clean_path_test extends phpbb_test_case public function setUp() { parent::setUp(); - $this->filesystem = new phpbb_filesystem(); + $this->filesystem = new \phpbb\filesystem( + new \phpbb\symfony_request( + new phpbb_mock_request() + ), + dirname(__FILE__) . './../../phpBB/', + 'php' + ); } public function clean_path_data() diff --git a/tests/filesystem/web_root_path_test.php b/tests/filesystem/web_root_path_test.php new file mode 100644 index 0000000000..e0f716cdae --- /dev/null +++ b/tests/filesystem/web_root_path_test.php @@ -0,0 +1,142 @@ +<?php +/** +* +* @package testing +* @copyright (c) 2013 phpBB Group +* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 +* +*/ + +class phpbb_filesystem_web_root_path_test extends phpbb_test_case +{ + protected $filesystem; + protected $phpbb_root_path = ''; + + public function setUp() + { + parent::setUp(); + + $this->set_phpbb_root_path(); + + $this->filesystem = new \phpbb\filesystem( + new \phpbb\symfony_request( + new phpbb_mock_request() + ), + $this->phpbb_root_path, + 'php' + ); + } + + /** + * Set the phpbb_root_path + * + * This is necessary because dataProvider functions are called + * before setUp or setUpBeforeClass; so we must set the path + * any time we wish to use it in one of these functions (and + * also in general for everything else) + */ + public function set_phpbb_root_path() + { + $this->phpbb_root_path = dirname(__FILE__) . './../../phpBB/'; + } + + public function test_get_web_root_path() + { + // Symfony Request = null, so always should return phpbb_root_path + $this->assertEquals($this->phpbb_root_path, $this->filesystem->get_web_root_path()); + } + + public function basic_update_web_root_path_data() + { + $this->set_phpbb_root_path(); + + return array( + array( + $this->phpbb_root_path . 'test.php', + $this->phpbb_root_path . 'test.php', + ), + array( + 'test.php', + $this->phpbb_root_path . 'test.php', + ), + array( + $this->phpbb_root_path . $this->phpbb_root_path . 'test.php', + $this->phpbb_root_path . $this->phpbb_root_path . 'test.php', + ), + ); + } + + /** + * @dataProvider basic_update_web_root_path_data + */ + public function test_basic_update_web_root_path($input, $expected) + { + $this->assertEquals($expected, $this->filesystem->update_web_root_path($input, $symfony_request)); + } + + public function update_web_root_path_data() + { + $this->set_phpbb_root_path(); + + return array( + array( + $this->phpbb_root_path . 'test.php', + $this->phpbb_root_path . 'test.php', + '/', + ), + array( + $this->phpbb_root_path . 'test.php', + $this->phpbb_root_path . '../test.php', + '//', + ), + array( + $this->phpbb_root_path . 'test.php', + $this->phpbb_root_path . '../test.php', + '//', + 'foo/bar.php', + 'bar.php', + ), + array( + $this->phpbb_root_path . 'test.php', + $this->phpbb_root_path . '../../test.php', + '/foo/template', + '/phpbb3-fork/phpBB/app.php/foo/template', + '/phpbb3-fork/phpBB/app.php', + ), + array( + $this->phpbb_root_path . 'test.php', + $this->phpbb_root_path . '../test.php', + '/foo/template', + '/phpbb3-fork/phpBB/foo/template', + '/phpbb3-fork/phpBB/app.php', + ), + ); + } + + /** + * @dataProvider update_web_root_path_data + */ + public function test_update_web_root_path($input, $expected, $getPathInfo, $getRequestUri = null, $getScriptName = null) + { + $symfony_request = $this->getMock("\phpbb\symfony_request", array(), array( + new phpbb_mock_request(), + )); + $symfony_request->expects($this->any()) + ->method('getPathInfo') + ->will($this->returnValue($getPathInfo)); + $symfony_request->expects($this->any()) + ->method('getRequestUri') + ->will($this->returnValue($getRequestUri)); + $symfony_request->expects($this->any()) + ->method('getScriptName') + ->will($this->returnValue($getScriptName)); + + $filesystem = new \phpbb\filesystem( + $symfony_request, + $this->phpbb_root_path, + 'php' + ); + + $this->assertEquals($expected, $filesystem->update_web_root_path($input, $symfony_request)); + } +} diff --git a/tests/functional/acp_permissions_test.php b/tests/functional/acp_permissions_test.php index a3d272906f..e17f33dc96 100644 --- a/tests/functional/acp_permissions_test.php +++ b/tests/functional/acp_permissions_test.php @@ -91,12 +91,12 @@ class phpbb_functional_acp_permissions_test extends phpbb_functional_test_case $crawler = self::request('GET', "adm/index.php?i=acp_permissions&icat=16&mode=$mode&${object_name}[0]=$object_id&type=$permission_type&sid=" . $this->sid); $this->assertContains($this->lang('ACL_SET'), $crawler->filter('h1')->eq(1)->text()); - // XXX globals for phpbb_auth, refactor it later + // XXX globals for \phpbb\auth\auth, refactor it later global $db, $cache; $db = $this->get_db(); $cache = new phpbb_mock_null_cache; - $auth = new phpbb_auth; + $auth = new \phpbb\auth\auth; // XXX hardcoded id $user_data = $auth->obtain_user_data(2); $auth->acl($user_data); @@ -114,7 +114,7 @@ class phpbb_functional_acp_permissions_test extends phpbb_functional_test_case $this->assertContains($this->lang('AUTH_UPDATED'), $crawler->text()); // check acl again - $auth = new phpbb_auth; + $auth = new \phpbb\auth\auth; // XXX hardcoded id $user_data = $auth->obtain_user_data(2); $auth->acl($user_data); diff --git a/tests/functional/common_avatar_test.php b/tests/functional/common_avatar_test.php index c0f21d07c2..1fd8f2ed6f 100644 --- a/tests/functional/common_avatar_test.php +++ b/tests/functional/common_avatar_test.php @@ -32,7 +32,7 @@ abstract class phpbb_functional_common_avatar_test extends phpbb_functional_test $crawler = self::request('GET', 'adm/index.php?i=acp_board&mode=avatar&sid=' . $this->sid); // Check the default entries we should have $this->assertContainsLang('ALLOW_GRAVATAR', $crawler->text()); - $this->assertContainsLang('ALLOW_REMOTE', $crawler->text()); + $this->assertContainsLang('ALLOW_REMOTE_UPLOAD', $crawler->text()); $this->assertContainsLang('ALLOW_AVATARS', $crawler->text()); $this->assertContainsLang('ALLOW_LOCAL', $crawler->text()); diff --git a/tests/functional/common_groups_test.php b/tests/functional/common_groups_test.php index 6c6572af62..950db24767 100644 --- a/tests/functional/common_groups_test.php +++ b/tests/functional/common_groups_test.php @@ -43,7 +43,7 @@ abstract class phpbb_functional_common_groups_test extends phpbb_functional_test $crawler = self::request('GET', 'adm/index.php?i=board&mode=avatar&sid=' . $this->sid); // Check the default entries we should have - $this->assertContains($this->lang('ALLOW_REMOTE'), $crawler->text()); + $this->assertContains($this->lang('ALLOW_REMOTE_UPLOAD'), $crawler->text()); $this->assertContains($this->lang('ALLOW_AVATARS'), $crawler->text()); $this->assertContains($this->lang('ALLOW_LOCAL'), $crawler->text()); diff --git a/tests/functional/extension_controller_test.php b/tests/functional/extension_controller_test.php index 7d29f0000c..41bd48c204 100644 --- a/tests/functional/extension_controller_test.php +++ b/tests/functional/extension_controller_test.php @@ -52,7 +52,7 @@ class phpbb_functional_extension_controller_test extends phpbb_functional_test_c public function test_foo_bar() { $this->phpbb_extension_manager->enable('foo/bar'); - $crawler = self::request('GET', 'app.php?controller=foo/bar', array(), false); + $crawler = self::request('GET', 'app.php/foo/bar', array(), false); self::assert_response_status_code(); $this->assertContains("foo/bar controller handle() method", $crawler->filter('body')->text()); $this->phpbb_extension_manager->purge('foo/bar'); @@ -64,7 +64,7 @@ class phpbb_functional_extension_controller_test extends phpbb_functional_test_c public function test_controller_with_template() { $this->phpbb_extension_manager->enable('foo/bar'); - $crawler = self::request('GET', 'app.php?controller=foo/template'); + $crawler = self::request('GET', 'app.php/foo/template'); $this->assertContains("I am a variable", $crawler->filter('#content')->text()); $this->phpbb_extension_manager->purge('foo/bar'); } @@ -76,9 +76,9 @@ class phpbb_functional_extension_controller_test extends phpbb_functional_test_c public function test_missing_argument() { $this->phpbb_extension_manager->enable('foo/bar'); - $crawler = self::request('GET', 'app.php?controller=foo/baz', array(), false); + $crawler = self::request('GET', 'app.php/foo/baz', array(), false); $this->assert_response_html(500); - $this->assertContains('Missing value for argument #1: test in class phpbb_ext_foo_bar_controller:baz', $crawler->filter('body')->text()); + $this->assertContains('Missing value for argument #1: test in class foo\bar\controller\controller:baz', $crawler->filter('body')->text()); $this->phpbb_extension_manager->purge('foo/bar'); } @@ -88,7 +88,7 @@ class phpbb_functional_extension_controller_test extends phpbb_functional_test_c public function test_exception_should_result_in_500_status_code() { $this->phpbb_extension_manager->enable('foo/bar'); - $crawler = self::request('GET', 'app.php?controller=foo/exception', array(), false); + $crawler = self::request('GET', 'app.php/foo/exception', array(), false); $this->assert_response_html(500); $this->assertContains('Exception thrown from foo/exception route', $crawler->filter('body')->text()); $this->phpbb_extension_manager->purge('foo/bar'); @@ -105,7 +105,7 @@ class phpbb_functional_extension_controller_test extends phpbb_functional_test_c */ public function test_error_ext_disabled_or_404() { - $crawler = self::request('GET', 'app.php?controller=does/not/exist', array(), false); + $crawler = self::request('GET', 'app.php/does/not/exist', array(), false); $this->assert_response_html(404); $this->assertContains('No route found for "GET /does/not/exist"', $crawler->filter('body')->text()); } diff --git a/tests/functional/extension_module_test.php b/tests/functional/extension_module_test.php index c31a892ce9..090cd38daf 100644 --- a/tests/functional/extension_module_test.php +++ b/tests/functional/extension_module_test.php @@ -69,7 +69,7 @@ class phpbb_functional_extension_module_test extends phpbb_functional_test_case $modules->update_module_data($parent_data, true); $module_data = array( - 'module_basename' => 'phpbb_ext_foo_bar_acp_main_module', + 'module_basename' => 'foo\\bar\\acp\\main_module', 'module_enabled' => 1, 'module_display' => 1, 'parent_id' => $parent_data['module_id'], @@ -90,7 +90,7 @@ class phpbb_functional_extension_module_test extends phpbb_functional_test_case { $this->login(); $this->admin_login(); - $crawler = self::request('GET', 'adm/index.php?i=phpbb_ext_foo_bar_acp_main_module&mode=mode&sid=' . $this->sid); + $crawler = self::request('GET', 'adm/index.php?i=foo%5cbar%5cacp%5cmain_module&mode=mode&sid=' . $this->sid); $this->assertContains("Bertie rulez!", $crawler->filter('#main')->text()); $this->phpbb_extension_manager->purge('foo/bar'); } diff --git a/tests/functional/fixtures/ext/foo/bar/acp/main_info.php b/tests/functional/fixtures/ext/foo/bar/acp/main_info.php index 21e38b09b5..2ad6d08503 100644 --- a/tests/functional/fixtures/ext/foo/bar/acp/main_info.php +++ b/tests/functional/fixtures/ext/foo/bar/acp/main_info.php @@ -8,6 +8,8 @@ * */ +namespace foo\bar\acp; + /** * @ignore */ @@ -16,12 +18,12 @@ if (!defined('IN_PHPBB')) exit; } -class phpbb_ext_foo_bar_acp_main_info +class main_info { function module() { return array( - 'filename' => 'phpbb_ext_foo_bar_acp_main_module', + 'filename' => 'foo\bar\acp\main_module', 'title' => 'ACP_FOOBAR_TITLE', 'version' => '1.0.0', 'modes' => array( diff --git a/tests/functional/fixtures/ext/foo/bar/acp/main_module.php b/tests/functional/fixtures/ext/foo/bar/acp/main_module.php index c4ab69fb38..c59b3c6820 100644 --- a/tests/functional/fixtures/ext/foo/bar/acp/main_module.php +++ b/tests/functional/fixtures/ext/foo/bar/acp/main_module.php @@ -8,6 +8,8 @@ * */ +namespace foo\bar\acp; + /** * @ignore */ @@ -16,7 +18,7 @@ if (!defined('IN_PHPBB')) exit; } -class phpbb_ext_foo_bar_acp_main_module +class main_module { var $u_action; diff --git a/tests/functional/fixtures/ext/foo/bar/config/services.yml b/tests/functional/fixtures/ext/foo/bar/config/services.yml index 33ced55af9..3bca4c6567 100644 --- a/tests/functional/fixtures/ext/foo/bar/config/services.yml +++ b/tests/functional/fixtures/ext/foo/bar/config/services.yml @@ -1,6 +1,6 @@ services: foo_bar.controller: - class: phpbb_ext_foo_bar_controller + class: foo\bar\controller\controller arguments: - @controller.helper - @template diff --git a/tests/functional/fixtures/ext/foo/bar/controller/controller.php b/tests/functional/fixtures/ext/foo/bar/controller/controller.php index 5a91b5f681..259d548299 100644 --- a/tests/functional/fixtures/ext/foo/bar/controller/controller.php +++ b/tests/functional/fixtures/ext/foo/bar/controller/controller.php @@ -1,11 +1,14 @@ <?php + +namespace foo\bar\controller; + use Symfony\Component\HttpFoundation\Response; -class phpbb_ext_foo_bar_controller +class controller { protected $template; - public function __construct(phpbb_controller_helper $helper, phpbb_template $template) + public function __construct(\phpbb\controller\helper $helper, \phpbb\template\template $template) { $this->template = $template; $this->helper = $helper; @@ -30,6 +33,6 @@ class phpbb_ext_foo_bar_controller public function exception() { - throw new phpbb_controller_exception('Exception thrown from foo/exception route'); + throw new \phpbb\controller\exception('Exception thrown from foo/exception route'); } } diff --git a/tests/functional/fixtures/ext/foo/bar/event/permission.php b/tests/functional/fixtures/ext/foo/bar/event/permission.php index 48688a586a..92e24074ad 100644 --- a/tests/functional/fixtures/ext/foo/bar/event/permission.php +++ b/tests/functional/fixtures/ext/foo/bar/event/permission.php @@ -8,6 +8,8 @@ * */ +namespace foo\bar\event; + /** * @ignore */ @@ -22,7 +24,7 @@ if (!defined('IN_PHPBB')) */ use Symfony\Component\EventDispatcher\EventSubscriberInterface; -class phpbb_ext_foo_bar_event_permission implements EventSubscriberInterface +class permission implements EventSubscriberInterface { static public function getSubscribedEvents() { diff --git a/tests/functional/fixtures/ext/foo/bar/event/user_setup.php b/tests/functional/fixtures/ext/foo/bar/event/user_setup.php index 3d2d0c5325..1409f97470 100644 --- a/tests/functional/fixtures/ext/foo/bar/event/user_setup.php +++ b/tests/functional/fixtures/ext/foo/bar/event/user_setup.php @@ -8,6 +8,8 @@ * */ +namespace foo\bar\event; + /** * @ignore */ @@ -22,7 +24,7 @@ if (!defined('IN_PHPBB')) */ use Symfony\Component\EventDispatcher\EventSubscriberInterface; -class phpbb_ext_foo_bar_event_user_setup implements EventSubscriberInterface +class user_setup implements EventSubscriberInterface { static public function getSubscribedEvents() { diff --git a/tests/functional/fixtures/ext/foo/bar/ext.php b/tests/functional/fixtures/ext/foo/bar/ext.php index 74359d51ab..1288edd5ec 100644 --- a/tests/functional/fixtures/ext/foo/bar/ext.php +++ b/tests/functional/fixtures/ext/foo/bar/ext.php @@ -1,6 +1,8 @@ <?php -class phpbb_ext_foo_bar_ext extends phpbb_extension_base +namespace foo\bar; + +class ext extends \phpbb\extension\base { } diff --git a/tests/functional/posting_test.php b/tests/functional/posting_test.php index 7fd1e4fdcf..dd95704952 100644 --- a/tests/functional/posting_test.php +++ b/tests/functional/posting_test.php @@ -22,8 +22,8 @@ class phpbb_functional_posting_test extends phpbb_functional_test_case $crawler = self::request('GET', "viewtopic.php?t={$post['topic_id']}&sid={$this->sid}"); $this->assertContains('This is a test topic posted by the testing framework.', $crawler->filter('html')->text()); - // Test creating a reply - $post2 = $this->create_post(2, $post['topic_id'], 'Re: Test Topic 1', 'This is a test post posted by the testing framework.'); + // Test creating a reply with bbcode + $post2 = $this->create_post(2, $post['topic_id'], 'Re: Test Topic 1', 'This is a test [b]post[/b] posted by the testing framework.'); $crawler = self::request('GET', "viewtopic.php?t={$post2['topic_id']}&sid={$this->sid}"); $this->assertContains('This is a test post posted by the testing framework.', $crawler->filter('html')->text()); diff --git a/tests/functional/registration_test.php b/tests/functional/registration_test.php new file mode 100644 index 0000000000..5baf33c59e --- /dev/null +++ b/tests/functional/registration_test.php @@ -0,0 +1,52 @@ +<?php +/** +* +* @package testing +* @copyright (c) 2013 phpBB Group +* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 +* +*/ + +/** +* @group functional +*/ +class phpbb_functional_registration_test extends phpbb_functional_test_case +{ + public function test_disable_captcha_on_registration() + { + $this->login(); + $this->admin_login(); + + $crawler = self::request('GET', "adm/index.php?i=acp_board&mode=registration&sid={$this->sid}"); + $form = $crawler->selectButton('Submit')->form(); + $form['config[enable_confirm]']->setValue('0'); + $crawler = self::submit($form); + + $this->assertContainsLang('CONFIG_UPDATED', $crawler->filter('#main .successbox')->text()); + } + + /** + * @depends test_disable_captcha_on_registration + */ + public function test_register_new_account() + { + $this->add_lang('ucp'); + + $crawler = self::request('GET', 'ucp.php?mode=register'); + $this->assertContainsLang('REGISTRATION', $crawler->filter('div.content h2')->text()); + + $form = $crawler->selectButton('I agree to these terms')->form(); + $crawler = self::submit($form); + + $form = $crawler->selectButton('Submit')->form(array( + 'username' => 'user-reg-test', + 'email' => 'user-reg-test@phpbb.com', + 'new_password' => 'testtest', + 'password_confirm' => 'testtest', + )); + $form['tz']->select('Europe/Berlin'); + $crawler = self::submit($form); + + $this->assertContainsLang('ACCOUNT_ADDED', $crawler->filter('#message')->text()); + } +} diff --git a/tests/functions/convert_30_dbms_to_31_test.php b/tests/functions/convert_30_dbms_to_31_test.php index d08bf87f15..4d210d7b29 100644 --- a/tests/functions/convert_30_dbms_to_31_test.php +++ b/tests/functions/convert_30_dbms_to_31_test.php @@ -31,7 +31,7 @@ class phpbb_convert_30_dbms_to_31_test extends phpbb_test_case */ public function test_convert_30_dbms_to_31($input) { - $expected = "phpbb_db_driver_$input"; + $expected = "phpbb\\db\\driver\\$input"; $output = phpbb_convert_30_dbms_to_31($input); diff --git a/tests/functions/obtain_online_test.php b/tests/functions/obtain_online_test.php index fe372431a9..624e05f77f 100644 --- a/tests/functions/obtain_online_test.php +++ b/tests/functions/obtain_online_test.php @@ -160,7 +160,7 @@ class phpbb_functions_obtain_online_test extends phpbb_database_test_case $config['load_online_guests'] = $display_guests; $user = new phpbb_mock_lang(); $user->lang = $this->load_language(); - $auth = $this->getMock('phpbb_auth'); + $auth = $this->getMock('\phpbb\auth\auth'); $acl_get_map = array( array('u_viewonline', true), array('u_viewprofile', true), diff --git a/tests/functions_user/group_user_attributes_test.php b/tests/functions_user/group_user_attributes_test.php index 4336fd894e..f8d52a9a6a 100644 --- a/tests/functions_user/group_user_attributes_test.php +++ b/tests/functions_user/group_user_attributes_test.php @@ -131,17 +131,17 @@ class phpbb_functions_user_group_user_attributes_test extends phpbb_database_tes $cache = new phpbb_mock_cache; $db = $this->new_dbal(); $phpbb_dispatcher = new phpbb_mock_event_dispatcher(); - $auth = $this->getMock('phpbb_auth'); + $auth = $this->getMock('\phpbb\auth\auth'); $auth->expects($this->any()) ->method('acl_clear_prefetch'); - $cache_driver = new phpbb_cache_driver_null(); + $cache_driver = new \phpbb\cache\driver\null(); $phpbb_container = $this->getMock('Symfony\Component\DependencyInjection\ContainerInterface'); $phpbb_container ->expects($this->any()) ->method('get') ->with('cache.driver') ->will($this->returnValue($cache_driver)); - $phpbb_log = new phpbb_log($db, $user, $auth, $phpbb_dispatcher, $phpbb_root_path, 'adm/', $phpEx, LOG_TABLE); + $phpbb_log = new \phpbb\log\log($db, $user, $auth, $phpbb_dispatcher, $phpbb_root_path, 'adm/', $phpEx, LOG_TABLE); group_user_attributes('default', $group_id, array($user_id), false, 'group_name', $group_row); diff --git a/tests/groupposition/legend_test.php b/tests/groupposition/legend_test.php index 16e33b390c..ac54a86b8e 100644 --- a/tests/groupposition/legend_test.php +++ b/tests/groupposition/legend_test.php @@ -20,7 +20,7 @@ class phpbb_groupposition_legend_test extends phpbb_database_test_case return array( array(1, 0, ''), array(3, 2, ''), - array(4, 0, 'phpbb_groupposition_exception'), + array(4, 0, '\phpbb\groupposition\exception'), ); } @@ -33,7 +33,7 @@ class phpbb_groupposition_legend_test extends phpbb_database_test_case $cache = new phpbb_mock_cache; $db = $this->new_dbal(); - $user = new phpbb_user; + $user = new \phpbb\user; $user->lang = array(); if ($throws_exception) @@ -41,7 +41,7 @@ class phpbb_groupposition_legend_test extends phpbb_database_test_case $this->setExpectedException($throws_exception); } - $test_class = new phpbb_groupposition_legend($db, $user); + $test_class = new \phpbb\groupposition\legend($db, $user); $this->assertEquals($expected, $test_class->get_group_value($group_id)); } @@ -51,10 +51,10 @@ class phpbb_groupposition_legend_test extends phpbb_database_test_case $cache = new phpbb_mock_cache; $db = $this->new_dbal(); - $user = new phpbb_user; + $user = new \phpbb\user; $user->lang = array(); - $test_class = new phpbb_groupposition_legend($db, $user); + $test_class = new \phpbb\groupposition\legend($db, $user); $this->assertEquals(2, $test_class->get_group_count()); } @@ -91,10 +91,10 @@ class phpbb_groupposition_legend_test extends phpbb_database_test_case $cache = new phpbb_mock_cache; $db = $this->new_dbal(); - $user = new phpbb_user; + $user = new \phpbb\user; $user->lang = array(); - $test_class = new phpbb_groupposition_legend($db, $user); + $test_class = new \phpbb\groupposition\legend($db, $user); $this->assertEquals($expected_added, $test_class->add_group($group_id)); $result = $db->sql_query('SELECT group_id, group_legend @@ -179,10 +179,10 @@ class phpbb_groupposition_legend_test extends phpbb_database_test_case $cache = new phpbb_mock_cache; $db = $this->new_dbal(); - $user = new phpbb_user; + $user = new \phpbb\user; $user->lang = array(); - $test_class = new phpbb_groupposition_legend($db, $user); + $test_class = new \phpbb\groupposition\legend($db, $user); $this->assertEquals($expected_deleted, $test_class->delete_group($group_id, $skip_group)); $result = $db->sql_query('SELECT group_id, group_legend @@ -234,10 +234,10 @@ class phpbb_groupposition_legend_test extends phpbb_database_test_case $cache = new phpbb_mock_cache; $db = $this->new_dbal(); - $user = new phpbb_user; + $user = new \phpbb\user; $user->lang = array(); - $test_class = new phpbb_groupposition_legend($db, $user); + $test_class = new \phpbb\groupposition\legend($db, $user); $this->assertEquals($excepted_moved, $test_class->move_up($group_id)); $result = $db->sql_query('SELECT group_id, group_legend @@ -289,10 +289,10 @@ class phpbb_groupposition_legend_test extends phpbb_database_test_case $cache = new phpbb_mock_cache; $db = $this->new_dbal(); - $user = new phpbb_user; + $user = new \phpbb\user; $user->lang = array(); - $test_class = new phpbb_groupposition_legend($db, $user); + $test_class = new \phpbb\groupposition\legend($db, $user); $this->assertEquals($excepted_moved, $test_class->move_down($group_id)); $result = $db->sql_query('SELECT group_id, group_legend @@ -387,10 +387,10 @@ class phpbb_groupposition_legend_test extends phpbb_database_test_case $cache = new phpbb_mock_cache; $db = $this->new_dbal(); - $user = new phpbb_user; + $user = new \phpbb\user; $user->lang = array(); - $test_class = new phpbb_groupposition_legend($db, $user); + $test_class = new \phpbb\groupposition\legend($db, $user); $this->assertEquals($excepted_moved, $test_class->move($group_id, $increment)); $result = $db->sql_query('SELECT group_id, group_legend diff --git a/tests/groupposition/teampage_test.php b/tests/groupposition/teampage_test.php index db26cd09d5..ec89f56775 100644 --- a/tests/groupposition/teampage_test.php +++ b/tests/groupposition/teampage_test.php @@ -22,7 +22,7 @@ class phpbb_groupposition_teampage_test extends phpbb_database_test_case return array( array(2, 3, ''), array(6, 8, ''), - array(10, 0, 'phpbb_groupposition_exception'), + array(10, 0, '\phpbb\groupposition\exception'), ); } @@ -35,7 +35,7 @@ class phpbb_groupposition_teampage_test extends phpbb_database_test_case $cache = new phpbb_mock_cache; $db = $this->new_dbal(); - $user = new phpbb_user; + $user = new \phpbb\user; $user->lang = array(); if ($throws_exception) @@ -43,7 +43,7 @@ class phpbb_groupposition_teampage_test extends phpbb_database_test_case $this->setExpectedException($throws_exception); } - $test_class = new phpbb_groupposition_teampage($db, $user, $cache); + $test_class = new \phpbb\groupposition\teampage($db, $user, $cache); $this->assertEquals($expected, $test_class->get_group_value($group_id)); } @@ -53,10 +53,10 @@ class phpbb_groupposition_teampage_test extends phpbb_database_test_case $cache = new phpbb_mock_cache; $db = $this->new_dbal(); - $user = new phpbb_user; + $user = new \phpbb\user; $user->lang = array(); - $test_class = new phpbb_groupposition_teampage($db, $user, $cache); + $test_class = new \phpbb\groupposition\teampage($db, $user, $cache); $this->assertEquals(8, $test_class->get_group_count()); } @@ -137,10 +137,10 @@ class phpbb_groupposition_teampage_test extends phpbb_database_test_case $cache = new phpbb_mock_cache; $db = $this->new_dbal(); - $user = new phpbb_user; + $user = new \phpbb\user; $user->lang = array(); - $test_class = new phpbb_groupposition_teampage($db, $user, $cache); + $test_class = new \phpbb\groupposition\teampage($db, $user, $cache); $this->assertEquals($expected_added, $test_class->add_group_teampage($group_id, $parent_id)); $result = $db->sql_query('SELECT teampage_position, group_id, teampage_parent, teampage_name @@ -180,10 +180,10 @@ class phpbb_groupposition_teampage_test extends phpbb_database_test_case $cache = new phpbb_mock_cache; $db = $this->new_dbal(); - $user = new phpbb_user; + $user = new \phpbb\user; $user->lang = array(); - $test_class = new phpbb_groupposition_teampage($db, $user, $cache); + $test_class = new \phpbb\groupposition\teampage($db, $user, $cache); $this->assertEquals($expected_added, $test_class->add_category_teampage($group_name)); $result = $db->sql_query('SELECT teampage_position, group_id, teampage_parent, teampage_name @@ -247,10 +247,10 @@ class phpbb_groupposition_teampage_test extends phpbb_database_test_case $cache = new phpbb_mock_cache; $db = $this->new_dbal(); - $user = new phpbb_user; + $user = new \phpbb\user; $user->lang = array(); - $test_class = new phpbb_groupposition_teampage($db, $user, $cache); + $test_class = new \phpbb\groupposition\teampage($db, $user, $cache); $this->assertEquals($expected_deleted, $test_class->delete_group($group_id, false)); $result = $db->sql_query('SELECT teampage_position, group_id, teampage_parent, teampage_name @@ -299,10 +299,10 @@ class phpbb_groupposition_teampage_test extends phpbb_database_test_case $cache = new phpbb_mock_cache; $db = $this->new_dbal(); - $user = new phpbb_user; + $user = new \phpbb\user; $user->lang = array(); - $test_class = new phpbb_groupposition_teampage($db, $user, $cache); + $test_class = new \phpbb\groupposition\teampage($db, $user, $cache); $this->assertEquals($expected_deleted, $test_class->delete_teampage($teampage_id, false)); $result = $db->sql_query('SELECT teampage_position, group_id, teampage_parent, teampage_name @@ -462,10 +462,10 @@ class phpbb_groupposition_teampage_test extends phpbb_database_test_case $cache = new phpbb_mock_cache; $db = $this->new_dbal(); - $user = new phpbb_user; + $user = new \phpbb\user; $user->lang = array(); - $test_class = new phpbb_groupposition_teampage($db, $user, $cache); + $test_class = new \phpbb\groupposition\teampage($db, $user, $cache); $this->assertEquals($excepted_moved, $test_class->move($group_id, $move_delta)); $result = $db->sql_query('SELECT teampage_position, group_id, teampage_parent, teampage_name @@ -625,10 +625,10 @@ class phpbb_groupposition_teampage_test extends phpbb_database_test_case $cache = new phpbb_mock_cache; $db = $this->new_dbal(); - $user = new phpbb_user; + $user = new \phpbb\user; $user->lang = array(); - $test_class = new phpbb_groupposition_teampage($db, $user, $cache); + $test_class = new \phpbb\groupposition\teampage($db, $user, $cache); $this->assertEquals($excepted_moved, $test_class->move_teampage($teampage_id, $move_delta)); $result = $db->sql_query('SELECT teampage_position, group_id, teampage_parent, teampage_name diff --git a/tests/lock/db_test.php b/tests/lock/db_test.php index de7a23fd05..da689b7fa3 100644 --- a/tests/lock/db_test.php +++ b/tests/lock/db_test.php @@ -25,9 +25,9 @@ class phpbb_lock_db_test extends phpbb_database_test_case global $db, $config; $db = $this->db = $this->new_dbal(); - $config = $this->config = new phpbb_config(array('rand_seed' => '', 'rand_seed_last_update' => '0')); + $config = $this->config = new \phpbb\config\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); + $this->lock = new \phpbb\lock\db('test_lock', $this->config, $this->db); } public function test_new_lock() @@ -38,7 +38,7 @@ class phpbb_lock_db_test extends phpbb_database_test_case $this->assertTrue($this->lock->owns_lock()); $this->assertTrue(isset($this->config['test_lock']), 'Lock was created'); - $lock2 = new phpbb_lock_db('test_lock', $this->config, $this->db); + $lock2 = new \phpbb\lock\db('test_lock', $this->config, $this->db); $this->assertFalse($lock2->acquire()); $this->assertFalse($lock2->owns_lock()); @@ -49,7 +49,7 @@ class phpbb_lock_db_test extends phpbb_database_test_case public function test_expire_lock() { - $lock = new phpbb_lock_db('foo_lock', $this->config, $this->db); + $lock = new \phpbb\lock\db('foo_lock', $this->config, $this->db); $this->assertTrue($lock->acquire()); } @@ -82,7 +82,7 @@ class phpbb_lock_db_test extends phpbb_database_test_case $this->assertFalse($this->lock->owns_lock()); $this->assertEquals('0', $this->config['test_lock'], 'First lock is released'); - $lock2 = new phpbb_lock_db('test_lock', $this->config, $this->db); + $lock2 = new \phpbb\lock\db('test_lock', $this->config, $this->db); $this->assertTrue($lock2->acquire()); $this->assertTrue($lock2->owns_lock()); $this->assertFalse(empty($this->config['test_lock']), 'Second lock is acquired'); diff --git a/tests/lock/flock_test.php b/tests/lock/flock_test.php index 8f0b866ab3..5e5ac5aa78 100644 --- a/tests/lock/flock_test.php +++ b/tests/lock/flock_test.php @@ -13,7 +13,7 @@ class phpbb_lock_flock_test extends phpbb_test_case { $path = __DIR__ . '/../tmp/precious'; - $lock = new phpbb_lock_flock($path); + $lock = new \phpbb\lock\flock($path); $ok = $lock->acquire(); $this->assertTrue($ok); $lock->release(); @@ -23,7 +23,7 @@ class phpbb_lock_flock_test extends phpbb_test_case { $path = __DIR__ . '/../tmp/precious'; - $lock = new phpbb_lock_flock($path); + $lock = new \phpbb\lock\flock($path); $ok = $lock->acquire(); $this->assertTrue($ok); $this->assertTrue($lock->owns_lock()); @@ -48,11 +48,11 @@ class phpbb_lock_flock_test extends phpbb_test_case { $path = __DIR__ . '/../tmp/precious'; - $lock1 = new phpbb_lock_flock($path); + $lock1 = new \phpbb\lock\flock($path); $ok = $lock1->acquire(); $this->assertTrue($ok); - $lock2 = new phpbb_lock_flock($path); + $lock2 = new \phpbb\lock\flock($path); $ok = $lock2->acquire(); $this->assertFalse($ok); @@ -78,7 +78,7 @@ class phpbb_lock_flock_test extends phpbb_test_case // wait 0.5 s, acquire the lock, note how long it took sleep(1); - $lock = new phpbb_lock_flock($path); + $lock = new \phpbb\lock\flock($path); $start = time(); $ok = $lock->acquire(); $delta = time() - $start; @@ -105,7 +105,7 @@ class phpbb_lock_flock_test extends phpbb_test_case { // child // immediately acquire the lock and sleep for 2 s - $lock = new phpbb_lock_flock($path); + $lock = new \phpbb\lock\flock($path); $ok = $lock->acquire(); $this->assertTrue($ok); $this->assertTrue($lock->owns_lock()); diff --git a/tests/log/add_test.php b/tests/log/add_test.php index a5f93232f2..032546f002 100644 --- a/tests/log/add_test.php +++ b/tests/log/add_test.php @@ -23,10 +23,10 @@ class phpbb_log_add_test extends phpbb_database_test_case $db = $this->new_dbal(); $cache = new phpbb_mock_cache; $phpbb_dispatcher = new phpbb_mock_event_dispatcher(); - $user = $this->getMock('phpbb_user'); - $auth = $this->getMock('phpbb_auth'); + $user = $this->getMock('\phpbb\user'); + $auth = $this->getMock('\phpbb\auth\auth'); - $log = new phpbb_log($db, $user, $auth, $phpbb_dispatcher, $phpbb_root_path, 'adm/', $phpEx, LOG_TABLE); + $log = new \phpbb\log\log($db, $user, $auth, $phpbb_dispatcher, $phpbb_root_path, 'adm/', $phpEx, LOG_TABLE); $this->assertTrue($log->is_enabled(), 'Initialise failed'); @@ -52,10 +52,10 @@ class phpbb_log_add_test extends phpbb_database_test_case $db = $this->new_dbal(); $cache = new phpbb_mock_cache; $phpbb_dispatcher = new phpbb_mock_event_dispatcher(); - $user = $this->getMock('phpbb_user'); - $auth = $this->getMock('phpbb_auth'); + $user = $this->getMock('\phpbb\user'); + $auth = $this->getMock('\phpbb\auth\auth'); - $log = new phpbb_log($db, $user, $auth, $phpbb_dispatcher, $phpbb_root_path, 'adm/', $phpEx, LOG_TABLE); + $log = new \phpbb\log\log($db, $user, $auth, $phpbb_dispatcher, $phpbb_root_path, 'adm/', $phpEx, LOG_TABLE); $mode = 'critical'; $user_id = ANONYMOUS; diff --git a/tests/log/function_add_log_test.php b/tests/log/function_add_log_test.php index 7aa42be6df..e1bcd4acaf 100644 --- a/tests/log/function_add_log_test.php +++ b/tests/log/function_add_log_test.php @@ -157,10 +157,10 @@ class phpbb_log_function_add_log_test extends phpbb_database_test_case $db = $this->new_dbal(); $cache = new phpbb_mock_cache; $phpbb_dispatcher = new phpbb_mock_event_dispatcher(); - $user = $this->getMock('phpbb_user'); - $auth = $this->getMock('phpbb_auth'); + $user = $this->getMock('\phpbb\user'); + $auth = $this->getMock('\phpbb\auth\auth'); - $phpbb_log = new phpbb_log($db, $user, $auth, $phpbb_dispatcher, $phpbb_root_path, 'adm/', $phpEx, LOG_TABLE); + $phpbb_log = new \phpbb\log\log($db, $user, $auth, $phpbb_dispatcher, $phpbb_root_path, 'adm/', $phpEx, LOG_TABLE); $user->ip = 'user_ip'; if ($user_id) diff --git a/tests/log/function_view_log_test.php b/tests/log/function_view_log_test.php index 6827aaa1b6..017484e8a7 100644 --- a/tests/log/function_view_log_test.php +++ b/tests/log/function_view_log_test.php @@ -306,7 +306,7 @@ class phpbb_log_function_view_log_test extends phpbb_database_test_case $phpbb_dispatcher = new phpbb_mock_event_dispatcher(); // Create auth mock - $auth = $this->getMock('phpbb_auth'); + $auth = $this->getMock('\phpbb\auth\auth'); $acl_get_map = array( array('f_read', 23, true), array('m_', 23, true), @@ -333,7 +333,7 @@ class phpbb_log_function_view_log_test extends phpbb_database_test_case 'LOG_INSTALL_INSTALLED' => 'installed: %s', ); - $phpbb_log = new phpbb_log($db, $user, $auth, $phpbb_dispatcher, $phpbb_root_path, 'adm/', $phpEx, LOG_TABLE); + $phpbb_log = new \phpbb\log\log($db, $user, $auth, $phpbb_dispatcher, $phpbb_root_path, 'adm/', $phpEx, LOG_TABLE); $log = array(); $this->assertEquals($expected_returned, view_log($mode, $log, $log_count, $limit, $offset, $forum_id, $topic_id, $user_id, $limit_days, $sort_by, $keywords)); diff --git a/tests/mock/auth_provider.php b/tests/mock/auth_provider.php index 9d002334d6..734e682ee9 100644 --- a/tests/mock/auth_provider.php +++ b/tests/mock/auth_provider.php @@ -10,14 +10,9 @@ /** * Mock auth provider class with basic functions to help test sessions. */ -class phpbb_mock_auth_provider implements phpbb_auth_provider_interface +class phpbb_mock_auth_provider extends \phpbb\auth\provider\base { - function init() - { - return null; - } - - function login($username, $password) + public function login($username, $password) { return array( 'status' => "", @@ -25,29 +20,4 @@ class phpbb_mock_auth_provider implements phpbb_auth_provider_interface 'user_row' => "", ); } - - function autologin() - { - return array(); - } - - function acp() - { - return array(); - } - - function logout($data, $new_session) - { - return null; - } - - function validate_session($user) - { - return null; - } - - public function get_acp_template($new_config) - { - return null; - } } diff --git a/tests/mock/cache.php b/tests/mock/cache.php index 440592665a..83bbb8ef30 100644 --- a/tests/mock/cache.php +++ b/tests/mock/cache.php @@ -7,7 +7,7 @@ * */ -class phpbb_mock_cache implements phpbb_cache_driver_interface +class phpbb_mock_cache implements \phpbb\cache\driver\driver_interface { protected $data; @@ -140,7 +140,7 @@ class phpbb_mock_cache implements phpbb_cache_driver_interface /** * {@inheritDoc} */ - public function sql_save(phpbb_db_driver $db, $query, $query_result, $ttl) + public function sql_save(\phpbb\db\driver\driver $db, $query, $query_result, $ttl) { return $query_result; } diff --git a/tests/mock/extension_manager.php b/tests/mock/extension_manager.php index 10b3595206..0c6b8447f1 100644 --- a/tests/mock/extension_manager.php +++ b/tests/mock/extension_manager.php @@ -7,13 +7,19 @@ * */ -class phpbb_mock_extension_manager extends phpbb_extension_manager +class phpbb_mock_extension_manager extends \phpbb\extension\manager { public function __construct($phpbb_root_path, $extensions = array()) { $this->phpbb_root_path = $phpbb_root_path; $this->php_ext = 'php'; $this->extensions = $extensions; - $this->filesystem = new phpbb_filesystem(); + $this->filesystem = new \phpbb\filesystem( + new \phpbb\symfony_request( + new phpbb_mock_request() + ), + $this->phpbb_root_path, + $this->php_ext + ); } } diff --git a/tests/mock/metadata_manager.php b/tests/mock/metadata_manager.php index a7fbf0681c..b6489acfa4 100644 --- a/tests/mock/metadata_manager.php +++ b/tests/mock/metadata_manager.php @@ -7,7 +7,7 @@ * */ -class phpbb_mock_metadata_manager extends phpbb_extension_metadata_manager +class phpbb_mock_metadata_manager extends \phpbb\extension\metadata_manager { public function set_metadata($metadata) { diff --git a/tests/mock/notifications_auth.php b/tests/mock/notifications_auth.php index d960acb81a..2d387d8c00 100644 --- a/tests/mock/notifications_auth.php +++ b/tests/mock/notifications_auth.php @@ -7,7 +7,7 @@ * */ -class phpbb_mock_notifications_auth extends phpbb_auth +class phpbb_mock_notifications_auth extends \phpbb\auth\auth { function acl_get_list($user_id = false, $opts = false, $forum_id = false) { diff --git a/tests/mock/request.php b/tests/mock/request.php index 2a272fc03b..60ba725abd 100644 --- a/tests/mock/request.php +++ b/tests/mock/request.php @@ -7,33 +7,33 @@ * */ -class phpbb_mock_request implements phpbb_request_interface +class phpbb_mock_request implements \phpbb\request\request_interface { protected $data; public function __construct($get = array(), $post = array(), $cookie = array(), $server = array(), $request = false, $files = array()) { - $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; - $this->data[phpbb_request_interface::SERVER] = $server; - $this->data[phpbb_request_interface::FILES] = $files; + $this->data[\phpbb\request\request_interface::GET] = $get; + $this->data[\phpbb\request\request_interface::POST] = $post; + $this->data[\phpbb\request\request_interface::COOKIE] = $cookie; + $this->data[\phpbb\request\request_interface::REQUEST] = ($request === false) ? $post + $get : $request; + $this->data[\phpbb\request\request_interface::SERVER] = $server; + $this->data[\phpbb\request\request_interface::FILES] = $files; } - public function overwrite($var_name, $value, $super_global = phpbb_request_interface::REQUEST) + public function overwrite($var_name, $value, $super_global = \phpbb\request\request_interface::REQUEST) { $this->data[$super_global][$var_name] = $value; } - public function variable($var_name, $default, $multibyte = false, $super_global = phpbb_request_interface::REQUEST) + public function variable($var_name, $default, $multibyte = false, $super_global = \phpbb\request\request_interface::REQUEST) { return isset($this->data[$super_global][$var_name]) ? $this->data[$super_global][$var_name] : $default; } public function server($var_name, $default = '') { - $super_global = phpbb_request_interface::SERVER; + $super_global = \phpbb\request\request_interface::SERVER; return isset($this->data[$super_global][$var_name]) ? $this->data[$super_global][$var_name] : $default; } @@ -45,16 +45,16 @@ class phpbb_mock_request implements phpbb_request_interface public function file($form_name) { - $super_global = phpbb_request_interface::FILES; + $super_global = \phpbb\request\request_interface::FILES; return isset($this->data[$super_global][$form_name]) ? $this->data[$super_global][$form_name] : array(); } public function is_set_post($name) { - return $this->is_set($name, phpbb_request_interface::POST); + return $this->is_set($name, \phpbb\request\request_interface::POST); } - public function is_set($var, $super_global = phpbb_request_interface::REQUEST) + public function is_set($var, $super_global = \phpbb\request\request_interface::REQUEST) { return isset($this->data[$super_global][$var]); } @@ -69,20 +69,25 @@ class phpbb_mock_request implements phpbb_request_interface return false; } - public function variable_names($super_global = phpbb_request_interface::REQUEST) + public function variable_names($super_global = \phpbb\request\request_interface::REQUEST) { return array_keys($this->data[$super_global]); } + public function get_super_global($super_global = \phpbb\request\request_interface::REQUEST) + { + return $this->data[$super_global]; + } + /* custom methods */ public function set_header($header_name, $value) { $var_name = 'HTTP_' . str_replace('-', '_', strtoupper($header_name)); - $this->data[phpbb_request_interface::SERVER][$var_name] = $value; + $this->data[\phpbb\request\request_interface::SERVER][$var_name] = $value; } - public function merge($super_global = phpbb_request_interface::REQUEST, $values) + public function merge($super_global = \phpbb\request\request_interface::REQUEST, $values) { $this->data[$super_global] = array_merge($this->data[$super_global], $values); } diff --git a/tests/mock/session_testable.php b/tests/mock/session_testable.php index 283f9af192..d81ae3163e 100644 --- a/tests/mock/session_testable.php +++ b/tests/mock/session_testable.php @@ -16,7 +16,7 @@ require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php'; * test it without warnings about sent headers. This class only stores cookie * data for later verification. */ -class phpbb_mock_session_testable extends phpbb_session +class phpbb_mock_session_testable extends \phpbb\session { private $_cookies = array(); diff --git a/tests/mock/sql_insert_buffer.php b/tests/mock/sql_insert_buffer.php index ba09aa8d7f..aa7c54dddd 100644 --- a/tests/mock/sql_insert_buffer.php +++ b/tests/mock/sql_insert_buffer.php @@ -7,7 +7,7 @@ * */ -class phpbb_mock_sql_insert_buffer extends phpbb_db_sql_insert_buffer +class phpbb_mock_sql_insert_buffer extends \phpbb\db\sql_insert_buffer { public function flush() { diff --git a/tests/notification/base.php b/tests/notification/base.php new file mode 100644 index 0000000000..549545f01b --- /dev/null +++ b/tests/notification/base.php @@ -0,0 +1,131 @@ +<?php +/** +* +* @package testing +* @copyright (c) 2013 phpBB Group +* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 +* +*/ + +require_once dirname(__FILE__) . '/manager_helper.php'; + +abstract class phpbb_tests_notification_base extends phpbb_database_test_case +{ + protected $notifications, $db, $container, $user, $config, $auth, $cache; + + protected function get_notification_types() + { + return array( + 'test', + 'approve_post', + 'approve_topic', + 'bookmark', + 'disapprove_post', + 'disapprove_topic', + 'pm', + 'post', + 'post_in_queue', + 'quote', + 'report_pm', + 'report_pm_closed', + 'report_post', + 'report_post_closed', + 'topic', + 'topic_in_queue', + ); + } + + protected function setUp() + { + parent::setUp(); + + global $phpbb_root_path, $phpEx; + + include_once(__DIR__ . '/ext/test/notification/type/test.' . $phpEx); + + global $db, $config, $user, $auth, $cache, $phpbb_container; + + $db = $this->db = $this->new_dbal(); + $config = $this->config = new \phpbb\config\config(array( + 'allow_privmsg' => true, + 'allow_bookmarks' => true, + 'allow_topic_notify' => true, + 'allow_forum_notify' => true, + )); + $user = $this->user = new \phpbb\user(); + $this->user_loader = new \phpbb\user_loader($this->db, $phpbb_root_path, $phpEx, 'phpbb_users'); + $auth = $this->auth = new phpbb_mock_notifications_auth(); + $cache = $this->cache = new \phpbb\cache\service( + new \phpbb\cache\driver\null(), + $this->config, + $this->db, + $phpbb_root_path, + $phpEx + ); + + $phpbb_container = $this->container = new phpbb_mock_container_builder(); + + $this->notifications = new phpbb_notification_manager_helper( + array(), + array(), + $this->container, + $this->user_loader, + $this->db, + $this->cache, + $this->user, + $phpbb_root_path, + $phpEx, + 'phpbb_notification_types', + 'phpbb_notifications', + 'phpbb_user_notifications' + ); + + $phpbb_container->set('notification_manager', $this->notifications); + + $this->notifications->setDependencies($this->auth, $this->config); + + $types = array(); + foreach ($this->get_notification_types() as $type) + { + $class = $this->build_type('phpbb\notification\type\\' . $type); + + $types[$type] = $class; + $this->container->set('notification.type.' . $type, $class); + } + + $this->notifications->set_var('notification_types', $types); + + $this->db->sql_query('DELETE FROM phpbb_notification_types'); + $this->db->sql_query('DELETE FROM phpbb_notifications'); + $this->db->sql_query('DELETE FROM phpbb_user_notifications'); + } + + protected function build_type($type) + { + global $phpbb_root_path, $phpEx; + + return new $type($this->user_loader, $this->db, $this->cache->get_driver(), $this->user, $this->auth, $this->config, $phpbb_root_path, $phpEx, 'phpbb_notification_types', 'phpbb_notifications', 'phpbb_user_notifications'); + } + + protected function assert_notifications($expected, $options = array()) + { + $notifications = $this->notifications->load_notifications(array_merge(array( + 'count_unread' => true, + 'order_by' => 'notification_time', + 'order_dir' => 'ASC', + ), $options)); + + $this->assertEquals(sizeof($expected), $notifications['unread_count']); + + $i = 0; + foreach ($notifications['notifications'] as $notification) + { + foreach ($expected[$i] as $key => $value) + { + $this->assertEquals($value, $notification->$key, $i . ' ' . $key); + } + + $i++; + } + } +} diff --git a/tests/notification/convert_test.php b/tests/notification/convert_test.php index c038020385..ed1fa9b1bf 100644 --- a/tests/notification/convert_test.php +++ b/tests/notification/convert_test.php @@ -25,10 +25,10 @@ class phpbb_notification_convert_test extends phpbb_database_test_case $this->db = $this->new_dbal(); - $this->migration = new phpbb_db_migration_data_310_notification_options_reconvert( - new phpbb_config(array()), + $this->migration = new \phpbb\db\migration\data\v310\notification_options_reconvert( + new \phpbb\config\config(array()), $this->db, - new phpbb_db_tools($this->db), + new \phpbb\db\tools($this->db), $phpbb_root_path, $phpEx, 'phpbb_' diff --git a/tests/notification/ext/test/notification/type/test.php b/tests/notification/ext/test/notification/type/test.php index 0d0c584e0d..cdb921ca3b 100644 --- a/tests/notification/ext/test/notification/type/test.php +++ b/tests/notification/ext/test/notification/type/test.php @@ -7,6 +7,8 @@ * */ +namespace phpbb\notification\type; + /** * @ignore */ @@ -15,7 +17,7 @@ if (!defined('IN_PHPBB')) exit; } -class phpbb_notification_type_test extends phpbb_notification_type_base +class test extends \phpbb\notification\type\base { public function get_type() { diff --git a/tests/notification/fixtures/group_request.xml b/tests/notification/fixtures/group_request.xml new file mode 100644 index 0000000000..1eb73f1e15 --- /dev/null +++ b/tests/notification/fixtures/group_request.xml @@ -0,0 +1,30 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<dataset> + <table name="phpbb_users"> + <column>user_id</column> + <column>username</column> + <column>username_clean</column> + <column>user_permissions</column> + <column>user_sig</column> + <column>user_occ</column> + <column>user_interests</column> + <row> + <value>2</value> + <value>2</value> + <value>2</value> + <value></value> + <value></value> + <value></value> + <value></value> + </row> + <row> + <value>3</value> + <value>3</value> + <value>3</value> + <value></value> + <value></value> + <value></value> + <value></value> + </row> + </table> +</dataset> diff --git a/tests/notification/group_request_test.php b/tests/notification/group_request_test.php new file mode 100644 index 0000000000..b812fff8f8 --- /dev/null +++ b/tests/notification/group_request_test.php @@ -0,0 +1,109 @@ +<?php +/** +* +* @package testing +* @copyright (c) 2013 phpBB Group +* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 +* +*/ + +require_once dirname(__FILE__) . '/base.php'; + +class phpbb_notification_group_request_test extends phpbb_tests_notification_base +{ + public function getDataSet() + { + return $this->createXMLDataSet(dirname(__FILE__) . '/fixtures/group_request.xml'); + } + + protected function get_notification_types() + { + return array_merge( + parent::get_notification_types(), + array( + 'group_request', + 'group_request_approved', + ) + ); + } + + public function test_notifications() + { + global $phpbb_root_path, $phpEx, $phpbb_dispatcher, $phpbb_log; + + include_once($phpbb_root_path . 'includes/utf/utf_tools.' . $phpEx); + include_once($phpbb_root_path . 'includes/functions_user.' . $phpEx); + include_once($phpbb_root_path . 'includes/functions_content.' . $phpEx); + + set_config(false, false, false, $this->config); + + $this->container->set('groupposition.legend', new \phpbb\groupposition\legend( + $this->db, + $this->user + )); + $this->container->set('groupposition.teampage', new \phpbb\groupposition\teampage( + $this->db, + $this->user, + $this->cache->get_driver() + )); + $phpbb_dispatcher = new phpbb_mock_event_dispatcher; + $phpbb_log = new \phpbb\log\null(); + + // Now on to the actual test + + $group_id = false; + group_create($group_id, GROUP_OPEN, 'test', 'test group', array()); + + // Add user 2 as group leader + group_user_add($group_id, 2, false, false, false, true, false); + + // Add user 3 as pending + group_user_add($group_id, 3, false, false, false, false, true); + + $this->assert_notifications( + array( + // user 3 pending notification + array( + 'item_id' => 3, // user_id of requesting join + 'item_parent_id' => $group_id, + 'user_id' => 2, + 'notification_read' => 0, + 'notification_data' => array( + 'group_name' => 'test', + ), + ), + ), + array( + 'user_id' => 2, + ) + ); + + // Approve user 3 joining the group + group_user_attributes('approve', $group_id, array(3)); + + // user 3 pending notification should have been deleted + $this->assert_notifications( + array(), + array( + 'user_id' => 2, + ) + ); + + $this->assert_notifications( + array( + // user 3 approved notification + array( + 'item_id' => $group_id, // user_id of requesting join + 'user_id' => 3, + 'notification_read' => 0, + 'notification_data' => array( + 'group_name' => 'test', + ), + ), + ), + array( + 'user_id' => 3, + ) + ); + } +} diff --git a/tests/notification/manager_helper.php b/tests/notification/manager_helper.php index 7a794f922f..731dd00b7a 100644 --- a/tests/notification/manager_helper.php +++ b/tests/notification/manager_helper.php @@ -19,7 +19,7 @@ if (!defined('IN_PHPBB')) * Notifications service class * @package notifications */ -class phpbb_notification_manager_helper extends phpbb_notification_manager +class phpbb_notification_manager_helper extends \phpbb\notification\manager { public function set_var($name, $value) { @@ -40,7 +40,7 @@ class phpbb_notification_manager_helper extends phpbb_notification_manager */ public function get_item_type_class($item_type, $data = array()) { - $item_type = 'phpbb_notification_type_' . $item_type; + $item_type = 'phpbb\notification\type\\' . $item_type; $item = new $item_type($this->user_loader, $this->db, $this->cache->get_driver(), $this->user, $this->auth, $this->config, $this->phpbb_root_path, $this->php_ext, $this->notification_types_table, $this->notifications_table, $this->user_notifications_table); @@ -56,7 +56,7 @@ class phpbb_notification_manager_helper extends phpbb_notification_manager */ public function get_method_class($method_name) { - $method_name = 'phpbb_notification_method_' . $method_name; + $method_name = 'phpbb\notification\method\\' . $method_name; $method = new $method_name($this->user_loader, $this->db, $this->cache->get_driver(), $this->user, $this->auth, $this->config, $this->phpbb_root_path, $this->php_ext, $this->notification_types_table, $this->notifications_table, $this->user_notifications_table); diff --git a/tests/notification/notification_test.php b/tests/notification/notification_test.php index 8f7eb3b8a8..e1788e8670 100644 --- a/tests/notification/notification_test.php +++ b/tests/notification/notification_test.php @@ -7,9 +7,9 @@ * */ -require_once dirname(__FILE__) . '/manager_helper.php'; +require_once dirname(__FILE__) . '/base.php'; -class phpbb_notification_test extends phpbb_database_test_case +class phpbb_notification_test extends phpbb_tests_notification_base { protected $notifications, $db, $container, $user, $config, $auth, $cache; @@ -18,98 +18,17 @@ class phpbb_notification_test extends phpbb_database_test_case return $this->createXMLDataSet(dirname(__FILE__) . '/fixtures/notification.xml'); } - protected function setUp() - { - parent::setUp(); - - global $phpbb_root_path, $phpEx; - - include_once(__DIR__ . '/ext/test/notification/type/test.' . $phpEx); - - $this->db = $this->new_dbal(); - $this->config = new phpbb_config(array( - 'allow_privmsg' => true, - 'allow_bookmarks' => true, - 'allow_topic_notify' => true, - 'allow_forum_notify' => true, - )); - $this->user = new phpbb_user(); - $this->user_loader = new phpbb_user_loader($this->db, $phpbb_root_path, $phpEx, 'phpbb_users'); - $this->auth = new phpbb_mock_notifications_auth(); - $this->cache = new phpbb_cache_service( - new phpbb_cache_driver_null(), - $this->config, - $this->db, - $phpbb_root_path, - $phpEx - ); - - $this->container = new phpbb_mock_container_builder(); - - $this->notifications = new phpbb_notification_manager_helper( - array(), - array(), - $this->container, - $this->user_loader, - $this->db, - $this->cache, - $this->user, - $phpbb_root_path, - $phpEx, - 'phpbb_notification_types', - 'phpbb_notifications', - 'phpbb_user_notifications' - ); - - $this->notifications->setDependencies($this->auth, $this->config); - - $types = array(); - foreach (array( - 'test', - 'approve_post', - 'approve_topic', - 'bookmark', - 'disapprove_post', - 'disapprove_topic', - 'pm', - 'post', - 'post_in_queue', - 'quote', - 'report_pm', - 'report_pm_closed', - 'report_post', - 'report_post_closed', - 'topic', - 'topic_in_queue', - ) as $type) - { - $class = $this->build_type('phpbb_notification_type_' . $type); - - $types[$type] = $class; - $this->container->set('notification.type.' . $type, $class); - } - - $this->notifications->set_var('notification_types', $types); - } - - protected function build_type($type) - { - global $phpbb_root_path, $phpEx; - - return new $type($this->user_loader, $this->db, $this->cache->get_driver(), $this->user, $this->auth, $this->config, $phpbb_root_path, $phpEx, 'phpbb_notification_types', 'phpbb_notifications', 'phpbb_user_notifications'); - } - public function test_get_notification_type_id() { // They should be inserted the first time - $this->assertEquals(1, $this->notifications->get_notification_type_id('post')); - $this->assertEquals(2, $this->notifications->get_notification_type_id('quote')); - $this->assertEquals(3, $this->notifications->get_notification_type_id('test')); + $post_type_id = $this->notifications->get_notification_type_id('post'); + $quote_type_id = $this->notifications->get_notification_type_id('quote'); + $test_type_id = $this->notifications->get_notification_type_id('test'); $this->assertEquals(array( - 'test' => 3, - 'quote' => 2, - 'post' => 1, + 'test' => $test_type_id, + 'quote' => $quote_type_id, + 'post' => $post_type_id, ), $this->notifications->get_notification_type_ids(array( 'test', @@ -117,11 +36,11 @@ class phpbb_notification_test extends phpbb_database_test_case 'post', ) )); - $this->assertEquals(2, $this->notifications->get_notification_type_id('quote')); + $this->assertEquals($quote_type_id, $this->notifications->get_notification_type_id('quote')); try { - $this->assertEquals(3, $this->notifications->get_notification_type_id('fail')); + $this->assertEquals(false, $this->notifications->get_notification_type_id('fail')); $this->fail('Non-existent type should throw an exception'); } @@ -241,88 +160,65 @@ class phpbb_notification_test extends phpbb_database_test_case 'post_time' => 1349413326, )); - $notifications = $this->notifications->load_notifications(array( - 'count_unread' => true, - )); - - $expected = array( - 1 => array( - 'notification_type_id' => 4, - 'item_id' => 1, - 'item_parent_id' => 1, - 'user_id' => 0, - 'notification_read' => 0, - 'notification_time' => 1349413321, - 'notification_data' => array(), - ), - 2 => array( - 'notification_type_id' => 4, - 'item_id' => 2, - 'item_parent_id' => 2, - 'user_id' => 0, - 'notification_read' => 0, - 'notification_time' => 1349413322, - 'notification_data' => array(), - ), - 3 => array( - 'notification_type_id' => 4, - 'item_id' => 3, - 'item_parent_id' => 2, - 'user_id' => 0, - 'notification_read' => 0, - 'notification_time' => 1349413323, - 'notification_data' => array(), - ), - 4 => array( - 'notification_type_id' => 3, - 'item_id' => 4, - 'item_parent_id' => 2, - 'user_id' => 0, - 'notification_read' => 0, - 'notification_time' => 1349413324, - 'notification_data' => array( - 'poster_id' => 2, - 'topic_title' => 'test-title', - 'post_subject' => 'Re: test-title', - 'post_username' => '', - 'forum_id' => 2, - 'forum_name' => 'Your first forum', + $this->assert_notifications( + array( + array( + 'item_id' => 1, + 'item_parent_id' => 1, + 'user_id' => 0, + 'notification_read' => 0, + 'notification_time' => 1349413321, + 'notification_data' => array(), ), - ), - 5 => array( - 'notification_type_id' => 2, - 'item_id' => 5, - 'item_parent_id' => 2, - 'user_id' => 0, - 'notification_read' => 0, - 'notification_time' => 1349413325, - 'notification_data' => array( - 'poster_id' => 2, - 'topic_title' => 'test-title', - 'post_subject' => 'Re: test-title', - 'post_username' => '', - 'forum_id' => 2, - 'forum_name' => 'Your first forum', + array( + 'item_id' => 2, + 'item_parent_id' => 2, + 'user_id' => 0, + 'notification_read' => 0, + 'notification_time' => 1349413322, + 'notification_data' => array(), ), - ), + array( + 'item_id' => 3, + 'item_parent_id' => 2, + 'user_id' => 0, + 'notification_read' => 0, + 'notification_time' => 1349413323, + 'notification_data' => array(), + ), + array( + 'item_id' => 4, + 'item_parent_id' => 2, + 'user_id' => 0, + 'notification_read' => 0, + 'notification_time' => 1349413324, + 'notification_data' => array( + 'poster_id' => 2, + 'topic_title' => 'test-title', + 'post_subject' => 'Re: test-title', + 'post_username' => '', + 'forum_id' => 2, + 'forum_name' => 'Your first forum', + ), + ), + array( + 'item_id' => 5, + 'item_parent_id' => 2, + 'user_id' => 0, + 'notification_read' => 0, + 'notification_time' => 1349413325, + 'notification_data' => array( + 'poster_id' => 2, + 'topic_title' => 'test-title', + 'post_subject' => 'Re: test-title', + 'post_username' => '', + 'forum_id' => 2, + 'forum_name' => 'Your first forum', + ), + ), + ) ); - $this->assertEquals(sizeof($expected), $notifications['unread_count']); - - $notifications = $notifications['notifications']; - - foreach ($expected as $notification_id => $notification_data) - { - //echo $notifications[$notification_id]; - - $this->assertEquals($notification_id, $notifications[$notification_id]->notification_id, 'notification_id'); - - foreach ($notification_data as $key => $value) - { - $this->assertEquals($value, $notifications[$notification_id]->$key, $key . ' ' . $notification_id); - } - } - // Now test updating ------------------------------- $this->notifications->update_notifications('test', array( @@ -347,86 +243,63 @@ class phpbb_notification_test extends phpbb_database_test_case 'forum_name' => 'Your second forum', // change forum_name )); - $notifications = $this->notifications->load_notifications(array( - 'count_unread' => true, - )); - - $expected = array( - 1 => array( - 'notification_type_id' => 4, - 'item_id' => 1, - 'item_parent_id' => 2, - 'user_id' => 0, - 'notification_read' => 0, - 'notification_time' => 1349413321, - 'notification_data' => array(), - ), - 2 => array( - 'notification_type_id' => 4, - 'item_id' => 2, - 'item_parent_id' => 2, - 'user_id' => 0, - 'notification_read' => 0, - 'notification_time' => 1349413322, - 'notification_data' => array(), - ), - 3 => array( - 'notification_type_id' => 4, - 'item_id' => 3, - 'item_parent_id' => 2, - 'user_id' => 0, - 'notification_read' => 0, - 'notification_time' => 1234, - 'notification_data' => array(), - ), - 4 => array( - 'notification_type_id' => 3, - 'item_id' => 4, - 'item_parent_id' => 2, - 'user_id' => 0, - 'notification_read' => 0, - 'notification_time' => 1349413324, - 'notification_data' => array( - 'poster_id' => 2, - 'topic_title' => 'test-title', - 'post_subject' => 'Re: test-title', - 'post_username' => '', - 'forum_id' => 2, - 'forum_name' => 'Your first forum', + $this->assert_notifications( + array( + array( + 'item_id' => 3, + 'item_parent_id' => 2, + 'user_id' => 0, + 'notification_read' => 0, + 'notification_time' => 1234, + 'notification_data' => array(), ), - ), - 5 => array( - 'notification_type_id' => 2, - 'item_id' => 5, - 'item_parent_id' => 2, - 'user_id' => 0, - 'notification_read' => 0, - 'notification_time' => 1349413325, - 'notification_data' => array( - 'poster_id' => 2, - 'topic_title' => 'test-title2', - 'post_subject' => 'Re: test-title2', - 'post_username' => '', - 'forum_id' => 3, - 'forum_name' => 'Your second forum', + array( + 'item_id' => 1, + 'item_parent_id' => 2, + 'user_id' => 0, + 'notification_read' => 0, + 'notification_time' => 1349413321, + 'notification_data' => array(), ), - ), + array( + 'item_id' => 2, + 'item_parent_id' => 2, + 'user_id' => 0, + 'notification_read' => 0, + 'notification_time' => 1349413322, + 'notification_data' => array(), + ), + array( + 'item_id' => 4, + 'item_parent_id' => 2, + 'user_id' => 0, + 'notification_read' => 0, + 'notification_time' => 1349413324, + 'notification_data' => array( + 'poster_id' => 2, + 'topic_title' => 'test-title', + 'post_subject' => 'Re: test-title', + 'post_username' => '', + 'forum_id' => 2, + 'forum_name' => 'Your first forum', + ), + ), + array( + 'item_id' => 5, + 'item_parent_id' => 2, + 'user_id' => 0, + 'notification_read' => 0, + 'notification_time' => 1349413325, + 'notification_data' => array( + 'poster_id' => 2, + 'topic_title' => 'test-title2', + 'post_subject' => 'Re: test-title2', + 'post_username' => '', + 'forum_id' => 3, + 'forum_name' => 'Your second forum', + ), + ), + ) ); - - $this->assertEquals(sizeof($expected), $notifications['unread_count']); - - $notifications = $notifications['notifications']; - - foreach ($expected as $notification_id => $notification_data) - { - //echo $notifications[$notification_id]; - - $this->assertEquals($notification_id, $notifications[$notification_id]->notification_id, 'notification_id'); - - foreach ($notification_data as $key => $value) - { - $this->assertEquals($value, $notifications[$notification_id]->$key, $key . ' ' . $notification_id); - } - } } } diff --git a/tests/notification/submit_post_base.php b/tests/notification/submit_post_base.php index 4e564ce23c..8597c626a4 100644 --- a/tests/notification/submit_post_base.php +++ b/tests/notification/submit_post_base.php @@ -53,7 +53,7 @@ class phpbb_notification_submit_post_base extends phpbb_database_test_case $db = $this->db; // Auth - $auth = $this->getMock('phpbb_auth'); + $auth = $this->getMock('\phpbb\auth\auth'); $auth->expects($this->any()) ->method('acl_get') ->with($this->stringContains('_'), @@ -65,12 +65,12 @@ class phpbb_notification_submit_post_base extends phpbb_database_test_case ))); // Config - $config = new phpbb_config(array('num_topics' => 1,'num_posts' => 1,)); + $config = new \phpbb\config\config(array('num_topics' => 1,'num_posts' => 1,)); set_config(null, null, null, $config); set_config_count(null, null, null, $config); - $cache = new phpbb_cache_service( - new phpbb_cache_driver_null(), + $cache = new \phpbb\cache\service( + new \phpbb\cache\driver\null(), $config, $db, $phpbb_root_path, @@ -81,7 +81,7 @@ class phpbb_notification_submit_post_base extends phpbb_database_test_case $phpbb_dispatcher = new phpbb_mock_event_dispatcher(); // User - $user = $this->getMock('phpbb_user'); + $user = $this->getMock('\phpbb\user'); $user->ip = ''; $user->data = array( 'user_id' => 2, @@ -91,21 +91,21 @@ class phpbb_notification_submit_post_base extends phpbb_database_test_case ); // Request - $type_cast_helper = $this->getMock('phpbb_request_type_cast_helper_interface'); - $request = $this->getMock('phpbb_request'); + $type_cast_helper = $this->getMock('\phpbb\request\type_cast_helper_interface'); + $request = $this->getMock('\phpbb\request\request'); // Container $phpbb_container = new phpbb_mock_container_builder(); - $phpbb_container->set('content.visibility', new phpbb_content_visibility($auth, $db, $user, $phpbb_root_path, $phpEx, FORUMS_TABLE, POSTS_TABLE, TOPICS_TABLE, USERS_TABLE)); + $phpbb_container->set('content.visibility', new \phpbb\content_visibility($auth, $db, $user, $phpbb_root_path, $phpEx, FORUMS_TABLE, POSTS_TABLE, TOPICS_TABLE, USERS_TABLE)); - $user_loader = new phpbb_user_loader($db, $phpbb_root_path, $phpEx, USERS_TABLE); + $user_loader = new \phpbb\user_loader($db, $phpbb_root_path, $phpEx, USERS_TABLE); // Notification Types $notification_types = array('quote', 'bookmark', 'post', 'post_in_queue', 'topic', 'approve_topic', 'approve_post'); $notification_types_array = array(); foreach ($notification_types as $type) { - $class_name = 'phpbb_notification_type_' . $type; + $class_name = '\phpbb\notification\type\\' . $type; $class = new $class_name( $user_loader, $db, $cache->get_driver(), $user, $auth, $config, $phpbb_root_path, $phpEx, @@ -117,7 +117,7 @@ class phpbb_notification_submit_post_base extends phpbb_database_test_case } // Notification Manager - $phpbb_notifications = new phpbb_notification_manager($notification_types_array, array(), + $phpbb_notifications = new \phpbb\notification\manager($notification_types_array, array(), $phpbb_container, $user_loader, $db, $cache, $user, $phpbb_root_path, $phpEx, NOTIFICATION_TYPES_TABLE, NOTIFICATIONS_TABLE, USER_NOTIFICATIONS_TABLE); diff --git a/tests/pagination/generate_template_test.php b/tests/pagination/generate_template_test.php new file mode 100644 index 0000000000..587a948583 --- /dev/null +++ b/tests/pagination/generate_template_test.php @@ -0,0 +1,111 @@ +<?php +/** +* +* @package testing +* @copyright (c) 2013 phpBB Group +* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 +* +*/ + +require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php'; +require_once dirname(__FILE__) . '/../template/template_test_case.php'; + +class phpbb_pagination_generate_template_test extends phpbb_template_template_test_case +{ + protected $test_path = 'tests/pagination'; + + public function phpbb_generate_template_pagination_data() + { + return array( + array( + 'page.php', + 'start', + 95, + 10, + 10, + 'pagination + :previous::page.php + :else:1:page.php + :current:2:page.php?start=10 + :else:3:page.php?start=20 + :else:4:page.php?start=30 + :else:5:page.php?start=40 + :ellipsis:9:page.php?start=80 + :else:10:page.php?start=90 + :next::page.php?start=20 + :u_prev:page.php + :u_next:page.php?start=20', + ), + array( + 'page.php', + 'start', + 95, + 10, + 20, + 'pagination + :previous::page.php?start=10 + :else:1:page.php + :else:2:page.php?start=10 + :current:3:page.php?start=20 + :else:4:page.php?start=30 + :else:5:page.php?start=40 + :else:6:page.php?start=50 + :ellipsis:9:page.php?start=80 + :else:10:page.php?start=90 + :next::page.php?start=30 + :u_prev:page.php?start=10 + :u_next:page.php?start=30', + ), + array( + 'test/page/%d', + '/page/%d', + 95, + 10, + 10, + 'pagination + :previous::test + :else:1:test + :current:2:test/page/2 + :else:3:test/page/3 + :else:4:test/page/4 + :else:5:test/page/5 + :ellipsis:9:test/page/9 + :else:10:test/page/10 + :next::test/page/3 + :u_prev:test + :u_next:test/page/3', + ), + array( + 'test/page/%d', + '/page/%d', + 95, + 10, + 20, + 'pagination + :previous::test/page/2 + :else:1:test + :else:2:test/page/2 + :current:3:test/page/3 + :else:4:test/page/4 + :else:5:test/page/5 + :else:6:test/page/6 + :ellipsis:9:test/page/9 + :else:10:test/page/10 + :next::test/page/4 + :u_prev:test/page/2 + :u_next:test/page/4', + ), + ); + } + + /** + * @dataProvider phpbb_generate_template_pagination_data + */ + public function test_phpbb_generate_template_pagination($base_url, $start_name, $num_items, $per_page, $start_item, $expect) + { + phpbb_generate_template_pagination($this->template, $base_url, 'pagination', $start_name, $num_items, $per_page, $start_item); + $this->template->set_filenames(array('test' => 'pagination.html')); + + $this->assertEquals(str_replace("\t", '', $expect), $this->display('test')); + } +} diff --git a/tests/pagination/templates/pagination.html b/tests/pagination/templates/pagination.html new file mode 100644 index 0000000000..7f2a329804 --- /dev/null +++ b/tests/pagination/templates/pagination.html @@ -0,0 +1,12 @@ +pagination +<!-- BEGIN pagination --> +<!-- IF pagination.S_IS_PREV -->:previous:{pagination.PAGE_NUMBER}:{pagination.PAGE_URL} +<!-- ELSEIF pagination.S_IS_CURRENT -->:current:{pagination.PAGE_NUMBER}:{pagination.PAGE_URL} +<!-- ELSEIF pagination.S_IS_ELLIPSIS -->:ellipsis:{pagination.PAGE_NUMBER}:{pagination.PAGE_URL} +<!-- ELSEIF pagination.S_IS_NEXT -->:next:{pagination.PAGE_NUMBER}:{pagination.PAGE_URL} +<!-- ELSE -->:else:{pagination.PAGE_NUMBER}:{pagination.PAGE_URL} +<!-- ENDIF --> +<!-- END pagination --> +<!-- IF U_PREVIOUS_PAGE -->:u_prev:{U_PREVIOUS_PAGE}<!-- ENDIF --> + +<!-- IF U_NEXT_PAGE -->:u_next:{U_NEXT_PAGE}<!-- ENDIF --> diff --git a/tests/request/deactivated_super_global_test.php b/tests/request/deactivated_super_global_test.php index 2e19928a5a..d28bd87eec 100644 --- a/tests/request/deactivated_super_global_test.php +++ b/tests/request/deactivated_super_global_test.php @@ -16,7 +16,7 @@ class phpbb_deactivated_super_global_test extends phpbb_test_case 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 = new \phpbb\request\deactivated_super_global($this->getMock('\phpbb\request\request_interface'), 'obj', \phpbb\request\request_interface::POST); $obj->offsetSet(0, 0); } } diff --git a/tests/request/request_test.php b/tests/request/request_test.php index 52c21abd2a..a25792e051 100644 --- a/tests/request/request_test.php +++ b/tests/request/request_test.php @@ -33,8 +33,8 @@ class phpbb_request_test extends phpbb_test_case $_SERVER['HTTP_ACCEPT'] = 'application/json'; $_SERVER['HTTP_SOMEVAR'] = '<value>'; - $this->type_cast_helper = $this->getMock('phpbb_request_type_cast_helper_interface'); - $this->request = new phpbb_request($this->type_cast_helper); + $this->type_cast_helper = $this->getMock('\phpbb\request\type_cast_helper_interface'); + $this->request = new \phpbb\request\request($this->type_cast_helper); } public function test_toggle_super_globals() @@ -135,7 +135,7 @@ class phpbb_request_test extends phpbb_test_case { $this->request->enable_super_globals(); $_SERVER['HTTP_X_REQUESTED_WITH'] = 'XMLHttpRequest'; - $this->request = new phpbb_request($this->type_cast_helper); + $this->request = new \phpbb\request\request($this->type_cast_helper); $this->assertTrue($this->request->is_ajax()); } @@ -146,7 +146,7 @@ class phpbb_request_test extends phpbb_test_case $this->request->enable_super_globals(); $_SERVER['HTTPS'] = 'on'; - $this->request = new phpbb_request($this->type_cast_helper); + $this->request = new \phpbb\request\request($this->type_cast_helper); $this->assertTrue($this->request->is_secure()); } diff --git a/tests/request/request_var_test.php b/tests/request/request_var_test.php index 0e85d4694b..d126fe1e8b 100644 --- a/tests/request/request_var_test.php +++ b/tests/request/request_var_test.php @@ -90,7 +90,7 @@ class phpbb_request_var_test extends phpbb_test_case { $this->unset_variables('var'); - // cannot set $_REQUEST directly because in phpbb_request implementation + // cannot set $_REQUEST directly because in \phpbb\request\request implementation // $_REQUEST = $_POST + $_GET $_POST['var'] = array( 0 => array( diff --git a/tests/request/type_cast_helper_test.php b/tests/request/type_cast_helper_test.php index f41db005af..98f4538c08 100644 --- a/tests/request/type_cast_helper_test.php +++ b/tests/request/type_cast_helper_test.php @@ -16,7 +16,7 @@ class phpbb_type_cast_helper_test extends phpbb_test_case protected function setUp() { - $this->type_cast_helper = new phpbb_request_type_cast_helper(); + $this->type_cast_helper = new \phpbb\request\type_cast_helper(); } public function test_addslashes_recursively() diff --git a/tests/search/mysql_test.php b/tests/search/mysql_test.php index 3ad15bd806..c08484c78d 100644 --- a/tests/search/mysql_test.php +++ b/tests/search/mysql_test.php @@ -34,7 +34,7 @@ class phpbb_search_mysql_test extends phpbb_search_common_test_case $this->db = $this->new_dbal(); $error = null; - $class = self::get_search_wrapper('phpbb_search_fulltext_mysql'); + $class = self::get_search_wrapper('\phpbb\search\fulltext_mysql'); $this->search = new $class($error, $phpbb_root_path, $phpEx, null, $config, $this->db, $user); } } diff --git a/tests/search/native_test.php b/tests/search/native_test.php index 4a2c210013..18c6df2445 100644 --- a/tests/search/native_test.php +++ b/tests/search/native_test.php @@ -30,7 +30,7 @@ class phpbb_search_native_test extends phpbb_search_test_case $this->db = $this->new_dbal(); $error = null; - $class = self::get_search_wrapper('phpbb_search_fulltext_native'); + $class = self::get_search_wrapper('\phpbb\search\fulltext_native'); $this->search = new $class($error, $phpbb_root_path, $phpEx, null, $config, $this->db, $user); } diff --git a/tests/search/postgres_test.php b/tests/search/postgres_test.php index 923af6f854..a59f5abc7d 100644 --- a/tests/search/postgres_test.php +++ b/tests/search/postgres_test.php @@ -34,7 +34,7 @@ class phpbb_search_postgres_test extends phpbb_search_common_test_case $this->db = $this->new_dbal(); $error = null; - $class = self::get_search_wrapper('phpbb_search_fulltext_postgres'); + $class = self::get_search_wrapper('\phpbb\search\fulltext_postgres'); $this->search = new $class($error, $phpbb_root_path, $phpEx, null, $config, $this->db, $user); } } diff --git a/tests/security/base.php b/tests/security/base.php index 08878ad60d..8cd24ff145 100644 --- a/tests/security/base.php +++ b/tests/security/base.php @@ -39,13 +39,13 @@ abstract class phpbb_security_test_base extends phpbb_test_case $request = new phpbb_mock_request(array(), array(), array(), $server); // Set no user and trick a bit to circumvent errors - $user = new phpbb_user(); + $user = new \phpbb\user(); $user->lang = true; $user->browser = $server['HTTP_USER_AGENT']; $user->referer = ''; $user->forwarded_for = ''; $user->host = $server['HTTP_HOST']; - $user->page = phpbb_session::extract_current_page($phpbb_root_path); + $user->page = \phpbb\session::extract_current_page($phpbb_root_path); } protected function tearDown() diff --git a/tests/security/extract_current_page_test.php b/tests/security/extract_current_page_test.php index d77cbbcaf3..e42f446b31 100644 --- a/tests/security/extract_current_page_test.php +++ b/tests/security/extract_current_page_test.php @@ -28,12 +28,12 @@ class phpbb_security_extract_current_page_test extends phpbb_security_test_base { global $request; - $request->merge(phpbb_request_interface::SERVER, array( + $request->merge(\phpbb\request\request_interface::SERVER, array( 'PHP_SELF' => $url, 'QUERY_STRING' => $query_string, )); - $result = phpbb_session::extract_current_page('./'); + $result = \phpbb\session::extract_current_page('./'); $label = 'Running extract_current_page on ' . $query_string . ' with PHP_SELF filled.'; $this->assertEquals($expected, $result['query_string'], $label); @@ -46,12 +46,12 @@ class phpbb_security_extract_current_page_test extends phpbb_security_test_base { global $request; - $request->merge(phpbb_request_interface::SERVER, array( + $request->merge(\phpbb\request\request_interface::SERVER, array( 'PHP_SELF' => $url, 'QUERY_STRING' => $query_string, )); - $result = phpbb_session::extract_current_page('./'); + $result = \phpbb\session::extract_current_page('./'); $label = 'Running extract_current_page on ' . $query_string . ' with REQUEST_URI filled.'; $this->assertEquals($expected, $result['query_string'], $label); diff --git a/tests/session/check_ban_test.php b/tests/session/check_ban_test.php index 8d6c9a866d..3f13b9f216 100644 --- a/tests/session/check_ban_test.php +++ b/tests/session/check_ban_test.php @@ -43,8 +43,8 @@ class phpbb_session_check_ban_test extends phpbb_session_test_case // Change the global cache object for this test because // the mock cache object does not hit the database as is needed // for this test. - $cache = new phpbb_cache_service( - new phpbb_cache_driver_file(), + $cache = new \phpbb\cache\service( + new \phpbb\cache\driver\file(), $config, $this->db, $phpbb_root_path, diff --git a/tests/session/testable_facade.php b/tests/session/testable_facade.php index 9f0a3c5f59..f289c48f69 100644 --- a/tests/session/testable_facade.php +++ b/tests/session/testable_facade.php @@ -14,11 +14,11 @@ require_once dirname(__FILE__) . '/../../phpBB/phpbb/session.php'; * This class exists to expose session.php's functions in a more testable way. * * Since many functions in session.php have global variables inside the function, - * this exposes those functions through a testable facade that uses - * testable_factory's mock global variables to modify global variables used in + * this exposes those functions through a testable facade that uses + * testable_factory's mock global variables to modify global variables used in * the functions. * - * This is using the facade pattern to provide a testable "front" to the + * This is using the facade pattern to provide a testable "front" to the * functions in sessions.php. * */ @@ -35,17 +35,17 @@ class phpbb_session_testable_facade function extract_current_page( $root_path, - $php_self, + $php_self, $query_string, $request_uri - ) + ) { $this->session_factory->get_session($this->db); global $request; - $request->overwrite('PHP_SELF', $php_self, phpbb_request_interface::SERVER); - $request->overwrite('QUERY_STRING', $query_string, phpbb_request_interface::SERVER); - $request->overwrite('REQUEST_URI', $request_uri, phpbb_request_interface::SERVER); - return phpbb_session::extract_current_page($root_path); + $request->overwrite('PHP_SELF', $php_self, \phpbb\request\request_interface::SERVER); + $request->overwrite('QUERY_STRING', $query_string, \phpbb\request\request_interface::SERVER); + $request->overwrite('REQUEST_URI', $request_uri, \phpbb\request\request_interface::SERVER); + return \phpbb\session::extract_current_page($root_path); } function extract_current_hostname( @@ -58,8 +58,8 @@ class phpbb_session_testable_facade global $config, $request; $config['server_name'] = $server_name_config; $config['cookie_domain'] = $cookie_domain_config; - $request->overwrite('SERVER_NAME', $host, phpbb_request_interface::SERVER); - $request->overwrite('Host', $host, phpbb_request_interface::SERVER); + $request->overwrite('SERVER_NAME', $host, \phpbb\request\request_interface::SERVER); + $request->overwrite('Host', $host, \phpbb\request\request_interface::SERVER); // Note: There is a php_uname function used as a fallthrough // that this function doesn't override return $session->extract_current_hostname(); @@ -135,7 +135,7 @@ class phpbb_session_testable_facade $session->host = $host; $config['force_server_vars'] = $force_server_vars; $config['server_name'] = $server_name; - $request->overwrite('SERVER_PORT', $server_port, phpbb_request_interface::SERVER); + $request->overwrite('SERVER_PORT', $server_port, \phpbb\request\request_interface::SERVER); return $session->validate_referer($check_script_path); } } diff --git a/tests/session/testable_factory.php b/tests/session/testable_factory.php index 8733ce15ef..a58e208efc 100644 --- a/tests/session/testable_factory.php +++ b/tests/session/testable_factory.php @@ -63,10 +63,10 @@ class phpbb_session_testable_factory /** * Retrieve the configured session class instance * - * @param phpbb_db_driver $dbal The database connection to use for session data + * @param \phpbb\db\driver\driver $dbal The database connection to use for session data * @return phpbb_mock_session_testable A session instance */ - public function get_session(phpbb_db_driver $dbal) + public function get_session(\phpbb\db\driver\driver $dbal) { // set up all the global variables used by session global $SID, $_SID, $db, $config, $cache, $request, $phpbb_container; @@ -79,7 +79,7 @@ class phpbb_session_testable_factory ); request_var(null, null, null, null, $request); - $config = $this->config = new phpbb_config($this->get_config_data()); + $config = $this->config = new \phpbb\config\config($this->get_config_data()); set_config(null, null, null, $config); $db = $dbal; diff --git a/tests/template/includephp_test.php b/tests/template/includephp_test.php index ff7b890d11..a0dd8368cf 100644 --- a/tests/template/includephp_test.php +++ b/tests/template/includephp_test.php @@ -46,7 +46,7 @@ class phpbb_template_includephp_test extends phpbb_template_template_test_case $this->setup_engine(array('tpl_allow_php' => true)); - $this->style->set_custom_style('tests', $cache_dir, array(), ''); + $this->template->set_custom_style('tests', $cache_dir); $this->run_template('includephp_absolute.html', array(), array(), array(), "Path is absolute.\ntesting included php"); diff --git a/tests/template/template_events_test.php b/tests/template/template_events_test.php index d3b65e763a..4155d5fd83 100644 --- a/tests/template/template_events_test.php +++ b/tests/template/template_events_test.php @@ -110,16 +110,20 @@ Zeta test event in all', global $phpbb_root_path, $phpEx, $user; $defaults = $this->config_defaults(); - $config = new phpbb_config(array_merge($defaults, $new_config)); + $config = new \phpbb\config\config(array_merge($defaults, $new_config)); $this->template_path = dirname(__FILE__) . "/datasets/$dataset/styles/silver/template"; - $this->style_resource_locator = new phpbb_style_resource_locator(); $this->extension_manager = new phpbb_mock_filesystem_extension_manager( dirname(__FILE__) . "/datasets/$dataset/" ); - $this->template = new phpbb_template_twig($phpbb_root_path, $phpEx, $config, $user, new phpbb_template_context, $this->extension_manager); - $this->style_provider = new phpbb_style_path_provider(); - $this->style = new phpbb_style($phpbb_root_path, $phpEx, $config, $user, $this->style_resource_locator, $this->style_provider, $this->template); - $this->style->set_custom_style('silver', array($this->template_path), $style_names, ''); + $phpbb_filesystem = new \phpbb\filesystem( + new \phpbb\symfony_request( + new phpbb_mock_request() + ), + $phpbb_root_path, + $phpEx + ); + $this->template = new \phpbb\template\twig\twig($phpbb_filesystem, $config, $user, new \phpbb\template\context, $this->extension_manager); + $this->template->set_custom_style(((!empty($style_names)) ? $style_names : 'silver'), array($this->template_path)); } } diff --git a/tests/template/template_includecss_test.php b/tests/template/template_includecss_test.php index f8999ad1a9..c00aa8e9bb 100644 --- a/tests/template/template_includecss_test.php +++ b/tests/template/template_includecss_test.php @@ -18,8 +18,8 @@ class phpbb_template_template_includecss_test extends phpbb_template_template_te // Prepare correct result $scripts = array( - '<link href="' . $this->test_path . '/templates/child_only.css?assets_version=1" rel="stylesheet" type="text/css" media="screen, projection" />', - '<link href="' . $this->test_path . '/parent_templates/parent_only.css?assets_version=1" rel="stylesheet" type="text/css" media="screen, projection" />', + '<link href="' . $this->phpbb_filesystem->get_web_root_path() . 'tests/template/templates/child_only.css?assets_version=1" rel="stylesheet" type="text/css" media="screen, projection" />', + '<link href="' . $this->phpbb_filesystem->get_web_root_path() . 'tests/template/parent_templates/parent_only.css?assets_version=1" rel="stylesheet" type="text/css" media="screen, projection" />', ); // Run test diff --git a/tests/template/template_includejs_test.php b/tests/template/template_includejs_test.php index b67fa123a1..2faeb5fcaa 100644 --- a/tests/template/template_includejs_test.php +++ b/tests/template/template_includejs_test.php @@ -13,6 +13,8 @@ class phpbb_template_template_includejs_test extends phpbb_template_template_tes { public function template_data() { + $this->setup_engine(); + return array( /* array( @@ -22,51 +24,51 @@ class phpbb_template_template_includejs_test extends phpbb_template_template_tes */ array( array('TEST' => 1), - '<script type="text/javascript" src="' . $this->test_path . '/templates/parent_and_child.js?assets_version=1"></script>', + '<script type="text/javascript" src="' . $this->phpbb_filesystem->get_web_root_path() . 'tests/template/templates/parent_and_child.js?assets_version=1"></script>', ), array( array('TEST' => 2), - '<script type="text/javascript" src="' . $this->test_path . '/templates/parent_and_child.js?assets_version=0"></script>', + '<script type="text/javascript" src="' . $this->phpbb_filesystem->get_web_root_path() . 'tests/template/templates/parent_and_child.js?assets_version=0"></script>', ), array( array('TEST' => 3), - '<script type="text/javascript" src="' . $this->test_path . '/templates/parent_and_child.js?test=1&assets_version=0"></script>', + '<script type="text/javascript" src="' . $this->phpbb_filesystem->get_web_root_path() . 'tests/template/templates/parent_and_child.js?test=1&assets_version=0"></script>', ), array( array('TEST' => 4), - '<script type="text/javascript" src="' . $this->test_path . '/templates/parent_and_child.js?test=1&assets_version=0"></script>', + '<script type="text/javascript" src="' . $this->phpbb_filesystem->get_web_root_path() . 'tests/template/templates/parent_and_child.js?test=1&assets_version=0"></script>', ), array( array('TEST' => 6), - '<script type="text/javascript" src="' . $this->test_path . '/parent_templates/parent_only.js?assets_version=1"></script>', + '<script type="text/javascript" src="' . $this->phpbb_filesystem->get_web_root_path() . 'tests/template/parent_templates/parent_only.js?assets_version=1"></script>', ), array( array('TEST' => 7), - '<script type="text/javascript" src="' . $this->test_path . '/templates/child_only.js?assets_version=1"></script>', + '<script type="text/javascript" src="' . $this->phpbb_filesystem->get_web_root_path() . 'tests/template/templates/child_only.js?assets_version=1"></script>', ), array( array('TEST' => 8), - '<script type="text/javascript" src="' . $this->test_path . '/templates/subdir/parent_only.js?assets_version=1"></script>', + '<script type="text/javascript" src="' . $this->phpbb_filesystem->get_web_root_path() . 'tests/template/templates/subdir/parent_only.js?assets_version=1"></script>', ), array( array('TEST' => 9), - '<script type="text/javascript" src="' . $this->test_path . '/templates/subdir/subsubdir/parent_only.js?assets_version=1"></script>', + '<script type="text/javascript" src="' . $this->phpbb_filesystem->get_web_root_path() . 'tests/template/templates/subdir/subsubdir/parent_only.js?assets_version=1"></script>', ), array( array('TEST' => 10), - '<script type="text/javascript" src="' . $this->test_path . '/templates/subdir/parent_only.js?assets_version=1"></script>', + '<script type="text/javascript" src="' . $this->phpbb_filesystem->get_web_root_path() . 'tests/template/templates/subdir/parent_only.js?assets_version=1"></script>', ), array( array('TEST' => 11), - '<script type="text/javascript" src="' . $this->test_path . '/templates/child_only.js?test1=1&test2=2&assets_version=1#test3"></script>', + '<script type="text/javascript" src="' . $this->phpbb_filesystem->get_web_root_path() . 'tests/template/templates/child_only.js?test1=1&test2=2&assets_version=1#test3"></script>', ), array( array('TEST' => 12), - '<script type="text/javascript" src="' . $this->test_path . '/parent_templates/parent_only.js?test1=1&test2=2&assets_version=1#test3"></script>', + '<script type="text/javascript" src="' . $this->phpbb_filesystem->get_web_root_path() . 'tests/template/parent_templates/parent_only.js?test1=1&test2=2&assets_version=1#test3"></script>', ), array( array('TEST' => 14), - '<script type="text/javascript" src="' . $this->test_path . '/parent_templates/parent_only.js?test1="&assets_version=1#test3"></script>', + '<script type="text/javascript" src="' . $this->phpbb_filesystem->get_web_root_path() . 'tests/template/parent_templates/parent_only.js?test1="&assets_version=1#test3"></script>', ), array( array('TEST' => 15), @@ -82,7 +84,7 @@ class phpbb_template_template_includejs_test extends phpbb_template_template_tes ), array( array('TEST' => 18), - '<script type="text/javascript" src="' . $this->test_path . '/templates/parent_and_child.js?test=1&test2=0&assets_version=1"></script>', + '<script type="text/javascript" src="' . $this->phpbb_filesystem->get_web_root_path() . 'tests/template/templates/parent_and_child.js?test=1&test2=0&assets_version=1"></script>', ), ); } diff --git a/tests/template/template_test.php b/tests/template/template_test.php index 0a6b680100..39eb08ab79 100644 --- a/tests/template/template_test.php +++ b/tests/template/template_test.php @@ -64,6 +64,13 @@ class phpbb_template_template_test extends phpbb_template_template_test_case ), array( 'if.html', + array('S_OTHER_OTHER_VALUE' => true), + array(), + array(), + '|S_OTHER_OTHER_VALUE|!false', + ), + array( + 'if.html', array('S_VALUE' => false, 'S_OTHER_VALUE' => true), array(), array(), @@ -151,7 +158,7 @@ class phpbb_template_template_test extends phpbb_template_template_test_case array(), array('test_loop' => array(array(), array(), array(), array(), array(), array(), array()), 'test' => array(array()), 'test.deep' => array(array()), 'test.deep.defines' => array(array())), array(), - "xyz\nabc\n\$VALUE == 'abc'abc\nbar\nbar\nabc\ntest!@#$%^&*()_-=+{}[]:;\",<.>/?", + "xyz\nabc\n\$VALUE == 'abc'\n(\$VALUE == 'abc')\n((\$VALUE == 'abc'))\n!\$DOESNT_EXIST\n(!\$DOESNT_EXIST)\nabc\nbar\nbar\nabc\ntest!@#$%^&*()_-=+{}[]:;\",<.>/?[]|foobar|", ), array( 'define_advanced.html', @@ -230,7 +237,7 @@ class phpbb_template_template_test extends phpbb_template_template_test_case array('VARIABLE' => 'variable.html'), array(), array(), - 'variable.html', + "variable.html\nvariable.html\nvariable.html", ), array( 'include_loop_define.html', @@ -410,7 +417,7 @@ class phpbb_template_template_test extends phpbb_template_template_test_case $this->setup_engine(array('tpl_allow_php' => true)); - $this->style->set_custom_style('tests', $cache_dir, array(), ''); + $this->template->set_custom_style('tests', $cache_dir); $this->run_template('php.html', array(), array(), array(), 'test'); } diff --git a/tests/template/template_test_case.php b/tests/template/template_test_case.php index 6d87e5ebc0..e9cbdec1d9 100644 --- a/tests/template/template_test_case.php +++ b/tests/template/template_test_case.php @@ -11,11 +11,8 @@ require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php'; class phpbb_template_template_test_case extends phpbb_test_case { - protected $style; protected $template; protected $template_path; - protected $style_resource_locator; - protected $style_provider; protected $user; protected $test_path = 'tests/template'; @@ -63,15 +60,20 @@ class phpbb_template_template_test_case extends phpbb_test_case global $phpbb_root_path, $phpEx; $defaults = $this->config_defaults(); - $config = new phpbb_config(array_merge($defaults, $new_config)); - $this->user = new phpbb_user; + $config = new \phpbb\config\config(array_merge($defaults, $new_config)); + $this->user = new \phpbb\user; + + $phpbb_filesystem = new \phpbb\filesystem( + new \phpbb\symfony_request( + new phpbb_mock_request() + ), + $phpbb_root_path, + $phpEx + ); $this->template_path = $this->test_path . '/templates'; - $this->style_resource_locator = new phpbb_style_resource_locator(); - $this->style_provider = new phpbb_style_path_provider(); - $this->template = new phpbb_template_twig($phpbb_root_path, $phpEx, $config, $this->user, new phpbb_template_context()); - $this->style = new phpbb_style($phpbb_root_path, $phpEx, $config, $this->user, $this->style_resource_locator, $this->style_provider, $this->template); - $this->style->set_custom_style('tests', $this->template_path, array(), ''); + $this->template = new \phpbb\template\twig\twig($phpbb_filesystem, $config, $this->user, new \phpbb\template\context()); + $this->template->set_custom_style('tests', $this->template_path); } protected function setUp() diff --git a/tests/template/template_test_case_with_tree.php b/tests/template/template_test_case_with_tree.php index 4b8cbada45..232331d37c 100644 --- a/tests/template/template_test_case_with_tree.php +++ b/tests/template/template_test_case_with_tree.php @@ -16,14 +16,19 @@ class phpbb_template_template_test_case_with_tree extends phpbb_template_templat global $phpbb_root_path, $phpEx, $user; $defaults = $this->config_defaults(); - $config = new phpbb_config(array_merge($defaults, $new_config)); + $config = new \phpbb\config\config(array_merge($defaults, $new_config)); + + $this->phpbb_filesystem = new \phpbb\filesystem( + new \phpbb\symfony_request( + new phpbb_mock_request() + ), + $phpbb_root_path, + $phpEx + ); $this->template_path = $this->test_path . '/templates'; $this->parent_template_path = $this->test_path . '/parent_templates'; - $this->style_resource_locator = new phpbb_style_resource_locator(); - $this->style_provider = new phpbb_style_path_provider(); - $this->template = new phpbb_template_twig($phpbb_root_path, $phpEx, $config, $user, new phpbb_template_context()); - $this->style = new phpbb_style($phpbb_root_path, $phpEx, $config, $user, $this->style_resource_locator, $this->style_provider, $this->template); - $this->style->set_custom_style('tests', array($this->template_path, $this->parent_template_path), array(), ''); + $this->template = new phpbb\template\twig\twig($this->phpbb_filesystem, $config, $user, new phpbb\template\context()); + $this->template->set_custom_style('tests', array($this->template_path, $this->parent_template_path)); } } diff --git a/tests/template/templates/define.html b/tests/template/templates/define.html index 66e874ca63..e7ce7f7def 100644 --- a/tests/template/templates/define.html +++ b/tests/template/templates/define.html @@ -7,6 +7,18 @@ $VALUE != 'abc' <!-- ELSEIF $VALUE == 'abc' --> $VALUE == 'abc' <!-- ENDIF --> +<!-- IF ($VALUE == 'abc') --> +($VALUE == 'abc') +<!-- ENDIF --> +<!-- IF (($VALUE == 'abc')) --> +(($VALUE == 'abc')) +<!-- ENDIF --> +<!-- IF !$DOESNT_EXIST --> +!$DOESNT_EXIST +<!-- ENDIF --> +<!-- IF (!$DOESNT_EXIST) --> +(!$DOESNT_EXIST) +<!-- ENDIF --> <!-- INCLUDE define_include.html --> {$INCLUDED_VALUE} {$VALUE} @@ -14,3 +26,6 @@ $VALUE == 'abc' {$VALUE} <!-- DEFINE $VALUE = 'test!@#$%^&*()_-=+{}[]:;",<.>/?' --> {$VALUE} +<!-- DEFINE $VALUE = '' --> +[{$VALUE}] +<!-- DEFINE $TEST -->foobar<!-- ENDDEFINE -->|{$TEST}| diff --git a/tests/template/templates/if.html b/tests/template/templates/if.html index c010aff7fa..f6ab6e575a 100644 --- a/tests/template/templates/if.html +++ b/tests/template/templates/if.html @@ -2,6 +2,8 @@ 1 <!-- ELSEIF S_OTHER_VALUE --> 2 +<!-- ELSE IF S_OTHER_OTHER_VALUE --> +|S_OTHER_OTHER_VALUE| <!-- ELSE --> 03 <!-- ENDIF --> diff --git a/tests/template/templates/include_define_variable.html b/tests/template/templates/include_define_variable.html index aff9b574c2..6052657c97 100644 --- a/tests/template/templates/include_define_variable.html +++ b/tests/template/templates/include_define_variable.html @@ -1,2 +1,8 @@ <!-- DEFINE $DEF = '{VARIABLE}' --> <!-- INCLUDE {$DEF} --> + +<!-- DEFINE $DEF_WITH_UNDERSCORES = '{VARIABLE}' --> +<!-- INCLUDE {$DEF_WITH_UNDERSCORES} --> + +<!-- DEFINE $DEF123 = '{VARIABLE}' --> +<!-- INCLUDE {$DEF123} --> diff --git a/tests/test_framework/phpbb_database_test_case.php b/tests/test_framework/phpbb_database_test_case.php index c72ea5f765..4c2e9ff600 100644 --- a/tests/test_framework/phpbb_database_test_case.php +++ b/tests/test_framework/phpbb_database_test_case.php @@ -82,7 +82,7 @@ abstract class phpbb_database_test_case extends PHPUnit_Extensions_Database_Test $db_config = $this->get_database_config(); // Firebird requires table and column names to be uppercase - if ($db_config['dbms'] == 'phpbb_db_driver_firebird') + if ($db_config['dbms'] == 'phpbb\db\driver\firebird') { $xml_data = file_get_contents($path); $xml_data = preg_replace_callback('/(?:(<table name="))([a-z_]+)(?:(">))/', 'phpbb_database_test_case::to_upper', $xml_data); diff --git a/tests/test_framework/phpbb_database_test_connection_manager.php b/tests/test_framework/phpbb_database_test_connection_manager.php index c93a777701..af9bd22662 100644 --- a/tests/test_framework/phpbb_database_test_connection_manager.php +++ b/tests/test_framework/phpbb_database_test_connection_manager.php @@ -108,7 +108,7 @@ class phpbb_database_test_connection_manager // These require different connection strings on the phpBB side than they do in PDO // so you must provide a DSN string for ODBC separately - if (!empty($this->config['custom_dsn']) && ($this->config['dbms'] == 'phpbb_db_driver_mssql' || $this->config['dbms'] == 'phpbb_db_driver_firebird')) + if (!empty($this->config['custom_dsn']) && ($this->config['dbms'] == 'phpbb\db\driver\mssql' || $this->config['dbms'] == 'phpbb\db\driver\firebird')) { $dsn = 'odbc:' . $this->config['custom_dsn']; } @@ -117,12 +117,12 @@ class phpbb_database_test_connection_manager { switch ($this->config['dbms']) { - case 'phpbb_db_driver_mssql': - case 'phpbb_db_driver_mssql_odbc': + case 'phpbb\db\driver\mssql': + case 'phpbb\db\driver\mssql_odbc': $this->pdo = new phpbb_database_connection_odbc_pdo_wrapper('mssql', 0, $dsn, $this->config['dbuser'], $this->config['dbpasswd']); break; - case 'phpbb_db_driver_firebird': + case 'phpbb\db\driver\firebird': if (!empty($this->config['custom_dsn'])) { $this->pdo = new phpbb_database_connection_odbc_pdo_wrapper('firebird', 0, $dsn, $this->config['dbuser'], $this->config['dbpasswd']); @@ -138,15 +138,15 @@ class phpbb_database_test_connection_manager catch (PDOException $e) { $cleaned_dsn = str_replace($this->config['dbpasswd'], '*password*', $dsn); - throw new Exception("Unable do connect to $cleaned_dsn using PDO with error: {$e->getMessage()}"); + throw new Exception("Unable to connect to $cleaned_dsn using PDO with error: {$e->getMessage()}"); } $this->pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); switch ($this->config['dbms']) { - case 'phpbb_db_driver_mysql': - case 'phpbb_db_driver_mysqli': + case 'phpbb\db\driver\mysql': + case 'phpbb\db\driver\mysqli': $this->pdo->exec('SET NAMES utf8'); /* @@ -187,8 +187,8 @@ class phpbb_database_test_connection_manager { switch ($this->config['dbms']) { - case 'phpbb_db_driver_sqlite': - case 'phpbb_db_driver_firebird': + case 'phpbb\db\driver\sqlite': + case 'phpbb\db\driver\firebird': $this->connect(); // Drop all of the tables foreach ($this->get_tables() as $table) @@ -198,7 +198,7 @@ class phpbb_database_test_connection_manager $this->purge_extras(); break; - case 'phpbb_db_driver_oracle': + case 'phpbb\db\driver\oracle': $this->connect(); // Drop all of the tables foreach ($this->get_tables() as $table) @@ -208,7 +208,7 @@ class phpbb_database_test_connection_manager $this->purge_extras(); break; - case 'phpbb_db_driver_postgres': + case 'phpbb\db\driver\postgres': $this->connect(); // Drop all of the tables foreach ($this->get_tables() as $table) @@ -258,38 +258,38 @@ class phpbb_database_test_connection_manager switch ($this->config['dbms']) { - case 'phpbb_db_driver_mysql': - case 'phpbb_db_driver_mysqli': + case 'phpbb\db\driver\mysql': + case 'phpbb\db\driver\mysqli': $sql = 'SHOW TABLES'; break; - case 'phpbb_db_driver_sqlite': + case 'phpbb\db\driver\sqlite': $sql = 'SELECT name FROM sqlite_master WHERE type = "table"'; break; - case 'phpbb_db_driver_mssql': - case 'phpbb_db_driver_mssql_odbc': - case 'phpbb_db_driver_mssqlnative': + case 'phpbb\db\driver\mssql': + case 'phpbb\db\driver\mssql_odbc': + case 'phpbb\db\driver\mssqlnative': $sql = "SELECT name FROM sysobjects WHERE type='U'"; break; - case 'phpbb_db_driver_postgres': + case 'phpbb\db\driver\postgres': $sql = 'SELECT relname FROM pg_stat_user_tables'; break; - case 'phpbb_db_driver_firebird': + case 'phpbb\db\driver\firebird': $sql = 'SELECT rdb$relation_name FROM rdb$relations WHERE rdb$view_source is null AND rdb$system_flag = 0'; break; - case 'phpbb_db_driver_oracle': + case 'phpbb\db\driver\oracle': $sql = 'SELECT table_name FROM USER_TABLES'; break; @@ -325,7 +325,7 @@ class phpbb_database_test_connection_manager { $schema = $this->dbms['SCHEMA']; - if ($this->config['dbms'] == 'phpbb_db_driver_mysql') + if ($this->config['dbms'] == 'phpbb\db\driver\mysql') { $sth = $this->pdo->query('SELECT VERSION() AS version'); $row = $sth->fetch(PDO::FETCH_ASSOC); @@ -359,47 +359,47 @@ class phpbb_database_test_connection_manager protected function get_dbms_data($dbms) { $available_dbms = array( - 'phpbb_db_driver_firebird' => array( + 'phpbb\db\driver\firebird' => array( 'SCHEMA' => 'firebird', 'DELIM' => ';;', 'PDO' => 'firebird', ), - 'phpbb_db_driver_mysqli' => array( + 'phpbb\db\driver\mysqli' => array( 'SCHEMA' => 'mysql_41', 'DELIM' => ';', 'PDO' => 'mysql', ), - 'phpbb_db_driver_mysql' => array( + 'phpbb\db\driver\mysql' => array( 'SCHEMA' => 'mysql', 'DELIM' => ';', 'PDO' => 'mysql', ), - 'phpbb_db_driver_mssql' => array( + 'phpbb\db\driver\mssql' => array( 'SCHEMA' => 'mssql', 'DELIM' => 'GO', 'PDO' => 'odbc', ), - 'phpbb_db_driver_mssql_odbc'=> array( + 'phpbb\db\driver\mssql_odbc'=> array( 'SCHEMA' => 'mssql', 'DELIM' => 'GO', 'PDO' => 'odbc', ), - 'phpbb_db_driver_mssqlnative' => array( + 'phpbb\db\driver\mssqlnative' => array( 'SCHEMA' => 'mssql', 'DELIM' => 'GO', 'PDO' => 'sqlsrv', ), - 'phpbb_db_driver_oracle' => array( + 'phpbb\db\driver\oracle' => array( 'SCHEMA' => 'oracle', 'DELIM' => '/', 'PDO' => 'oci', ), - 'phpbb_db_driver_postgres' => array( + 'phpbb\db\driver\postgres' => array( 'SCHEMA' => 'postgres', 'DELIM' => ';', 'PDO' => 'pgsql', ), - 'phpbb_db_driver_sqlite' => array( + 'phpbb\db\driver\sqlite' => array( 'SCHEMA' => 'sqlite', 'DELIM' => ';', 'PDO' => 'sqlite2', @@ -428,7 +428,7 @@ class phpbb_database_test_connection_manager switch ($this->config['dbms']) { - case 'phpbb_db_driver_firebird': + case 'phpbb\db\driver\firebird': $sql = 'SELECT RDB$GENERATOR_NAME FROM RDB$GENERATORS WHERE RDB$SYSTEM_FLAG = 0'; @@ -440,7 +440,7 @@ class phpbb_database_test_connection_manager } break; - case 'phpbb_db_driver_oracle': + case 'phpbb\db\driver\oracle': $sql = 'SELECT sequence_name FROM USER_SEQUENCES'; $result = $this->pdo->query($sql); @@ -451,7 +451,7 @@ class phpbb_database_test_connection_manager } break; - case 'phpbb_db_driver_postgres': + case 'phpbb\db\driver\postgres': $sql = 'SELECT sequence_name FROM information_schema.sequences'; $result = $this->pdo->query($sql); @@ -509,7 +509,7 @@ class phpbb_database_test_connection_manager switch ($this->config['dbms']) { - case 'phpbb_db_driver_oracle': + case 'phpbb\db\driver\oracle': // Get all of the information about the sequences $sql = "SELECT t.table_name, tc.column_name, d.referenced_name as sequence_name, s.increment_by, s.min_value FROM USER_TRIGGERS t @@ -544,14 +544,14 @@ class phpbb_database_test_connection_manager * Since we have no objects attached to our sequencers (triggers aren't attached), this works fine. */ $queries[] = 'DROP SEQUENCE ' . $row['SEQUENCE_NAME']; - $queries[] = "CREATE SEQUENCE {$row['SEQUENCE_NAME']} - MINVALUE {$row['MIN_VALUE']} - INCREMENT BY {$row['INCREMENT_BY']} + $queries[] = "CREATE SEQUENCE {$row['SEQUENCE_NAME']} + MINVALUE {$row['MIN_VALUE']} + INCREMENT BY {$row['INCREMENT_BY']} START WITH $max_val"; } break; - case 'phpbb_db_driver_postgres': + case 'phpbb\db\driver\postgres': // Get the sequences attached to the tables $sql = 'SELECT column_name, table_name FROM information_schema.columns WHERE table_name IN (' . implode(', ', $table_names) . ") diff --git a/tests/test_framework/phpbb_functional_test_case.php b/tests/test_framework/phpbb_functional_test_case.php index ce748bb9cf..f87b3538a1 100644 --- a/tests/test_framework/phpbb_functional_test_case.php +++ b/tests/test_framework/phpbb_functional_test_case.php @@ -150,7 +150,7 @@ class phpbb_functional_test_case extends phpbb_test_case { global $phpbb_root_path, $phpEx; // so we don't reopen an open connection - if (!($this->db instanceof phpbb_db_driver)) + if (!($this->db instanceof \phpbb\db\driver\driver)) { $dbms = self::$config['dbms']; $this->db = new $dbms(); @@ -163,7 +163,7 @@ class phpbb_functional_test_case extends phpbb_test_case { if (!$this->cache) { - $this->cache = new phpbb_cache_driver_file; + $this->cache = new \phpbb\cache\driver\file; } return $this->cache; @@ -182,11 +182,11 @@ class phpbb_functional_test_case extends phpbb_test_case { global $phpbb_root_path, $phpEx; - $config = new phpbb_config(array()); + $config = new \phpbb\config\config(array()); $db = $this->get_db(); - $db_tools = new phpbb_db_tools($db); + $db_tools = new \phpbb\db\tools($db); - $migrator = new phpbb_db_migrator( + $migrator = new \phpbb\db\migrator( $config, $db, $db_tools, @@ -199,11 +199,17 @@ class phpbb_functional_test_case extends phpbb_test_case $container = new phpbb_mock_container_builder(); $container->set('migrator', $migrator); - $extension_manager = new phpbb_extension_manager( + $extension_manager = new \phpbb\extension\manager( $container, $db, $config, - new phpbb_filesystem(), + new phpbb\filesystem( + new phpbb\symfony_request( + new phpbb_mock_request() + ), + $phpbb_root_path, + $php_ext + ), self::$config['table_prefix'] . 'ext', dirname(__FILE__) . '/', $php_ext, @@ -265,7 +271,7 @@ class phpbb_functional_test_case extends phpbb_test_case self::assertContains('Database configuration', $crawler->filter('#main')->text()); $form = $crawler->selectButton('submit')->form(array( // Installer uses 3.0-style dbms name - 'dbms' => str_replace('phpbb_db_driver_', '', self::$config['dbms']), + 'dbms' => str_replace('phpbb\db\driver\\', '', self::$config['dbms']), 'dbhost' => self::$config['dbhost'], 'dbport' => self::$config['dbport'], 'dbname' => self::$config['dbname'], @@ -471,7 +477,7 @@ class phpbb_functional_test_case extends phpbb_test_case // Required by unique_id global $config; - $config = new phpbb_config(array()); + $config = new \phpbb\config\config(array()); $config['rand_seed'] = ''; $config['rand_seed_last_update'] = time() + 600; @@ -484,7 +490,7 @@ class phpbb_functional_test_case extends phpbb_test_case } $cache = new phpbb_mock_null_cache; - $cache_driver = new phpbb_cache_driver_null(); + $cache_driver = new \phpbb\cache\driver\null(); $phpbb_container = $this->getMock('Symfony\Component\DependencyInjection\ContainerInterface'); $phpbb_container ->expects($this->any()) @@ -521,24 +527,21 @@ class phpbb_functional_test_case extends phpbb_test_case { global $db, $cache, $auth, $config, $phpbb_dispatcher, $phpbb_log, $phpbb_container, $phpbb_root_path, $phpEx; - $config = new phpbb_config(array()); + $config = new \phpbb\config\config(array()); $config['coppa_enable'] = 0; $db = $this->get_db(); $phpbb_dispatcher = new phpbb_mock_event_dispatcher(); - $user = $this->getMock('phpbb_user'); - $auth = $this->getMock('phpbb_auth'); + $user = $this->getMock('\phpbb\user'); + $auth = $this->getMock('\phpbb\auth\auth'); - $phpbb_log = new phpbb_log($db, $user, $auth, $phpbb_dispatcher, $phpbb_root_path, 'adm/', $phpEx, LOG_TABLE); + $phpbb_log = new \phpbb\log\log($db, $user, $auth, $phpbb_dispatcher, $phpbb_root_path, 'adm/', $phpEx, LOG_TABLE); $cache = new phpbb_mock_null_cache; - $cache_driver = new phpbb_cache_driver_null(); - $phpbb_container = $this->getMock('Symfony\Component\DependencyInjection\ContainerInterface'); - $phpbb_container - ->expects($this->any()) - ->method('get') - ->with('cache.driver') - ->will($this->returnValue($cache_driver)); + $cache_driver = new \phpbb\cache\driver\null(); + $phpbb_container = new phpbb_mock_container_builder(); + $phpbb_container->set('cache.driver', $cache_driver); + $phpbb_container->set('notification_manager', new phpbb_mock_notification_manager()); if (!function_exists('utf_clean_string')) { @@ -563,18 +566,18 @@ class phpbb_functional_test_case extends phpbb_test_case { global $db, $cache, $auth, $config, $phpbb_dispatcher, $phpbb_log, $phpbb_container, $phpbb_root_path, $phpEx; - $config = new phpbb_config(array()); + $config = new \phpbb\config\config(array()); $config['coppa_enable'] = 0; $db = $this->get_db(); $phpbb_dispatcher = new phpbb_mock_event_dispatcher(); - $user = $this->getMock('phpbb_user'); - $auth = $this->getMock('phpbb_auth'); + $user = $this->getMock('\phpbb\user'); + $auth = $this->getMock('\phpbb\auth\auth'); - $phpbb_log = new phpbb_log($db, $user, $auth, $phpbb_dispatcher, $phpbb_root_path, 'adm/', $phpEx, LOG_TABLE); + $phpbb_log = new \phpbb\log\log($db, $user, $auth, $phpbb_dispatcher, $phpbb_root_path, 'adm/', $phpEx, LOG_TABLE); $cache = new phpbb_mock_null_cache; - $cache_driver = new phpbb_cache_driver_null(); + $cache_driver = new \phpbb\cache\driver\null(); $phpbb_container = $this->getMock('Symfony\Component\DependencyInjection\ContainerInterface'); $phpbb_container ->expects($this->any()) @@ -928,7 +931,7 @@ class phpbb_functional_test_case extends phpbb_test_case $hidden_fields = array( $crawler->filter('[type="hidden"]')->each(function ($node, $i) { - return array('name' => $node->getAttribute('name'), 'value' => $node->getAttribute('value')); + return array('name' => $node->attr('name'), 'value' => $node->attr('value')); }), ); diff --git a/tests/test_framework/phpbb_search_test_case.php b/tests/test_framework/phpbb_search_test_case.php index 418d352c17..b929e740ea 100644 --- a/tests/test_framework/phpbb_search_test_case.php +++ b/tests/test_framework/phpbb_search_test_case.php @@ -11,7 +11,7 @@ abstract class phpbb_search_test_case extends phpbb_database_test_case { static protected function get_search_wrapper($class) { - $wrapped = $class . '_wrapper'; + $wrapped = str_replace('\\', '_', $class) . '_wrapper'; if (!class_exists($wrapped)) { $code = " diff --git a/tests/test_framework/phpbb_test_case_helpers.php b/tests/test_framework/phpbb_test_case_helpers.php index 3d9cd10f32..351a3a9594 100644 --- a/tests/test_framework/phpbb_test_case_helpers.php +++ b/tests/test_framework/phpbb_test_case_helpers.php @@ -107,7 +107,7 @@ class phpbb_test_case_helpers if (extension_loaded('sqlite') && version_compare(PHPUnit_Runner_Version::id(), '3.4.15', '>=')) { $config = array_merge($config, array( - 'dbms' => 'phpbb_db_driver_sqlite', + 'dbms' => 'phpbb\db\driver\sqlite', 'dbhost' => dirname(__FILE__) . '/../phpbb_unit_tests.sqlite2', // filename 'dbport' => '', 'dbname' => '', diff --git a/tests/tree/nestedset_forum_base.php b/tests/tree/nestedset_forum_base.php index 43680609f8..ce03c1fc21 100644 --- a/tests/tree/nestedset_forum_base.php +++ b/tests/tree/nestedset_forum_base.php @@ -52,11 +52,11 @@ class phpbb_tests_tree_nestedset_forum_base extends phpbb_database_test_case global $config; - $config = $this->config = new phpbb_config(array('nestedset_forum_lock' => 0)); + $config = $this->config = new \phpbb\config\config(array('nestedset_forum_lock' => 0)); set_config(null, null, null, $this->config); - $this->lock = new phpbb_lock_db('nestedset_forum_lock', $this->config, $this->db); - $this->set = new phpbb_tree_nestedset_forum($this->db, $this->lock, 'phpbb_forums'); + $this->lock = new \phpbb\lock\db('nestedset_forum_lock', $this->config, $this->db); + $this->set = new \phpbb\tree\nestedset_forum($this->db, $this->lock, 'phpbb_forums'); $this->set_up_forums(); } @@ -97,7 +97,7 @@ class phpbb_tests_tree_nestedset_forum_base extends phpbb_database_test_case } else { - $buffer = new phpbb_db_sql_insert_buffer($this->db, 'phpbb_forums'); + $buffer = new \phpbb\db\sql_insert_buffer($this->db, 'phpbb_forums'); $buffer->insert_all($forums); $buffer->flush(); diff --git a/tests/user/lang_test.php b/tests/user/lang_test.php index d7ff451a70..c7c858c59d 100644 --- a/tests/user/lang_test.php +++ b/tests/user/lang_test.php @@ -11,7 +11,7 @@ class phpbb_user_lang_test extends phpbb_test_case { public function test_user_lang_sprintf() { - $user = new phpbb_user; + $user = new \phpbb\user; $user->lang = array( 'FOO' => 'BAR', 'BARZ' => 'PENG', @@ -93,7 +93,7 @@ class phpbb_user_lang_test extends phpbb_test_case $this->assertEquals($user->lang('ARRY', 1, 's', 2), '1 post'); // ticket PHPBB3-10345 - different plural rules, not just 0/1/2+ - $user = new phpbb_user; + $user = new \phpbb\user; $user->lang = array( 'PLURAL_RULE' => 13, 'ARRY' => array( diff --git a/tests/user/user_loader_test.php b/tests/user/user_loader_test.php index 5cdb654b18..13c35030f9 100644 --- a/tests/user/user_loader_test.php +++ b/tests/user/user_loader_test.php @@ -24,7 +24,7 @@ class phpbb_user_loader_test extends phpbb_database_test_case parent::setUp(); $this->db = $this->new_dbal(); - $this->user_loader = new phpbb_user_loader($this->db, __DIR__ . '/../../phpBB/', 'php', 'phpbb_users'); + $this->user_loader = new \phpbb\user_loader($this->db, __DIR__ . '/../../phpBB/', 'php', 'phpbb_users'); } public function test_load_get() diff --git a/tests/wrapper/phpbb_php_ini_fake.php b/tests/wrapper/phpbb_php_ini_fake.php index 49bc5936e5..d9e96447e3 100644 --- a/tests/wrapper/phpbb_php_ini_fake.php +++ b/tests/wrapper/phpbb_php_ini_fake.php @@ -7,7 +7,7 @@ * */ -class phpbb_php_ini_fake extends phpbb_php_ini +class phpbb_php_ini_fake extends \phpbb\php\ini { function get($varname) { |