From ff83580af1af7623012843c56fba605ec2ad7df1 Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Sat, 15 Dec 2012 13:45:33 -0500 Subject: [ticket/10758] Add a test for acp login. PHPBB3-10758 --- tests/functional/auth_test.php | 11 +++++++++++ tests/test_framework/phpbb_functional_test_case.php | 6 ++++-- 2 files changed, 15 insertions(+), 2 deletions(-) (limited to 'tests') diff --git a/tests/functional/auth_test.php b/tests/functional/auth_test.php index 662b1bd38b..f92a4a2210 100644 --- a/tests/functional/auth_test.php +++ b/tests/functional/auth_test.php @@ -49,4 +49,15 @@ class phpbb_functional_auth_test extends phpbb_functional_test_case $this->assert_response_success(); $this->assertContains($this->lang('REGISTER'), $crawler->filter('.navbar')->text()); } + + public function test_acp_login() + { + $this->login(); + $this->admin_login(); + + // check that we are logged in + $crawler = $this->request('GET', 'adm/index.php?sid=' . $this->sid); + $this->assert_response_success(); + $this->assertContains($this->lang('ADMIN_PANEL'), $crawler->filter('h1')->text()); + } } diff --git a/tests/test_framework/phpbb_functional_test_case.php b/tests/test_framework/phpbb_functional_test_case.php index 67a5050892..c599abcbcd 100644 --- a/tests/test_framework/phpbb_functional_test_case.php +++ b/tests/test_framework/phpbb_functional_test_case.php @@ -323,7 +323,7 @@ class phpbb_functional_test_case extends phpbb_test_case * Login to the ACP * You must run login() before calling this. */ - protected function admin_login() + protected function admin_login($username = 'admin') { $this->add_lang('acp/common'); @@ -343,7 +343,9 @@ class phpbb_functional_test_case extends phpbb_test_case { if (strpos($field, 'password_') === 0) { - $login = $this->client->submit($form, array('username' => 'admin', $field => 'admin')); + $crawler = $this->client->submit($form, array('username' => $username, $field => $username)); + $this->assert_response_success(); + $this->assertContains($this->lang('LOGIN_ADMIN_SUCCESS'), $crawler->filter('html')->text()); $cookies = $this->cookieJar->all(); -- cgit v1.2.1 From 7b9092ea3b4ea63bd8c20c1b66b8bd4240e2c497 Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Sat, 15 Dec 2012 16:17:18 -0500 Subject: [ticket/10758] Functional test for changing a user's permission. PHPBB3-10758 --- tests/functional/acp_permissions_test.php | 53 +++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 tests/functional/acp_permissions_test.php (limited to 'tests') diff --git a/tests/functional/acp_permissions_test.php b/tests/functional/acp_permissions_test.php new file mode 100644 index 0000000000..4c5ae9bbb1 --- /dev/null +++ b/tests/functional/acp_permissions_test.php @@ -0,0 +1,53 @@ +login(); + $this->admin_login(); + $this->add_lang('acp/permissions'); + + // Permissions tab + // XXX hardcoded ids + $crawler = $this->request('GET', 'adm/index.php?i=16&sid=' . $this->sid); + $this->assert_response_success(); + // these language strings are html + $this->assertContains($this->lang('ACP_PERMISSIONS_EXPLAIN'), $this->client->getResponse()->getContent()); + + // User permissions + $crawler = $this->request('GET', 'adm/index.php?i=acp_permissions&icat=16&mode=setting_user_global&sid=' . $this->sid); + $this->assert_response_success(); + $this->assertContains($this->lang('ACP_USERS_PERMISSIONS_EXPLAIN'), $this->client->getResponse()->getContent()); + + // Select admin + $form = $crawler->selectButton($this->lang('SUBMIT'))->form(); + $data = array('username[0]' => 'admin'); + $form->setValues($data); + $crawler = $this->client->submit($form); + $this->assert_response_success(); + $this->assertContains($this->lang('ACL_SET'), $crawler->filter('h1')->eq(1)->text()); + + // Set u_hideonline to never + $form = $crawler->selectButton($this->lang('APPLY_PERMISSIONS'))->form(); + // initially it should be a yes + $values = $form->getValues(); + $this->assertEquals(1, $values['setting[2][0][u_hideonline]']); + // set to never + $data = array('setting[2][0][u_hideonline]' => '0'); + $form->setValues($data); + $crawler = $this->client->submit($form); + $this->assert_response_success(); + $this->assertContains($this->lang('AUTH_UPDATED'), $crawler->text()); + } +} -- cgit v1.2.1 From ac3e69cb0856779016dcc02060e8e30b804fcd67 Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Wed, 19 Dec 2012 21:49:41 -0500 Subject: [ticket/10758] Check that acl was changed in the test. PHPBB3-10758 --- tests/functional/acp_permissions_test.php | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/functional/acp_permissions_test.php b/tests/functional/acp_permissions_test.php index 4c5ae9bbb1..0fa7898963 100644 --- a/tests/functional/acp_permissions_test.php +++ b/tests/functional/acp_permissions_test.php @@ -19,7 +19,7 @@ class phpbb_functional_acp_permissions_test extends phpbb_functional_test_case $this->add_lang('acp/permissions'); // Permissions tab - // XXX hardcoded ids + // XXX hardcoded id $crawler = $this->request('GET', 'adm/index.php?i=16&sid=' . $this->sid); $this->assert_response_success(); // these language strings are html @@ -38,6 +38,17 @@ class phpbb_functional_acp_permissions_test extends phpbb_functional_test_case $this->assert_response_success(); $this->assertContains($this->lang('ACL_SET'), $crawler->filter('h1')->eq(1)->text()); + // XXX globals for phpbb_auth, refactor it later + global $db, $cache; + $db = $this->get_db(); + $cache = new phpbb_mock_null_cache; + + $auth = new phpbb_auth; + // XXX hardcoded id + $user_data = $auth->obtain_user_data(2); + $auth->acl($user_data); + $this->assertEquals(1, $auth->acl_get('u_hideonline')); + // Set u_hideonline to never $form = $crawler->selectButton($this->lang('APPLY_PERMISSIONS'))->form(); // initially it should be a yes @@ -49,5 +60,12 @@ class phpbb_functional_acp_permissions_test extends phpbb_functional_test_case $crawler = $this->client->submit($form); $this->assert_response_success(); $this->assertContains($this->lang('AUTH_UPDATED'), $crawler->text()); + + // check acl again + $auth = new phpbb_auth; + // XXX hardcoded id + $user_data = $auth->obtain_user_data(2); + $auth->acl($user_data); + $this->assertEquals(0, $auth->acl_get('u_hideonline')); } } -- cgit v1.2.1 From 3327a4676ce2f894881485aa8f5a5c40c9ea260e Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Sat, 15 Dec 2012 17:26:48 -0500 Subject: [ticket/10758] Test moderator and admin permissions. PHPBB3-10758 --- tests/functional/acp_permissions_test.php | 65 ++++++++++++++++++++++++++++--- 1 file changed, 60 insertions(+), 5 deletions(-) (limited to 'tests') diff --git a/tests/functional/acp_permissions_test.php b/tests/functional/acp_permissions_test.php index 0fa7898963..511306ac84 100644 --- a/tests/functional/acp_permissions_test.php +++ b/tests/functional/acp_permissions_test.php @@ -12,19 +12,27 @@ */ class phpbb_functional_acp_permissions_test extends phpbb_functional_test_case { - public function test_set_permission() + public function setUp() { + parent::setUp(); + $this->login(); $this->admin_login(); $this->add_lang('acp/permissions'); + } + public function test_permissions_tab() + { // Permissions tab // XXX hardcoded id $crawler = $this->request('GET', 'adm/index.php?i=16&sid=' . $this->sid); $this->assert_response_success(); // these language strings are html $this->assertContains($this->lang('ACP_PERMISSIONS_EXPLAIN'), $this->client->getResponse()->getContent()); + } + public function test_select_user() + { // User permissions $crawler = $this->request('GET', 'adm/index.php?i=acp_permissions&icat=16&mode=setting_user_global&sid=' . $this->sid); $this->assert_response_success(); @@ -37,6 +45,53 @@ class phpbb_functional_acp_permissions_test extends phpbb_functional_test_case $crawler = $this->client->submit($form); $this->assert_response_success(); $this->assertContains($this->lang('ACL_SET'), $crawler->filter('h1')->eq(1)->text()); + } + + public function permissions_data() + { + return array( + // description + // permission type + // permission name + // mode + // object name + // object id + array( + 'user permission', + 'u_', + 'u_hideonline', + 'setting_user_global', + 'user_id', + 2, + ), + array( + 'moderator permission', + 'm_', + 'm_ban', + 'setting_mod_global', + 'group_id', + 4, + ), + array( + 'admin permission', + 'a_', + 'a_forum', + 'setting_admin_global', + 'group_id', + 5, + ), + ); + } + + /** + * @dataProvider permissions_data + */ + public function test_change_permission($description, $permission_type, $permission, $mode, $object_name, $object_id) + { + // Get the form + $crawler = $this->request('GET', "adm/index.php?i=acp_permissions&icat=16&mode=$mode&${object_name}[0]=$object_id&type=$permission_type&sid=" . $this->sid); + $this->assert_response_success(); + $this->assertContains($this->lang('ACL_SET'), $crawler->filter('h1')->eq(1)->text()); // XXX globals for phpbb_auth, refactor it later global $db, $cache; @@ -47,15 +102,15 @@ class phpbb_functional_acp_permissions_test extends phpbb_functional_test_case // XXX hardcoded id $user_data = $auth->obtain_user_data(2); $auth->acl($user_data); - $this->assertEquals(1, $auth->acl_get('u_hideonline')); + $this->assertEquals(1, $auth->acl_get($permission)); // Set u_hideonline to never $form = $crawler->selectButton($this->lang('APPLY_PERMISSIONS'))->form(); // initially it should be a yes $values = $form->getValues(); - $this->assertEquals(1, $values['setting[2][0][u_hideonline]']); + $this->assertEquals(1, $values["setting[$object_id][0][$permission]"]); // set to never - $data = array('setting[2][0][u_hideonline]' => '0'); + $data = array("setting[$object_id][0][$permission]" => '0'); $form->setValues($data); $crawler = $this->client->submit($form); $this->assert_response_success(); @@ -66,6 +121,6 @@ class phpbb_functional_acp_permissions_test extends phpbb_functional_test_case // XXX hardcoded id $user_data = $auth->obtain_user_data(2); $auth->acl($user_data); - $this->assertEquals(0, $auth->acl_get('u_hideonline')); + $this->assertEquals(0, $auth->acl_get($permission)); } } -- cgit v1.2.1 From f9cee47003ad76c124822675cf4db0406af1bd70 Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Sat, 15 Dec 2012 17:33:07 -0500 Subject: [ticket/10758] Admin is not working yet. PHPBB3-10758 --- tests/functional/acp_permissions_test.php | 2 ++ 1 file changed, 2 insertions(+) (limited to 'tests') diff --git a/tests/functional/acp_permissions_test.php b/tests/functional/acp_permissions_test.php index 511306ac84..f7fd44fc89 100644 --- a/tests/functional/acp_permissions_test.php +++ b/tests/functional/acp_permissions_test.php @@ -72,6 +72,7 @@ class phpbb_functional_acp_permissions_test extends phpbb_functional_test_case 'group_id', 4, ), + /* Admin does not work yet, probably because founder can do everything array( 'admin permission', 'a_', @@ -80,6 +81,7 @@ class phpbb_functional_acp_permissions_test extends phpbb_functional_test_case 'group_id', 5, ), + */ ); } -- cgit v1.2.1 From c0b3151f0d8c394ab1522332549132ffc4ca3d63 Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Tue, 25 Dec 2012 07:15:58 -0500 Subject: [ticket/11294] Update required/optional extension list for olympus. PHPBB3-11294 --- tests/RUNNING_TESTS.txt | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/RUNNING_TESTS.txt b/tests/RUNNING_TESTS.txt index 7c2a7c3fce..95c6b0a057 100644 --- a/tests/RUNNING_TESTS.txt +++ b/tests/RUNNING_TESTS.txt @@ -17,7 +17,24 @@ PHP extensions Unit tests use several PHP extensions that board code does not use. Currently the following PHP extensions must be installed and enabled to run unit tests: -- ctype +- ctype (also a phpunit dependency) +- dom (phpunit dependency) + +Some of the functionality in phpBB and/or the test suite uses additional +PHP extensions. If these extensions are not loaded, respective tests +will be skipped: + +- apc (APC cache driver) +- bz2 (compress tests) +- interbase, pdo_firebird (Firebird database driver) +- mysql, pdo_mysql (MySQL database driver) +- mysqli, pdo_mysql (MySQLi database driver) +- pdo (any database tests) +- pgsql, pdo_pgsql (PostgreSQL database driver) +- simplexml (any database tests) +- sqlite, pdo_sqlite (SQLite database driver, requires SQLite 2.x support + in pdo_sqlite) +- zlib (compress tests) Database Tests -------------- -- cgit v1.2.1 From bc797c7da22ef1b0c68494d9a93eb23b981e2ebd Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Wed, 26 Dec 2012 10:41:13 -0500 Subject: [ticket/11294] Capitalize phpunit. PHPBB3-11294 --- tests/RUNNING_TESTS.txt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'tests') diff --git a/tests/RUNNING_TESTS.txt b/tests/RUNNING_TESTS.txt index 95c6b0a057..de9c751238 100644 --- a/tests/RUNNING_TESTS.txt +++ b/tests/RUNNING_TESTS.txt @@ -17,8 +17,8 @@ PHP extensions Unit tests use several PHP extensions that board code does not use. Currently the following PHP extensions must be installed and enabled to run unit tests: -- ctype (also a phpunit dependency) -- dom (phpunit dependency) +- ctype (also a PHPUnit dependency) +- dom (PHPUnit dependency) Some of the functionality in phpBB and/or the test suite uses additional PHP extensions. If these extensions are not loaded, respective tests @@ -61,7 +61,7 @@ to use in the environment as follows: $ PHPBB_TEST_CONFIG=tests/test_config.php phpunit Alternatively you can specify parameters in the environment, so e.g. the -following will run phpunit with the same parameters as in the shown +following will run PHPUnit with the same parameters as in the shown test_config.php file: $ PHPBB_TEST_DBMS='mysqli' PHPBB_TEST_DBHOST='localhost' \ -- cgit v1.2.1 From ca7327ba2671b6070b865d013d76f0a8894f2879 Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Tue, 25 Dec 2012 07:17:41 -0500 Subject: [ticket/11294] Update required/optional extension list for develop. PHPBB3-11294 --- tests/RUNNING_TESTS.txt | 3 +++ 1 file changed, 3 insertions(+) (limited to 'tests') diff --git a/tests/RUNNING_TESTS.txt b/tests/RUNNING_TESTS.txt index ee2657c85f..cede81d59d 100644 --- a/tests/RUNNING_TESTS.txt +++ b/tests/RUNNING_TESTS.txt @@ -19,6 +19,7 @@ the following PHP extensions must be installed and enabled to run unit tests: - ctype (also a PHPUnit dependency) - dom (PHPUnit dependency) +- json (also a phpBB dependency) Some of the functionality in phpBB and/or the test suite uses additional PHP extensions. If these extensions are not loaded, respective tests @@ -29,8 +30,10 @@ will be skipped: - interbase, pdo_firebird (Firebird database driver) - mysql, pdo_mysql (MySQL database driver) - mysqli, pdo_mysql (MySQLi database driver) +- pcntl (flock class) - pdo (any database tests) - pgsql, pdo_pgsql (PostgreSQL database driver) +- redis (https://github.com/nicolasff/phpredis, Redis cache driver) - simplexml (any database tests) - sqlite, pdo_sqlite (SQLite database driver, requires SQLite 2.x support in pdo_sqlite) -- cgit v1.2.1 From 9c7772040c473fd453971eeb2c9ee8ed26069a2d Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Sat, 29 Dec 2012 14:23:14 -0500 Subject: [ticket/11037] Fix unit tests. PHPBB3-11037 --- tests/cache/common_test_case.php | 5 +++-- tests/cache/null_driver_test.php | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-) (limited to 'tests') diff --git a/tests/cache/common_test_case.php b/tests/cache/common_test_case.php index fa298ec9ae..a5bc2bfda9 100644 --- a/tests/cache/common_test_case.php +++ b/tests/cache/common_test_case.php @@ -64,9 +64,10 @@ abstract class phpbb_cache_common_test_case extends phpbb_database_test_case public function test_cache_sql() { - global $db, $cache; + global $db, $cache, $phpbb_root_path, $phpEx; + $config = new phpbb_config(array()); $db = $this->new_dbal(); - $cache = new phpbb_cache_service($this->driver); + $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/null_driver_test.php b/tests/cache/null_driver_test.php index 86553d4dc5..43a0cc806c 100644 --- a/tests/cache/null_driver_test.php +++ b/tests/cache/null_driver_test.php @@ -47,9 +47,10 @@ class phpbb_cache_null_driver_test extends phpbb_database_test_case public function test_cache_sql() { - global $db, $cache; + global $db, $cache, $phpbb_root_path, $phpEx; + $config = new phpbb_config(array()); $db = $this->new_dbal(); - $cache = new phpbb_cache_service($this->driver); + $cache = new phpbb_cache_service($this->driver, $config, $db, $phpbb_root_path, $phpEx); $sql = "SELECT * FROM phpbb_config WHERE config_name = 'foo'"; -- cgit v1.2.1 From 0483971f7786b10c3359dfbe4912501de0d6c7de Mon Sep 17 00:00:00 2001 From: Igor Wiedler Date: Wed, 2 Jan 2013 21:44:22 +0100 Subject: [ticket/11305] Mock container for cache driver in functional create_user() create_user has calls to fetch the cache driver from the container. This PR mocks the container and returns a null cache driver in that case. PHPBB3-11305 --- tests/test_framework/phpbb_functional_test_case.php | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/test_framework/phpbb_functional_test_case.php b/tests/test_framework/phpbb_functional_test_case.php index 59979e035d..e346223a4b 100644 --- a/tests/test_framework/phpbb_functional_test_case.php +++ b/tests/test_framework/phpbb_functional_test_case.php @@ -262,7 +262,7 @@ class phpbb_functional_test_case extends phpbb_test_case $config['rand_seed_last_update'] = time() + 600; // Required by user_add - global $db, $cache, $phpbb_dispatcher; + global $db, $cache, $phpbb_dispatcher, $phpbb_container; $db = $this->get_db(); if (!function_exists('phpbb_mock_null_cache')) { @@ -270,6 +270,14 @@ class phpbb_functional_test_case extends phpbb_test_case } $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)); + if (!function_exists('utf_clean_string')) { require_once(__DIR__ . '/../../phpBB/includes/utf/utf_tools.php'); -- cgit v1.2.1