diff options
author | Joas Schilling <nickvergessen@gmx.de> | 2013-03-06 07:35:47 +0100 |
---|---|---|
committer | Joas Schilling <nickvergessen@gmx.de> | 2013-03-06 07:35:47 +0100 |
commit | 0bbde4c12291de7c2effdfbce2f87b212190799e (patch) | |
tree | 917287070d7cabc4e419939033fa6133e028627b /tests | |
parent | 001572f76425a1fdb6621d26dae875438152cc97 (diff) | |
parent | 597c16a9363858e343480f70b1852bce2bba5ca3 (diff) | |
download | forums-0bbde4c12291de7c2effdfbce2f87b212190799e.tar forums-0bbde4c12291de7c2effdfbce2f87b212190799e.tar.gz forums-0bbde4c12291de7c2effdfbce2f87b212190799e.tar.bz2 forums-0bbde4c12291de7c2effdfbce2f87b212190799e.tar.xz forums-0bbde4c12291de7c2effdfbce2f87b212190799e.zip |
Merge branch 'develop' of https://github.com/phpbb/phpbb3 into ticket/11166
* 'develop' of https://github.com/phpbb/phpbb3: (799 commits)
[ticket/11402] Fix undefined index in post/topic_in_queue
[ticket/11400] If email is disabled, disable it for notifications
[ticket/11398] Correctly call permission_set method in permission tool
[ticket/11394] Relax Migration Tools
[ticket/11386] Fix missing ;
[ticket/10714] Get log from container in install, update and download/file
[feature/avatars] Update module_auth of ucp module and fix small issues
[ticket/11396] Rename insert_migration to set_migration_state
[ticket/11395] Prevent acp_modules::get_modules_info from reincluding files
[ticket/11393] Give more information on database updater
[ticket/11386] Send list of migrations instead of using load_migrations
[feature/avatars] Add migrations data file for avatars
[feature/avatars] Reduce module auth of ucp avatar settings
[ticket/10714] Use $phpbb_adm_relative_path instead of hardcoded adm/
[ticket/10714] Logs are disabled for this page call only
[ticket/6723] Show info that message has been deleted before delivery
[ticket/11385] Fix issue with migration module tool not getting extension module info
[ticket/11386] Fix failing tests from constructor changes
[ticket/11386] Fix circular reference error & serialize error
[ticket/11386] Remove tests that check if finder cache is working
...
Conflicts:
phpBB/assets/javascript/core.js
Diffstat (limited to 'tests')
58 files changed, 4619 insertions, 397 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/avatar/driver/barfoo.php b/tests/avatar/driver/barfoo.php new file mode 100644 index 0000000000..0b701a4d70 --- /dev/null +++ b/tests/avatar/driver/barfoo.php @@ -0,0 +1,19 @@ +<?php
+
+class phpbb_avatar_driver_barfoo extends phpbb_avatar_driver
+{
+ public function get_data($row)
+ {
+ return array();
+ }
+
+ public function prepare_form($request, $template, $user, $row, &$error)
+ {
+ return false;
+ }
+
+ public function process_form($request, $template, $user, $row, &$error)
+ {
+ return false;
+ }
+}
diff --git a/tests/avatar/driver/foobar.php b/tests/avatar/driver/foobar.php new file mode 100644 index 0000000000..995f35818b --- /dev/null +++ b/tests/avatar/driver/foobar.php @@ -0,0 +1,19 @@ +<?php
+
+class phpbb_avatar_driver_foobar extends phpbb_avatar_driver
+{
+ public function get_data($row)
+ {
+ return array();
+ }
+
+ public function prepare_form($request, $template, $user, $row, &$error)
+ {
+ return false;
+ }
+
+ public function process_form($request, $template, $user, $row, &$error)
+ {
+ return false;
+ }
+}
diff --git a/tests/avatar/manager_test.php b/tests/avatar/manager_test.php new file mode 100644 index 0000000000..f01ea47c25 --- /dev/null +++ b/tests/avatar/manager_test.php @@ -0,0 +1,90 @@ +<?php
+/**
+*
+* @package testing
+* @version $Id$
+* @copyright (c) 2012 phpBB Group
+* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
+*
+*/
+
+require_once dirname(__FILE__) . '/driver/foobar.php';
+
+class phpbb_avatar_manager_test extends PHPUnit_Framework_TestCase
+{
+ public function setUp()
+ {
+ global $phpbb_root_path, $phpEx;
+
+ // Mock phpbb_container
+ $this->phpbb_container = $this->getMock('Symfony\Component\DependencyInjection\ContainerInterface');
+ $this->phpbb_container->expects($this->any())
+ ->method('get')
+ ->with('avatar.driver.foobar')->will($this->returnValue('avatar.driver.foobar'));
+
+ // Prepare dependencies for avatar manager and driver
+ $config = new phpbb_config(array());
+ $request = $this->getMock('phpbb_request');
+ $cache = $this->getMock('phpbb_cache_driver_interface');
+
+ $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'));
+ $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'));
+
+ $avatar_drivers = array($this->avatar_foobar, $this->avatar_barfoo);
+
+ $config['allow_avatar_' . get_class($this->avatar_foobar)] = true;
+ $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);
+ }
+
+ public function test_get_driver()
+ {
+ $driver = $this->manager->get_driver('avatar.driver.foobar', false);
+ $this->assertEquals('avatar.driver.foobar', $driver);
+
+ $driver = $this->manager->get_driver('avatar.driver.foo_wrong', false);
+ $this->assertNull($driver);
+
+ $driver = $this->manager->get_driver('avatar.driver.foobar');
+ $this->assertEquals('avatar.driver.foobar', $driver);
+
+ $driver = $this->manager->get_driver('avatar.driver.foo_wrong');
+ $this->assertNull($driver);
+ }
+
+ public function test_get_all_drivers()
+ {
+ $drivers = $this->manager->get_all_drivers();
+ $this->assertArrayHasKey('avatar.driver.foobar', $drivers);
+ $this->assertArrayHasKey('avatar.driver.barfoo', $drivers);
+ $this->assertEquals('avatar.driver.foobar', $drivers['avatar.driver.foobar']);
+ $this->assertEquals('avatar.driver.barfoo', $drivers['avatar.driver.barfoo']);
+ }
+
+ public function test_get_enabled_drivers()
+ {
+ $drivers = $this->manager->get_enabled_drivers();
+ $this->assertArrayHasKey('avatar.driver.foobar', $drivers);
+ $this->assertArrayNotHasKey('avatar.driver.barfoo', $drivers);
+ $this->assertEquals('avatar.driver.foobar', $drivers['avatar.driver.foobar']);
+ }
+
+ public function test_get_avatar_settings()
+ {
+ $avatar_settings = $this->manager->get_avatar_settings($this->avatar_foobar);
+
+ $expected_settings = array(
+ 'allow_avatar_' . get_class($this->avatar_foobar) => array('lang' => 'ALLOW_' . strtoupper(get_class($this->avatar_foobar)), 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => false),
+ );
+
+ $this->assertEquals($expected_settings, $avatar_settings);
+ }
+}
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/compress/compress_test.php b/tests/compress/compress_test.php index ac8dd358d3..6623f7ed8a 100644 --- a/tests/compress/compress_test.php +++ b/tests/compress/compress_test.php @@ -38,10 +38,16 @@ class phpbb_compress_test extends phpbb_test_case $phpbb_root_path = ''; $this->path = dirname(__FILE__) . '/fixtures/'; + } - if (!@extension_loaded('zlib') || !@extension_loaded('bz2')) + protected function check_extensions($extensions) + { + foreach ($extensions as $extension) { - $this->markTestSkipped('PHP needs to be compiled with --with-zlib and --with-bz2 in order to run these tests'); + if (!@extension_loaded($extension)) + { + $this->markTestSkipped("$extension extension is not loaded"); + } } } @@ -114,17 +120,18 @@ class phpbb_compress_test extends phpbb_test_case public function tar_archive_list() { return array( - array('archive.tar', '.tar'), - array('archive.tar.gz', '.tar.gz'), - array('archive.tar.bz2', '.tar.bz2'), + array('archive.tar', '.tar', array()), + array('archive.tar.gz', '.tar.gz', array('zlib')), + array('archive.tar.bz2', '.tar.bz2', array('bz2')), ); } /** * @dataProvider tar_archive_list */ - public function test_extract_tar($filename, $type) + public function test_extract_tar($filename, $type, $extensions) { + $this->check_extensions($extensions); $compress = new compress_tar('r', $this->path . $filename); $compress->extract('tests/compress/' . self::EXTRACT_DIR); $this->valid_extraction(); @@ -141,8 +148,10 @@ class phpbb_compress_test extends phpbb_test_case * @depends test_extract_tar * @dataProvider tar_archive_list */ - public function test_compress_tar($filename, $type) + public function test_compress_tar($filename, $type, $extensions) { + $this->check_extensions($extensions); + $tar = dirname(__FILE__) . self::ARCHIVE_DIR . $filename; $compress = new compress_tar('w', $tar); $this->archive_files($compress); @@ -160,6 +169,8 @@ class phpbb_compress_test extends phpbb_test_case */ public function test_compress_zip() { + $this->check_extensions(array('zlib')); + $zip = dirname(__FILE__) . self::ARCHIVE_DIR . 'archive.zip'; $compress = new compress_zip('w', $zip); $this->archive_files($compress); diff --git a/tests/dbal/fixtures/migrator.xml b/tests/dbal/fixtures/migrator.xml new file mode 100644 index 0000000000..25be4d4129 --- /dev/null +++ b/tests/dbal/fixtures/migrator.xml @@ -0,0 +1,29 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<dataset> + <table name="phpbb_migrations"> + <column>migration_name</column> + <column>migration_depends_on</column> + <column>migration_schema_done</column> + <column>migration_data_done</column> + <column>migration_data_state</column> + <column>migration_start_time</column> + <column>migration_end_time</column> + <row> + <value>installed_migration</value> + <value></value> + <value>1</value> + <value>1</value> + <value></value> + <value>1234</value> + <value>5678</value> + </row> + </table> + <table name="phpbb_config"> + <column>config_name</column> + <column>config_value</column> + <row> + <value>foo</value> + <value>bar</value> + </row> + </table> +</dataset> diff --git a/tests/dbal/fixtures/migrator_module.xml b/tests/dbal/fixtures/migrator_module.xml new file mode 100644 index 0000000000..32afe7e6f3 --- /dev/null +++ b/tests/dbal/fixtures/migrator_module.xml @@ -0,0 +1,42 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<dataset> + <table name="phpbb_modules"> + <column>module_id</column> + <column>module_enabled</column> + <column>module_display</column> + <column>module_basename</column> + <column>module_class</column> + <column>parent_id</column> + <column>left_id</column> + <column>right_id</column> + <column>module_langname</column> + <column>module_mode</column> + <column>module_auth</column> + <row> + <value>1</value> + <value>1</value> + <value>1</value> + <value></value> + <value>acp</value> + <value>0</value> + <value>1</value> + <value>4</value> + <value>ACP_CAT</value> + <value></value> + <value></value> + </row> + <row> + <value>2</value> + <value>1</value> + <value>1</value> + <value>acp_test</value> + <value>acp</value> + <value>1</value> + <value>2</value> + <value>3</value> + <value>ACP_MODULE</value> + <value>test</value> + <value></value> + </row> + </table> +</dataset> diff --git a/tests/dbal/fixtures/migrator_permission.xml b/tests/dbal/fixtures/migrator_permission.xml new file mode 100644 index 0000000000..08cec42a42 --- /dev/null +++ b/tests/dbal/fixtures/migrator_permission.xml @@ -0,0 +1,31 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<dataset> + <table name="phpbb_acl_options"> + <column>auth_option_id</column> + <column>auth_option</column> + <column>is_global</column> + <column>is_local</column> + <column>founder_only</column> + <row> + <value>1</value> + <value>global</value> + <value>1</value> + <value>0</value> + <value>0</value> + </row> + <row> + <value>2</value> + <value>local</value> + <value>0</value> + <value>1</value> + <value>0</value> + </row> + <row> + <value>3</value> + <value>both</value> + <value>1</value> + <value>1</value> + <value>0</value> + </row> + </table> +</dataset> diff --git a/tests/dbal/migration/dummy.php b/tests/dbal/migration/dummy.php new file mode 100644 index 0000000000..0ac6e733a1 --- /dev/null +++ b/tests/dbal/migration/dummy.php @@ -0,0 +1,27 @@ +<?php +/** +* +* @package testing +* @copyright (c) 2011 phpBB Group +* @license http://opensource.org/licenses/gpl-license.php GNU Public License +* +*/ + +class phpbb_dbal_migration_dummy extends phpbb_db_migration +{ + static public function depends_on() + { + return array('installed_migration'); + } + + function update_schema() + { + return array( + 'add_columns' => array( + 'phpbb_config' => array( + 'extra_column' => array('UINT', 1), + ), + ), + ); + } +} diff --git a/tests/dbal/migration/fail.php b/tests/dbal/migration/fail.php new file mode 100644 index 0000000000..f88d8169f5 --- /dev/null +++ b/tests/dbal/migration/fail.php @@ -0,0 +1,41 @@ +<?php +/** +* +* @package migration +* @copyright (c) 2012 phpBB Group +* @license http://opensource.org/licenses/gpl-license.php GNU Public License v2 +* +*/ + +class phpbb_dbal_migration_fail extends phpbb_db_migration +{ + function update_schema() + { + return array( + 'add_columns' => array( + $this->table_prefix . 'config' => array( + 'test_column' => array('BOOL', 1), + ), + ), + ); + } + + function revert_schema() + { + return array( + 'drop_columns' => array( + $this->table_prefix . 'config' => array( + 'test_column', + ), + ), + ); + } + + function update_data() + { + return array( + array('config.add', array('foobar3', true)), + array('config.update', array('does_not_exist', true)), + ); + } +} diff --git a/tests/dbal/migration/if.php b/tests/dbal/migration/if.php new file mode 100644 index 0000000000..83fe21bd21 --- /dev/null +++ b/tests/dbal/migration/if.php @@ -0,0 +1,44 @@ +<?php +/** +* +* @package testing +* @copyright (c) 2011 phpBB Group +* @license http://opensource.org/licenses/gpl-license.php GNU Public License +* +*/ + +class phpbb_dbal_migration_if extends phpbb_db_migration +{ + function update_schema() + { + return array(); + } + + function update_data() + { + return array( + array('if', array( + true, + array('custom', array(array(&$this, 'test_true'))), + )), + array('if', array( + false, + array('custom', array(array(&$this, 'test_false'))), + )), + ); + } + + function test_true() + { + global $migrator_test_if_true_failed; + + $migrator_test_if_true_failed = false; + } + + function test_false() + { + global $migrator_test_if_false_failed; + + $migrator_test_if_false_failed = true; + } +} diff --git a/tests/dbal/migration/installed.php b/tests/dbal/migration/installed.php new file mode 100644 index 0000000000..01829f7a99 --- /dev/null +++ b/tests/dbal/migration/installed.php @@ -0,0 +1,30 @@ +<?php +/** +* +* @package testing +* @copyright (c) 2011 phpBB Group +* @license http://opensource.org/licenses/gpl-license.php GNU Public License +* +*/ + +class phpbb_dbal_migration_installed extends phpbb_db_migration +{ + function effectively_installed() + { + return true; + } + + function update_data() + { + return array( + array('custom', array(array(&$this, 'test'))), + ); + } + + function test() + { + global $migrator_test_installed_failed; + + $migrator_test_installed_failed = true; + } +} diff --git a/tests/dbal/migration/recall.php b/tests/dbal/migration/recall.php new file mode 100644 index 0000000000..6c2f04bf08 --- /dev/null +++ b/tests/dbal/migration/recall.php @@ -0,0 +1,38 @@ +<?php +/** +* +* @package testing +* @copyright (c) 2011 phpBB Group +* @license http://opensource.org/licenses/gpl-license.php GNU Public License +* +*/ + +class phpbb_dbal_migration_recall extends phpbb_db_migration +{ + function update_schema() + { + return array(); + } + + function update_data() + { + return array( + array('custom', array(array(&$this, 'test_call'))), + ); + } + + // This function should be called 10 times + function test_call($input) + { + global $migrator_test_call_input; + + $migrator_test_call_input = (int) $input; + + if ($migrator_test_call_input < 10) + { + return ($migrator_test_call_input + 1); + } + + return; + } +} diff --git a/tests/dbal/migration/revert.php b/tests/dbal/migration/revert.php new file mode 100644 index 0000000000..ac01987cd4 --- /dev/null +++ b/tests/dbal/migration/revert.php @@ -0,0 +1,40 @@ +<?php +/** +* +* @package testing +* @copyright (c) 2011 phpBB Group +* @license http://opensource.org/licenses/gpl-license.php GNU Public License +* +*/ + +class phpbb_dbal_migration_revert extends phpbb_db_migration +{ + function update_schema() + { + return array( + 'add_columns' => array( + 'phpbb_config' => array( + 'bar_column' => array('UINT', 1), + ), + ), + ); + } + + function revert_schema() + { + return array( + 'drop_columns' => array( + 'phpbb_config' => array( + 'bar_column', + ), + ), + ); + } + + function update_data() + { + return array( + array('config.add', array('foobartest', 0)), + ); + } +} diff --git a/tests/dbal/migration/revert_with_dependency.php b/tests/dbal/migration/revert_with_dependency.php new file mode 100644 index 0000000000..ca2c070e8c --- /dev/null +++ b/tests/dbal/migration/revert_with_dependency.php @@ -0,0 +1,16 @@ +<?php +/** +* +* @package testing +* @copyright (c) 2011 phpBB Group +* @license http://opensource.org/licenses/gpl-license.php GNU Public License +* +*/ + +class phpbb_dbal_migration_revert_with_dependency extends phpbb_db_migration +{ + static public function depends_on() + { + return array('phpbb_dbal_migration_revert'); + } +} diff --git a/tests/dbal/migration/unfulfillable.php b/tests/dbal/migration/unfulfillable.php new file mode 100644 index 0000000000..6d375e6880 --- /dev/null +++ b/tests/dbal/migration/unfulfillable.php @@ -0,0 +1,26 @@ +<?php +/** +* +* @package testing +* @copyright (c) 2011 phpBB Group +* @license http://opensource.org/licenses/gpl-license.php GNU Public License +* +*/ + +class phpbb_dbal_migration_unfulfillable extends phpbb_db_migration +{ + static public function depends_on() + { + return array('installed_migration', 'phpbb_dbal_migration_dummy', 'non_existant_migration'); + } + + function update_schema() + { + trigger_error('Schema update of migration with unfulfillable dependency was run!'); + } + + function update_data() + { + trigger_error('Data update of migration with unfulfillable dependency was run!'); + } +} diff --git a/tests/dbal/migrator_test.php b/tests/dbal/migrator_test.php new file mode 100644 index 0000000000..89669b85ec --- /dev/null +++ b/tests/dbal/migrator_test.php @@ -0,0 +1,277 @@ +<?php +/** +* +* @package testing +* @copyright (c) 2011 phpBB Group +* @license http://opensource.org/licenses/gpl-license.php GNU Public License +* +*/ + +require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php'; +require_once dirname(__FILE__) . '/../../phpBB/includes/db/migrator.php'; +require_once dirname(__FILE__) . '/../../phpBB/includes/db/migration/migration.php'; +require_once dirname(__FILE__) . '/../../phpBB/includes/db/db_tools.php'; + +require_once dirname(__FILE__) . '/migration/dummy.php'; +require_once dirname(__FILE__) . '/migration/unfulfillable.php'; +require_once dirname(__FILE__) . '/migration/if.php'; +require_once dirname(__FILE__) . '/migration/recall.php'; +require_once dirname(__FILE__) . '/migration/revert.php'; +require_once dirname(__FILE__) . '/migration/revert_with_dependency.php'; +require_once dirname(__FILE__) . '/migration/fail.php'; +require_once dirname(__FILE__) . '/migration/installed.php'; + +class phpbb_dbal_migrator_test extends phpbb_database_test_case +{ + protected $db; + protected $db_tools; + protected $migrator; + + public function getDataSet() + { + return $this->createXMLDataSet(dirname(__FILE__).'/fixtures/migrator.xml'); + } + + public function setUp() + { + parent::setUp(); + + $this->db = $this->new_dbal(); + $this->db_tools = new phpbb_db_tools($this->db); + + $this->config = new phpbb_config_db($this->db, new phpbb_mock_cache, 'phpbb_config'); + + $tools = array( + new phpbb_db_migration_tool_config($this->config), + ); + + $this->migrator = new phpbb_db_migrator( + $this->config, + $this->db, + $this->db_tools, + 'phpbb_migrations', + dirname(__FILE__) . '/../../phpBB/', + 'php', + 'phpbb_', + $tools + ); + $this->extension_manager = new phpbb_extension_manager( + new phpbb_mock_container_builder(), + $this->db, + $this->config, + $this->migrator, + 'phpbb_ext', + dirname(__FILE__) . '/../../phpBB/', + '.php', + null + ); + } + + public function test_update() + { + $this->migrator->set_migrations(array('phpbb_dbal_migration_dummy')); + + // schema + $this->migrator->update(); + $this->assertFalse($this->migrator->finished()); + + $this->assertSqlResultEquals( + array(array('success' => '1')), + "SELECT 1 as success + FROM phpbb_migrations + WHERE migration_name = 'phpbb_dbal_migration_dummy' + AND migration_start_time >= " . (time() - 1) . " + AND migration_start_time <= " . (time() + 1), + 'Start time set correctly' + ); + + // data + $this->migrator->update(); + $this->assertTrue($this->migrator->finished()); + + $this->assertSqlResultEquals( + array(array('extra_column' => '1')), + "SELECT extra_column FROM phpbb_config WHERE config_name = 'foo'", + 'Dummy migration created extra_column with value 1 in all rows.' + ); + + $this->assertSqlResultEquals( + array(array('success' => '1')), + "SELECT 1 as success + FROM phpbb_migrations + WHERE migration_name = 'phpbb_dbal_migration_dummy' + AND migration_start_time <= migration_end_time + AND migration_end_time >= " . (time() - 1) . " + AND migration_end_time <= " . (time() + 1), + 'End time set correctly' + ); + + // cleanup + $this->db_tools->sql_column_remove('phpbb_config', 'extra_column'); + } + + public function test_unfulfillable() + { + $this->migrator->set_migrations(array('phpbb_dbal_migration_unfulfillable', 'phpbb_dbal_migration_dummy')); + + while (!$this->migrator->finished()) + { + $this->migrator->update(); + } + + $this->assertTrue($this->migrator->finished()); + + $this->assertSqlResultEquals( + array(array('extra_column' => '1')), + "SELECT extra_column FROM phpbb_config WHERE config_name = 'foo'", + 'Dummy migration was run, even though an unfulfillable migration was found.' + ); + + $this->db_tools->sql_column_remove('phpbb_config', 'extra_column'); + } + + public function test_if() + { + $this->migrator->set_migrations(array('phpbb_dbal_migration_if')); + + // Don't like this, but I'm not sure there is any other way to do this + global $migrator_test_if_true_failed, $migrator_test_if_false_failed; + $migrator_test_if_true_failed = true; + $migrator_test_if_false_failed = false; + + while (!$this->migrator->finished()) + { + $this->migrator->update(); + } + + if ($migrator_test_if_true_failed) + { + $this->fail('True test failed'); + } + + if ($migrator_test_if_false_failed) + { + $this->fail('False test failed'); + } + } + + public function test_recall() + { + $this->migrator->set_migrations(array('phpbb_dbal_migration_recall')); + + global $migrator_test_call_input; + + // Run the schema first + $this->migrator->update(); + + $i = 0; + while (!$this->migrator->finished()) + { + $this->migrator->update(); + + $this->assertSame($i, $migrator_test_call_input); + + $i++; + } + + $this->assertSame(10, $migrator_test_call_input); + } + + public function test_revert() + { + // Make sure there are no other migrations in the db, this could cause issues + $this->db->sql_query("DELETE FROM phpbb_migrations"); + $this->migrator->load_migration_state(); + + $this->migrator->set_migrations(array('phpbb_dbal_migration_revert', 'phpbb_dbal_migration_revert_with_dependency')); + + $this->assertFalse($this->migrator->migration_state('phpbb_dbal_migration_revert')); + $this->assertFalse($this->migrator->migration_state('phpbb_dbal_migration_revert_with_dependency')); + + // Install the migration first + while (!$this->migrator->finished()) + { + $this->migrator->update(); + } + + $this->assertTrue($this->migrator->migration_state('phpbb_dbal_migration_revert') !== false); + $this->assertTrue($this->migrator->migration_state('phpbb_dbal_migration_revert_with_dependency') !== false); + + $this->assertSqlResultEquals( + array(array('bar_column' => '1')), + "SELECT bar_column FROM phpbb_config WHERE config_name = 'foo'", + 'Installing revert migration failed to create bar_column.' + ); + + $this->assertTrue(isset($this->config['foobartest'])); + + while ($this->migrator->migration_state('phpbb_dbal_migration_revert') !== false) + { + $this->migrator->revert('phpbb_dbal_migration_revert'); + } + + $this->assertFalse($this->migrator->migration_state('phpbb_dbal_migration_revert')); + $this->assertFalse($this->migrator->migration_state('phpbb_dbal_migration_revert_with_dependency')); + + $this->assertFalse(isset($this->config['foobartest'])); + + $sql = 'SELECT * FROM phpbb_config'; + $result = $this->db->sql_query_limit($sql, 1); + $row = $this->db->sql_fetchrow($result); + $this->db->sql_freeresult($result); + + if (isset($row['bar_column'])) + { + $this->fail('Revert did not remove test_column.'); + } + } + + public function test_fail() + { + $this->migrator->set_migrations(array('phpbb_dbal_migration_fail')); + + $this->assertFalse(isset($this->config['foobar3'])); + + try + { + while (!$this->migrator->finished()) + { + $this->migrator->update(); + } + } + 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'])); + + $sql = 'SELECT * FROM phpbb_config'; + $result = $this->db->sql_query_limit($sql, 1); + $row = $this->db->sql_fetchrow($result); + $this->db->sql_freeresult($result); + + if (isset($row['test_column'])) + { + $this->fail('Revert did not remove test_column.'); + } + } + + public function test_installed() + { + $this->migrator->set_migrations(array('phpbb_dbal_migration_installed')); + + global $migrator_test_installed_failed; + $migrator_test_installed_failed = false; + + while (!$this->migrator->finished()) + { + $this->migrator->update(); + } + + $this->assertTrue($this->migrator->migration_state('phpbb_dbal_migration_installed') !== false); + + if ($migrator_test_installed_failed) + { + $this->fail('Installed test failed'); + } + } +} diff --git a/tests/dbal/migrator_tool_config_test.php b/tests/dbal/migrator_tool_config_test.php new file mode 100644 index 0000000000..7d582f230b --- /dev/null +++ b/tests/dbal/migrator_tool_config_test.php @@ -0,0 +1,124 @@ +<?php +/** +* +* @package testing +* @copyright (c) 2011 phpBB Group +* @license http://opensource.org/licenses/gpl-license.php GNU Public License +* +*/ + +require_once dirname(__FILE__) . '/../../phpBB/includes/db/migration/tool/config.php'; +require_once dirname(__FILE__) . '/../../phpBB/includes/db/migration/exception.php'; + +class phpbb_dbal_migrator_tool_config_test extends phpbb_test_case +{ + public function setup() + { + $this->config = new phpbb_config(array()); + + $this->tool = new phpbb_db_migration_tool_config($this->config); + + parent::setup(); + } + + public function test_add() + { + try + { + $this->tool->add('foo', 'bar'); + } + catch (Exception $e) + { + $this->fail($e); + } + $this->assertEquals('bar', $this->config['foo']); + + try + { + $this->tool->add('foo', 'bar'); + $this->fail('Exception not thrown'); + } + catch (Exception $e) {} + } + + public function test_update() + { + $this->config->set('foo', 'bar'); + try + { + $this->tool->update('foo', 'bar2'); + } + catch (Exception $e) + { + $this->fail($e); + } + $this->assertEquals('bar2', $this->config['foo']); + } + + public function test_update_if_equals() + { + $this->config->set('foo', 'bar'); + + try + { + $this->tool->update_if_equals('', 'foo', 'bar2'); + } + catch (Exception $e) + { + $this->fail($e); + } + $this->assertEquals('bar', $this->config['foo']); + + try + { + $this->tool->update_if_equals('bar', 'foo', 'bar2'); + } + catch (Exception $e) + { + $this->fail($e); + } + $this->assertEquals('bar2', $this->config['foo']); + } + + public function test_remove() + { + $this->config->set('foo', 'bar'); + + try + { + $this->tool->remove('foo'); + } + catch (Exception $e) + { + $this->fail($e); + } + $this->assertFalse(isset($this->config['foo'])); + } + + public function test_reverse() + { + $this->config->set('foo', 'bar'); + + try + { + $this->tool->reverse('add', 'foo'); + } + catch (Exception $e) + { + $this->fail($e); + } + $this->assertFalse(isset($this->config['foo'])); + + $this->config->set('foo', 'bar'); + + try + { + $this->tool->reverse('update_if_equals', 'test', 'foo', 'bar'); + } + catch (Exception $e) + { + $this->fail($e); + } + $this->assertEquals('test', $this->config['foo']); + } +} diff --git a/tests/dbal/migrator_tool_module.php b/tests/dbal/migrator_tool_module.php new file mode 100644 index 0000000000..6937b6f8c5 --- /dev/null +++ b/tests/dbal/migrator_tool_module.php @@ -0,0 +1,150 @@ +<?php +/** +* +* @package testing +* @copyright (c) 2011 phpBB Group +* @license http://opensource.org/licenses/gpl-license.php GNU Public License +* +*/ + +require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php'; +require_once dirname(__FILE__) . '/../../phpBB/includes/db/migration/tool/module.php'; +require_once dirname(__FILE__) . '/../../phpBB/includes/db/migration/exception.php'; + +class phpbb_dbal_migrator_tool_module_test extends phpbb_database_test_case +{ + public function getDataSet() + { + return $this->createXMLDataSet(dirname(__FILE__).'/fixtures/migrator_module.xml'); + } + + public function setup() + { + // Need global $db, $user for delete_module function in acp_modules + global $phpbb_root_path, $phpEx, $skip_add_log, $db, $user; + + parent::setup(); + + // Force add_log function to not be used + $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->tool = new phpbb_db_migration_tool_module($this->db, $this->cache, $this->user, $phpbb_root_path, $phpEx, 'phpbb_modules'); + } + + public function exists_data() + { + return array( + // Test the category + array( + '', + 'ACP_CAT', + true, + ), + array( + 0, + 'ACP_CAT', + true, + ), + + // Test the module + array( + '', + 'ACP_MODULE', + false, + ), + array( + false, + 'ACP_MODULE', + true, + ), + array( + 'ACP_CAT', + 'ACP_MODULE', + true, + ), + ); + } + + /** + * @dataProvider exists_data + */ + public function test_exists($parent, $module, $expected) + { + $this->assertEquals($expected, $this->tool->exists('acp', $parent, $module)); + } + + public function test_add() + { + try + { + $this->tool->add('acp', 0, 'ACP_NEW_CAT'); + } + catch (Exception $e) + { + $this->fail($e); + } + $this->assertEquals(true, $this->tool->exists('acp', 0, 'ACP_NEW_CAT')); + + // Should throw an exception when trying to add a module that already exists + try + { + $this->tool->add('acp', 0, 'ACP_NEW_CAT'); + $this->fail('Exception not thrown'); + } + catch (Exception $e) {} + + try + { + $this->tool->add('acp', 'ACP_NEW_CAT', array( + 'module_basename' => 'acp_new_module', + 'module_langname' => 'ACP_NEW_MODULE', + 'module_mode' => 'test', + 'module_auth' => '', + )); + } + catch (Exception $e) + { + $this->fail($e); + } + $this->assertEquals(true, $this->tool->exists('acp', 'ACP_NEW_CAT', 'ACP_NEW_MODULE')); + } + + public function test_remove() + { + try + { + $this->tool->remove('acp', 'ACP_CAT', 'ACP_MODULE'); + } + catch (Exception $e) + { + $this->fail($e); + } + $this->assertEquals(false, $this->tool->exists('acp', 'ACP_CAT', 'ACP_MODULE')); + } + + public function test_reverse() + { + try + { + $this->tool->add('acp', 0, 'ACP_NEW_CAT'); + } + catch (Exception $e) + { + $this->fail($e); + } + + try + { + $this->tool->reverse('add', 'acp', 0, 'ACP_NEW_CAT'); + } + catch (Exception $e) + { + $this->fail($e); + } + $this->assertFalse($this->tool->exists('acp', 0, 'ACP_NEW_CAT')); + } +} diff --git a/tests/dbal/migrator_tool_permission.php b/tests/dbal/migrator_tool_permission.php new file mode 100644 index 0000000000..438ab2b28e --- /dev/null +++ b/tests/dbal/migrator_tool_permission.php @@ -0,0 +1,159 @@ +<?php +/** +* +* @package testing +* @copyright (c) 2011 phpBB Group +* @license http://opensource.org/licenses/gpl-license.php GNU Public License +* +*/ + +require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php'; +require_once dirname(__FILE__) . '/../../phpBB/includes/db/migration/tool/permission.php'; +require_once dirname(__FILE__) . '/../../phpBB/includes/db/migration/exception.php'; + +class phpbb_dbal_migrator_tool_permission_test extends phpbb_database_test_case +{ + public function getDataSet() + { + return $this->createXMLDataSet(dirname(__FILE__).'/fixtures/migrator_permission.xml'); + } + + public function setup() + { + // Global $db and $cache are needed in acp/auth.php constructor + global $phpbb_root_path, $phpEx, $db, $cache; + + 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(); + + $this->tool = new phpbb_db_migration_tool_permission($this->db, $this->cache, $this->auth, $phpbb_root_path, $phpEx); + } + + public function exists_data() + { + return array( + array( + 'global', + true, + true, + ), + array( + 'local', + false, + true, + ), + array( + 'both', + true, + true, + ), + array( + 'both', + false, + true, + ), + array( + 'does_not_exist', + true, + false, + ), + ); + } + + /** + * @dataProvider exists_data + */ + public function test_exists($auth_option, $global, $expected) + { + $this->assertEquals($expected, $this->tool->exists($auth_option, $global)); + } + + public function test_add() + { + try + { + $this->tool->add('new', true); + } + catch (Exception $e) + { + $this->fail($e); + } + $this->assertEquals(true, $this->tool->exists('new', true)); + $this->assertEquals(false, $this->tool->exists('new', false)); + + try + { + $this->tool->add('new', false); + } + catch (Exception $e) + { + $this->fail($e); + } + $this->assertEquals(true, $this->tool->exists('new', false)); + + // Should fail (duplicate) + try + { + $this->tool->add('new', true); + $this->fail('Did not throw exception on duplicate'); + } + catch (Exception $e) {} + } + + public function test_remove() + { + try + { + $this->tool->remove('global', true); + } + catch (Exception $e) + { + $this->fail($e); + } + $this->assertEquals(false, $this->tool->exists('global', true)); + + try + { + $this->tool->remove('both', false); + } + catch (Exception $e) + { + $this->fail($e); + } + $this->assertEquals(false, $this->tool->exists('both', false)); + + // Should fail (does not exist) + try + { + $this->tool->remove('new', true); + $this->fail('Did not throw exception on duplicate'); + } + catch (Exception $e) {} + } + + public function test_reverse() + { + try + { + $this->tool->reverse('remove', 'global_test', true); + } + catch (Exception $e) + { + $this->fail($e); + } + $this->assertTrue($this->tool->exists('global_test', true)); + + try + { + $this->tool->reverse('add', 'global_test', true); + } + catch (Exception $e) + { + $this->fail($e); + } + $this->assertFalse($this->tool->exists('global_test', true)); + } +} diff --git a/tests/extension/finder_test.php b/tests/extension/finder_test.php index 622f404786..c96b11a73c 100644 --- a/tests/extension/finder_test.php +++ b/tests/extension/finder_test.php @@ -142,6 +142,9 @@ class phpbb_extension_finder_test extends phpbb_test_case ); } + /** + * These do not work because of changes with PHPBB3-11386 + * They do not seem neccessary to me, so I am commenting them out for now public function test_get_classes_create_cache() { $cache = new phpbb_mock_cache; @@ -183,11 +186,15 @@ class phpbb_extension_finder_test extends phpbb_test_case 'is_dir' => false, ); - $finder = new phpbb_extension_finder($this->extension_manager, dirname(__FILE__) . '/', new phpbb_mock_cache(array( - '_ext_finder' => array( - md5(serialize($query)) => array('file_name' => 'extension'), - ), - ))); + $finder = new phpbb_extension_finder( + $this->extension_manager, + dirname(__FILE__) . '/', + new phpbb_mock_cache(array( + '_ext_finder' => array( + md5(serialize($query)) => array('file_name' => 'extension'), + ), + )) + ); $classes = $finder ->core_path($query['core_path']) @@ -200,4 +207,5 @@ class phpbb_extension_finder_test extends phpbb_test_case $classes ); } + */ } diff --git a/tests/extension/manager_test.php b/tests/extension/manager_test.php index 5cde5bccdb..1f311116f4 100644 --- a/tests/extension/manager_test.php +++ b/tests/extension/manager_test.php @@ -25,14 +25,7 @@ class phpbb_extension_manager_test extends phpbb_database_test_case { parent::setUp(); - $this->extension_manager = new phpbb_extension_manager( - $this->new_dbal(), - new phpbb_config(array()), - 'phpbb_ext', - dirname(__FILE__) . '/', - '.php', - new phpbb_mock_cache - ); + $this->extension_manager = $this->create_extension_manager(); } public function test_available() @@ -89,15 +82,40 @@ class phpbb_extension_manager_test extends phpbb_database_test_case public function test_enabled_no_cache() { - $extension_manager = new phpbb_extension_manager( - $this->new_dbal(), - new phpbb_config(array()), - 'phpbb_ext', - dirname(__FILE__) . '/', - '.php' - ); + $extension_manager = $this->create_extension_manager(false); $this->assertEquals(array('foo'), array_keys($extension_manager->all_enabled())); } + protected function create_extension_manager($with_cache = true) + { + + $config = new phpbb_config(array()); + $db = $this->new_dbal(); + $db_tools = new phpbb_db_tools($db); + $phpbb_root_path = __DIR__ . './../../phpBB/'; + $php_ext = 'php'; + $table_prefix = 'phpbb_'; + + $migrator = new phpbb_db_migrator( + $config, + $db, + $db_tools, + 'phpbb_migrations', + $phpbb_root_path, + $php_ext, + $table_prefix, + array() + ); + return new phpbb_extension_manager( + new phpbb_mock_container_builder(), + $db, + $config, + $migrator, + 'phpbb_ext', + dirname(__FILE__) . '/', + '.' . $php_ext, + ($with_cache) ? new phpbb_mock_cache() : null + ); + } } diff --git a/tests/extension/metadata_manager_test.php b/tests/extension/metadata_manager_test.php index ce7be0dea5..081a32e277 100644 --- a/tests/extension/metadata_manager_test.php +++ b/tests/extension/metadata_manager_test.php @@ -34,9 +34,11 @@ class metadata_manager_test extends phpbb_database_test_case 'version' => '3.1.0', )); $this->db = $this->new_dbal(); + $this->db_tools = new phpbb_db_tools($this->db); $this->phpbb_root_path = dirname(__FILE__) . '/'; $this->phpEx = '.php'; $this->user = new phpbb_user(); + $this->table_prefix = 'phpbb_'; $this->template = new phpbb_template( $this->phpbb_root_path, @@ -47,9 +49,21 @@ class metadata_manager_test extends phpbb_database_test_case new phpbb_template_context() ); + $this->migrator = new phpbb_db_migrator( + $this->config, + $this->db, + $this->db_tools, + 'phpbb_migrations', + $this->phpbb_root_path, + 'php', + $this->table_prefix, + array() + ); $this->extension_manager = new phpbb_extension_manager( + new phpbb_mock_container_builder(), $this->db, $this->config, + $this->migrator, 'phpbb_ext', $this->phpbb_root_path, $this->phpEx, 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/functional/fileupload_form_test.php b/tests/functional/fileupload_form_test.php index 99afcfdc3d..b663c89e95 100644 --- a/tests/functional/fileupload_form_test.php +++ b/tests/functional/fileupload_form_test.php @@ -44,8 +44,9 @@ class phpbb_functional_fileupload_form_test extends phpbb_functional_test_case public function test_empty_file() { + $this->markTestIncomplete('Test fails intermittently.'); $crawler = $this->upload_file('empty.png', 'image/png'); - $this->assertEquals($this->lang('ATTACHED_IMAGE_NOT_IMAGE'), $crawler->filter('div#message p')->text()); + $this->assertEquals($this->lang('ATTACHED_IMAGE_NOT_IMAGE'), $this->assert_filter($crawler, 'div#message p')->text()); } public function test_invalid_extension() @@ -63,6 +64,7 @@ class phpbb_functional_fileupload_form_test extends phpbb_functional_test_case public function test_valid_file() { + $this->markTestIncomplete('Test fails intermittently.'); $crawler = $this->upload_file('valid.jpg', 'image/jpeg'); $this->assert_response_success(); // ensure there was no error message rendered diff --git a/tests/functions_user/fixtures/group_user_attributes.xml b/tests/functions_user/fixtures/group_user_attributes.xml new file mode 100644 index 0000000000..f4edbdca49 --- /dev/null +++ b/tests/functions_user/fixtures/group_user_attributes.xml @@ -0,0 +1,121 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<dataset> + <table name="phpbb_groups"> + <column>group_id</column> + <column>group_avatar</column> + <column>group_rank</column> + <column>group_desc</column> + <row> + <value>1</value> + <value>default</value> + <value>1</value> + <value></value> + </row> + <row> + <value>2</value> + <value></value> + <value>0</value> + <value></value> + </row> + <row> + <value>3</value> + <value>default2</value> + <value>3</value> + <value></value> + </row> + </table> + <table name="phpbb_users"> + <column>user_id</column> + <column>group_id</column> + <column>user_avatar</column> + <column>user_rank</column> + <column>username_clean</column> + <column>user_permissions</column> + <column>user_sig</column> + <column>user_occ</column> + <column>user_interests</column> + <row> + <value>1</value> + <value>1</value> + <value></value> + <value>0</value> + <value>barfoo</value> + <value></value> + <value></value> + <value></value> + <value></value> + </row> + <row> + <value>2</value> + <value>1</value> + <value>default</value> + <value>1</value> + <value>foobar</value> + <value></value> + <value></value> + <value></value> + <value></value> + </row> + <row> + <value>3</value> + <value>1</value> + <value>custom</value> + <value>2</value> + <value>bertie</value> + <value></value> + <value></value> + <value></value> + <value></value> + </row> + </table> + <table name="phpbb_user_group"> + <column>user_id</column> + <column>group_id</column> + <column>user_pending</column> + <row> + <value>1</value> + <value>1</value> + <value>0</value> + </row> + <row> + <value>1</value> + <value>2</value> + <value>0</value> + </row> + <row> + <value>1</value> + <value>3</value> + <value>0</value> + </row> + <row> + <value>2</value> + <value>1</value> + <value>0</value> + </row> + <row> + <value>2</value> + <value>2</value> + <value>0</value> + </row> + <row> + <value>2</value> + <value>3</value> + <value>0</value> + </row> + <row> + <value>3</value> + <value>1</value> + <value>0</value> + </row> + <row> + <value>3</value> + <value>2</value> + <value>0</value> + </row> + <row> + <value>3</value> + <value>3</value> + <value>0</value> + </row> + </table> +</dataset> diff --git a/tests/functions_user/group_user_attributes_test.php b/tests/functions_user/group_user_attributes_test.php new file mode 100644 index 0000000000..4336fd894e --- /dev/null +++ b/tests/functions_user/group_user_attributes_test.php @@ -0,0 +1,157 @@ +<?php +/** +* +* @package testing +* @copyright (c) 2008 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__) . '/../../phpBB/includes/functions_user.php'; +require_once dirname(__FILE__) . '/../../phpBB/includes/utf/utf_tools.php'; + +class phpbb_functions_user_group_user_attributes_test extends phpbb_database_test_case +{ + public function getDataSet() + { + return $this->createXMLDataSet(dirname(__FILE__).'/fixtures/group_user_attributes.xml'); + } + + public function group_user_attributes_data() + { + return array( + array( + 'Setting new default group without settings for user with no settings - no change', + 1, + 2, + array( + 'group_avatar' => '', + 'group_avatar_type' => 0, + 'group_avatar_height' => 0, + 'group_avatar_width' => 0, + 'group_rank' => 0, + ), + array( + 'user_avatar' => '', + 'user_rank' => 0, + ), + ), + array( + 'Setting new default group without settings for user with default settings - user settings overwritten', + 2, + 2, + array( + 'group_avatar' => '', + 'group_avatar_type' => 0, + 'group_avatar_height' => 0, + 'group_avatar_width' => 0, + 'group_rank' => 0, + ), + array( + 'user_avatar' => '', + 'user_rank' => 0, + ), + ), + array( + 'Setting new default group without settings for user with custom settings - no change', + 3, + 2, + array( + 'group_avatar' => '', + 'group_avatar_type' => 0, + 'group_avatar_height' => 0, + 'group_avatar_width' => 0, + 'group_rank' => 0, + ), + array( + 'user_avatar' => 'custom', + 'user_rank' => 2, + ), + ), + array( + 'Setting new default group with settings for user with no settings - user settings overwritten', + 1, + 3, + array( + 'group_avatar' => 'default2', + 'group_avatar_type' => 1, + 'group_avatar_height' => 1, + 'group_avatar_width' => 1, + 'group_rank' => 3, + ), + array( + 'user_avatar' => 'default2', + 'user_rank' => 3, + ), + ), + array( + 'Setting new default group with settings for user with default settings - user settings overwritten', + 2, + 3, + array( + 'group_avatar' => 'default2', + 'group_avatar_type' => 1, + 'group_avatar_height' => 1, + 'group_avatar_width' => 1, + 'group_rank' => 3, + ), + array( + 'user_avatar' => 'default2', + 'user_rank' => 3, + ), + ), + array( + 'Setting new default group with settings for user with custom settings - no change', + 3, + 3, + array( + 'group_avatar' => 'default2', + 'group_avatar_type' => 1, + 'group_avatar_height' => 1, + 'group_avatar_width' => 1, + 'group_rank' => 3, + ), + array( + 'user_avatar' => 'custom', + 'user_rank' => 2, + ), + ), + ); + } + + /** + * @dataProvider group_user_attributes_data + */ + public function test_group_user_attributes($description, $user_id, $group_id, $group_row, $expected) + { + global $auth, $cache, $db, $phpbb_dispatcher, $user, $phpbb_container, $phpbb_log, $phpbb_root_path, $phpEx; + + $user->ip = ''; + $cache = new phpbb_mock_cache; + $db = $this->new_dbal(); + $phpbb_dispatcher = new phpbb_mock_event_dispatcher(); + $auth = $this->getMock('phpbb_auth'); + $auth->expects($this->any()) + ->method('acl_clear_prefetch'); + $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); + + group_user_attributes('default', $group_id, array($user_id), false, 'group_name', $group_row); + + $sql = 'SELECT user_avatar, user_rank + FROM ' . USERS_TABLE . ' + WHERE user_id = ' . $user_id; + $result = $db->sql_query($sql); + + $this->assertEquals(array($expected), $db->sql_fetchrowset($result)); + + $db->sql_freeresult($result); + } +} diff --git a/tests/group_positions/group_positions_test.php b/tests/group_positions/group_positions_test.php deleted file mode 100644 index c17e25511b..0000000000 --- a/tests/group_positions/group_positions_test.php +++ /dev/null @@ -1,287 +0,0 @@ -<?php -/** -* -* @package testing -* @copyright (c) 2011 phpBB Group -* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 -* -*/ - - -class phpbb_group_positions_test extends phpbb_database_test_case -{ - public function getDataSet() - { - return $this->createXMLDataSet(dirname(__FILE__) . '/fixtures/group_positions.xml'); - } - - public function get_group_value_data() - { - return array( - array('teampage', 1, 0), - array('teampage', 2, 1), - array('legend', 1, 0), - array('legend', 3, 1), - ); - } - - /** - * @dataProvider get_group_value_data - */ - public function test_get_group_value($field, $group_id, $expected) - { - global $db; - - $db = $this->new_dbal(); - - $test_class = new phpbb_group_positions($db, $field); - $this->assertEquals($expected, $test_class->get_group_value($group_id)); - } - - public function get_group_count_data() - { - return array( - array('teampage', 2), - array('legend', 1), - ); - } - - /** - * @dataProvider get_group_count_data - */ - public function test_get_group_count($field, $expected) - { - global $db; - - $db = $this->new_dbal(); - - $test_class = new phpbb_group_positions($db, $field); - $this->assertEquals($expected, $test_class->get_group_count()); - } - - public function add_group_data() - { - return array( - array('teampage', 1, array( - array('group_id' => 1, 'group_teampage' => 3, 'group_legend' => 0), - array('group_id' => 2, 'group_teampage' => 1, 'group_legend' => 0), - array('group_id' => 3, 'group_teampage' => 2, 'group_legend' => 1), - )), - array('teampage', 2, array( - array('group_id' => 1, 'group_teampage' => 0, 'group_legend' => 0), - array('group_id' => 2, 'group_teampage' => 1, 'group_legend' => 0), - array('group_id' => 3, 'group_teampage' => 2, 'group_legend' => 1), - )), - ); - } - - /** - * @dataProvider add_group_data - */ - public function test_add_group($field, $group_id, $expected) - { - global $db; - - $db = $this->new_dbal(); - $test_class = new phpbb_group_positions($db, $field); - $test_class->add_group($group_id); - - $result = $db->sql_query('SELECT group_id, group_teampage, group_legend - FROM ' . GROUPS_TABLE . ' - ORDER BY group_id ASC'); - - $this->assertEquals($expected, $db->sql_fetchrowset($result)); - } - - public function delete_group_data() - { - return array( - array('teampage', 1, false, array( - array('group_id' => 1, 'group_teampage' => 0, 'group_legend' => 0), - array('group_id' => 2, 'group_teampage' => 1, 'group_legend' => 0), - array('group_id' => 3, 'group_teampage' => 2, 'group_legend' => 1), - )), - array('teampage', 2, false, array( - array('group_id' => 1, 'group_teampage' => 0, 'group_legend' => 0), - array('group_id' => 2, 'group_teampage' => 0, 'group_legend' => 0), - array('group_id' => 3, 'group_teampage' => 1, 'group_legend' => 1), - )), - array('teampage', 3, false, array( - array('group_id' => 1, 'group_teampage' => 0, 'group_legend' => 0), - array('group_id' => 2, 'group_teampage' => 1, 'group_legend' => 0), - array('group_id' => 3, 'group_teampage' => 0, 'group_legend' => 1), - )), - array('teampage', 1, true, array( - array('group_id' => 1, 'group_teampage' => 0, 'group_legend' => 0), - array('group_id' => 2, 'group_teampage' => 1, 'group_legend' => 0), - array('group_id' => 3, 'group_teampage' => 2, 'group_legend' => 1), - )), - array('teampage', 2, true, array( - array('group_id' => 1, 'group_teampage' => 0, 'group_legend' => 0), - array('group_id' => 2, 'group_teampage' => 1, 'group_legend' => 0), - array('group_id' => 3, 'group_teampage' => 1, 'group_legend' => 1), - )), - array('teampage', 3, true, array( - array('group_id' => 1, 'group_teampage' => 0, 'group_legend' => 0), - array('group_id' => 2, 'group_teampage' => 1, 'group_legend' => 0), - array('group_id' => 3, 'group_teampage' => 2, 'group_legend' => 1), - )), - ); - } - - /** - * @dataProvider delete_group_data - */ - public function test_delete_group($field, $group_id, $skip_group, $expected) - { - global $db; - - $db = $this->new_dbal(); - $test_class = new phpbb_group_positions($db, $field); - $test_class->delete_group($group_id, $skip_group); - - $result = $db->sql_query('SELECT group_id, group_teampage, group_legend - FROM ' . GROUPS_TABLE . ' - ORDER BY group_id ASC'); - - $this->assertEquals($expected, $db->sql_fetchrowset($result)); - } - - public function move_up_data() - { - return array( - array('teampage', 1, array( - array('group_id' => 1, 'group_teampage' => 0, 'group_legend' => 0), - array('group_id' => 2, 'group_teampage' => 1, 'group_legend' => 0), - array('group_id' => 3, 'group_teampage' => 2, 'group_legend' => 1), - )), - array('teampage', 2, array( - array('group_id' => 1, 'group_teampage' => 0, 'group_legend' => 0), - array('group_id' => 2, 'group_teampage' => 1, 'group_legend' => 0), - array('group_id' => 3, 'group_teampage' => 2, 'group_legend' => 1), - )), - array('teampage', 3, array( - array('group_id' => 1, 'group_teampage' => 0, 'group_legend' => 0), - array('group_id' => 2, 'group_teampage' => 2, 'group_legend' => 0), - array('group_id' => 3, 'group_teampage' => 1, 'group_legend' => 1), - )), - ); - } - - /** - * @dataProvider move_up_data - */ - public function test_move_up($field, $group_id, $expected) - { - global $db; - - $db = $this->new_dbal(); - $test_class = new phpbb_group_positions($db, $field); - $test_class->move_up($group_id); - - $result = $db->sql_query('SELECT group_id, group_teampage, group_legend - FROM ' . GROUPS_TABLE . ' - ORDER BY group_id ASC'); - - $this->assertEquals($expected, $db->sql_fetchrowset($result)); - } - - public function move_down_data() - { - return array( - array('teampage', 1, array( - array('group_id' => 1, 'group_teampage' => 0, 'group_legend' => 0), - array('group_id' => 2, 'group_teampage' => 1, 'group_legend' => 0), - array('group_id' => 3, 'group_teampage' => 2, 'group_legend' => 1), - )), - array('teampage', 2, array( - array('group_id' => 1, 'group_teampage' => 0, 'group_legend' => 0), - array('group_id' => 2, 'group_teampage' => 2, 'group_legend' => 0), - array('group_id' => 3, 'group_teampage' => 1, 'group_legend' => 1), - )), - array('teampage', 3, array( - array('group_id' => 1, 'group_teampage' => 0, 'group_legend' => 0), - array('group_id' => 2, 'group_teampage' => 1, 'group_legend' => 0), - array('group_id' => 3, 'group_teampage' => 2, 'group_legend' => 1), - )), - ); - } - - /** - * @dataProvider move_down_data - */ - public function test_move_down($field, $group_id, $expected) - { - global $db; - - $db = $this->new_dbal(); - $test_class = new phpbb_group_positions($db, $field); - $test_class->move_down($group_id); - - $result = $db->sql_query('SELECT group_id, group_teampage, group_legend - FROM ' . GROUPS_TABLE . ' - ORDER BY group_id ASC'); - - $this->assertEquals($expected, $db->sql_fetchrowset($result)); - } - - public function move_data() - { - return array( - array('teampage', 1, 1, array( - array('group_id' => 1, 'group_teampage' => 0, 'group_legend' => 0), - array('group_id' => 2, 'group_teampage' => 1, 'group_legend' => 0), - array('group_id' => 3, 'group_teampage' => 2, 'group_legend' => 1), - )), - array('teampage', 1, -1, array( - array('group_id' => 1, 'group_teampage' => 0, 'group_legend' => 0), - array('group_id' => 2, 'group_teampage' => 1, 'group_legend' => 0), - array('group_id' => 3, 'group_teampage' => 2, 'group_legend' => 1), - )), - array('teampage', 3, 3, array( - array('group_id' => 1, 'group_teampage' => 0, 'group_legend' => 0), - array('group_id' => 2, 'group_teampage' => 2, 'group_legend' => 0), - array('group_id' => 3, 'group_teampage' => 1, 'group_legend' => 1), - )), - array('teampage', 2, 0, array( - array('group_id' => 1, 'group_teampage' => 0, 'group_legend' => 0), - array('group_id' => 2, 'group_teampage' => 1, 'group_legend' => 0), - array('group_id' => 3, 'group_teampage' => 2, 'group_legend' => 1), - )), - array('teampage', 2, -1, array( - array('group_id' => 1, 'group_teampage' => 0, 'group_legend' => 0), - array('group_id' => 2, 'group_teampage' => 2, 'group_legend' => 0), - array('group_id' => 3, 'group_teampage' => 1, 'group_legend' => 1), - )), - array('teampage', 2, -3, array( - array('group_id' => 1, 'group_teampage' => 0, 'group_legend' => 0), - array('group_id' => 2, 'group_teampage' => 2, 'group_legend' => 0), - array('group_id' => 3, 'group_teampage' => 1, 'group_legend' => 1), - )), - array('teampage', 3, -1, array( - array('group_id' => 1, 'group_teampage' => 0, 'group_legend' => 0), - array('group_id' => 2, 'group_teampage' => 1, 'group_legend' => 0), - array('group_id' => 3, 'group_teampage' => 2, 'group_legend' => 1), - )), - ); - } - - /** - * @dataProvider move_data - */ - public function test_move($field, $group_id, $increment, $expected) - { - global $db; - - $db = $this->new_dbal(); - $test_class = new phpbb_group_positions($db, $field); - $test_class->move($group_id, $increment); - - $result = $db->sql_query('SELECT group_id, group_teampage, group_legend - FROM ' . GROUPS_TABLE . ' - ORDER BY group_id ASC'); - - $this->assertEquals($expected, $db->sql_fetchrowset($result)); - } -} - diff --git a/tests/group_positions/fixtures/group_positions.xml b/tests/groupposition/fixtures/legend.xml index 00ea18fe4f..a9209309bd 100644 --- a/tests/group_positions/fixtures/group_positions.xml +++ b/tests/groupposition/fixtures/legend.xml @@ -2,25 +2,21 @@ <dataset> <table name="phpbb_groups"> <column>group_id</column> - <column>group_teampage</column> <column>group_legend</column> <column>group_desc</column> <row> <value>1</value> <value>0</value> - <value>0</value> <value></value> </row> <row> <value>2</value> <value>1</value> - <value>0</value> <value></value> </row> <row> <value>3</value> <value>2</value> - <value>1</value> <value></value> </row> </table> diff --git a/tests/groupposition/fixtures/teampage.xml b/tests/groupposition/fixtures/teampage.xml new file mode 100644 index 0000000000..b6c39045e3 --- /dev/null +++ b/tests/groupposition/fixtures/teampage.xml @@ -0,0 +1,102 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<dataset> + <table name="phpbb_groups"> + <column>group_id</column> + <column>group_desc</column> + <row> + <value>1</value> + <value></value> + </row> + <row> + <value>2</value> + <value></value> + </row> + <row> + <value>3</value> + <value></value> + </row> + <row> + <value>4</value> + <value></value> + </row> + <row> + <value>5</value> + <value></value> + </row> + <row> + <value>6</value> + <value></value> + </row> + <row> + <value>7</value> + <value></value> + </row> + <row> + <value>8</value> + <value></value> + </row> + </table> + <table name="phpbb_teampage"> + <column>teampage_id</column> + <column>group_id</column> + <column>teampage_name</column> + <column>teampage_position</column> + <column>teampage_parent</column> + <row> + <value>1</value> + <value>1</value> + <value></value> + <value>1</value> + <value>0</value> + </row> + <row> + <value>2</value> + <value>0</value> + <value>category - 2 children</value> + <value>2</value> + <value>0</value> + </row> + <row> + <value>3</value> + <value>2</value> + <value></value> + <value>3</value> + <value>2</value> + </row> + <row> + <value>4</value> + <value>3</value> + <value></value> + <value>4</value> + <value>2</value> + </row> + <row> + <value>5</value> + <value>0</value> + <value>category2 - 2 children</value> + <value>5</value> + <value>0</value> + </row> + <row> + <value>6</value> + <value>4</value> + <value></value> + <value>6</value> + <value>5</value> + </row> + <row> + <value>7</value> + <value>5</value> + <value></value> + <value>7</value> + <value>5</value> + </row> + <row> + <value>8</value> + <value>6</value> + <value></value> + <value>8</value> + <value>0</value> + </row> + </table> +</dataset> diff --git a/tests/groupposition/legend_test.php b/tests/groupposition/legend_test.php new file mode 100644 index 0000000000..16e33b390c --- /dev/null +++ b/tests/groupposition/legend_test.php @@ -0,0 +1,403 @@ +<?php +/** +* +* @package testing +* @copyright (c) 2012 phpBB Group +* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 +* +*/ + + +class phpbb_groupposition_legend_test extends phpbb_database_test_case +{ + public function getDataSet() + { + return $this->createXMLDataSet(dirname(__FILE__) . '/fixtures/legend.xml'); + } + + public function get_group_value_data() + { + return array( + array(1, 0, ''), + array(3, 2, ''), + array(4, 0, 'phpbb_groupposition_exception'), + ); + } + + /** + * @dataProvider get_group_value_data + */ + public function test_get_group_value($group_id, $expected, $throws_exception) + { + global $cache; + + $cache = new phpbb_mock_cache; + $db = $this->new_dbal(); + $user = new phpbb_user; + $user->lang = array(); + + if ($throws_exception) + { + $this->setExpectedException($throws_exception); + } + + $test_class = new phpbb_groupposition_legend($db, $user); + $this->assertEquals($expected, $test_class->get_group_value($group_id)); + } + + public function test_get_group_count() + { + global $cache; + + $cache = new phpbb_mock_cache; + $db = $this->new_dbal(); + $user = new phpbb_user; + $user->lang = array(); + + $test_class = new phpbb_groupposition_legend($db, $user); + $this->assertEquals(2, $test_class->get_group_count()); + } + + public function add_group_data() + { + return array( + array( + 1, + true, + array( + array('group_id' => 1, 'group_legend' => 3), + array('group_id' => 2, 'group_legend' => 1), + array('group_id' => 3, 'group_legend' => 2), + ), + ), + array( + 2, + false, + array( + array('group_id' => 1, 'group_legend' => 0), + array('group_id' => 2, 'group_legend' => 1), + array('group_id' => 3, 'group_legend' => 2), + ), + ), + ); + } + + /** + * @dataProvider add_group_data + */ + public function test_add_group($group_id, $expected_added, $expected) + { + global $cache; + + $cache = new phpbb_mock_cache; + $db = $this->new_dbal(); + $user = new phpbb_user; + $user->lang = array(); + + $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 + FROM ' . GROUPS_TABLE . ' + ORDER BY group_id ASC'); + + $this->assertEquals($expected, $db->sql_fetchrowset($result)); + } + + public function delete_group_data() + { + return array( + array( + 1, + false, + false, + array( + array('group_id' => 1, 'group_legend' => 0), + array('group_id' => 2, 'group_legend' => 1), + array('group_id' => 3, 'group_legend' => 2), + ), + ), + array( + 2, + false, + true, + array( + array('group_id' => 1, 'group_legend' => 0), + array('group_id' => 2, 'group_legend' => 0), + array('group_id' => 3, 'group_legend' => 1), + ), + ), + array( + 3, + false, + true, + array( + array('group_id' => 1, 'group_legend' => 0), + array('group_id' => 2, 'group_legend' => 1), + array('group_id' => 3, 'group_legend' => 0), + ), + ), + array( + 1, + true, + false, + array( + array('group_id' => 1, 'group_legend' => 0), + array('group_id' => 2, 'group_legend' => 1), + array('group_id' => 3, 'group_legend' => 2), + ), + ), + array( + 2, + true, + true, + array( + array('group_id' => 1, 'group_legend' => 0), + array('group_id' => 2, 'group_legend' => 1), + array('group_id' => 3, 'group_legend' => 1), + ), + ), + array( + 3, + true, + true, + array( + array('group_id' => 1, 'group_legend' => 0), + array('group_id' => 2, 'group_legend' => 1), + array('group_id' => 3, 'group_legend' => 2), + ), + ), + ); + } + + /** + * @dataProvider delete_group_data + */ + public function test_delete_group($group_id, $skip_group, $expected_deleted, $expected) + { + global $cache; + + $cache = new phpbb_mock_cache; + $db = $this->new_dbal(); + $user = new phpbb_user; + $user->lang = array(); + + $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 + FROM ' . GROUPS_TABLE . ' + ORDER BY group_id ASC'); + + $this->assertEquals($expected, $db->sql_fetchrowset($result)); + } + + public function move_up_data() + { + return array( + array( + 1, + false, + array( + array('group_id' => 1, 'group_legend' => 0), + array('group_id' => 2, 'group_legend' => 1), + array('group_id' => 3, 'group_legend' => 2), + ), + ), + array( + 2, + false, + array( + array('group_id' => 1, 'group_legend' => 0), + array('group_id' => 2, 'group_legend' => 1), + array('group_id' => 3, 'group_legend' => 2), + ), + ), + array( + 3, + true, + array( + array('group_id' => 1, 'group_legend' => 0), + array('group_id' => 2, 'group_legend' => 2), + array('group_id' => 3, 'group_legend' => 1), + ), + ), + ); + } + + /** + * @dataProvider move_up_data + */ + public function test_move_up($group_id, $excepted_moved, $expected) + { + global $cache; + + $cache = new phpbb_mock_cache; + $db = $this->new_dbal(); + $user = new phpbb_user; + $user->lang = array(); + + $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 + FROM ' . GROUPS_TABLE . ' + ORDER BY group_id ASC'); + + $this->assertEquals($expected, $db->sql_fetchrowset($result)); + } + + public function move_down_data() + { + return array( + array( + 1, + false, + array( + array('group_id' => 1, 'group_legend' => 0), + array('group_id' => 2, 'group_legend' => 1), + array('group_id' => 3, 'group_legend' => 2), + ), + ), + array( + 2, + true, + array( + array('group_id' => 1, 'group_legend' => 0), + array('group_id' => 2, 'group_legend' => 2), + array('group_id' => 3, 'group_legend' => 1), + ), + ), + array( + 3, + false, + array( + array('group_id' => 1, 'group_legend' => 0), + array('group_id' => 2, 'group_legend' => 1), + array('group_id' => 3, 'group_legend' => 2), + ), + ), + ); + } + + /** + * @dataProvider move_down_data + */ + public function test_move_down($group_id, $excepted_moved, $expected) + { + global $cache; + + $cache = new phpbb_mock_cache; + $db = $this->new_dbal(); + $user = new phpbb_user; + $user->lang = array(); + + $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 + FROM ' . GROUPS_TABLE . ' + ORDER BY group_id ASC'); + + $this->assertEquals($expected, $db->sql_fetchrowset($result)); + } + + public function move_data() + { + return array( + array( + 1, + 1, + false, + array( + array('group_id' => 1, 'group_legend' => 0), + array('group_id' => 2, 'group_legend' => 1), + array('group_id' => 3, 'group_legend' => 2), + ), + ), + array( + 1, + -1, + false, + array( + array('group_id' => 1, 'group_legend' => 0), + array('group_id' => 2, 'group_legend' => 1), + array('group_id' => 3, 'group_legend' => 2), + ), + ), + array( + 3, + 3, + true, + array( + array('group_id' => 1, 'group_legend' => 0), + array('group_id' => 2, 'group_legend' => 2), + array('group_id' => 3, 'group_legend' => 1), + ), + ), + array( + 2, + 0, + false, + array( + array('group_id' => 1, 'group_legend' => 0), + array('group_id' => 2, 'group_legend' => 1), + array('group_id' => 3, 'group_legend' => 2), + ), + ), + array( + 2, + -1, + true, + array( + array('group_id' => 1, 'group_legend' => 0), + array('group_id' => 2, 'group_legend' => 2), + array('group_id' => 3, 'group_legend' => 1), + ), + ), + array( + 2, + -3, + true, + array( + array('group_id' => 1, 'group_legend' => 0), + array('group_id' => 2, 'group_legend' => 2), + array('group_id' => 3, 'group_legend' => 1), + ), + ), + array( + 3, + -1, + false, + array( + array('group_id' => 1, 'group_legend' => 0), + array('group_id' => 2, 'group_legend' => 1), + array('group_id' => 3, 'group_legend' => 2), + ), + ), + ); + } + + /** + * @dataProvider move_data + */ + public function test_move($group_id, $increment, $excepted_moved, $expected) + { + global $cache; + + $cache = new phpbb_mock_cache; + $db = $this->new_dbal(); + $user = new phpbb_user; + $user->lang = array(); + + $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 + FROM ' . GROUPS_TABLE . ' + ORDER BY group_id ASC'); + + $this->assertEquals($expected, $db->sql_fetchrowset($result)); + } +} + diff --git a/tests/groupposition/teampage_test.php b/tests/groupposition/teampage_test.php new file mode 100644 index 0000000000..db26cd09d5 --- /dev/null +++ b/tests/groupposition/teampage_test.php @@ -0,0 +1,641 @@ +<?php +/** +* +* @package testing +* @copyright (c) 2012 phpBB Group +* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 +* +*/ + +require_once dirname(__FILE__) . '/../../phpBB/includes/utf/utf_tools.php'; +require_once dirname(__FILE__) . '/../../phpBB/includes/functions_content.php'; + +class phpbb_groupposition_teampage_test extends phpbb_database_test_case +{ + public function getDataSet() + { + return $this->createXMLDataSet(dirname(__FILE__) . '/fixtures/teampage.xml'); + } + + public function get_group_value_data() + { + return array( + array(2, 3, ''), + array(6, 8, ''), + array(10, 0, 'phpbb_groupposition_exception'), + ); + } + + /** + * @dataProvider get_group_value_data + */ + public function test_get_group_value($group_id, $expected, $throws_exception) + { + global $cache; + + $cache = new phpbb_mock_cache; + $db = $this->new_dbal(); + $user = new phpbb_user; + $user->lang = array(); + + if ($throws_exception) + { + $this->setExpectedException($throws_exception); + } + + $test_class = new phpbb_groupposition_teampage($db, $user, $cache); + $this->assertEquals($expected, $test_class->get_group_value($group_id)); + } + + public function test_get_group_count() + { + global $cache; + + $cache = new phpbb_mock_cache; + $db = $this->new_dbal(); + $user = new phpbb_user; + $user->lang = array(); + + $test_class = new phpbb_groupposition_teampage($db, $user, $cache); + $this->assertEquals(8, $test_class->get_group_count()); + } + + public function add_group_teampage_data() + { + return array( + array( + 1, + 2, + false, + array( + array('teampage_position' => 1, 'group_id' => 1, 'teampage_parent' => 0, 'teampage_name' => ''), + array('teampage_position' => 2, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category - 2 children'), + array('teampage_position' => 3, 'group_id' => 2, 'teampage_parent' => 2, 'teampage_name' => ''), + array('teampage_position' => 4, 'group_id' => 3, 'teampage_parent' => 2, 'teampage_name' => ''), + array('teampage_position' => 5, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category2 - 2 children'), + array('teampage_position' => 6, 'group_id' => 4, 'teampage_parent' => 5, 'teampage_name' => ''), + array('teampage_position' => 7, 'group_id' => 5, 'teampage_parent' => 5, 'teampage_name' => ''), + array('teampage_position' => 8, 'group_id' => 6, 'teampage_parent' => 0, 'teampage_name' => ''), + ), + ), + array( + 6, + 2, + false, + array( + array('teampage_position' => 1, 'group_id' => 1, 'teampage_parent' => 0, 'teampage_name' => ''), + array('teampage_position' => 2, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category - 2 children'), + array('teampage_position' => 3, 'group_id' => 2, 'teampage_parent' => 2, 'teampage_name' => ''), + array('teampage_position' => 4, 'group_id' => 3, 'teampage_parent' => 2, 'teampage_name' => ''), + array('teampage_position' => 5, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category2 - 2 children'), + array('teampage_position' => 6, 'group_id' => 4, 'teampage_parent' => 5, 'teampage_name' => ''), + array('teampage_position' => 7, 'group_id' => 5, 'teampage_parent' => 5, 'teampage_name' => ''), + array('teampage_position' => 8, 'group_id' => 6, 'teampage_parent' => 0, 'teampage_name' => ''), + ), + ), + array( + 7, + 2, + true, + array( + array('teampage_position' => 1, 'group_id' => 1, 'teampage_parent' => 0, 'teampage_name' => ''), + array('teampage_position' => 2, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category - 2 children'), + array('teampage_position' => 3, 'group_id' => 2, 'teampage_parent' => 2, 'teampage_name' => ''), + array('teampage_position' => 4, 'group_id' => 3, 'teampage_parent' => 2, 'teampage_name' => ''), + array('teampage_position' => 5, 'group_id' => 7, 'teampage_parent' => 2, 'teampage_name' => ''), + array('teampage_position' => 6, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category2 - 2 children'), + array('teampage_position' => 7, 'group_id' => 4, 'teampage_parent' => 5, 'teampage_name' => ''), + array('teampage_position' => 8, 'group_id' => 5, 'teampage_parent' => 5, 'teampage_name' => ''), + array('teampage_position' => 9, 'group_id' => 6, 'teampage_parent' => 0, 'teampage_name' => ''), + ), + ), + array( + 7, + 0, + true, + array( + array('teampage_position' => 1, 'group_id' => 1, 'teampage_parent' => 0, 'teampage_name' => ''), + array('teampage_position' => 2, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category - 2 children'), + array('teampage_position' => 3, 'group_id' => 2, 'teampage_parent' => 2, 'teampage_name' => ''), + array('teampage_position' => 4, 'group_id' => 3, 'teampage_parent' => 2, 'teampage_name' => ''), + array('teampage_position' => 5, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category2 - 2 children'), + array('teampage_position' => 6, 'group_id' => 4, 'teampage_parent' => 5, 'teampage_name' => ''), + array('teampage_position' => 7, 'group_id' => 5, 'teampage_parent' => 5, 'teampage_name' => ''), + array('teampage_position' => 8, 'group_id' => 6, 'teampage_parent' => 0, 'teampage_name' => ''), + array('teampage_position' => 9, 'group_id' => 7, 'teampage_parent' => 0, 'teampage_name' => ''), + ), + ), + ); + } + + /** + * @dataProvider add_group_teampage_data + */ + public function test_add_group_teampage($group_id, $parent_id, $expected_added, $expected) + { + global $cache; + + $cache = new phpbb_mock_cache; + $db = $this->new_dbal(); + $user = new phpbb_user; + $user->lang = array(); + + $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 + FROM ' . TEAMPAGE_TABLE . ' + ORDER BY teampage_position ASC'); + + $this->assertEquals($expected, $db->sql_fetchrowset($result)); + } + + public function add_category_teampage_data() + { + return array( + array( + 'new', + true, + array( + array('teampage_position' => 1, 'group_id' => 1, 'teampage_parent' => 0, 'teampage_name' => ''), + array('teampage_position' => 2, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category - 2 children'), + array('teampage_position' => 3, 'group_id' => 2, 'teampage_parent' => 2, 'teampage_name' => ''), + array('teampage_position' => 4, 'group_id' => 3, 'teampage_parent' => 2, 'teampage_name' => ''), + array('teampage_position' => 5, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category2 - 2 children'), + array('teampage_position' => 6, 'group_id' => 4, 'teampage_parent' => 5, 'teampage_name' => ''), + array('teampage_position' => 7, 'group_id' => 5, 'teampage_parent' => 5, 'teampage_name' => ''), + array('teampage_position' => 8, 'group_id' => 6, 'teampage_parent' => 0, 'teampage_name' => ''), + array('teampage_position' => 9, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'new'), + ), + ), + ); + } + + /** + * @dataProvider add_category_teampage_data + */ + public function test_add_category_teampage($group_name, $expected_added, $expected) + { + global $cache; + + $cache = new phpbb_mock_cache; + $db = $this->new_dbal(); + $user = new phpbb_user; + $user->lang = array(); + + $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 + FROM ' . TEAMPAGE_TABLE . ' + ORDER BY teampage_position ASC'); + + $this->assertEquals($expected, $db->sql_fetchrowset($result)); + } + + public function delete_group_data() + { + return array( + array( + 1, + true, + array( + array('teampage_position' => 1, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category - 2 children'), + array('teampage_position' => 2, 'group_id' => 2, 'teampage_parent' => 2, 'teampage_name' => ''), + array('teampage_position' => 3, 'group_id' => 3, 'teampage_parent' => 2, 'teampage_name' => ''), + array('teampage_position' => 4, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category2 - 2 children'), + array('teampage_position' => 5, 'group_id' => 4, 'teampage_parent' => 5, 'teampage_name' => ''), + array('teampage_position' => 6, 'group_id' => 5, 'teampage_parent' => 5, 'teampage_name' => ''), + array('teampage_position' => 7, 'group_id' => 6, 'teampage_parent' => 0, 'teampage_name' => ''), + ), + ), + array( + 2, + true, + array( + array('teampage_position' => 1, 'group_id' => 1, 'teampage_parent' => 0, 'teampage_name' => ''), + array('teampage_position' => 2, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category - 2 children'), + array('teampage_position' => 3, 'group_id' => 3, 'teampage_parent' => 2, 'teampage_name' => ''), + array('teampage_position' => 4, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category2 - 2 children'), + array('teampage_position' => 5, 'group_id' => 4, 'teampage_parent' => 5, 'teampage_name' => ''), + array('teampage_position' => 6, 'group_id' => 5, 'teampage_parent' => 5, 'teampage_name' => ''), + array('teampage_position' => 7, 'group_id' => 6, 'teampage_parent' => 0, 'teampage_name' => ''), + ), + ), + array( + 6, + true, + array( + array('teampage_position' => 1, 'group_id' => 1, 'teampage_parent' => 0, 'teampage_name' => ''), + array('teampage_position' => 2, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category - 2 children'), + array('teampage_position' => 3, 'group_id' => 2, 'teampage_parent' => 2, 'teampage_name' => ''), + array('teampage_position' => 4, 'group_id' => 3, 'teampage_parent' => 2, 'teampage_name' => ''), + array('teampage_position' => 5, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category2 - 2 children'), + array('teampage_position' => 6, 'group_id' => 4, 'teampage_parent' => 5, 'teampage_name' => ''), + array('teampage_position' => 7, 'group_id' => 5, 'teampage_parent' => 5, 'teampage_name' => ''), + ), + ), + ); + } + + /** + * @dataProvider delete_group_data + */ + public function test_delete_group($group_id, $expected_deleted, $expected) + { + global $cache; + + $cache = new phpbb_mock_cache; + $db = $this->new_dbal(); + $user = new phpbb_user; + $user->lang = array(); + + $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 + FROM ' . TEAMPAGE_TABLE . ' + ORDER BY teampage_position ASC'); + + $this->assertEquals($expected, $db->sql_fetchrowset($result)); + } + + public function delete_teampage_data() + { + return array( + array( + 1, + true, + array( + array('teampage_position' => 1, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category - 2 children'), + array('teampage_position' => 2, 'group_id' => 2, 'teampage_parent' => 2, 'teampage_name' => ''), + array('teampage_position' => 3, 'group_id' => 3, 'teampage_parent' => 2, 'teampage_name' => ''), + array('teampage_position' => 4, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category2 - 2 children'), + array('teampage_position' => 5, 'group_id' => 4, 'teampage_parent' => 5, 'teampage_name' => ''), + array('teampage_position' => 6, 'group_id' => 5, 'teampage_parent' => 5, 'teampage_name' => ''), + array('teampage_position' => 7, 'group_id' => 6, 'teampage_parent' => 0, 'teampage_name' => ''), + ), + ), + array( + 2, + true, + array( + array('teampage_position' => 1, 'group_id' => 1, 'teampage_parent' => 0, 'teampage_name' => ''), + array('teampage_position' => 2, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category2 - 2 children'), + array('teampage_position' => 3, 'group_id' => 4, 'teampage_parent' => 5, 'teampage_name' => ''), + array('teampage_position' => 4, 'group_id' => 5, 'teampage_parent' => 5, 'teampage_name' => ''), + array('teampage_position' => 5, 'group_id' => 6, 'teampage_parent' => 0, 'teampage_name' => ''), + ), + ), + ); + } + + /** + * @dataProvider delete_teampage_data + */ + public function test_delete_teampage($teampage_id, $expected_deleted, $expected) + { + global $cache; + + $cache = new phpbb_mock_cache; + $db = $this->new_dbal(); + $user = new phpbb_user; + $user->lang = array(); + + $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 + FROM ' . TEAMPAGE_TABLE . ' + ORDER BY teampage_position ASC'); + + $this->assertEquals($expected, $db->sql_fetchrowset($result)); + } + + public function move_data() + { + return array( + array( + 1, + 1, + false, + array( + array('teampage_position' => 1, 'group_id' => 1, 'teampage_parent' => 0, 'teampage_name' => ''), + array('teampage_position' => 2, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category - 2 children'), + array('teampage_position' => 3, 'group_id' => 2, 'teampage_parent' => 2, 'teampage_name' => ''), + array('teampage_position' => 4, 'group_id' => 3, 'teampage_parent' => 2, 'teampage_name' => ''), + array('teampage_position' => 5, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category2 - 2 children'), + array('teampage_position' => 6, 'group_id' => 4, 'teampage_parent' => 5, 'teampage_name' => ''), + array('teampage_position' => 7, 'group_id' => 5, 'teampage_parent' => 5, 'teampage_name' => ''), + array('teampage_position' => 8, 'group_id' => 6, 'teampage_parent' => 0, 'teampage_name' => ''), + ), + ), + array( + 2, + 1, + false, + array( + array('teampage_position' => 1, 'group_id' => 1, 'teampage_parent' => 0, 'teampage_name' => ''), + array('teampage_position' => 2, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category - 2 children'), + array('teampage_position' => 3, 'group_id' => 2, 'teampage_parent' => 2, 'teampage_name' => ''), + array('teampage_position' => 4, 'group_id' => 3, 'teampage_parent' => 2, 'teampage_name' => ''), + array('teampage_position' => 5, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category2 - 2 children'), + array('teampage_position' => 6, 'group_id' => 4, 'teampage_parent' => 5, 'teampage_name' => ''), + array('teampage_position' => 7, 'group_id' => 5, 'teampage_parent' => 5, 'teampage_name' => ''), + array('teampage_position' => 8, 'group_id' => 6, 'teampage_parent' => 0, 'teampage_name' => ''), + ), + ), + array( + 5, + 1, + true, + array( + array('teampage_position' => 1, 'group_id' => 1, 'teampage_parent' => 0, 'teampage_name' => ''), + array('teampage_position' => 2, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category - 2 children'), + array('teampage_position' => 3, 'group_id' => 2, 'teampage_parent' => 2, 'teampage_name' => ''), + array('teampage_position' => 4, 'group_id' => 3, 'teampage_parent' => 2, 'teampage_name' => ''), + array('teampage_position' => 5, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category2 - 2 children'), + array('teampage_position' => 6, 'group_id' => 5, 'teampage_parent' => 5, 'teampage_name' => ''), + array('teampage_position' => 7, 'group_id' => 4, 'teampage_parent' => 5, 'teampage_name' => ''), + array('teampage_position' => 8, 'group_id' => 6, 'teampage_parent' => 0, 'teampage_name' => ''), + ), + ), + array( + 6, + 1, + true, + array( + array('teampage_position' => 1, 'group_id' => 1, 'teampage_parent' => 0, 'teampage_name' => ''), + array('teampage_position' => 2, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category - 2 children'), + array('teampage_position' => 3, 'group_id' => 2, 'teampage_parent' => 2, 'teampage_name' => ''), + array('teampage_position' => 4, 'group_id' => 3, 'teampage_parent' => 2, 'teampage_name' => ''), + array('teampage_position' => 5, 'group_id' => 6, 'teampage_parent' => 0, 'teampage_name' => ''), + array('teampage_position' => 6, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category2 - 2 children'), + array('teampage_position' => 7, 'group_id' => 4, 'teampage_parent' => 5, 'teampage_name' => ''), + array('teampage_position' => 8, 'group_id' => 5, 'teampage_parent' => 5, 'teampage_name' => ''), + ), + ), + array( + 1, + -1, + true, + array( + array('teampage_position' => 1, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category - 2 children'), + array('teampage_position' => 2, 'group_id' => 2, 'teampage_parent' => 2, 'teampage_name' => ''), + array('teampage_position' => 3, 'group_id' => 3, 'teampage_parent' => 2, 'teampage_name' => ''), + array('teampage_position' => 4, 'group_id' => 1, 'teampage_parent' => 0, 'teampage_name' => ''), + array('teampage_position' => 5, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category2 - 2 children'), + array('teampage_position' => 6, 'group_id' => 4, 'teampage_parent' => 5, 'teampage_name' => ''), + array('teampage_position' => 7, 'group_id' => 5, 'teampage_parent' => 5, 'teampage_name' => ''), + array('teampage_position' => 8, 'group_id' => 6, 'teampage_parent' => 0, 'teampage_name' => ''), + ), + ), + array( + 2, + -1, + true, + array( + array('teampage_position' => 1, 'group_id' => 1, 'teampage_parent' => 0, 'teampage_name' => ''), + array('teampage_position' => 2, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category - 2 children'), + array('teampage_position' => 3, 'group_id' => 3, 'teampage_parent' => 2, 'teampage_name' => ''), + array('teampage_position' => 4, 'group_id' => 2, 'teampage_parent' => 2, 'teampage_name' => ''), + array('teampage_position' => 5, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category2 - 2 children'), + array('teampage_position' => 6, 'group_id' => 4, 'teampage_parent' => 5, 'teampage_name' => ''), + array('teampage_position' => 7, 'group_id' => 5, 'teampage_parent' => 5, 'teampage_name' => ''), + array('teampage_position' => 8, 'group_id' => 6, 'teampage_parent' => 0, 'teampage_name' => ''), + ), + ), + array( + 5, + -1, + false, + array( + array('teampage_position' => 1, 'group_id' => 1, 'teampage_parent' => 0, 'teampage_name' => ''), + array('teampage_position' => 2, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category - 2 children'), + array('teampage_position' => 3, 'group_id' => 2, 'teampage_parent' => 2, 'teampage_name' => ''), + array('teampage_position' => 4, 'group_id' => 3, 'teampage_parent' => 2, 'teampage_name' => ''), + array('teampage_position' => 5, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category2 - 2 children'), + array('teampage_position' => 6, 'group_id' => 4, 'teampage_parent' => 5, 'teampage_name' => ''), + array('teampage_position' => 7, 'group_id' => 5, 'teampage_parent' => 5, 'teampage_name' => ''), + array('teampage_position' => 8, 'group_id' => 6, 'teampage_parent' => 0, 'teampage_name' => ''), + ), + ), + array( + 6, + -1, + false, + array( + array('teampage_position' => 1, 'group_id' => 1, 'teampage_parent' => 0, 'teampage_name' => ''), + array('teampage_position' => 2, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category - 2 children'), + array('teampage_position' => 3, 'group_id' => 2, 'teampage_parent' => 2, 'teampage_name' => ''), + array('teampage_position' => 4, 'group_id' => 3, 'teampage_parent' => 2, 'teampage_name' => ''), + array('teampage_position' => 5, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category2 - 2 children'), + array('teampage_position' => 6, 'group_id' => 4, 'teampage_parent' => 5, 'teampage_name' => ''), + array('teampage_position' => 7, 'group_id' => 5, 'teampage_parent' => 5, 'teampage_name' => ''), + array('teampage_position' => 8, 'group_id' => 6, 'teampage_parent' => 0, 'teampage_name' => ''), + ), + ), + array( + 6, + 3, + true, + array( + array('teampage_position' => 1, 'group_id' => 6, 'teampage_parent' => 0, 'teampage_name' => ''), + array('teampage_position' => 2, 'group_id' => 1, 'teampage_parent' => 0, 'teampage_name' => ''), + array('teampage_position' => 3, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category - 2 children'), + array('teampage_position' => 4, 'group_id' => 2, 'teampage_parent' => 2, 'teampage_name' => ''), + array('teampage_position' => 5, 'group_id' => 3, 'teampage_parent' => 2, 'teampage_name' => ''), + array('teampage_position' => 6, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category2 - 2 children'), + array('teampage_position' => 7, 'group_id' => 4, 'teampage_parent' => 5, 'teampage_name' => ''), + array('teampage_position' => 8, 'group_id' => 5, 'teampage_parent' => 5, 'teampage_name' => ''), + ), + ), + ); + } + + /** + * @dataProvider move_data + */ + public function test_move($group_id, $move_delta, $excepted_moved, $expected) + { + global $cache; + + $cache = new phpbb_mock_cache; + $db = $this->new_dbal(); + $user = new phpbb_user; + $user->lang = array(); + + $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 + FROM ' . TEAMPAGE_TABLE . ' + ORDER BY teampage_position ASC'); + + $this->assertEquals($expected, $db->sql_fetchrowset($result)); + } + + public function move_teampage_data() + { + return array( + array( + 1, + 1, + false, + array( + array('teampage_position' => 1, 'group_id' => 1, 'teampage_parent' => 0, 'teampage_name' => ''), + array('teampage_position' => 2, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category - 2 children'), + array('teampage_position' => 3, 'group_id' => 2, 'teampage_parent' => 2, 'teampage_name' => ''), + array('teampage_position' => 4, 'group_id' => 3, 'teampage_parent' => 2, 'teampage_name' => ''), + array('teampage_position' => 5, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category2 - 2 children'), + array('teampage_position' => 6, 'group_id' => 4, 'teampage_parent' => 5, 'teampage_name' => ''), + array('teampage_position' => 7, 'group_id' => 5, 'teampage_parent' => 5, 'teampage_name' => ''), + array('teampage_position' => 8, 'group_id' => 6, 'teampage_parent' => 0, 'teampage_name' => ''), + ), + ), + array( + 2, + 1, + true, + array( + array('teampage_position' => 1, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category - 2 children'), + array('teampage_position' => 2, 'group_id' => 2, 'teampage_parent' => 2, 'teampage_name' => ''), + array('teampage_position' => 3, 'group_id' => 3, 'teampage_parent' => 2, 'teampage_name' => ''), + array('teampage_position' => 4, 'group_id' => 1, 'teampage_parent' => 0, 'teampage_name' => ''), + array('teampage_position' => 5, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category2 - 2 children'), + array('teampage_position' => 6, 'group_id' => 4, 'teampage_parent' => 5, 'teampage_name' => ''), + array('teampage_position' => 7, 'group_id' => 5, 'teampage_parent' => 5, 'teampage_name' => ''), + array('teampage_position' => 8, 'group_id' => 6, 'teampage_parent' => 0, 'teampage_name' => ''), + ), + ), + array( + 5, + 1, + true, + array( + array('teampage_position' => 1, 'group_id' => 1, 'teampage_parent' => 0, 'teampage_name' => ''), + array('teampage_position' => 2, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category2 - 2 children'), + array('teampage_position' => 3, 'group_id' => 4, 'teampage_parent' => 5, 'teampage_name' => ''), + array('teampage_position' => 4, 'group_id' => 5, 'teampage_parent' => 5, 'teampage_name' => ''), + array('teampage_position' => 5, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category - 2 children'), + array('teampage_position' => 6, 'group_id' => 2, 'teampage_parent' => 2, 'teampage_name' => ''), + array('teampage_position' => 7, 'group_id' => 3, 'teampage_parent' => 2, 'teampage_name' => ''), + array('teampage_position' => 8, 'group_id' => 6, 'teampage_parent' => 0, 'teampage_name' => ''), + ), + ), + array( + 6, + 1, + false, + array( + array('teampage_position' => 1, 'group_id' => 1, 'teampage_parent' => 0, 'teampage_name' => ''), + array('teampage_position' => 2, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category - 2 children'), + array('teampage_position' => 3, 'group_id' => 2, 'teampage_parent' => 2, 'teampage_name' => ''), + array('teampage_position' => 4, 'group_id' => 3, 'teampage_parent' => 2, 'teampage_name' => ''), + array('teampage_position' => 5, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category2 - 2 children'), + array('teampage_position' => 6, 'group_id' => 4, 'teampage_parent' => 5, 'teampage_name' => ''), + array('teampage_position' => 7, 'group_id' => 5, 'teampage_parent' => 5, 'teampage_name' => ''), + array('teampage_position' => 8, 'group_id' => 6, 'teampage_parent' => 0, 'teampage_name' => ''), + ), + ), + array( + 1, + -1, + true, + array( + array('teampage_position' => 1, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category - 2 children'), + array('teampage_position' => 2, 'group_id' => 2, 'teampage_parent' => 2, 'teampage_name' => ''), + array('teampage_position' => 3, 'group_id' => 3, 'teampage_parent' => 2, 'teampage_name' => ''), + array('teampage_position' => 4, 'group_id' => 1, 'teampage_parent' => 0, 'teampage_name' => ''), + array('teampage_position' => 5, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category2 - 2 children'), + array('teampage_position' => 6, 'group_id' => 4, 'teampage_parent' => 5, 'teampage_name' => ''), + array('teampage_position' => 7, 'group_id' => 5, 'teampage_parent' => 5, 'teampage_name' => ''), + array('teampage_position' => 8, 'group_id' => 6, 'teampage_parent' => 0, 'teampage_name' => ''), + ), + ), + array( + 2, + -1, + true, + array( + array('teampage_position' => 1, 'group_id' => 1, 'teampage_parent' => 0, 'teampage_name' => ''), + array('teampage_position' => 2, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category2 - 2 children'), + array('teampage_position' => 3, 'group_id' => 4, 'teampage_parent' => 5, 'teampage_name' => ''), + array('teampage_position' => 4, 'group_id' => 5, 'teampage_parent' => 5, 'teampage_name' => ''), + array('teampage_position' => 5, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category - 2 children'), + array('teampage_position' => 6, 'group_id' => 2, 'teampage_parent' => 2, 'teampage_name' => ''), + array('teampage_position' => 7, 'group_id' => 3, 'teampage_parent' => 2, 'teampage_name' => ''), + array('teampage_position' => 8, 'group_id' => 6, 'teampage_parent' => 0, 'teampage_name' => ''), + ), + ), + array( + 5, + -1, + true, + array( + array('teampage_position' => 1, 'group_id' => 1, 'teampage_parent' => 0, 'teampage_name' => ''), + array('teampage_position' => 2, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category - 2 children'), + array('teampage_position' => 3, 'group_id' => 2, 'teampage_parent' => 2, 'teampage_name' => ''), + array('teampage_position' => 4, 'group_id' => 3, 'teampage_parent' => 2, 'teampage_name' => ''), + array('teampage_position' => 5, 'group_id' => 6, 'teampage_parent' => 0, 'teampage_name' => ''), + array('teampage_position' => 6, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category2 - 2 children'), + array('teampage_position' => 7, 'group_id' => 4, 'teampage_parent' => 5, 'teampage_name' => ''), + array('teampage_position' => 8, 'group_id' => 5, 'teampage_parent' => 5, 'teampage_name' => ''), + ), + ), + array( + 6, + -1, + true, + array( + array('teampage_position' => 1, 'group_id' => 1, 'teampage_parent' => 0, 'teampage_name' => ''), + array('teampage_position' => 2, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category - 2 children'), + array('teampage_position' => 3, 'group_id' => 2, 'teampage_parent' => 2, 'teampage_name' => ''), + array('teampage_position' => 4, 'group_id' => 3, 'teampage_parent' => 2, 'teampage_name' => ''), + array('teampage_position' => 5, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category2 - 2 children'), + array('teampage_position' => 6, 'group_id' => 5, 'teampage_parent' => 5, 'teampage_name' => ''), + array('teampage_position' => 7, 'group_id' => 4, 'teampage_parent' => 5, 'teampage_name' => ''), + array('teampage_position' => 8, 'group_id' => 6, 'teampage_parent' => 0, 'teampage_name' => ''), + ), + ), + array( + 8, + 3, + true, + array( + array('teampage_position' => 1, 'group_id' => 6, 'teampage_parent' => 0, 'teampage_name' => ''), + array('teampage_position' => 2, 'group_id' => 1, 'teampage_parent' => 0, 'teampage_name' => ''), + array('teampage_position' => 3, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category - 2 children'), + array('teampage_position' => 4, 'group_id' => 2, 'teampage_parent' => 2, 'teampage_name' => ''), + array('teampage_position' => 5, 'group_id' => 3, 'teampage_parent' => 2, 'teampage_name' => ''), + array('teampage_position' => 6, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category2 - 2 children'), + array('teampage_position' => 7, 'group_id' => 4, 'teampage_parent' => 5, 'teampage_name' => ''), + array('teampage_position' => 8, 'group_id' => 5, 'teampage_parent' => 5, 'teampage_name' => ''), + ), + ), + ); + } + + /** + * @dataProvider move_teampage_data + */ + public function test_move_teampage($teampage_id, $move_delta, $excepted_moved, $expected) + { + global $cache; + + $cache = new phpbb_mock_cache; + $db = $this->new_dbal(); + $user = new phpbb_user; + $user->lang = array(); + + $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 + FROM ' . TEAMPAGE_TABLE . ' + ORDER BY teampage_position ASC'); + + $this->assertEquals($expected, $db->sql_fetchrowset($result)); + } +} + diff --git a/tests/log/add_test.php b/tests/log/add_test.php new file mode 100644 index 0000000000..a5f93232f2 --- /dev/null +++ b/tests/log/add_test.php @@ -0,0 +1,88 @@ +<?php +/** +* +* @package testing +* @copyright (c) 2012 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_log_add_test extends phpbb_database_test_case +{ + public function getDataSet() + { + return $this->createXMLDataSet(dirname(__FILE__) . '/fixtures/empty_log.xml'); + } + + public function test_log_enabled() + { + global $phpbb_root_path, $phpEx, $db, $phpbb_dispatcher; + + $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'); + + $log = new phpbb_log($db, $user, $auth, $phpbb_dispatcher, $phpbb_root_path, 'adm/', $phpEx, LOG_TABLE); + + $this->assertTrue($log->is_enabled(), 'Initialise failed'); + + $log->disable(); + $this->assertFalse($log->is_enabled(), 'Disable all failed'); + + $log->enable(); + $this->assertTrue($log->is_enabled(), 'Enable all failed'); + + $log->disable('admin'); + $this->assertFalse($log->is_enabled('admin'), 'Disable admin failed'); + $this->assertTrue($log->is_enabled('user'), 'User should be enabled, is disabled'); + $this->assertTrue($log->is_enabled(), 'Disable admin disabled all'); + + $log->enable('admin'); + $this->assertTrue($log->is_enabled('admin'), 'Enable admin failed'); + } + + public function test_log_add() + { + global $phpbb_root_path, $phpEx, $db, $phpbb_dispatcher; + + $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'); + + $log = new phpbb_log($db, $user, $auth, $phpbb_dispatcher, $phpbb_root_path, 'adm/', $phpEx, LOG_TABLE); + + $mode = 'critical'; + $user_id = ANONYMOUS; + $log_ip = 'user_ip'; + $log_time = time(); + $log_operation = 'LOG_OPERATION'; + $additional_data = array(); + + // Add an entry successful + $this->assertEquals(1, $log->add($mode, $user_id, $log_ip, $log_operation, $log_time)); + + // Disable logging for all types + $log->disable(); + $this->assertFalse($log->add($mode, $user_id, $log_ip, $log_operation, $log_time), 'Disable for all types failed'); + $log->enable(); + + // Disable logging for same type + $log->disable('critical'); + $this->assertFalse($log->add($mode, $user_id, $log_ip, $log_operation, $log_time), 'Disable for same type failed'); + $log->enable(); + + // Disable logging for different type + $log->disable('admin'); + $this->assertEquals(2, $log->add($mode, $user_id, $log_ip, $log_operation, $log_time), 'Disable for different types failed'); + $log->enable(); + + // Invalid mode specified + $this->assertFalse($log->add('mode_does_not_exist', $user_id, $log_ip, $log_operation, $log_time)); + } +} diff --git a/tests/log/fixtures/empty_log.xml b/tests/log/fixtures/empty_log.xml new file mode 100644 index 0000000000..261b6a622a --- /dev/null +++ b/tests/log/fixtures/empty_log.xml @@ -0,0 +1,15 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<dataset> + <table name="phpbb_log"> + <column>log_id</column> + <column>log_type</column> + <column>user_id</column> + <column>forum_id</column> + <column>topic_id</column> + <column>reportee_id</column> + <column>log_ip</column> + <column>log_time</column> + <column>log_operation</column> + <column>log_data</column> + </table> +</dataset> diff --git a/tests/log/fixtures/full_log.xml b/tests/log/fixtures/full_log.xml new file mode 100644 index 0000000000..2ce2643d26 --- /dev/null +++ b/tests/log/fixtures/full_log.xml @@ -0,0 +1,166 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<dataset> + <table name="phpbb_log"> + <column>log_id</column> + <column>log_type</column> + <column>user_id</column> + <column>forum_id</column> + <column>topic_id</column> + <column>reportee_id</column> + <column>log_ip</column> + <column>log_time</column> + <column>log_operation</column> + <column>log_data</column> + <row> + <value>1</value> + <value>0</value> + <value>1</value> + <value>0</value> + <value>0</value> + <value>0</value> + <value>127.0.0.1</value> + <value>1</value> + <value>LOG_INSTALL_INSTALLED</value> + <value>a:1:{i:0;s:9:"3.1.0-dev";}</value> + </row> + <row> + <value>2</value> + <value>0</value> + <value>1</value> + <value>0</value> + <value>0</value> + <value>0</value> + <value>127.0.0.1</value> + <value>1</value> + <value>LOG_KEY_NOT_EXISTS</value> + <value>a:1:{i:0;s:15:"additional_data";}</value> + </row> + <row> + <value>3</value> + <value>2</value> + <value>1</value> + <value>0</value> + <value>0</value> + <value>0</value> + <value>127.0.0.1</value> + <value>1</value> + <value>LOG_CRITICAL</value> + <value>a:1:{i:0;s:13:"critical data";}</value> + </row> + <row> + <value>4</value> + <value>1</value> + <value>1</value> + <value>12</value> + <value>34</value> + <value>0</value> + <value>127.0.0.1</value> + <value>1</value> + <value>LOG_MOD</value> + <value></value> + </row> + <row> + <value>5</value> + <value>1</value> + <value>1</value> + <value>12</value> + <value>45</value> + <value>0</value> + <value>127.0.0.1</value> + <value>1</value> + <value>LOG_MOD</value> + <value></value> + </row> + <row> + <value>6</value> + <value>1</value> + <value>1</value> + <value>23</value> + <value>56</value> + <value>0</value> + <value>127.0.0.1</value> + <value>1</value> + <value>LOG_MOD</value> + <value></value> + </row> + <row> + <value>7</value> + <value>1</value> + <value>1</value> + <value>12</value> + <value>45</value> + <value>0</value> + <value>127.0.0.1</value> + <value>1</value> + <value>LOG_MOD2</value> + <value></value> + </row> + <row> + <value>8</value> + <value>3</value> + <value>1</value> + <value>0</value> + <value>0</value> + <value>2</value> + <value>127.0.0.1</value> + <value>1</value> + <value>LOG_USER</value> + <value>a:1:{i:0;s:5:"admin";}</value> + </row> + <row> + <value>9</value> + <value>3</value> + <value>1</value> + <value>0</value> + <value>0</value> + <value>1</value> + <value>127.0.0.1</value> + <value>1</value> + <value>LOG_USER</value> + <value>a:1:{i:0;s:5:"guest";}</value> + </row> + </table> + <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>1</value> + <value>Anonymous</value> + <value>Anonymous</value> + <value></value> + <value></value> + <value></value> + <value></value> + </row> + <row> + <value>2</value> + <value>admin</value> + <value>admin</value> + <value></value> + <value></value> + <value></value> + <value></value> + </row> + </table> + <table name="phpbb_topics"> + <column>topic_id</column> + <column>forum_id</column> + <row> + <value>34</value> + <value>12</value> + </row> + <row> + <value>45</value> + <value>12</value> + </row> + <row> + <value>56</value> + <value>23</value> + </row> + </table> +</dataset> diff --git a/tests/log/function_add_log_test.php b/tests/log/function_add_log_test.php new file mode 100644 index 0000000000..864b364862 --- /dev/null +++ b/tests/log/function_add_log_test.php @@ -0,0 +1,193 @@ +<?php +/** +* +* @package testing +* @copyright (c) 2012 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_log_function_add_log_test extends phpbb_database_test_case +{ + public function getDataSet() + { + return $this->createXMLDataSet(dirname(__FILE__) . '/fixtures/empty_log.xml'); + } + + public static function test_add_log_function_data() + { + return array( + /** + * Case documentation + array( + // Row that is in the database afterwards + array( + 'user_id' => ANONYMOUS, + 'log_type' => LOG_MOD, + 'log_operation' => 'LOG_MOD_ADDITIONAL', + // log_data will be serialized + 'log_data' => array( + 'argument3', + ), + 'reportee_id' => 0, + 'forum_id' => 56, + 'topic_id' => 78, + ), + // user_id Can also be false, then ANONYMOUS is used + false, + // log_mode Used to determine the log_type + 'mod', + // Followed by some additional arguments + // forum_id, topic_id and reportee_id are specified before log_operation + // The rest is specified afterwards. + 56, + 78, + 'LOG_MOD_ADDITIONAL', // log_operation + 'argument3', + ), + */ + array( + array( + 'user_id' => 2, + 'log_type' => LOG_CRITICAL, + 'log_operation' => 'LOG_NO_ADDITIONAL', + 'log_data' => '', + 'reportee_id' => 0, + 'forum_id' => 0, + 'topic_id' => 0, + ), + 2, 'critical', 'LOG_NO_ADDITIONAL', + ), + array( + array( + 'user_id' => 2, + 'log_type' => LOG_CRITICAL, + 'log_operation' => 'LOG_ONE_ADDITIONAL', + 'log_data' => array( + 'argument1', + ), + 'reportee_id' => 0, + 'forum_id' => 0, + 'topic_id' => 0, + ), + 2, 'critical', 'LOG_ONE_ADDITIONAL', 'argument1', + ), + array( + array( + 'user_id' => ANONYMOUS, + 'log_type' => LOG_ADMIN, + 'log_operation' => 'LOG_TWO_ADDITIONAL', + 'log_data' => array( + 'argument1', + 'argument2', + ), + 'reportee_id' => 0, + 'forum_id' => 0, + 'topic_id' => 0, + ), + false, 'admin', 'LOG_TWO_ADDITIONAL', 'argument1', 'argument2', + ), + array( + array( + 'user_id' => ANONYMOUS, + 'log_type' => LOG_USERS, + 'log_operation' => 'LOG_USERS_ADDITIONAL', + 'log_data' => array( + 'argument2', + ), + 'reportee_id' => 2, + 'forum_id' => 0, + 'topic_id' => 0, + ), + false, 'user', 2, 'LOG_USERS_ADDITIONAL', 'argument2', + ), + array( + array( + 'user_id' => ANONYMOUS, + 'log_type' => LOG_MOD, + 'log_operation' => 'LOG_MOD_TOPIC_AND_FORUM', + 'log_data' => '', + 'reportee_id' => 0, + 'forum_id' => 12, + 'topic_id' => 34, + ), + false, 'mod', 12, 34, 'LOG_MOD_TOPIC_AND_FORUM', + ), + array( + array( + 'user_id' => ANONYMOUS, + 'log_type' => LOG_MOD, + 'log_operation' => 'LOG_MOD_ADDITIONAL', + 'log_data' => array( + 'argument3', + ), + 'reportee_id' => 0, + 'forum_id' => 56, + 'topic_id' => 78, + ), + false, 'mod', 56, 78, 'LOG_MOD_ADDITIONAL', 'argument3', + ), + array( + array( + ), + false, 'mode_does_not_exist', 'LOG_MOD_ADDITIONAL', 'argument1', + ), + ); + } + + /** + * @dataProvider test_add_log_function_data + */ + public function test_add_log_function($expected, $user_id, $mode, $required1, $additional1 = null, $additional2 = null, $additional3 = null) + { + global $db, $cache, $user, $phpbb_log, $phpbb_dispatcher, $phpbb_root_path, $phpEx; + + if ($expected) + { + // Serialize the log data if we have some + if (is_array($expected['log_data'])) + { + $expected['log_data'] = serialize($expected['log_data']); + } + $expected = array($expected); + } + + $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'); + + $phpbb_log = new phpbb_log($db, $user, $auth, $phpbb_dispatcher, $phpbb_root_path, 'adm/', $phpEx, LOG_TABLE); + + $user->ip = 'user_ip'; + if ($user_id) + { + $user->data['user_id'] = $user_id; + } + + if ($additional3 != null) + { + add_log($mode, $required1, $additional1, $additional2, $additional3); + } + else if ($additional2 != null) + { + add_log($mode, $required1, $additional1, $additional2); + } + else if ($additional1 != null) + { + add_log($mode, $required1, $additional1); + } + else + { + add_log($mode, $required1); + } + + $result = $db->sql_query('SELECT user_id, log_type, log_operation, log_data, reportee_id, forum_id, topic_id + FROM ' . LOG_TABLE); + + $this->assertEquals($expected, $db->sql_fetchrowset($result)); + } +} diff --git a/tests/log/function_view_log_test.php b/tests/log/function_view_log_test.php new file mode 100644 index 0000000000..2ecf77aeb8 --- /dev/null +++ b/tests/log/function_view_log_test.php @@ -0,0 +1,344 @@ +<?php +/** +* +* @package testing +* @copyright (c) 2012 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__) . '/../../phpBB/includes/functions_admin.php'; +require_once dirname(__FILE__) . '/../../phpBB/includes/functions_content.php'; +require_once dirname(__FILE__) . '/../../phpBB/includes/utf/utf_tools.php'; +require_once dirname(__FILE__) . '/../../phpBB/includes/session.php'; +require_once dirname(__FILE__) . '/../mock/user.php'; +require_once dirname(__FILE__) . '/../mock/cache.php'; + +class phpbb_log_function_view_log_test extends phpbb_database_test_case +{ + public function getDataSet() + { + return $this->createXMLDataSet(dirname(__FILE__) . '/fixtures/full_log.xml'); + } + + public static function test_view_log_function_data() + { + global $phpEx, $phpbb_dispatcher; + $phpbb_dispatcher = new phpbb_mock_event_dispatcher(); + + $expected_data_sets = array( + 1 => array( + 'id' => 1, + + 'reportee_id' => 0, + 'reportee_username' => '', + 'reportee_username_full'=> '', + + 'user_id' => 1, + 'username' => 'Anonymous', + 'username_full' => 'Anonymous', + + 'ip' => '127.0.0.1', + 'time' => 1, + 'forum_id' => 0, + 'topic_id' => 0, + + 'viewforum' => '', + 'action' => 'installed: 3.1.0-dev', + ), + 2 => array( + 'id' => 2, + + 'reportee_id' => 0, + 'reportee_username' => '', + 'reportee_username_full'=> '', + + 'user_id' => 1, + 'username' => 'Anonymous', + 'username_full' => 'Anonymous', + + 'ip' => '127.0.0.1', + 'time' => 1, + 'forum_id' => 0, + 'topic_id' => 0, + + 'viewforum' => '', + 'action' => '{LOG KEY NOT EXISTS}<br />additional_data', + ), + 3 => array( + 'id' => 3, + + 'reportee_id' => 0, + 'reportee_username' => '', + 'reportee_username_full'=> '', + + 'user_id' => 1, + 'username' => 'Anonymous', + 'username_full' => 'Anonymous', + + 'ip' => '127.0.0.1', + 'time' => 1, + 'forum_id' => 0, + 'topic_id' => 0, + + 'viewforum' => '', + 'action' => '{LOG CRITICAL}<br />critical data', + ), + 4 => array( + 'id' => 4, + + 'reportee_id' => 0, + 'reportee_username' => '', + 'reportee_username_full'=> '', + + 'user_id' => 1, + 'username' => 'Anonymous', + 'username_full' => 'Anonymous', + + 'ip' => '127.0.0.1', + 'time' => 1, + 'forum_id' => 12, + 'topic_id' => 34, + + 'viewforum' => '', + 'action' => '{LOG MOD}', + 'viewtopic' => '', + 'viewlogs' => '', + ), + 5 => array( + 'id' => 5, + + 'reportee_id' => 0, + 'reportee_username' => '', + 'reportee_username_full'=> '', + + 'user_id' => 1, + 'username' => 'Anonymous', + 'username_full' => 'Anonymous', + + 'ip' => '127.0.0.1', + 'time' => 1, + 'forum_id' => 12, + 'topic_id' => 45, + + 'viewforum' => '', + 'action' => '{LOG MOD}', + 'viewtopic' => '', + 'viewlogs' => '', + ), + 6 => array( + 'id' => 6, + + 'reportee_id' => 0, + 'reportee_username' => '', + 'reportee_username_full'=> '', + + 'user_id' => 1, + 'username' => 'Anonymous', + 'username_full' => 'Anonymous', + + 'ip' => '127.0.0.1', + 'time' => 1, + 'forum_id' => 23, + 'topic_id' => 56, + + 'viewforum' => append_sid("phpBB/viewforum.$phpEx", 'f=23'), + 'action' => '{LOG MOD}', + 'viewtopic' => append_sid("phpBB/viewtopic.$phpEx", 'f=23&t=56'), + 'viewlogs' => append_sid("phpBB/mcp.$phpEx", 'i=logs&mode=topic_logs&t=56'), + ), + 7 => array( + 'id' => 7, + + 'reportee_id' => 0, + 'reportee_username' => '', + 'reportee_username_full'=> '', + + 'user_id' => 1, + 'username' => 'Anonymous', + 'username_full' => 'Anonymous', + + 'ip' => '127.0.0.1', + 'time' => 1, + 'forum_id' => 12, + 'topic_id' => 45, + + 'viewforum' => '', + 'action' => '{LOG MOD2}', + 'viewtopic' => '', + 'viewlogs' => '', + ), + 8 => array( + 'id' => 8, + + 'reportee_id' => 2, + 'reportee_username' => 'admin', + 'reportee_username_full'=> 'admin', + + 'user_id' => 1, + 'username' => 'Anonymous', + 'username_full' => 'Anonymous', + + 'ip' => '127.0.0.1', + 'time' => 1, + 'forum_id' => 0, + 'topic_id' => 0, + + 'viewforum' => '', + 'action' => '{LOG USER}<br />admin', + ), + 9 => array( + 'id' => 9, + + 'reportee_id' => 1, + 'reportee_username' => 'Anonymous', + 'reportee_username_full'=> 'Anonymous', + + 'user_id' => 1, + 'username' => 'Anonymous', + 'username_full' => 'Anonymous', + + 'ip' => '127.0.0.1', + 'time' => 1, + 'forum_id' => 0, + 'topic_id' => 0, + + 'viewforum' => '', + 'action' => '{LOG USER}<br />guest', + ), + ); + + $test_cases = array( + /** + * Case documentation + array( + // Array of datasets that should be in $log after running the function + 'expected' => array(5, 7), + // Offset that will be returned from the function + 'expected_returned' => 0, + // view_log parameters (see includes/functions_admin.php for docblock) + // $log is ommited! + 'mod', 5, 0, 12, 45, + ), + */ + array( + 'expected' => array(1, 2), + 'expected_returned' => 0, + 'admin', false, + ), + array( + 'expected' => array(1), + 'expected_returned' => 0, + 'admin', false, 1, + ), + array( + 'expected' => array(2), + 'expected_returned' => 1, + 'admin', false, 1, 1, + ), + array( + 'expected' => array(2), + 'expected_returned' => 1, + 'admin', 0, 1, 1, + ), + array( + 'expected' => array(2), + 'expected_returned' => 1, + 'admin', 0, 1, 5, + ), + array( + 'expected' => array(3), + 'expected_returned' => 0, + 'critical', false, + ), + array( + 'expected' => array(), + 'expected_returned' => null, + 'mode_does_not_exist', false, + ), + array( + 'expected' => array(4, 5, 7), + 'expected_returned' => 0, + 'mod', 0, 5, 0, 12, + ), + array( + 'expected' => array(5, 7), + 'expected_returned' => 0, + 'mod', 0, 5, 0, 12, 45, + ), + array( + 'expected' => array(6), + 'expected_returned' => 0, + 'mod', 0, 5, 0, 23, + ), + array( + 'expected' => array(8), + 'expected_returned' => 0, + 'user', 0, 5, 0, 0, 0, 2, + ), + array( + 'expected' => array(8, 9), + 'expected_returned' => 0, + 'users', 0, + ), + ); + + foreach ($test_cases as $case => $case_data) + { + foreach ($case_data['expected'] as $data_set => $expected) + { + $test_cases[$case]['expected'][$data_set] = $expected_data_sets[$expected]; + } + } + + return $test_cases; + } + + /** + * @dataProvider test_view_log_function_data + */ + public function test_view_log_function($expected, $expected_returned, $mode, $log_count, $limit = 5, $offset = 0, $forum_id = 0, $topic_id = 0, $user_id = 0, $limit_days = 0, $sort_by = 'l.log_id ASC', $keywords = '') + { + global $cache, $db, $user, $auth, $phpbb_log, $phpbb_dispatcher, $phpbb_root_path, $phpEx; + + $db = $this->new_dbal(); + $cache = new phpbb_mock_cache; + $phpbb_dispatcher = new phpbb_mock_event_dispatcher(); + + // Create auth mock + $auth = $this->getMock('phpbb_auth'); + $acl_get_map = array( + array('f_read', 23, true), + array('m_', 23, true), + ); + $acl_gets_map = array( + array('a_', 'm_', 23, true), + ); + + $auth->expects($this->any()) + ->method('acl_get') + ->with($this->stringContains('_'), + $this->anything()) + ->will($this->returnValueMap($acl_get_map)); + $auth->expects($this->any()) + ->method('acl_gets') + ->with($this->stringContains('_'), + $this->anything()) + ->will($this->returnValueMap($acl_gets_map)); + + $user = new phpbb_mock_user; + $user->optionset('viewcensors', false); + // Test sprintf() of the data into the action + $user->lang = array( + 'LOG_INSTALL_INSTALLED' => 'installed: %s', + ); + + $phpbb_log = new phpbb_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)); + + $this->assertEquals($expected, $log); + } +} diff --git a/tests/mock/cache.php b/tests/mock/cache.php index bc18ca066b..71af3037f5 100644 --- a/tests/mock/cache.php +++ b/tests/mock/cache.php @@ -121,7 +121,11 @@ class phpbb_mock_cache implements phpbb_cache_driver_interface public function sql_load($query) { } - public function sql_save($query, $query_result, $ttl) + + /** + * {@inheritDoc} + */ + public function sql_save(phpbb_db_driver $db, $query, $query_result, $ttl) { return $query_result; } diff --git a/tests/mock/container_builder.php b/tests/mock/container_builder.php index 8a81dd72d1..734d3e1741 100644 --- a/tests/mock/container_builder.php +++ b/tests/mock/container_builder.php @@ -11,6 +11,9 @@ use Symfony\Component\DependencyInjection\ScopeInterface; class phpbb_mock_container_builder implements ContainerInterface { + protected $services = array(); + protected $parameters = array(); + /** * Sets a service. * @@ -22,6 +25,7 @@ class phpbb_mock_container_builder implements ContainerInterface */ public function set($id, $service, $scope = self::SCOPE_CONTAINER) { + $this->services[$id] = $service; } /** @@ -42,6 +46,12 @@ class phpbb_mock_container_builder implements ContainerInterface */ public function get($id, $invalidBehavior = self::EXCEPTION_ON_INVALID_REFERENCE) { + if ($this->has($id)) + { + return $this->services[$id]; + } + + throw new Exception('Could not find service: ' . $id); } /** @@ -55,6 +65,7 @@ class phpbb_mock_container_builder implements ContainerInterface */ public function has($id) { + return isset($this->services[$id]); } /** @@ -70,6 +81,12 @@ class phpbb_mock_container_builder implements ContainerInterface */ public function getParameter($name) { + if ($this->hasParameter($name)) + { + return $this->parameters[$name]; + } + + throw new Exception('Could not find parameter: ' . $name); } /** @@ -83,6 +100,7 @@ class phpbb_mock_container_builder implements ContainerInterface */ public function hasParameter($name) { + return isset($this->parameters[$name]); } /** @@ -95,6 +113,7 @@ class phpbb_mock_container_builder implements ContainerInterface */ public function setParameter($name, $value) { + $this->parameters[$name] = $value; } /** diff --git a/tests/mock/notification_manager.php b/tests/mock/notification_manager.php new file mode 100644 index 0000000000..47fe30730f --- /dev/null +++ b/tests/mock/notification_manager.php @@ -0,0 +1,94 @@ +<?php +/** +* +* @package notifications +* @copyright (c) 2012 phpBB Group +* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 +* +*/ + +/** +* @ignore +*/ +if (!defined('IN_PHPBB')) +{ + exit; +} + +/** +* Notifications service class +* @package notifications +*/ +class phpbb_mock_notification_manager +{ + public function load_notifications() + { + return array( + 'notifications' => array(), + 'unread_count' => 0, + ); + } + + public function mark_notifications_read() + { + } + + public function mark_notifications_read_by_parent() + { + } + + public function mark_notifications_read_by_id() + { + } + + + public function add_notifications() + { + return array(); + } + + public function add_notifications_for_users() + { + } + + public function update_notifications() + { + } + + public function delete_notifications() + { + } + + public function get_subscription_types() + { + return array(); + } + + public function get_subscription_methods() + { + return array(); + } + + + public function get_global_subscriptions() + { + return array(); + } + + public function add_subscription() + { + } + + public function delete_subscription() + { + } + + public function load_users() + { + } + + public function get_user() + { + return null; + } +} diff --git a/tests/mock/notifications_auth.php b/tests/mock/notifications_auth.php new file mode 100644 index 0000000000..d960acb81a --- /dev/null +++ b/tests/mock/notifications_auth.php @@ -0,0 +1,40 @@ +<?php +/** +* +* @package testing +* @copyright (c) 2012 phpBB Group +* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 +* +*/ + +class phpbb_mock_notifications_auth extends phpbb_auth +{ + function acl_get_list($user_id = false, $opts = false, $forum_id = false) + { + $user_id = (!is_array($user_id)) ? array($user_id) : $user_id; + $opts = (!is_array($opts)) ? array($opts) : $opts; + $forum_id = (!is_array($forum_id)) ? array($forum_id) : $forum_id; + + $auth_list = array(); + + foreach ($forum_id as $fid) + { + foreach ($opts as $opt) + { + $auth_list[$fid][$opt] = array(); + + foreach ($user_id as $uid) + { + $auth_list[$fid][$opt][] = $uid; + } + } + } + + return $auth_list; + } + + function acl_get($opt, $f = 0) + { + return true; + } +} diff --git a/tests/mock/notifications_notification_manager.php b/tests/mock/notifications_notification_manager.php new file mode 100644 index 0000000000..c995afb9ab --- /dev/null +++ b/tests/mock/notifications_notification_manager.php @@ -0,0 +1,69 @@ +<?php +/** +* +* @package notifications +* @copyright (c) 2012 phpBB Group +* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 +* +*/ + +/** +* @ignore +*/ +if (!defined('IN_PHPBB')) +{ + exit; +} + +/** +* Notifications service class +* @package notifications +*/ +class phpbb_mock_notifications_notification_manager extends phpbb_notification_manager +{ + public function set_var($name, $value) + { + $this->$name = $value; + } + + // Extra dependencies for get_*_class functions + protected $auth = null; + protected $cache = null; + protected $config = null; + public function setDependencies($auth, $cache, $config) + { + $this->auth = $auth; + $this->cache = $cache; + $this->config = $config; + } + + /** + * Helper to get the notifications item type class and set it up + */ + public function get_item_type_class($item_type, $data = array()) + { + $item_type = 'phpbb_notification_type_' . $item_type; + + $item = new $item_type($this->user_loader, $this->db, $this->cache, $this->user, $this->auth, $this->config, $this->phpbb_root_path, $this->php_ext, $this->notification_types_table, $this->notifications_table, $this->user_notifications_table); + + $item->set_notification_manager($this); + + $item->set_initial_data($data); + + return $item; + } + + /** + * Helper to get the notifications method class and set it up + */ + public function get_method_class($method_name) + { + $method_name = 'phpbb_notification_method_' . $method_name; + + $method = new $method_name($this->user_loader, $this->db, $this->cache, $this->user, $this->auth, $this->config, $this->phpbb_root_path, $this->php_ext, $this->notification_types_table, $this->notifications_table, $this->user_notifications_table); + + $method->set_notification_manager($this); + + return $method; + } +} diff --git a/tests/notification/ext/test/notification/type/test.php b/tests/notification/ext/test/notification/type/test.php new file mode 100644 index 0000000000..0d0c584e0d --- /dev/null +++ b/tests/notification/ext/test/notification/type/test.php @@ -0,0 +1,85 @@ +<?php +/** +* +* @package notifications +* @copyright (c) 2012 phpBB Group +* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 +* +*/ + +/** +* @ignore +*/ +if (!defined('IN_PHPBB')) +{ + exit; +} + +class phpbb_notification_type_test extends phpbb_notification_type_base +{ + public function get_type() + { + return 'test'; + } + + public static function get_item_id($post) + { + return (int) $post['post_id']; + } + + public static function get_item_parent_id($post) + { + return (int) $post['topic_id']; + } + + public function find_users_for_notification($post, $options = array()) + { + return $this->check_user_notification_options(array(0), $options); + } + + public function create_insert_array($post, $pre_create_data = array()) + { + $this->notification_time = $post['post_time']; + + return parent::create_insert_array($post, $pre_create_data); + } + + public function create_update_array($type_data) + { + $data = $this->create_insert_array($type_data); + + // Unset data unique to each row + unset( + $data['notification_id'], + $data['notification_read'], + $data['user_id'] + ); + + return $data; + } + + public function get_title() + { + return 'test title'; + } + + public function users_to_query() + { + return array(); + } + + public function get_url() + { + return ''; + } + + public function get_email_template() + { + return false; + } + + public function get_email_template_variables() + { + return array(); + } +} diff --git a/tests/notification/fixtures/notification.xml b/tests/notification/fixtures/notification.xml new file mode 100644 index 0000000000..38e5f811dd --- /dev/null +++ b/tests/notification/fixtures/notification.xml @@ -0,0 +1,5 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<dataset> + <table name="phpbb_notifications"> + </table> +</dataset> diff --git a/tests/notification/notification.php b/tests/notification/notification.php new file mode 100644 index 0000000000..13c868a0c7 --- /dev/null +++ b/tests/notification/notification.php @@ -0,0 +1,385 @@ +<?php +/** +* +* @package testing +* @copyright (c) 2012 phpBB Group +* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 +* +*/ + +class phpbb_notification_test extends phpbb_database_test_case +{ + protected $notifications, $db, $container, $user, $config, $auth, $cache; + + public function getDataSet() + { + return $this->createXMLDataSet(dirname(__FILE__) . '/fixtures/notification.xml'); + } + + protected function setUp() + { + parent::setUp(); + + global $phpbb_root_path, $phpEx; + + if (!function_exists('set_var')) + { + include($phpbb_root_path . 'includes/functions.' . $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_mock_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_mock_cache(); + + $this->container = new phpbb_mock_container_builder(); + + $this->notifications = new phpbb_mock_notifications_notification_manager( + array(), + array(), + $this->container, + $this->user_loader, + $this->db, + $this->user, + $phpbb_root_path, + $phpEx, + 'phpbb_notification_types', + 'phpbb_notifications', + 'phpbb_user_notifications' + ); + + $this->notifications->setDependencies($this->auth, $this->cache, $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, $this->user, $this->auth, $this->config, $phpbb_root_path, $phpEx, 'phpbb_notification_types', 'phpbb_notifications', 'phpbb_user_notifications'); + } + + public function test_get_subscription_types() + { + $subscription_types = $this->notifications->get_subscription_types(); + + $this->assertArrayHasKey('NOTIFICATION_GROUP_MISCELLANEOUS', $subscription_types); + $this->assertArrayHasKey('NOTIFICATION_GROUP_POSTING', $subscription_types); + + $this->assertArrayHasKey('bookmark', $subscription_types['NOTIFICATION_GROUP_POSTING']); + $this->assertArrayHasKey('post', $subscription_types['NOTIFICATION_GROUP_POSTING']); + $this->assertArrayHasKey('quote', $subscription_types['NOTIFICATION_GROUP_POSTING']); + $this->assertArrayHasKey('topic', $subscription_types['NOTIFICATION_GROUP_POSTING']); + + $this->assertArrayHasKey('pm', $subscription_types['NOTIFICATION_GROUP_MISCELLANEOUS']); + + //get_subscription_types + //get_subscription_methods + } + + public function test_subscriptions() + { + $this->notifications->delete_subscription('post', 0, '', 2); + + $this->assertArrayNotHasKey('post', $this->notifications->get_global_subscriptions(2)); + + $this->notifications->add_subscription('post', 0, '', 2); + + $this->assertArrayHasKey('post', $this->notifications->get_global_subscriptions(2)); + } + + public function test_notifications() + { + // Used to test post notifications later + $this->db->sql_query('INSERT INTO ' . TOPICS_WATCH_TABLE . ' ' . $this->db->sql_build_array('INSERT', array( + 'topic_id' => 2, + 'notify_status' => NOTIFY_YES, + 'user_id' => 0, + ))); + + $this->assertEquals(array( + 'notifications' => array(), + 'unread_count' => 0, + 'total_count' => 0, + ), $this->notifications->load_notifications(array( + 'count_unread' => true, + ))); + + $this->notifications->add_notifications('test', array( + 'post_id' => '1', + 'topic_id' => '1', + 'post_time' => 1349413321, + )); + + $this->notifications->add_notifications('test', array( + 'post_id' => '2', + 'topic_id' => '2', + 'post_time' => 1349413322, + )); + + $this->notifications->add_notifications('test', array( + 'post_id' => '3', + 'topic_id' => '2', + 'post_time' => 1349413323, + )); + + $this->notifications->add_notifications(array('quote', 'bookmark', 'post', 'test'), array( + 'post_id' => '4', + 'topic_id' => '2', + 'post_time' => 1349413324, + 'poster_id' => 2, + 'topic_title' => 'test-title', + 'post_subject' => 'Re: test-title', + 'forum_id' => 2, + 'forum_name' => 'Your first forum', + )); + + $this->db->sql_query('INSERT INTO ' . BOOKMARKS_TABLE . ' ' . $this->db->sql_build_array('INSERT', array( + 'topic_id' => 2, + 'user_id' => 0, + ))); + + $this->notifications->add_notifications(array('quote', 'bookmark', 'post', 'test'), array( + 'post_id' => '5', + 'topic_id' => '2', + 'post_time' => 1349413325, + 'poster_id' => 2, + 'topic_title' => 'test-title', + 'post_subject' => 'Re: test-title', + 'forum_id' => 2, + 'forum_name' => 'Your first forum', + )); + + $this->notifications->delete_subscription('test'); + + $this->notifications->add_notifications('test', array( + 'post_id' => '6', + 'topic_id' => '2', + 'post_time' => 1349413326, + )); + + $notifications = $this->notifications->load_notifications(array( + 'count_unread' => true, + )); + + $expected = array( + 1 => array( + 'item_type' => 'test', + 'item_id' => 1, + 'item_parent_id' => 1, + 'user_id' => 0, + 'notification_read' => 0, + 'notification_time' => 1349413321, + 'notification_data' => array(), + ), + 2 => array( + 'item_type' => 'test', + 'item_id' => 2, + 'item_parent_id' => 2, + 'user_id' => 0, + 'notification_read' => 0, + 'notification_time' => 1349413322, + 'notification_data' => array(), + ), + 3 => array( + 'item_type' => 'test', + 'item_id' => 3, + 'item_parent_id' => 2, + 'user_id' => 0, + 'notification_read' => 0, + 'notification_time' => 1349413323, + 'notification_data' => array(), + ), + 4 => array( + 'item_type' => 'post', + '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', + ), + ), + 5 => array( + 'item_type' => 'bookmark', + '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( + 'post_id' => '1', + 'topic_id' => '2', // change parent_id + 'post_time' => 1349413321, + )); + + $this->notifications->update_notifications('test', array( + 'post_id' => '3', + 'topic_id' => '2', + 'post_time' => 1234, // change time + )); + + $this->notifications->update_notifications(array('quote', 'bookmark', 'post', 'test'), array( + 'post_id' => '5', + 'topic_id' => '2', + 'poster_id' => 2, + 'topic_title' => 'test-title2', // change topic_title + 'post_subject' => 'Re: test-title2', // change post_subject + 'forum_id' => 3, // change forum_id + 'forum_name' => 'Your second forum', // change forum_name + )); + + $notifications = $this->notifications->load_notifications(array( + 'count_unread' => true, + )); + + $expected = array( + 1 => array( + 'item_type' => 'test', + 'item_id' => 1, + 'item_parent_id' => 2, + 'user_id' => 0, + 'notification_read' => 0, + 'notification_time' => 1349413321, + 'notification_data' => array(), + ), + 2 => array( + 'item_type' => 'test', + 'item_id' => 2, + 'item_parent_id' => 2, + 'user_id' => 0, + 'notification_read' => 0, + 'notification_time' => 1349413322, + 'notification_data' => array(), + ), + 3 => array( + 'item_type' => 'test', + 'item_id' => 3, + 'item_parent_id' => 2, + 'user_id' => 0, + 'notification_read' => 0, + 'notification_time' => 1234, + 'notification_data' => array(), + ), + 4 => array( + 'item_type' => 'post', + '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', + ), + ), + 5 => array( + 'item_type' => 'bookmark', + '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/privmsgs/delete_user_pms_test.php b/tests/privmsgs/delete_user_pms_test.php index f705825262..92ee7c5f2a 100644 --- a/tests/privmsgs/delete_user_pms_test.php +++ b/tests/privmsgs/delete_user_pms_test.php @@ -81,10 +81,13 @@ class phpbb_privmsgs_delete_user_pms_test extends phpbb_database_test_case */ public function test_delete_user_pms($delete_user, $remaining_privmsgs, $remaining_privmsgs_to) { - global $db; + global $db, $phpbb_container; $db = $this->new_dbal(); + $phpbb_container = new phpbb_mock_container_builder(); + $phpbb_container->set('notification_manager', new phpbb_mock_notification_manager()); + phpbb_delete_user_pms($delete_user); $sql = 'SELECT msg_id diff --git a/tests/session/append_sid_test.php b/tests/session/append_sid_test.php index 34f6dea8ca..b9e9ac1aa9 100644 --- a/tests/session/append_sid_test.php +++ b/tests/session/append_sid_test.php @@ -1,54 +1,54 @@ -<?php
-/**
-*
-* @package testing
-* @copyright (c) 2011 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_session_append_sid_test extends phpbb_test_case
-{
-
- public function append_sid_data()
- {
- return array(
- array('viewtopic.php?t=1&f=2', false, true, false, 'viewtopic.php?t=1&f=2', 'parameters in url-argument'),
- array('viewtopic.php', 't=1&f=2', true, false, 'viewtopic.php?t=1&f=2', 'parameters in params-argument using amp'),
- array('viewtopic.php', 't=1&f=2', false, false, 'viewtopic.php?t=1&f=2', 'parameters in params-argument using &'),
- array('viewtopic.php', array('t' => 1, 'f' => 2), true, false, 'viewtopic.php?t=1&f=2', 'parameters in params-argument as array'),
-
- // Custom sid parameter
- array('viewtopic.php', 't=1&f=2', true, 'custom-sid', 'viewtopic.php?t=1&f=2&sid=custom-sid', 'using session_id'),
-
- // Testing anchors
- array('viewtopic.php?t=1&f=2#anchor', false, true, false, 'viewtopic.php?t=1&f=2#anchor', 'anchor in url-argument'),
- array('viewtopic.php', 't=1&f=2#anchor', true, false, 'viewtopic.php?t=1&f=2#anchor', 'anchor in params-argument'),
- array('viewtopic.php', array('t' => 1, 'f' => 2, '#' => 'anchor'), true, false, 'viewtopic.php?t=1&f=2#anchor', 'anchor in params-argument (array)'),
-
- // Anchors and custom sid
- array('viewtopic.php?t=1&f=2#anchor', false, true, 'custom-sid', 'viewtopic.php?t=1&f=2&sid=custom-sid#anchor', 'anchor in url-argument using session_id'),
- array('viewtopic.php', 't=1&f=2#anchor', true, 'custom-sid', 'viewtopic.php?t=1&f=2&sid=custom-sid#anchor', 'anchor in params-argument using session_id'),
- array('viewtopic.php', array('t' => 1, 'f' => 2, '#' => 'anchor'), true, 'custom-sid', 'viewtopic.php?t=1&f=2&sid=custom-sid#anchor', 'anchor in params-argument (array) using session_id'),
-
- // Empty parameters should not append the ?
- array('viewtopic.php', false, true, false, 'viewtopic.php', 'no params using bool false'),
- array('viewtopic.php', '', true, false, 'viewtopic.php', 'no params using empty string'),
- array('viewtopic.php', array(), true, false, 'viewtopic.php', 'no params using empty array'),
- );
- }
-
- /**
- * @dataProvider append_sid_data
- */
- public function test_append_sid($url, $params, $is_amp, $session_id, $expected, $description)
- {
- global $phpbb_dispatcher;
-
- $phpbb_dispatcher = new phpbb_mock_event_dispatcher;
- $this->assertEquals($expected, append_sid($url, $params, $is_amp, $session_id));
- }
-}
-
+<?php +/** +* +* @package testing +* @copyright (c) 2011 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_session_append_sid_test extends phpbb_test_case +{ + + public function append_sid_data() + { + return array( + array('viewtopic.php?t=1&f=2', false, true, false, 'viewtopic.php?t=1&f=2', 'parameters in url-argument'), + array('viewtopic.php', 't=1&f=2', true, false, 'viewtopic.php?t=1&f=2', 'parameters in params-argument using amp'), + array('viewtopic.php', 't=1&f=2', false, false, 'viewtopic.php?t=1&f=2', 'parameters in params-argument using &'), + array('viewtopic.php', array('t' => 1, 'f' => 2), true, false, 'viewtopic.php?t=1&f=2', 'parameters in params-argument as array'), + + // Custom sid parameter + array('viewtopic.php', 't=1&f=2', true, 'custom-sid', 'viewtopic.php?t=1&f=2&sid=custom-sid', 'using session_id'), + + // Testing anchors + array('viewtopic.php?t=1&f=2#anchor', false, true, false, 'viewtopic.php?t=1&f=2#anchor', 'anchor in url-argument'), + array('viewtopic.php', 't=1&f=2#anchor', true, false, 'viewtopic.php?t=1&f=2#anchor', 'anchor in params-argument'), + array('viewtopic.php', array('t' => 1, 'f' => 2, '#' => 'anchor'), true, false, 'viewtopic.php?t=1&f=2#anchor', 'anchor in params-argument (array)'), + + // Anchors and custom sid + array('viewtopic.php?t=1&f=2#anchor', false, true, 'custom-sid', 'viewtopic.php?t=1&f=2&sid=custom-sid#anchor', 'anchor in url-argument using session_id'), + array('viewtopic.php', 't=1&f=2#anchor', true, 'custom-sid', 'viewtopic.php?t=1&f=2&sid=custom-sid#anchor', 'anchor in params-argument using session_id'), + array('viewtopic.php', array('t' => 1, 'f' => 2, '#' => 'anchor'), true, 'custom-sid', 'viewtopic.php?t=1&f=2&sid=custom-sid#anchor', 'anchor in params-argument (array) using session_id'), + + // Empty parameters should not append the ? + array('viewtopic.php', false, true, false, 'viewtopic.php', 'no params using bool false'), + array('viewtopic.php', '', true, false, 'viewtopic.php', 'no params using empty string'), + array('viewtopic.php', array(), true, false, 'viewtopic.php', 'no params using empty array'), + ); + } + + /** + * @dataProvider append_sid_data + */ + public function test_append_sid($url, $params, $is_amp, $session_id, $expected, $description) + { + global $phpbb_dispatcher; + + $phpbb_dispatcher = new phpbb_mock_event_dispatcher; + $this->assertEquals($expected, append_sid($url, $params, $is_amp, $session_id)); + } +} + diff --git a/tests/template/template_test.php b/tests/template/template_test.php index 83995cb4ac..f43157775a 100644 --- a/tests/template/template_test.php +++ b/tests/template/template_test.php @@ -196,7 +196,25 @@ class phpbb_template_template_test extends phpbb_template_template_test_case array('loop' => array(array('VARIABLE' => 'x'), array('VARIABLE' => 'y')), 'loop.inner' => array(array(), array())), array('loop'), '', - ),/* no top level nested loops + ), + /* Currently fail on develop: + http://tracker.phpbb.com/browse/PHPBB3-11323 + array( + 'include_define_variable.html', + array('VARIABLE' => 'variable.html'), + array(), + array(), + 'variable.html', + ), + array( + 'include_loop_define.html', + array('VARIABLE' => 'value'), + array('loop' => array(array('NESTED_FILE' => 'variable.html'))), + array(), + 'value', + ), + */ + /* no top level nested loops array( 'loop_vars.html', array(), diff --git a/tests/template/templates/include_define_variable.html b/tests/template/templates/include_define_variable.html new file mode 100644 index 0000000000..aff9b574c2 --- /dev/null +++ b/tests/template/templates/include_define_variable.html @@ -0,0 +1,2 @@ +<!-- DEFINE $DEF = '{VARIABLE}' --> +<!-- INCLUDE {$DEF} --> diff --git a/tests/template/templates/include_loop_define.html b/tests/template/templates/include_loop_define.html new file mode 100644 index 0000000000..f539b21396 --- /dev/null +++ b/tests/template/templates/include_loop_define.html @@ -0,0 +1,4 @@ +<!-- BEGIN loop --> +<!-- DEFINE $DEF = '{loop.NESTED_FILE}' --> +<!-- INCLUDE {$DEF} --> +<!-- END loop --> diff --git a/tests/test_framework/phpbb_database_test_connection_manager.php b/tests/test_framework/phpbb_database_test_connection_manager.php index 03097a10a0..29058cc815 100644 --- a/tests/test_framework/phpbb_database_test_connection_manager.php +++ b/tests/test_framework/phpbb_database_test_connection_manager.php @@ -186,6 +186,16 @@ class phpbb_database_test_connection_manager $this->purge_extras(); break; + case 'phpbb_db_driver_postgres': + $this->connect(); + // Drop all of the tables + foreach ($this->get_tables() as $table) + { + $this->pdo->exec('DROP TABLE ' . $table . ' CASCADE'); + } + $this->purge_extras(); + break; + default: $this->connect(false); @@ -418,6 +428,19 @@ class phpbb_database_test_connection_manager $queries[] = 'DROP SEQUENCE ' . current($row); } break; + + case 'phpbb_db_driver_postgres': + $sql = 'SELECT sequence_name + FROM information_schema.sequences'; + $result = $this->pdo->query($sql); + + while ($row = $result->fetch(PDO::FETCH_NUM)) + { + $queries[] = 'DROP SEQUENCE ' . current($row); + } + + $queries[] = 'DROP TYPE IF EXISTS varchar_ci CASCADE'; + break; } foreach ($queries as $query) diff --git a/tests/test_framework/phpbb_functional_test_case.php b/tests/test_framework/phpbb_functional_test_case.php index 67a5050892..887dfea3b5 100644 --- a/tests/test_framework/phpbb_functional_test_case.php +++ b/tests/test_framework/phpbb_functional_test_case.php @@ -134,19 +134,32 @@ class phpbb_functional_test_case extends phpbb_test_case { global $phpbb_root_path, $phpEx; - if (!$this->extension_manager) - { - $this->extension_manager = new phpbb_extension_manager( - $this->get_db(), - new phpbb_config(array()), - self::$config['table_prefix'] . 'ext', - $phpbb_root_path, - ".$phpEx", - $this->get_cache_driver() - ); - } + $config = new phpbb_config(array()); + $db = $this->get_db(); + $db_tools = new phpbb_db_tools($db); + + $migrator = new phpbb_db_migrator( + $config, + $db, + $db_tools, + self::$config['table_prefix'] . 'migrations', + $phpbb_root_path, + $php_ext, + self::$config['table_prefix'], + array() + ); + $extension_manager = new phpbb_extension_manager( + new phpbb_mock_container_builder(), + $db, + $config, + $migrator, + self::$config['table_prefix'] . 'ext', + dirname(__FILE__) . '/', + '.' . $php_ext, + $this->get_cache_driver() + ); - return $this->extension_manager; + return $extension_manager; } static protected function install_board() @@ -262,7 +275,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 +283,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 +344,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 +364,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(); @@ -424,4 +447,20 @@ class phpbb_functional_test_case extends phpbb_test_case $content = $this->client->getResponse()->getContent(); $this->assertNotContains('Fatal error:', $content); } + + public function assert_filter($crawler, $expr, $msg = null) + { + $nodes = $crawler->filter($expr); + if ($msg) + { + $msg .= "\n"; + } + else + { + $msg = ''; + } + $msg .= "`$expr` not found in DOM."; + $this->assertGreaterThan(0, count($nodes), $msg); + return $nodes; + } } diff --git a/tests/test_framework/phpbb_test_case_helpers.php b/tests/test_framework/phpbb_test_case_helpers.php index 47459832d5..20ae384f21 100644 --- a/tests/test_framework/phpbb_test_case_helpers.php +++ b/tests/test_framework/phpbb_test_case_helpers.php @@ -77,6 +77,11 @@ class phpbb_test_case_helpers { include($test_config); + if (!function_exists('phpbb_convert_30_dbms_to_31')) + { + require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php'; + } + $config = array_merge($config, array( 'dbms' => phpbb_convert_30_dbms_to_31($dbms), 'dbhost' => $dbhost, diff --git a/tests/user/fixtures/user_loader.xml b/tests/user/fixtures/user_loader.xml new file mode 100644 index 0000000000..737376f326 --- /dev/null +++ b/tests/user/fixtures/user_loader.xml @@ -0,0 +1,23 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<dataset> + <table name="phpbb_users"> + <column>user_id</column> + <column>username</column> + <column>username_clean</column> + <row> + <value>1</value> + <value>Guest</value> + <value>guest</value> + </row> + <row> + <value>2</value> + <value>Admin</value> + <value>admin</value> + </row> + <row> + <value>3</value> + <value>Test</value> + <value>test</value> + </row> + </table> +</dataset> diff --git a/tests/user/user_loader.php b/tests/user/user_loader.php new file mode 100644 index 0000000000..0beb804729 --- /dev/null +++ b/tests/user/user_loader.php @@ -0,0 +1,49 @@ +<?php +/** +* +* @package testing +* @copyright (c) 2011 phpBB Group +* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 +* +*/ + +include_once(__DIR__ . '/../../phpBB/includes/utf/utf_tools.php'); + +class phpbb_user_lang_test extends phpbb_database_test_case +{ + public function getDataSet() + { + return $this->createXMLDataSet(dirname(__FILE__) . '/fixtures/user_loader.xml'); + } + + public function test_user_loader() + { + $db = $this->new_dbal(); + + $user_loader = new phpbb_user_loader($db, __DIR__ . '/../../phpBB/', 'php', 'phpbb_users'); + + $user_loader->load_users(array(2)); + + $user = $user_loader->get_user(1); + $this->assertEquals(1, $user['user_id']); + $this->assertEquals('Guest', $user['username']); + + $user = $user_loader->get_user(2); + $this->assertEquals(2, $user['user_id']); + $this->assertEquals('Admin', $user['username']); + + // Not loaded + $user = $user_loader->get_user(3); + $this->assertEquals(1, $user['user_id']); + $this->assertEquals('Guest', $user['username']); + + $user = $user_loader->get_user(3, true); + $this->assertEquals(3, $user['user_id']); + $this->assertEquals('Test', $user['username']); + + $user_id = $user_loader->load_user_by_username('Test'); + $user = $user_loader->get_user($user_id); + $this->assertEquals(3, $user['user_id']); + $this->assertEquals('Test', $user['username']); + } +} |