[ticket/14831] Add more tests, better name for $e placeholder

PHPBB3-14831
This commit is contained in:
rxu 2016-10-23 22:44:47 +07:00
parent a02b124dd0
commit 51ef1ae346
2 changed files with 61 additions and 10 deletions

View file

@ -482,7 +482,7 @@ class module implements \phpbb\db\migration\tool\tool_interface
public function get_parent_module_id($parent_id, $data = '', $throw_exception = true)
{
// Initialize exception object placeholder
$e = false;
$exception = false;
// Allow '' to be sent as 0
$parent_id = $parent_id ?: 0;
@ -505,7 +505,7 @@ class module implements \phpbb\db\migration\tool\tool_interface
{
// No parent with the given module_langname exist
case 0:
$e = new \phpbb\db\migration\exception('MODULE_NOT_EXIST', $parent_id);
$exception = new \phpbb\db\migration\exception('MODULE_NOT_EXIST', $parent_id);
break;
// Return the module id
@ -527,7 +527,7 @@ class module implements \phpbb\db\migration\tool\tool_interface
$parent_id = (int) $this->db->sql_fetchfield('parent_id');
if (!$parent_id)
{
$e = new \phpbb\db\migration\exception('PARENT_MODULE_FIND_ERROR', $data['parent_id']);
$exception = new \phpbb\db\migration\exception('PARENT_MODULE_FIND_ERROR', $data['parent_id']);
}
}
else if (!empty($data) && !is_array($data))
@ -545,17 +545,17 @@ class module implements \phpbb\db\migration\tool\tool_interface
else
{
//Unable to get the parent module id, throwing an exception
$e = new \phpbb\db\migration\exception('MODULE_EXIST_MULTIPLE', $parent_id);
$exception = new \phpbb\db\migration\exception('MODULE_EXIST_MULTIPLE', $parent_id);
}
break;
}
}
if ($e !== false)
if ($exception !== false)
{
if ($throw_exception)
{
throw $e;
throw $exception;
}
return false;
}

View file

@ -42,10 +42,10 @@ class phpbb_dbal_migrator_tool_module_test extends phpbb_database_test_case
$this->tool = new \phpbb\db\migration\tool\module($this->db, $this->cache, $this->user, $phpbb_root_path, $phpEx, 'phpbb_modules');
}
public function exists_data()
public function exists_data_acp()
{
return array(
// Test the category
// Test the existing category
array(
'',
'ACP_CAT',
@ -57,7 +57,7 @@ class phpbb_dbal_migrator_tool_module_test extends phpbb_database_test_case
true,
),
// Test the module
// Test the existing module
array(
'',
'ACP_MODULE',
@ -73,11 +73,23 @@ class phpbb_dbal_migrator_tool_module_test extends phpbb_database_test_case
'ACP_MODULE',
true,
),
// Test for non-existant modules
array(
'',
'ACP_NON_EXISTANT_CAT',
false,
),
array(
'ACP_CAT',
'ACP_NON_EXISTANT_MODULE',
false,
),
);
}
/**
* @dataProvider exists_data
* @dataProvider exists_data_acp
*/
public function test_exists($parent, $module, $expected)
{
@ -156,6 +168,45 @@ class phpbb_dbal_migrator_tool_module_test extends phpbb_database_test_case
$this->fail($e);
}
$this->assertEquals(true, $this->tool->exists('acp', 'ACP_FORUM_BASED_PERMISSIONS', 'ACP_NEW_PERMISSIONS_MODULE'));
// Test adding UCP modules
// Test adding new UCP category
try
{
$this->tool->add('ucp', 0, 'UCP_NEW_CAT');
}
catch (Exception $e)
{
$this->fail($e);
}
$this->assertEquals(true, $this->tool->exists('ucp', 0, 'UCP_NEW_CAT'));
// Test adding new UCP subcategory
try
{
$this->tool->add('ucp', 'UCP_NEW_CAT', 'UCP_NEW_SUBCAT');
}
catch (Exception $e)
{
$this->fail($e);
}
$this->assertEquals(true, $this->tool->exists('ucp', 'UCP_NEW_CAT', 'UCP_NEW_SUBCAT'));
// Test adding new UCP module
try
{
$this->tool->add('ucp', 'UCP_NEW_SUBCAT', array(
'module_basename' => 'ucp_new_module',
'module_langname' => 'UCP_NEW_MODULE',
'module_mode' => 'ucp_test',
'module_auth' => '',
));
}
catch (Exception $e)
{
$this->fail($e);
}
$this->assertEquals(true, $this->tool->exists('ucp', 'UCP_NEW_SUBCAT', 'UCP_NEW_MODULE'));
}
public function test_remove()