aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/RUNNING_TESTS.txt24
-rw-r--r--tests/cache/common_test_case.php5
-rw-r--r--tests/cache/null_driver_test.php5
-rw-r--r--tests/functional/acp_permissions_test.php128
-rw-r--r--tests/functional/auth_test.php11
-rw-r--r--tests/test_framework/phpbb_functional_test_case.php16
6 files changed, 180 insertions, 9 deletions
diff --git a/tests/RUNNING_TESTS.txt b/tests/RUNNING_TESTS.txt
index cb0ec629d3..cede81d59d 100644
--- a/tests/RUNNING_TESTS.txt
+++ b/tests/RUNNING_TESTS.txt
@@ -17,7 +17,27 @@ 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)
+- 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
+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)
+- 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)
+- zlib (compress tests)
Database Tests
--------------
@@ -44,7 +64,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' \
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'";
diff --git a/tests/functional/acp_permissions_test.php b/tests/functional/acp_permissions_test.php
new file mode 100644
index 0000000000..f7fd44fc89
--- /dev/null
+++ b/tests/functional/acp_permissions_test.php
@@ -0,0 +1,128 @@
+<?php
+/**
+*
+* @package testing
+* @copyright (c) 2012 phpBB Group
+* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
+*
+*/
+
+/**
+* @group functional
+*/
+class phpbb_functional_acp_permissions_test extends phpbb_functional_test_case
+{
+ 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();
+ $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());
+ }
+
+ 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,
+ ),
+ /* Admin does not work yet, probably because founder can do everything
+ 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;
+ $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($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[$object_id][0][$permission]"]);
+ // set to never
+ $data = array("setting[$object_id][0][$permission]" => '0');
+ $form->setValues($data);
+ $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($permission));
+ }
+}
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 a051410d7b..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');
@@ -323,7 +331,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 +351,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();