[ticket/416] Use modules manager in acp and tests
B3P-416
This commit is contained in:
@@ -7,7 +7,7 @@
|
||||
*
|
||||
*/
|
||||
|
||||
namespace board3\portal\acp;
|
||||
namespace board3\portal\portal\modules;
|
||||
|
||||
require_once(dirname(__FILE__) . '/../../../includes/functions.php');
|
||||
require_once(dirname(__FILE__) . '/../../../acp/portal_module.php');
|
||||
@@ -18,6 +18,12 @@ class phpbb_acp_move_module_test extends \board3\portal\tests\testframework\data
|
||||
static public $error = false;
|
||||
static public $override_trigger_error = false;
|
||||
|
||||
/** @var \board3\portal\portal\modules\manager */
|
||||
protected $modules_manager;
|
||||
|
||||
/** @var \board3\portal\portal\columns */
|
||||
protected $portal_columns;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
@@ -39,7 +45,8 @@ class phpbb_acp_move_module_test extends \board3\portal\tests\testframework\data
|
||||
new \board3\portal\modules\welcome($config, new \phpbb_mock_request, $this->db, $user, $phpbb_root_path, $phpEx),
|
||||
new \board3\portal\modules\donation($config, $template, $user),
|
||||
));
|
||||
$phpbb_container->set('board3.portal.helper', new \board3\portal\includes\helper($phpbb_container->get('board3.portal.module_collection')));
|
||||
$portal_helper = new \board3\portal\includes\helper($phpbb_container->get('board3.portal.module_collection'));
|
||||
$phpbb_container->set('board3.portal.helper', $portal_helper);
|
||||
$phpbb_container->set('board3.portal.modules_helper', new \board3\portal\includes\modules_helper(new \phpbb\auth\auth(), $config, $request));
|
||||
$phpbb_container->setParameter('board3.portal.modules.table', $table_prefix . 'portal_modules');
|
||||
$phpbb_container->setParameter('board3.portal.config.table', $table_prefix . 'portal_config');
|
||||
@@ -64,17 +71,19 @@ class phpbb_acp_move_module_test extends \board3\portal\tests\testframework\data
|
||||
'UNABLE_TO_MOVE' => 'UNABLE_TO_MOVE',
|
||||
'UNABLE_TO_MOVE_ROW' => 'UNABLE_TO_MOVE_ROW',
|
||||
));
|
||||
$this->modules_manager = new \board3\portal\portal\modules\manager($cache, $db, $this->portal_columns, $portal_helper, $request, $user);
|
||||
$phpbb_container->set('board3.portal.modules.manager', $this->modules_manager);
|
||||
$this->portal_module = new \board3\portal\acp\portal_module();
|
||||
$this->update_portal_modules();
|
||||
}
|
||||
|
||||
protected function update_portal_modules()
|
||||
{
|
||||
$this->portal_module->module_column = array();
|
||||
$this->modules_manager->module_column = array();
|
||||
$portal_modules = obtain_portal_modules();
|
||||
foreach($portal_modules as $cur_module)
|
||||
{
|
||||
$this->portal_module->module_column[$cur_module['module_classname']][] = $this->portal_columns->number_to_string($cur_module['module_column']);
|
||||
$this->modules_manager->module_column[$cur_module['module_classname']][] = $this->portal_columns->number_to_string($cur_module['module_column']);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -85,7 +94,7 @@ class phpbb_acp_move_module_test extends \board3\portal\tests\testframework\data
|
||||
|
||||
public function test_get_move_module_data()
|
||||
{
|
||||
$module_data = $this->portal_module->get_move_module_data(1);
|
||||
$module_data = $this->modules_manager->get_move_module_data(1);
|
||||
$this->assertEquals(array(
|
||||
'module_order' => '1',
|
||||
'module_column' => '1',
|
||||
@@ -115,30 +124,30 @@ class phpbb_acp_move_module_test extends \board3\portal\tests\testframework\data
|
||||
*/
|
||||
public function test_get_last_module_order($expected, $column)
|
||||
{
|
||||
$this->assertEquals($expected, $this->portal_module->get_last_module_order($column));
|
||||
$this->assertEquals($expected, $this->modules_manager->get_last_module_order($column));
|
||||
}
|
||||
|
||||
public function test_move_module_up()
|
||||
{
|
||||
self::$redirected = false;
|
||||
$this->portal_module->move_module_up(2);
|
||||
$this->modules_manager->move_module_up(2);
|
||||
$this->assertTrue(self::$redirected);
|
||||
|
||||
$this->setExpectedTriggerError(E_USER_NOTICE, 'UNABLE_TO_MOVE_ROW');
|
||||
self::$redirected = false;
|
||||
$this->portal_module->move_module_up(2);
|
||||
$this->modules_manager->move_module_up(2);
|
||||
$this->assertFalse(self::$redirected);
|
||||
}
|
||||
|
||||
public function test_move_module_down()
|
||||
{
|
||||
self::$redirected = false;
|
||||
$this->portal_module->move_module_down(3);
|
||||
$this->modules_manager->move_module_down(3);
|
||||
$this->assertTrue(self::$redirected);
|
||||
|
||||
$this->setExpectedTriggerError(E_USER_NOTICE, 'UNABLE_TO_MOVE_ROW');
|
||||
self::$redirected = false;
|
||||
$this->portal_module->move_module_down(3);
|
||||
$this->modules_manager->move_module_down(3);
|
||||
$this->assertFalse(self::$redirected);
|
||||
}
|
||||
|
||||
@@ -165,7 +174,7 @@ class phpbb_acp_move_module_test extends \board3\portal\tests\testframework\data
|
||||
self::$redirected = false;
|
||||
}
|
||||
|
||||
$this->portal_module->handle_after_move($success, $is_row);
|
||||
$this->modules_manager->handle_after_move($success, $is_row);
|
||||
|
||||
if (!$error)
|
||||
{
|
||||
@@ -193,26 +202,26 @@ class phpbb_acp_move_module_test extends \board3\portal\tests\testframework\data
|
||||
if ($column_start > 3)
|
||||
{
|
||||
$this->setExpectedTriggerError(E_USER_ERROR, 'CLASS_NOT_FOUND');
|
||||
$this->portal_module->move_module_right($module_id);
|
||||
$this->modules_manager->move_module_right($module_id);
|
||||
return;
|
||||
}
|
||||
|
||||
if ($add_to_column)
|
||||
{
|
||||
$module_data = $this->portal_module->get_move_module_data($module_id);
|
||||
$this->portal_module->module_column[$module_data['module_classname']][] = $this->portal_columns->number_to_string($add_to_column);
|
||||
$module_data = $this->modules_manager->get_move_module_data($module_id);
|
||||
$this->modules_manager->module_column[$module_data['module_classname']][] = $this->portal_columns->number_to_string($add_to_column);
|
||||
}
|
||||
|
||||
for ($i = 1; $i <= $move_right; $i++)
|
||||
{
|
||||
$data = $this->portal_module->get_move_module_data($module_id);
|
||||
$data = $this->modules_manager->get_move_module_data($module_id);
|
||||
$this->assertEquals($column_start, $data['module_column']);
|
||||
$this->portal_module->move_module_right($module_id);
|
||||
$this->modules_manager->move_module_right($module_id);
|
||||
$column_start++;
|
||||
$this->update_portal_modules();
|
||||
}
|
||||
$this->setExpectedTriggerError(E_USER_NOTICE, 'UNABLE_TO_MOVE');
|
||||
$this->portal_module->move_module_right($module_id);
|
||||
$this->modules_manager->move_module_right($module_id);
|
||||
}
|
||||
|
||||
public function data_move_module_left()
|
||||
@@ -235,37 +244,37 @@ class phpbb_acp_move_module_test extends \board3\portal\tests\testframework\data
|
||||
if ($column_start > 3)
|
||||
{
|
||||
$this->setExpectedTriggerError(E_USER_ERROR, 'CLASS_NOT_FOUND');
|
||||
$this->portal_module->move_module_left($module_id);
|
||||
$this->modules_manager->move_module_left($module_id);
|
||||
return;
|
||||
}
|
||||
|
||||
for ($i = 1; $i <= $move_right; $i++)
|
||||
{
|
||||
$data = $this->portal_module->get_move_module_data($module_id);
|
||||
$data = $this->modules_manager->get_move_module_data($module_id);
|
||||
$this->assertEquals($column_start, $data['module_column']);
|
||||
$this->portal_module->move_module_right($module_id);
|
||||
$this->modules_manager->move_module_right($module_id);
|
||||
$this->update_portal_modules();
|
||||
$column_start++;
|
||||
}
|
||||
|
||||
if ($add_to_column)
|
||||
{
|
||||
$module_data = $this->portal_module->get_move_module_data($module_id);
|
||||
$this->portal_module->module_column[$module_data['module_classname']][] = $this->portal_columns->number_to_string($add_to_column);
|
||||
$module_data = $this->modules_manager->get_move_module_data($module_id);
|
||||
$this->modules_manager->module_column[$module_data['module_classname']][] = $this->portal_columns->number_to_string($add_to_column);
|
||||
}
|
||||
|
||||
// We always start in the right column = 3
|
||||
$column_start = 3;
|
||||
for ($i = 1; $i <= $move_left; $i++)
|
||||
{
|
||||
$data = $this->portal_module->get_move_module_data($module_id);
|
||||
$data = $this->modules_manager->get_move_module_data($module_id);
|
||||
$this->assertEquals($column_start, $data['module_column']);
|
||||
$this->portal_module->move_module_left($module_id);
|
||||
$this->modules_manager->move_module_left($module_id);
|
||||
$this->update_portal_modules();
|
||||
$column_start--;
|
||||
}
|
||||
$this->setExpectedTriggerError(E_USER_NOTICE, 'UNABLE_TO_MOVE');
|
||||
$this->portal_module->move_module_left($module_id);
|
||||
$this->modules_manager->move_module_left($module_id);
|
||||
}
|
||||
|
||||
public function data_can_move_module()
|
||||
@@ -286,7 +295,7 @@ class phpbb_acp_move_module_test extends \board3\portal\tests\testframework\data
|
||||
public function test_can_move_module($expected, $target_column, $module_class)
|
||||
{
|
||||
$this->update_portal_modules();
|
||||
$this->assertEquals($expected, $this->portal_module->can_move_module($target_column, $module_class));
|
||||
$this->assertEquals($expected, $this->modules_manager->can_move_module($target_column, $module_class));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user