diff options
Diffstat (limited to 'tests/extension')
| -rw-r--r-- | tests/extension/finder_test.php | 4 | ||||
| -rw-r--r-- | tests/extension/manager_test.php | 4 | ||||
| -rw-r--r-- | tests/extension/metadata_manager_test.php | 51 | ||||
| -rw-r--r-- | tests/extension/modules_test.php | 51 |
4 files changed, 54 insertions, 56 deletions
diff --git a/tests/extension/finder_test.php b/tests/extension/finder_test.php index 2116cc057b..463b69e9a9 100644 --- a/tests/extension/finder_test.php +++ b/tests/extension/finder_test.php @@ -244,7 +244,7 @@ class phpbb_extension_finder_test extends phpbb_test_case public function test_get_classes_create_cache() { $cache = new phpbb_mock_cache; - $finder = new \phpbb\finder(new \phpbb\filesystem(), dirname(__FILE__) . '/', $cache, 'php', '_custom_cache_name'); + $finder = new \phpbb\finder(new \phpbb\filesystem\filesystem(), dirname(__FILE__) . '/', $cache, 'php', '_custom_cache_name'); $finder->set_extensions(array_keys($this->extension_manager->all_enabled())); $files = $finder->suffix('_class.php')->get_files(); @@ -284,7 +284,7 @@ class phpbb_extension_finder_test extends phpbb_test_case ); $finder = new \phpbb\finder( - new \phpbb\filesystem(), + new \phpbb\filesystem\filesystem(), dirname(__FILE__) . '/', new phpbb_mock_cache(array( '_ext_finder' => array( diff --git a/tests/extension/manager_test.php b/tests/extension/manager_test.php index 0126216701..a24b0cf178 100644 --- a/tests/extension/manager_test.php +++ b/tests/extension/manager_test.php @@ -155,7 +155,6 @@ class phpbb_extension_manager_test extends phpbb_database_test_case $phpbb_root_path = __DIR__ . './../../phpBB/'; $php_ext = 'php'; $table_prefix = 'phpbb_'; - $user = new \phpbb\user('\phpbb\user'); $container = new phpbb_mock_container_builder(); @@ -177,8 +176,7 @@ class phpbb_extension_manager_test extends phpbb_database_test_case $container, $db, $config, - new \phpbb\filesystem(), - $user, + new \phpbb\filesystem\filesystem(), 'phpbb_ext', dirname(__FILE__) . '/', $php_ext, diff --git a/tests/extension/metadata_manager_test.php b/tests/extension/metadata_manager_test.php index 8514ed3dbd..53bd3d109b 100644 --- a/tests/extension/metadata_manager_test.php +++ b/tests/extension/metadata_manager_test.php @@ -45,24 +45,25 @@ class phpbb_extension_metadata_manager_test extends phpbb_database_test_case $this->db_tools = $factory->get($this->db); $this->phpbb_root_path = dirname(__FILE__) . '/'; $this->phpEx = 'php'; - $this->user = new \phpbb\user('\phpbb\datetime'); $this->table_prefix = 'phpbb_'; $container = new phpbb_mock_container_builder(); $cache_path = $this->phpbb_root_path . 'cache/twig'; $context = new \phpbb\template\context(); - $loader = new \phpbb\template\twig\loader(''); - $phpbb_path_helper =new \phpbb\path_helper( + $loader = new \phpbb\template\twig\loader(new \phpbb\filesystem\filesystem(), ''); + $filesystem = new \phpbb\filesystem\filesystem(); + $phpbb_path_helper = new \phpbb\path_helper( new \phpbb\symfony_request( new phpbb_mock_request() ), - new \phpbb\filesystem(), + $filesystem, $this->getMock('\phpbb\request\request'), $this->phpbb_root_path, $this->phpEx ); $twig = new \phpbb\template\twig\environment( $this->config, + $filesystem, $phpbb_path_helper, $container, $cache_path, @@ -75,8 +76,6 @@ class phpbb_extension_metadata_manager_test extends phpbb_database_test_case 'autoescape' => false, ) ); - $this->template = new phpbb\template\twig\twig($phpbb_path_helper, $this->config, $this->user, $context, $twig, $cache_path, array(new \phpbb\template\twig\extension($context, $this->user))); - $container->set('template.twig.lexer', new \phpbb\template\twig\lexer($twig)); $container = new phpbb_mock_container_builder(); @@ -98,13 +97,22 @@ class phpbb_extension_metadata_manager_test extends phpbb_database_test_case $container, $this->db, $this->config, - new \phpbb\filesystem(), - $this->user, + new \phpbb\filesystem\filesystem(), 'phpbb_ext', $this->phpbb_root_path, $this->phpEx, $this->cache ); + + global $phpbb_root_path; + + $lang_loader = new \phpbb\language\language_file_loader($phpbb_root_path, $this->phpEx); + $lang_loader->set_extension_manager($this->extension_manager); + $lang = new \phpbb\language\language($lang_loader); + $this->user = new \phpbb\user($lang, '\phpbb\datetime'); + + $this->template = new phpbb\template\twig\twig($phpbb_path_helper, $this->config, $context, $twig, $cache_path, $this->user, array(new \phpbb\template\twig\extension($context, $this->user))); + $container->set('template.twig.lexer', new \phpbb\template\twig\lexer($twig)); } // Should fail from missing composer.json @@ -120,7 +128,8 @@ class phpbb_extension_metadata_manager_test extends phpbb_database_test_case } catch (\phpbb\extension\exception $e) { - $this->assertEquals((string) $e, $this->user->lang('FILE_NOT_FOUND', $this->phpbb_root_path . $this->extension_manager->get_extension_path($ext_name) . 'composer.json')); + $message = call_user_func_array(array($this->user, 'lang'), array_merge(array($e->getMessage()), $e->get_parameters())); + $this->assertEquals($message, $this->user->lang('FILE_NOT_FOUND', $this->phpbb_root_path . $this->extension_manager->get_extension_path($ext_name) . 'composer.json')); } } @@ -137,7 +146,8 @@ class phpbb_extension_metadata_manager_test extends phpbb_database_test_case } catch (\phpbb\extension\exception $e) { - $this->fail($e); + $message = call_user_func_array(array($this->user, 'lang'), array_merge(array($e->getMessage()), $e->get_parameters())); + $this->fail($message); } $json = json_decode(file_get_contents($this->phpbb_root_path . 'ext/vendor2/foo/composer.json'), true); @@ -167,9 +177,10 @@ class phpbb_extension_metadata_manager_test extends phpbb_database_test_case $manager->validate($field_name); $this->fail('Exception not triggered'); } - catch(\phpbb\extension\exception $e) + catch (\phpbb\extension\exception $e) { - $this->assertEquals((string) $e, $this->user->lang('META_FIELD_NOT_SET', $field_name)); + $message = call_user_func_array(array($this->user, 'lang'), array_merge(array($e->getMessage()), $e->get_parameters())); + $this->assertEquals($message, $this->user->lang('META_FIELD_NOT_SET', $field_name)); } } @@ -183,7 +194,8 @@ class phpbb_extension_metadata_manager_test extends phpbb_database_test_case } catch (\phpbb\extension\exception $e) { - $this->assertEquals((string) $e, $this->user->lang('META_FIELD_NOT_SET', 'authors')); + $message = call_user_func_array(array($this->user, 'lang'), array_merge(array($e->getMessage()), $e->get_parameters())); + $this->assertEquals($message, $this->user->lang('META_FIELD_NOT_SET', 'authors')); } $manager->merge_metadata(array( @@ -199,7 +211,8 @@ class phpbb_extension_metadata_manager_test extends phpbb_database_test_case } catch (\phpbb\extension\exception $e) { - $this->assertEquals((string) $e, $this->user->lang('META_FIELD_NOT_SET', 'author name')); + $message = call_user_func_array(array($this->user, 'lang'), array_merge(array($e->getMessage()), $e->get_parameters())); + $this->assertEquals($message, $this->user->lang('META_FIELD_NOT_SET', 'author name')); } } @@ -230,9 +243,10 @@ class phpbb_extension_metadata_manager_test extends phpbb_database_test_case $manager->validate($field_name); $this->fail('Exception not triggered'); } - catch(\phpbb\extension\exception $e) + catch (\phpbb\extension\exception $e) { - $this->assertEquals((string) $e, $this->user->lang('META_FIELD_INVALID', $field_name)); + $message = call_user_func_array(array($this->user, 'lang'), array_merge(array($e->getMessage()), $e->get_parameters())); + $this->assertEquals($message, $this->user->lang('META_FIELD_INVALID', $field_name)); } } @@ -254,9 +268,9 @@ class phpbb_extension_metadata_manager_test extends phpbb_database_test_case { $this->assertEquals(true, $manager->validate('enable')); } - catch(\phpbb\extension\exception $e) + catch (\phpbb\extension\exception $e) { - $this->fail($e); + $message = call_user_func_array(array($this->user, 'lang'), array_merge(array($e->getMessage()), $e->get_parameters())); } } @@ -352,7 +366,6 @@ class phpbb_extension_metadata_manager_test extends phpbb_database_test_case $this->config, $this->extension_manager, $this->template, - $this->user, $this->phpbb_root_path ); } diff --git a/tests/extension/modules_test.php b/tests/extension/modules_test.php index cbcfdfb787..88634bc6ba 100644 --- a/tests/extension/modules_test.php +++ b/tests/extension/modules_test.php @@ -22,6 +22,7 @@ class phpbb_extension_modules_test extends phpbb_test_case { protected $extension_manager; protected $finder; + protected $module_manager; public function setUp() { @@ -43,7 +44,14 @@ class phpbb_extension_modules_test extends phpbb_test_case )); $phpbb_extension_manager = $this->extension_manager; - $this->acp_modules = new acp_modules(); + $this->module_manager = new \phpbb\module\module_manager( + new \phpbb\cache\driver\dummy(), + $this->getMock('\phpbb\db\driver\driver_interface'), + $this->extension_manager, + MODULES_TABLE, + dirname(__FILE__) . '/', + 'php' + ); } public function test_get_module_infos() @@ -56,8 +64,7 @@ class phpbb_extension_modules_test extends phpbb_test_case $phpbb_root_path = dirname(__FILE__) . '/'; // Find acp module info files - $this->acp_modules->module_class = 'acp'; - $acp_modules = $this->acp_modules->get_module_infos(); + $acp_modules = $this->module_manager->get_module_infos('acp'); $this->assertEquals(array( 'vendor2\\foo\\acp\\a_module' => array( 'filename' => 'vendor2\\foo\\acp\\a_module', @@ -76,8 +83,7 @@ class phpbb_extension_modules_test extends phpbb_test_case ), $acp_modules); // Find mcp module info files - $this->acp_modules->module_class = 'mcp'; - $acp_modules = $this->acp_modules->get_module_infos(); + $acp_modules = $this->module_manager->get_module_infos('mcp'); $this->assertEquals(array( 'vendor2\\foo\\mcp\\a_module' => array( 'filename' => 'vendor2\\foo\\mcp\\a_module', @@ -89,21 +95,7 @@ class phpbb_extension_modules_test extends phpbb_test_case ), $acp_modules); // Find a specific module info file (mcp_a_module) - $this->acp_modules->module_class = 'mcp'; - $acp_modules = $this->acp_modules->get_module_infos('mcp_a_module'); - $this->assertEquals(array( - 'vendor2\\foo\\mcp\\a_module' => array( - 'filename' => 'vendor2\\foo\\mcp\\a_module', - 'title' => 'Foobar', - 'modes' => array( - 'config' => array('title' => 'Config', 'auth' => '', 'cat' => array('MCP_MAIN')), - ), - ), - ), $acp_modules); - - // Find a specific module info file (mcp_a_module) with passing the module_class - $this->acp_modules->module_class = ''; - $acp_modules = $this->acp_modules->get_module_infos('mcp_a_module', 'mcp'); + $acp_modules = $this->module_manager->get_module_infos('mcp', 'mcp_a_module'); $this->assertEquals(array( 'vendor2\\foo\\mcp\\a_module' => array( 'filename' => 'vendor2\\foo\\mcp\\a_module', @@ -115,18 +107,15 @@ class phpbb_extension_modules_test extends phpbb_test_case ), $acp_modules); // The mcp module info file we're looking for shouldn't exist - $this->acp_modules->module_class = 'mcp'; - $acp_modules = $this->acp_modules->get_module_infos('mcp_a_fail'); + $acp_modules = $this->module_manager->get_module_infos('mcp', 'mcp_a_fail'); $this->assertEquals(array(), $acp_modules); // As there are no ucp modules we shouldn't find any - $this->acp_modules->module_class = 'ucp'; - $acp_modules = $this->acp_modules->get_module_infos(); + $acp_modules = $this->module_manager->get_module_infos('ucp'); $this->assertEquals(array(), $acp_modules); // Get module info of specified extension module - $this->acp_modules->module_class = 'acp'; - $acp_modules = $this->acp_modules->get_module_infos('foo_acp_a_module'); + $acp_modules = $this->module_manager->get_module_infos('acp', 'foo_acp_a_module'); $this->assertEquals(array( 'vendor2\\foo\\acp\\a_module' => array ( 'filename' => 'vendor2\\foo\\acp\\a_module', @@ -138,18 +127,16 @@ class phpbb_extension_modules_test extends phpbb_test_case ), $acp_modules); // No specific module and module class set to an incorrect name - $acp_modules = $this->acp_modules->get_module_infos('', 'wcp', true); + $acp_modules = $this->module_manager->get_module_infos('wcp', '', true); $this->assertEquals(array(), $acp_modules); // No specific module, no module_class set in the function parameter, and an incorrect module class - $this->acp_modules->module_class = 'wcp'; - $acp_modules = $this->acp_modules->get_module_infos(); + $acp_modules = $this->module_manager->get_module_infos('wcp'); $this->assertEquals(array(), $acp_modules); // No specific module, module class set to false (will default to the above acp) // Setting $use_all_available will cause get_module_infos() to also load not enabled extensions (vendor2/bar) - $this->acp_modules->module_class = 'acp'; - $acp_modules = $this->acp_modules->get_module_infos('', false, true); + $acp_modules = $this->module_manager->get_module_infos('acp', '', true); $this->assertEquals(array( 'vendor2\\foo\\acp\\a_module' => array( 'filename' => 'vendor2\\foo\\acp\\a_module', @@ -175,7 +162,7 @@ class phpbb_extension_modules_test extends phpbb_test_case ), $acp_modules); // Specific module set to disabled extension - $acp_modules = $this->acp_modules->get_module_infos('vendor2_bar_acp_a_module', 'acp', true); + $acp_modules = $this->module_manager->get_module_infos('acp', 'vendor2_bar_acp_a_module', true); $this->assertEquals(array( 'vendor2\\bar\\acp\\a_module' => array( 'filename' => 'vendor2\\bar\\acp\\a_module', |
