forked from phpbb/phpbb
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request phpbb#5260 from senky/ticket/15696
[ticket/15696] 'if' module tool should support calling other tools * github.com:/phpbb/phpbb: [ticket/15696] Add tests [ticket/15696] Add support of other tools to 'if'
- Loading branch information
Showing
2 changed files
with
137 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,136 @@ | ||
<?php | ||
/** | ||
* | ||
* This file is part of the phpBB Forum Software package. | ||
* | ||
* @copyright (c) phpBB Limited <https://www.phpbb.com> | ||
* @license GNU General Public License, version 2 (GPL-2.0) | ||
* | ||
* For full copyright and license information, please see | ||
* the docs/CREDITS.txt file. | ||
* | ||
*/ | ||
|
||
class get_callable_from_step_test extends phpbb_database_test_case | ||
{ | ||
public function setUp() | ||
{ | ||
global $phpbb_root_path, $php_ext, $table_prefix, $phpbb_log; | ||
|
||
parent::setUp(); | ||
|
||
$phpbb_log = $this->getMockBuilder('\phpbb\log\log')->disableOriginalConstructor()->getMock(); | ||
$db = $this->new_dbal(); | ||
$factory = new \phpbb\db\tools\factory(); | ||
$cache_service = $this->getMockBuilder('\phpbb\cache\service')->disableOriginalConstructor()->getMock(); | ||
$user = $this->getMockBuilder('\phpbb\user')->disableOriginalConstructor()->getMock(); | ||
$module_manager = new \phpbb\module\module_manager( | ||
$this->getMockBuilder('\phpbb\cache\driver\dummy')->disableOriginalConstructor()->getMock(), | ||
$db, | ||
new phpbb_mock_extension_manager($phpbb_root_path), | ||
'phpbb_modules', | ||
$phpbb_root_path, | ||
$php_ext | ||
); | ||
$module_tools = new \phpbb\db\migration\tool\module($db, $cache_service, $user, $module_manager, $phpbb_root_path, $php_ext, 'phpbb_modules'); | ||
$this->migrator = new \phpbb\db\migrator( | ||
new phpbb_mock_container_builder(), | ||
new \phpbb\config\config(array()), | ||
$db, | ||
$factory->get($db), | ||
'phpbb_migrations', | ||
$phpbb_root_path, | ||
$php_ext, | ||
$table_prefix, | ||
array($module_tools), | ||
new \phpbb\db\migration\helper() | ||
); | ||
|
||
if (!$module_tools->exists('acp', 0, 'new_module_langname')) | ||
{ | ||
$module_tools->add('acp', 0, array( | ||
'module_basename' => 'new_module_basename', | ||
'module_langname' => 'new_module_langname', | ||
'module_mode' => 'settings', | ||
'module_auth' => '', | ||
'module_display' => true, | ||
'before' => false, | ||
'after' => false, | ||
)); | ||
$this->module_added = true; | ||
} | ||
} | ||
|
||
public function getDataSet() | ||
{ | ||
return $this->createXMLDataSet(dirname(__FILE__).'/../dbal/fixtures/migrator.xml'); | ||
} | ||
|
||
public function get_callable_from_step_provider() | ||
{ | ||
return array( | ||
array( | ||
array('if', array( | ||
false, | ||
array('permission.add', array('some_data')), | ||
)), | ||
true, // expects false | ||
), | ||
array( | ||
array('if', array( | ||
array('module.exists', array( | ||
'mcp', | ||
'RANDOM_PARENT', | ||
'RANDOM_MODULE' | ||
)), | ||
array('permission.add', array('some_data')), | ||
)), | ||
true, // expects false | ||
), | ||
array( | ||
array('if', array( | ||
array('module.exists', array( | ||
'acp', | ||
0, | ||
'new_module_langname' | ||
)), | ||
array('module.add', array( | ||
'acp', | ||
0, | ||
'module_basename' => 'new_module_basename2', | ||
'module_langname' => 'new_module_langname2', | ||
'module_mode' => 'settings', | ||
'module_auth' => '', | ||
'module_display' => true, | ||
'before' => false, | ||
'after' => false, | ||
)), | ||
)), | ||
false, // expects false | ||
), | ||
); | ||
} | ||
|
||
/** | ||
* @dataProvider get_callable_from_step_provider | ||
*/ | ||
public function test_get_callable_from_step($step, $expects_false) | ||
{ | ||
if ($expects_false) | ||
{ | ||
$this->assertFalse($this->call_get_callable_from_step($step)); | ||
} | ||
else | ||
{ | ||
$this->assertNotFalse($this->call_get_callable_from_step($step)); | ||
} | ||
} | ||
|
||
protected function call_get_callable_from_step($step) | ||
{ | ||
$class = new ReflectionClass($this->migrator); | ||
$method = $class->getMethod('get_callable_from_step'); | ||
$method->setAccessible(true); | ||
return $method->invokeArgs($this->migrator, array($step)); | ||
} | ||
} |