mirror of
https://github.com/phpbb/phpbb.git
synced 2025-08-01 14:30:32 +02:00
Merge branch 'develop' of https://github.com/phpbb/phpbb3 into feature/softdelete-1-permission
* 'develop' of https://github.com/phpbb/phpbb3: (234 commits) [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/10411] Fix call to function on non-object $db->...() [ticket/10411] Remove ajax delete, so the page is refreshed [feature/avatars] Auto-clear avatar dimensions when first changing avatars [ticket/10411] Update schema file with new table and remove the column [ticket/10411] Add unit tests for move() with values >1 [ticket/10411] Add migrations file for teampage table [ticket/10411] Revert database_update.php changes from for easier update ...
This commit is contained in:
19
tests/avatar/driver/barfoo.php
Normal file
19
tests/avatar/driver/barfoo.php
Normal file
@@ -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;
|
||||
}
|
||||
}
|
19
tests/avatar/driver/foobar.php
Normal file
19
tests/avatar/driver/foobar.php
Normal file
@@ -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;
|
||||
}
|
||||
}
|
90
tests/avatar/manager_test.php
Normal file
90
tests/avatar/manager_test.php
Normal file
@@ -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);
|
||||
}
|
||||
}
|
@@ -45,15 +45,6 @@ class phpbb_dbal_migrator_test extends phpbb_database_test_case
|
||||
new phpbb_db_migration_tool_config($this->config),
|
||||
);
|
||||
|
||||
$this->extension_manager = new phpbb_extension_manager(
|
||||
new phpbb_mock_container_builder(),
|
||||
$this->db,
|
||||
$this->config,
|
||||
'phpbb_ext',
|
||||
dirname(__FILE__) . '/../../phpBB/',
|
||||
'.php',
|
||||
null
|
||||
);
|
||||
$this->migrator = new phpbb_db_migrator(
|
||||
$this->config,
|
||||
$this->db,
|
||||
@@ -64,7 +55,16 @@ class phpbb_dbal_migrator_test extends phpbb_database_test_case
|
||||
'phpbb_',
|
||||
$tools
|
||||
);
|
||||
$this->migrator->set_extension_manager($this->extension_manager);
|
||||
$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()
|
||||
|
@@ -97,15 +97,6 @@ class phpbb_extension_manager_test extends phpbb_database_test_case
|
||||
$php_ext = 'php';
|
||||
$table_prefix = 'phpbb_';
|
||||
|
||||
$manager = new phpbb_extension_manager(
|
||||
new phpbb_mock_container_builder(),
|
||||
$db,
|
||||
$config,
|
||||
'phpbb_ext',
|
||||
dirname(__FILE__) . '/',
|
||||
'.' . $php_ext,
|
||||
($with_cache) ? new phpbb_mock_cache() : null
|
||||
);
|
||||
$migrator = new phpbb_db_migrator(
|
||||
$config,
|
||||
$db,
|
||||
@@ -116,9 +107,15 @@ class phpbb_extension_manager_test extends phpbb_database_test_case
|
||||
$table_prefix,
|
||||
array()
|
||||
);
|
||||
$manager->set_migrator($migrator);
|
||||
$migrator->set_extension_manager($manager);
|
||||
|
||||
return $manager;
|
||||
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
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@@ -49,10 +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,
|
||||
|
@@ -125,7 +125,7 @@ class phpbb_functions_user_group_user_attributes_test extends phpbb_database_tes
|
||||
*/
|
||||
public function test_group_user_attributes($description, $user_id, $group_id, $group_row, $expected)
|
||||
{
|
||||
global $auth, $cache, $db, $phpbb_dispatcher, $user, $phpbb_container;
|
||||
global $auth, $cache, $db, $phpbb_dispatcher, $user, $phpbb_container, $phpbb_log, $phpbb_root_path, $phpEx;
|
||||
|
||||
$user->ip = '';
|
||||
$cache = new phpbb_mock_cache;
|
||||
@@ -141,6 +141,7 @@ class phpbb_functions_user_group_user_attributes_test extends phpbb_database_tes
|
||||
->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);
|
||||
|
||||
|
@@ -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));
|
||||
}
|
||||
}
|
||||
|
@@ -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>
|
102
tests/groupposition/fixtures/teampage.xml
Normal file
102
tests/groupposition/fixtures/teampage.xml
Normal file
@@ -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>
|
403
tests/groupposition/legend_test.php
Normal file
403
tests/groupposition/legend_test.php
Normal file
@@ -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));
|
||||
}
|
||||
}
|
||||
|
641
tests/groupposition/teampage_test.php
Normal file
641
tests/groupposition/teampage_test.php
Normal file
@@ -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));
|
||||
}
|
||||
}
|
||||
|
88
tests/log/add_test.php
Normal file
88
tests/log/add_test.php
Normal file
@@ -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));
|
||||
}
|
||||
}
|
15
tests/log/fixtures/empty_log.xml
Normal file
15
tests/log/fixtures/empty_log.xml
Normal file
@@ -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>
|
166
tests/log/fixtures/full_log.xml
Normal file
166
tests/log/fixtures/full_log.xml
Normal file
@@ -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>
|
193
tests/log/function_add_log_test.php
Normal file
193
tests/log/function_add_log_test.php
Normal file
@@ -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));
|
||||
}
|
||||
}
|
344
tests/log/function_view_log_test.php
Normal file
344
tests/log/function_view_log_test.php
Normal file
@@ -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);
|
||||
}
|
||||
}
|
@@ -138,15 +138,6 @@ class phpbb_functional_test_case extends phpbb_test_case
|
||||
$db = $this->get_db();
|
||||
$db_tools = new phpbb_db_tools($db);
|
||||
|
||||
$extension_manager = new phpbb_extension_manager(
|
||||
new phpbb_mock_container_builder(),
|
||||
$db,
|
||||
$config,
|
||||
self::$config['table_prefix'] . 'ext',
|
||||
dirname(__FILE__) . '/',
|
||||
'.' . $php_ext,
|
||||
$this->get_cache_driver()
|
||||
);
|
||||
$migrator = new phpbb_db_migrator(
|
||||
$config,
|
||||
$db,
|
||||
@@ -157,8 +148,16 @@ class phpbb_functional_test_case extends phpbb_test_case
|
||||
self::$config['table_prefix'],
|
||||
array()
|
||||
);
|
||||
$extension_manager->set_migrator($migrator);
|
||||
$migrator->set_extension_manager($extension_manager);
|
||||
$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 $extension_manager;
|
||||
}
|
||||
|
Reference in New Issue
Block a user