[ticket/416] Add handler for module constraints

B3P-416
This commit is contained in:
Marc Alexander
2014-11-30 15:27:24 +01:00
parent 74933dd425
commit a2dd8671b6
7 changed files with 238 additions and 125 deletions

View File

@@ -25,6 +25,9 @@ class phpbb_acp_move_module_test extends \board3\portal\tests\testframework\data
/** @var \board3\portal\portal\columns */
protected $portal_columns;
/** @var \board3\portal\portal\modules\constraints_handler */
protected $constraints_handler;
public function setUp()
{
parent::setUp();
@@ -73,19 +76,21 @@ class phpbb_acp_move_module_test extends \board3\portal\tests\testframework\data
'UNABLE_TO_MOVE_ROW' => 'UNABLE_TO_MOVE_ROW',
));
$this->database_handler = new \board3\portal\portal\modules\database_handler($db);
$this->modules_manager = new \board3\portal\portal\modules\manager($cache, $db, $this->portal_columns, $portal_helper, $this->database_handler, $request, $user);
$this->constraints_handler = new \board3\portal\portal\modules\constraints_handler($this->portal_columns, $user);
$this->modules_manager = new \board3\portal\portal\modules\manager($cache, $db, $this->portal_columns, $portal_helper, $this->constraints_handler, $this->database_handler, $request, $user);
$phpbb_container->set('board3.portal.modules.manager', $this->modules_manager);
$phpbb_container->set('board3.portal.modules.constraints_handler', $this->constraints_handler);
$this->portal_module = new \board3\portal\acp\portal_module();
$this->update_portal_modules();
}
protected function update_portal_modules()
{
$this->modules_manager->module_column = array();
$this->constraints_handler->module_column = array();
$portal_modules = obtain_portal_modules();
foreach($portal_modules as $cur_module)
{
$this->modules_manager->module_column[$cur_module['module_classname']][] = $this->portal_columns->number_to_string($cur_module['module_column']);
$this->constraints_handler->module_column[$cur_module['module_classname']][] = $this->portal_columns->number_to_string($cur_module['module_column']);
}
}
@@ -211,7 +216,7 @@ class phpbb_acp_move_module_test extends \board3\portal\tests\testframework\data
if ($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);
$this->constraints_handler->module_column[$module_data['module_classname']][] = $this->portal_columns->number_to_string($add_to_column);
}
for ($i = 1; $i <= $move_right; $i++)
@@ -262,7 +267,7 @@ class phpbb_acp_move_module_test extends \board3\portal\tests\testframework\data
if ($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);
$this->constraints_handler->module_column[$module_data['module_classname']][] = $this->portal_columns->number_to_string($add_to_column);
}
// We always start in the right column = 3
@@ -297,7 +302,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->modules_manager->can_move_module($target_column, $module_class));
$this->assertEquals($expected, $this->constraints_handler->can_move_module($target_column, $module_class));
}
}

View File

@@ -23,6 +23,9 @@ class modules_manager_confirm_box_test extends \board3\portal\tests\testframewor
/** @var \board3\portal\portal\modules\manager */
protected $modules_manager;
/** @var \board3\portal\portal\modules\constraints_handler */
protected $constraints_handler;
public function getDataSet()
{
return $this->createXMLDataSet(dirname(__FILE__) . '/../acp/fixtures/modules.xml');
@@ -74,7 +77,8 @@ class modules_manager_confirm_box_test extends \board3\portal\tests\testframewor
));
$this->database_handler = new \board3\portal\portal\modules\database_handler($db);
$this->modules_manager = new \board3\portal\portal\modules\manager($this->cache, $db, $this->portal_columns, $this->portal_helper, $this->database_handler, $request, $user);
$this->constraints_handler = new \board3\portal\portal\modules\constraints_handler($this->portal_columns, $user);
$this->modules_manager = new \board3\portal\portal\modules\manager($this->cache, $db, $this->portal_columns, $this->portal_helper, $this->constraints_handler, $this->database_handler, $request, $user);
$portal_config = array();
}
@@ -122,7 +126,7 @@ class modules_manager_confirm_box_test extends \board3\portal\tests\testframewor
$this->cache->expects($this->any())
->method('purge');
$this->request->overwrite('module_classname', '\board3\portal\modules\donation');
$this->modules_manager = new \board3\portal\portal\modules\manager($this->cache, $this->db, $this->portal_columns, $this->portal_helper, $this->database_handler, $this->request, $this->user);
$this->modules_manager = new \board3\portal\portal\modules\manager($this->cache, $this->db, $this->portal_columns, $this->portal_helper, $this->constraints_handler, $this->database_handler, $this->request, $this->user);
$this->modules_manager->set_u_action('adm/index.php?i=15&amp;mode=foobar')->set_acp_class('foo\bar');
// Trigger confirm box creation

View File

@@ -7,6 +7,8 @@
*
*/
namespace board3\portal\portal\modules;
class board3_portal_modules_manager_test extends \board3\portal\tests\testframework\database_test_case
{
protected $portal_columns;
@@ -15,6 +17,9 @@ class board3_portal_modules_manager_test extends \board3\portal\tests\testframew
/** @var \board3\portal\portal\modules\manager */
protected $modules_manager;
/** @var \board3\portal\portal\modules\constraints_handler */
protected $constraints_handler;
public function getDataSet()
{
return $this->createXMLDataSet(dirname(__FILE__) . '/../acp/fixtures/modules.xml');
@@ -22,6 +27,8 @@ class board3_portal_modules_manager_test extends \board3\portal\tests\testframew
public function setUp()
{
global $cache, $db;
parent::setUp();
$user = new \board3\portal\tests\mock\user();
@@ -57,7 +64,13 @@ class board3_portal_modules_manager_test extends \board3\portal\tests\testframew
'UNABLE_TO_MOVE_ROW' => 'UNABLE_TO_MOVE_ROW',
));
$this->database_handler = new \board3\portal\portal\modules\database_handler($db);
$this->modules_manager = new \board3\portal\portal\modules\manager($cache, $db, $this->portal_columns, $portal_helper, $this->database_handler, $request, $user);
$this->constraints_handler = new \board3\portal\portal\modules\constraints_handler($this->portal_columns, $user);
$this->modules_manager = new \board3\portal\portal\modules\manager($cache, $db, $this->portal_columns, $portal_helper, $this->constraints_handler, $this->database_handler, $request, $user);
$portal_modules = obtain_portal_modules();
foreach($portal_modules as $cur_module)
{
$this->constraints_handler->module_column[$cur_module['module_classname']][] = $this->portal_columns->number_to_string($cur_module['module_column']);
}
}
public function test_set_u_action()
@@ -86,4 +99,24 @@ class board3_portal_modules_manager_test extends \board3\portal\tests\testframew
$this->setExpectedTriggerError(E_USER_NOTICE, 'UNABLE_TO_MOVE');
$this->modules_manager->get_horizontal_move_action(array(), 6);
}
public function test_set_module_column()
{
$module_column = $this->constraints_handler->module_column;
$this->constraints_handler->set_module_column(array());
$this->assertEquals(array(), $this->constraints_handler->module_column);
$this->constraints_handler->set_module_column($module_column);
$this->assertEquals($module_column, $this->constraints_handler->module_column);
}
public function test_check_module_conflict()
{
phpbb_acp_move_module_test::$override_trigger_error = true;
phpbb_acp_move_module_test::$error = '';
phpbb_acp_move_module_test::$error_type = 0;
$move_action = 1;
$this->constraints_handler->check_module_conflict($this->modules_manager->get_move_module_data(2), $move_action);
$this->assertEquals('UNABLE_TO_MOVE', phpbb_acp_move_module_test::$error);
phpbb_acp_move_module_test::$override_trigger_error = false;
}
}