diff options
Diffstat (limited to 'tests/extension')
31 files changed, 1343 insertions, 0 deletions
diff --git a/tests/extension/ext/bar/ext.php b/tests/extension/ext/bar/ext.php new file mode 100644 index 0000000000..22ff5e8077 --- /dev/null +++ b/tests/extension/ext/bar/ext.php @@ -0,0 +1,26 @@ +<?php + +namespace bar; + +class ext extends \phpbb\extension\base +{ + static public $state; + + public function enable_step($old_state) + { + // run 4 steps, then quit + if ($old_state === 4) + { + return false; + } + + if ($old_state === false) + { + $old_state = 0; + } + + self::$state = ++$old_state; + + return self::$state; + } +} diff --git a/tests/extension/ext/bar/my/hidden_class.php b/tests/extension/ext/bar/my/hidden_class.php new file mode 100644 index 0000000000..504c1873dc --- /dev/null +++ b/tests/extension/ext/bar/my/hidden_class.php @@ -0,0 +1,7 @@ +<?php + +namespace bar\my; + +class hidden_class +{ +} diff --git a/tests/extension/ext/bar/styles/prosilver/template/foobar_body.html b/tests/extension/ext/bar/styles/prosilver/template/foobar_body.html new file mode 100644 index 0000000000..00c2a84a18 --- /dev/null +++ b/tests/extension/ext/bar/styles/prosilver/template/foobar_body.html @@ -0,0 +1 @@ +bertie rules! diff --git a/tests/extension/ext/barfoo/acp/a_info.php b/tests/extension/ext/barfoo/acp/a_info.php new file mode 100644 index 0000000000..ea07189f7a --- /dev/null +++ b/tests/extension/ext/barfoo/acp/a_info.php @@ -0,0 +1,18 @@ +<?php + +namespace barfoo\acp; + +class a_info +{ + public function module() + { + return array( + 'filename' => 'barfoo\\acp\\a_module', + 'title' => 'Barfoo', + 'version' => '3.1.0-dev', + 'modes' => array( + 'config' => array('title' => 'Config', 'auth' => '', 'cat' => array('ACP_MODS')), + ), + ); + } +} diff --git a/tests/extension/ext/barfoo/acp/a_module.php b/tests/extension/ext/barfoo/acp/a_module.php new file mode 100644 index 0000000000..0ae8775013 --- /dev/null +++ b/tests/extension/ext/barfoo/acp/a_module.php @@ -0,0 +1,7 @@ +<?php + +namespace barfoo\acp; + +class a_module +{ +} diff --git a/tests/extension/ext/barfoo/ext.php b/tests/extension/ext/barfoo/ext.php new file mode 100644 index 0000000000..1b7bb7ca5e --- /dev/null +++ b/tests/extension/ext/barfoo/ext.php @@ -0,0 +1,7 @@ +<?php + +namespace barfoo; + +class ext extends \phpbb\extension\base +{ +} diff --git a/tests/extension/ext/foo/a_class.php b/tests/extension/ext/foo/a_class.php new file mode 100644 index 0000000000..9db45a697f --- /dev/null +++ b/tests/extension/ext/foo/a_class.php @@ -0,0 +1,7 @@ +<?php + +namespace foo; + +class a_class +{ +} diff --git a/tests/extension/ext/foo/acp/a_info.php b/tests/extension/ext/foo/acp/a_info.php new file mode 100644 index 0000000000..3b7d8cdd42 --- /dev/null +++ b/tests/extension/ext/foo/acp/a_info.php @@ -0,0 +1,18 @@ +<?php + +namespace foo\acp; + +class a_info +{ + public function module() + { + return array( + 'filename' => 'foo\\acp\\a_module', + 'title' => 'Foobar', + 'version' => '3.1.0-dev', + 'modes' => array( + 'config' => array('title' => 'Config', 'auth' => '', 'cat' => array('ACP_MODS')), + ), + ); + } +} diff --git a/tests/extension/ext/foo/acp/a_module.php b/tests/extension/ext/foo/acp/a_module.php new file mode 100644 index 0000000000..7aa2351ab3 --- /dev/null +++ b/tests/extension/ext/foo/acp/a_module.php @@ -0,0 +1,7 @@ +<?php + +namespace foo\acp; + +class a_module +{ +} diff --git a/tests/extension/ext/foo/acp/fail_info.php b/tests/extension/ext/foo/acp/fail_info.php new file mode 100644 index 0000000000..01d29fc5eb --- /dev/null +++ b/tests/extension/ext/foo/acp/fail_info.php @@ -0,0 +1,22 @@ +<?php + +namespace foo\acp; + +/* +* Due to the mismatch between the class name and the file name, this module +* file shouldn't be found by the extension finder +*/ +class foo_info +{ + public function module() + { + return array( + 'filename' => 'foo\acp\fail_module', + 'title' => 'Foobar', + 'version' => '3.1.0-dev', + 'modes' => array( + 'config' => array('title' => 'Config', 'auth' => '', 'cat' => array('ACP_MODS')), + ), + ); + } +} diff --git a/tests/extension/ext/foo/acp/fail_module.php b/tests/extension/ext/foo/acp/fail_module.php new file mode 100644 index 0000000000..8070929d3c --- /dev/null +++ b/tests/extension/ext/foo/acp/fail_module.php @@ -0,0 +1,11 @@ +<?php + +namespace foo\acp; + +/* +* Due to the mismatch between the class name and the file name of the module +* info file, this module's info file shouldn't be found +*/ +class fail_module +{ +} diff --git a/tests/extension/ext/foo/b_class.php b/tests/extension/ext/foo/b_class.php new file mode 100644 index 0000000000..bb2a77c05e --- /dev/null +++ b/tests/extension/ext/foo/b_class.php @@ -0,0 +1,7 @@ +<?php + +namespace foo; + +class b_class +{ +} diff --git a/tests/extension/ext/foo/composer.json b/tests/extension/ext/foo/composer.json new file mode 100644 index 0000000000..744f7be625 --- /dev/null +++ b/tests/extension/ext/foo/composer.json @@ -0,0 +1,22 @@ +{ + "name": "foo/example", + "type": "phpbb3-extension", + "description": "An example/sample extension to be used for testing purposes in phpBB Development.", + "version": "1.0.0", + "time": "2012-02-15 01:01:01", + "licence": "GPL-2.0", + "authors": [{ + "name": "Nathan Guse", + "username": "EXreaction", + "email": "email@phpbb.com", + "homepage": "http://lithiumstudios.org", + "role": "N/A" + }], + "require": { + "php": ">=5.3", + "phpbb": "3.1.0-dev" + }, + "extra": { + "display-name": "phpBB Foo Extension" + } +} diff --git a/tests/extension/ext/foo/ext.php b/tests/extension/ext/foo/ext.php new file mode 100644 index 0000000000..ac6098f2f1 --- /dev/null +++ b/tests/extension/ext/foo/ext.php @@ -0,0 +1,15 @@ +<?php + +namespace foo; + +class ext extends \phpbb\extension\base +{ + static public $disabled; + + public function disable_step($old_state) + { + self::$disabled = true; + + return false; + } +} diff --git a/tests/extension/ext/foo/mcp/a_info.php b/tests/extension/ext/foo/mcp/a_info.php new file mode 100644 index 0000000000..9a896ce808 --- /dev/null +++ b/tests/extension/ext/foo/mcp/a_info.php @@ -0,0 +1,18 @@ +<?php + +namespace foo\mcp; + +class a_info +{ + public function module() + { + return array( + 'filename' => 'foo\\mcp\\a_module', + 'title' => 'Foobar', + 'version' => '3.1.0-dev', + 'modes' => array( + 'config' => array('title' => 'Config', 'auth' => '', 'cat' => array('MCP_MAIN')), + ), + ); + } +} diff --git a/tests/extension/ext/foo/mcp/a_module.php b/tests/extension/ext/foo/mcp/a_module.php new file mode 100644 index 0000000000..ca397e7004 --- /dev/null +++ b/tests/extension/ext/foo/mcp/a_module.php @@ -0,0 +1,7 @@ +<?php + +namespace foo\mcp; + +class a_module +{ +} diff --git a/tests/extension/ext/foo/sub/type/alternative.php b/tests/extension/ext/foo/sub/type/alternative.php new file mode 100644 index 0000000000..1eaf794609 --- /dev/null +++ b/tests/extension/ext/foo/sub/type/alternative.php @@ -0,0 +1,7 @@ +<?php + +namespace foo\sub\type; + +class alternative +{ +} diff --git a/tests/extension/ext/foo/type/alternative.php b/tests/extension/ext/foo/type/alternative.php new file mode 100644 index 0000000000..8f753491ef --- /dev/null +++ b/tests/extension/ext/foo/type/alternative.php @@ -0,0 +1,7 @@ +<?php + +namespace foo\type; + +class alternative +{ +} diff --git a/tests/extension/ext/foo/type/dummy/empty.txt b/tests/extension/ext/foo/type/dummy/empty.txt new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/tests/extension/ext/foo/type/dummy/empty.txt diff --git a/tests/extension/ext/foo/typewrong/error.php b/tests/extension/ext/foo/typewrong/error.php new file mode 100644 index 0000000000..5020926043 --- /dev/null +++ b/tests/extension/ext/foo/typewrong/error.php @@ -0,0 +1,7 @@ +<?php + +namespace foo\typewrong; + +class error +{ +} diff --git a/tests/extension/ext/vendor/moo/composer.json b/tests/extension/ext/vendor/moo/composer.json new file mode 100644 index 0000000000..c91a5e027b --- /dev/null +++ b/tests/extension/ext/vendor/moo/composer.json @@ -0,0 +1,22 @@ +{ + "name": "moo/example", + "type": "phpbb3-extension", + "description": "An example/sample extension to be used for testing purposes in phpBB Development.", + "version": "1.0.0", + "time": "2012-02-15 01:01:01", + "licence": "GNU GPL v2", + "authors": [{ + "name": "Nathan Guse", + "username": "EXreaction", + "email": "email@phpbb.com", + "homepage": "http://lithiumstudios.org", + "role": "N/A" + }], + "require": { + "php": ">=5.3", + "phpbb": "3.1.0-dev" + }, + "extra": { + "display-name": "phpBB Moo Extension" + } +} diff --git a/tests/extension/ext/vendor/moo/ext.php b/tests/extension/ext/vendor/moo/ext.php new file mode 100644 index 0000000000..41ef570452 --- /dev/null +++ b/tests/extension/ext/vendor/moo/ext.php @@ -0,0 +1,15 @@ +<?php + +namespace vendor\moo; + +class ext extends \phpbb\extension\base +{ + static public $purged; + + public function purge_step($old_state) + { + self::$purged = true; + + return false; + } +} diff --git a/tests/extension/ext/vendor/moo/feature_class.php b/tests/extension/ext/vendor/moo/feature_class.php new file mode 100644 index 0000000000..cb8bb3da56 --- /dev/null +++ b/tests/extension/ext/vendor/moo/feature_class.php @@ -0,0 +1,7 @@ +<?php + +namespace vendor\moo; + +class feature_class +{ +} diff --git a/tests/extension/finder_test.php b/tests/extension/finder_test.php new file mode 100644 index 0000000000..8e6e71aaf8 --- /dev/null +++ b/tests/extension/finder_test.php @@ -0,0 +1,245 @@ +<?php +/** +* +* @package testing +* @copyright (c) 2011 phpBB Group +* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 +* +*/ +require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php'; + +class phpbb_extension_finder_test extends phpbb_test_case +{ + protected $extension_manager; + protected $finder; + + public function setUp() + { + $this->extension_manager = new phpbb_mock_extension_manager( + dirname(__FILE__) . '/', + array( + 'foo' => array( + 'ext_name' => 'foo', + 'ext_active' => '1', + 'ext_path' => 'ext/foo/', + ), + 'bar' => array( + 'ext_name' => 'bar', + 'ext_active' => '1', + 'ext_path' => 'ext/bar/', + ), + )); + + $this->finder = $this->extension_manager->get_finder(); + } + + public function test_suffix_get_classes() + { + $classes = $this->finder + ->core_path('phpbb/default/') + ->extension_suffix('_class') + ->get_classes(); + + sort($classes); + $this->assertEquals( + array( + '\bar\my\hidden_class', + '\foo\a_class', + '\foo\b_class', + '\phpbb\default\implementation', + ), + $classes + ); + } + + public function test_get_directories() + { + $dirs = $this->finder + ->directory('/type') + ->get_directories(); + + sort($dirs); + $this->assertEquals(array( + dirname(__FILE__) . '/ext/foo/type/', + ), $dirs); + } + + public function test_prefix_get_directories() + { + $dirs = $this->finder + ->prefix('ty') + ->get_directories(); + + sort($dirs); + $this->assertEquals(array( + dirname(__FILE__) . '/ext/foo/sub/type/', + dirname(__FILE__) . '/ext/foo/type/', + dirname(__FILE__) . '/ext/foo/typewrong/', + ), $dirs); + } + + public function test_prefix_get_classes() + { + $classes = $this->finder + ->core_path('phpbb/default/') + ->extension_prefix('hidden_') + ->get_classes(); + + sort($classes); + $this->assertEquals( + array( + '\bar\my\hidden_class', + '\phpbb\default\implementation', + ), + $classes + ); + } + + public function test_directory_get_classes() + { + $classes = $this->finder + ->core_path('phpbb/default/') + ->extension_directory('type') + ->get_classes(); + + sort($classes); + $this->assertEquals( + array( + '\foo\sub\type\alternative', + '\foo\type\alternative', + '\phpbb\default\implementation', + ), + $classes + ); + } + + public function test_absolute_directory_get_classes() + { + $classes = $this->finder + ->directory('/type/') + ->get_classes(); + + sort($classes); + $this->assertEquals( + array( + '\foo\type\alternative', + ), + $classes + ); + } + + public function test_sub_directory_get_classes() + { + $classes = $this->finder + ->directory('/sub/type') + ->get_classes(); + + sort($classes); + $this->assertEquals( + array( + '\foo\sub\type\alternative', + ), + $classes + ); + } + + public function test_uncleansub_directory_get_classes() + { + $classes = $this->finder + ->directory('/sub/../sub/type') + ->get_classes(); + + sort($classes); + $this->assertEquals( + array( + '\foo\sub\type\alternative', + ), + $classes + ); + } + + public function test_find_from_extension() + { + $files = $this->finder + ->extension_directory('/type') + ->find_from_extension('foo', dirname(__FILE__) . '/ext/foo/'); + $classes = $this->finder->get_classes_from_files($files); + + sort($classes); + $this->assertEquals( + array( + '\foo\type\alternative', + '\foo\type\dummy\empty', + ), + $classes + ); + } + + /** + * These do not work because of changes with PHPBB3-11386 + * They do not seem neccessary to me, so I am commenting them out for now + public function test_get_classes_create_cache() + { + $cache = new phpbb_mock_cache; + $finder = new \phpbb\extension\finder($this->extension_manager, new \phpbb\filesystem(), dirname(__FILE__) . '/', $cache, 'php', '_custom_cache_name'); + $files = $finder->suffix('_class.php')->get_files(); + + $expected_files = array( + 'ext/bar/my/hidden_class.php' => 'bar', + 'ext/foo/a_class.php' => 'foo', + 'ext/foo/b_class.php' => 'foo', + ); + + $query = array( + 'core_path' => false, + 'core_suffix' => '_class.php', + 'core_prefix' => false, + 'core_directory' => false, + 'extension_suffix' => '_class.php', + 'extension_prefix' => false, + 'extension_directory' => false, + 'is_dir' => false, + ); + + $cache->checkAssociativeVar($this, '_custom_cache_name', array( + md5(serialize($query)) => $expected_files, + ), false); + } + + public function test_cached_get_files() + { + $query = array( + 'core_path' => 'phpbb/foo', + 'core_suffix' => false, + 'core_prefix' => false, + 'core_directory' => 'bar', + 'extension_suffix' => false, + 'extension_prefix' => false, + 'extension_directory' => false, + 'is_dir' => false, + ); + + $finder = new \phpbb\extension\finder( + $this->extension_manager, + new \phpbb\filesystem(), + dirname(__FILE__) . '/', + new phpbb_mock_cache(array( + '_ext_finder' => array( + md5(serialize($query)) => array('file_name' => 'extension'), + ), + )) + ); + + $classes = $finder + ->core_path($query['core_path']) + ->core_directory($query['core_directory']) + ->get_files(); + + sort($classes); + $this->assertEquals( + array(dirname(__FILE__) . '/file_name'), + $classes + ); + } + */ +} diff --git a/tests/extension/fixtures/extensions.xml b/tests/extension/fixtures/extensions.xml new file mode 100644 index 0000000000..6eb6fd11a5 --- /dev/null +++ b/tests/extension/fixtures/extensions.xml @@ -0,0 +1,18 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<dataset> + <table name="phpbb_ext"> + <column>ext_name</column> + <column>ext_active</column> + <column>ext_state</column> + <row> + <value>foo</value> + <value>1</value> + <value></value> + </row> + <row> + <value>vendor/moo</value> + <value>0</value> + <value></value> + </row> + </table> +</dataset> diff --git a/tests/extension/includes/acp/acp_foobar.php b/tests/extension/includes/acp/acp_foobar.php new file mode 100644 index 0000000000..c256a432e2 --- /dev/null +++ b/tests/extension/includes/acp/acp_foobar.php @@ -0,0 +1,28 @@ +<?php +/** +* +* @package testing +* @copyright (c) 2013 phpBB Group +* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 +* +*/ + +/** +* @ignore +*/ +if (!defined('IN_PHPBB')) +{ + exit; +} + +/** +* @package acp +*/ +class acp_foobar +{ + var $u_action; + + function main($id, $mode) + { + } +} diff --git a/tests/extension/includes/acp/info/acp_foobar.php b/tests/extension/includes/acp/info/acp_foobar.php new file mode 100644 index 0000000000..b89cfb9574 --- /dev/null +++ b/tests/extension/includes/acp/info/acp_foobar.php @@ -0,0 +1,26 @@ +<?php +/** +* +* @package testing +* @copyright (c) 2013 phpBB Group +* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 +* +*/ + +/** +* @package module_install +*/ +class acp_foobar_info +{ + function module() + { + return array( + 'filename' => 'acp_foobar', + 'title' => 'ACP Foobar', + 'version' => '3.1.0-dev', + 'modes' => array( + 'test' => array('title' => 'Test', 'auth' => '', 'cat' => array('ACP_GENERAL')), + ), + ); + } +} diff --git a/tests/extension/manager_test.php b/tests/extension/manager_test.php new file mode 100644 index 0000000000..b127daf2ed --- /dev/null +++ b/tests/extension/manager_test.php @@ -0,0 +1,124 @@ +<?php +/** +* +* @package testing +* @copyright (c) 2011 phpBB Group +* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 +* +*/ + +require_once dirname(__FILE__) . '/ext/bar/ext.php'; +require_once dirname(__FILE__) . '/ext/foo/ext.php'; +require_once dirname(__FILE__) . '/ext/vendor/moo/ext.php'; + +class phpbb_extension_manager_test extends phpbb_database_test_case +{ + protected $extension_manager; + protected $class_loader; + + public function getDataSet() + { + return $this->createXMLDataSet(dirname(__FILE__) . '/fixtures/extensions.xml'); + } + + protected function setUp() + { + parent::setUp(); + + $this->extension_manager = $this->create_extension_manager(); + } + + public function test_available() + { + $this->assertEquals(array('bar', 'barfoo', 'foo', 'vendor/moo'), array_keys($this->extension_manager->all_available())); + } + + public function test_enabled() + { + $this->assertEquals(array('foo'), array_keys($this->extension_manager->all_enabled())); + } + + public function test_configured() + { + $this->assertEquals(array('foo', 'vendor/moo'), array_keys($this->extension_manager->all_configured())); + } + + public function test_enable() + { + bar\ext::$state = 0; + + $this->assertEquals(array('foo'), array_keys($this->extension_manager->all_enabled())); + $this->extension_manager->enable('bar'); + $this->assertEquals(array('bar', 'foo'), array_keys($this->extension_manager->all_enabled())); + $this->assertEquals(array('bar', 'foo', 'vendor/moo'), array_keys($this->extension_manager->all_configured())); + + $this->assertEquals(4, bar\ext::$state); + } + + public function test_disable() + { + foo\ext::$disabled = false; + + $this->assertEquals(array('foo'), array_keys($this->extension_manager->all_enabled())); + $this->extension_manager->disable('foo'); + $this->assertEquals(array(), array_keys($this->extension_manager->all_enabled())); + $this->assertEquals(array('foo', 'vendor/moo'), array_keys($this->extension_manager->all_configured())); + + $this->assertTrue(foo\ext::$disabled); + } + + public function test_purge() + { + vendor\moo\ext::$purged = false; + + $this->assertEquals(array('foo'), array_keys($this->extension_manager->all_enabled())); + $this->assertEquals(array('foo', 'vendor/moo'), array_keys($this->extension_manager->all_configured())); + $this->extension_manager->purge('vendor/moo'); + $this->assertEquals(array('foo'), array_keys($this->extension_manager->all_enabled())); + $this->assertEquals(array('foo'), array_keys($this->extension_manager->all_configured())); + + $this->assertTrue(vendor\moo\ext::$purged); + } + + public function test_enabled_no_cache() + { + $extension_manager = $this->create_extension_manager(false); + + $this->assertEquals(array('foo'), array_keys($extension_manager->all_enabled())); + } + + protected function create_extension_manager($with_cache = true) + { + + $config = new \phpbb\config\config(array()); + $db = $this->new_dbal(); + $db_tools = new \phpbb\db\tools($db); + $phpbb_root_path = __DIR__ . './../../phpBB/'; + $php_ext = 'php'; + $table_prefix = 'phpbb_'; + + $migrator = new \phpbb\db\migrator( + $config, + $db, + $db_tools, + 'phpbb_migrations', + $phpbb_root_path, + $php_ext, + $table_prefix, + array() + ); + $container = new phpbb_mock_container_builder(); + $container->set('migrator', $migrator); + + return new \phpbb\extension\manager( + $container, + $db, + $config, + new \phpbb\filesystem(), + 'phpbb_ext', + dirname(__FILE__) . '/', + $php_ext, + ($with_cache) ? new phpbb_mock_cache() : null + ); + } +} diff --git a/tests/extension/metadata_manager_test.php b/tests/extension/metadata_manager_test.php new file mode 100644 index 0000000000..242ec38908 --- /dev/null +++ b/tests/extension/metadata_manager_test.php @@ -0,0 +1,438 @@ +<?php +/** +* +* @package testing +* @copyright (c) 2011 phpBB Group +* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 +* +*/ + +class phpbb_extension_metadata_manager_test extends phpbb_database_test_case +{ + protected $class_loader; + protected $extension_manager; + + protected $cache; + protected $config; + protected $db; + protected $phpbb_root_path; + protected $phpEx; + protected $template; + protected $user; + + public function getDataSet() + { + return $this->createXMLDataSet(dirname(__FILE__) . '/fixtures/extensions.xml'); + } + + protected function setUp() + { + parent::setUp(); + + $this->cache = new phpbb_mock_cache(); + $this->config = new \phpbb\config\config(array( + 'version' => '3.1.0', + )); + $this->db = $this->new_dbal(); + $this->db_tools = new \phpbb\db\tools($this->db); + $this->phpbb_root_path = dirname(__FILE__) . '/'; + $this->phpEx = 'php'; + $this->user = new \phpbb\user(); + $this->table_prefix = 'phpbb_'; + + $this->template = new \phpbb\template\twig\twig( + new \phpbb\path_helper( + new \phpbb\symfony_request( + new phpbb_mock_request() + ), + new \phpbb\filesystem(), + $this->phpbb_root_path, + $this->phpEx + ), + $this->config, + $this->user, + new \phpbb\template\context() + ); + + $this->migrator = new \phpbb\db\migrator( + $this->config, + $this->db, + $this->db_tools, + 'phpbb_migrations', + $this->phpbb_root_path, + 'php', + $this->table_prefix, + array() + ); + $container = new phpbb_mock_container_builder(); + $container->set('migrator', $migrator); + + $this->extension_manager = new \phpbb\extension\manager( + $container, + $this->db, + $this->config, + new \phpbb\filesystem(), + 'phpbb_ext', + $this->phpbb_root_path, + $this->phpEx, + $this->cache + ); + } + + // Should fail from missing composer.json + public function test_bar() + { + $ext_name = 'bar'; + + $manager = $this->get_metadata_manager($ext_name); + + try + { + $manager->get_metadata(); + } + catch(\phpbb\extension\exception $e){} + + $this->assertEquals((string) $e, 'The required file does not exist: ' . $this->phpbb_root_path . $this->extension_manager->get_extension_path($ext_name) . 'composer.json'); + } + + // Should be the same as a direct json_decode of the composer.json file + public function test_foo() + { + $ext_name = 'foo'; + + $manager = $this->get_metadata_manager($ext_name); + + try + { + $metadata = $manager->get_metadata(); + } + catch(\phpbb\extension\exception $e) + { + $this->fail($e); + } + + $json = json_decode(file_get_contents($this->phpbb_root_path . 'ext/foo/composer.json'), true); + + $this->assertEquals($metadata, $json); + } + + public function test_validator_non_existant() + { + $ext_name = 'validator'; + + $manager = $this->get_metadata_manager($ext_name); + + // Non-existant data + try + { + $manager->validate('name'); + + $this->fail('Exception not triggered'); + } + catch(\phpbb\extension\exception $e) + { + $this->assertEquals((string) $e, 'Required meta field \'name\' has not been set.'); + } + + try + { + $manager->validate('type'); + + $this->fail('Exception not triggered'); + } + catch(\phpbb\extension\exception $e) + { + $this->assertEquals((string) $e, 'Required meta field \'type\' has not been set.'); + } + + try + { + $manager->validate('licence'); + + $this->fail('Exception not triggered'); + } + catch(\phpbb\extension\exception $e) + { + $this->assertEquals((string) $e, 'Required meta field \'licence\' has not been set.'); + } + + try + { + $manager->validate('version'); + + $this->fail('Exception not triggered'); + } + catch(\phpbb\extension\exception $e) + { + $this->assertEquals((string) $e, 'Required meta field \'version\' has not been set.'); + } + + try + { + $manager->validate_authors(); + + $this->fail('Exception not triggered'); + } + catch(\phpbb\extension\exception $e) + { + $this->assertEquals((string) $e, 'Required meta field \'authors\' has not been set.'); + } + + $manager->merge_metadata(array( + 'authors' => array( + array(), + ), + )); + + try + { + $manager->validate_authors(); + + $this->fail('Exception not triggered'); + } + catch(\phpbb\extension\exception $e) + { + $this->assertEquals((string) $e, 'Required meta field \'author name\' has not been set.'); + } + } + + + public function test_validator_invalid() + { + $ext_name = 'validator'; + + $manager = $this->get_metadata_manager($ext_name); + + // Invalid data + $manager->set_metadata(array( + 'name' => 'asdf', + 'type' => 'asdf', + 'licence' => '', + 'version' => '', + )); + + try + { + $manager->validate('name'); + + $this->fail('Exception not triggered'); + } + catch(\phpbb\extension\exception $e) + { + $this->assertEquals((string) $e, 'Meta field \'name\' is invalid.'); + } + + try + { + $manager->validate('type'); + + $this->fail('Exception not triggered'); + } + catch(\phpbb\extension\exception $e) + { + $this->assertEquals((string) $e, 'Meta field \'type\' is invalid.'); + } + + try + { + $manager->validate('licence'); + + $this->fail('Exception not triggered'); + } + catch(\phpbb\extension\exception $e) + { + $this->assertEquals((string) $e, 'Meta field \'licence\' is invalid.'); + } + + try + { + $manager->validate('version'); + + $this->fail('Exception not triggered'); + } + catch(\phpbb\extension\exception $e) + { + $this->assertEquals((string) $e, 'Meta field \'version\' is invalid.'); + } + } + + public function test_validator_valid() + { + $ext_name = 'validator'; + + $manager = $this->get_metadata_manager($ext_name); + + // Valid data + $manager->set_metadata(array( + 'name' => 'test/foo', + 'type' => 'phpbb3-extension', + 'licence' => 'GPL v2', + 'version' => '1.0.0', + )); + + try + { + $this->assertEquals(true, $manager->validate('enable')); + } + catch(\phpbb\extension\exception $e) + { + $this->fail($e); + } + } + + + public function test_validator_requirements() + { + $ext_name = 'validator'; + + $manager = $this->get_metadata_manager($ext_name); + // Too high of requirements + $manager->merge_metadata(array( + 'require' => array( + 'php' => '10.0.0', + 'phpbb' => '3.2.0', // config is set to 3.1.0 + ), + )); + + try + { + $this->assertEquals(false, $manager->validate_require_php()); + $this->assertEquals(false, $manager->validate_require_phpbb()); + } + catch(\phpbb\extension\exception $e) + { + $this->fail($e); + } + + + // Too high of requirements + $manager->merge_metadata(array( + 'require' => array( + 'php' => '5.3.0', + 'phpbb' => '3.1.0-beta', // config is set to 3.1.0 + ), + )); + + try + { + $this->assertEquals(true, $manager->validate_require_php()); + $this->assertEquals(true, $manager->validate_require_phpbb()); + } + catch(\phpbb\extension\exception $e) + { + $this->fail($e); + } + + + // Too high of requirements + $manager->merge_metadata(array( + 'require' => array( + 'php' => '>' . phpversion(), + 'phpbb' => '>3.1.0', // config is set to 3.1.0 + ), + )); + + try + { + $this->assertEquals(false, $manager->validate_require_php()); + $this->assertEquals(false, $manager->validate_require_phpbb()); + } + catch(\phpbb\extension\exception $e) + { + $this->fail($e); + } + + + // Too high of current install + $manager->merge_metadata(array( + 'require' => array( + 'php' => '<' . phpversion(), + 'phpbb' => '<3.1.0', // config is set to 3.1.0 + ), + )); + + try + { + $this->assertEquals(false, $manager->validate_require_php()); + $this->assertEquals(false, $manager->validate_require_phpbb()); + } + catch(\phpbb\extension\exception $e) + { + $this->fail($e); + } + + + // Matching requirements + $manager->merge_metadata(array( + 'require' => array( + 'php' => phpversion(), + 'phpbb' => '3.1.0', // config is set to 3.1.0 + ), + )); + + try + { + $this->assertEquals(true, $manager->validate_require_php()); + $this->assertEquals(true, $manager->validate_require_phpbb()); + } + catch(\phpbb\extension\exception $e) + { + $this->fail($e); + } + + + // Matching requirements + $manager->merge_metadata(array( + 'require' => array( + 'php' => '>=' . phpversion(), + 'phpbb' => '>=3.1.0', // config is set to 3.1.0 + ), + )); + + try + { + $this->assertEquals(true, $manager->validate_require_php()); + $this->assertEquals(true, $manager->validate_require_phpbb()); + } + catch(\phpbb\extension\exception $e) + { + $this->fail($e); + } + + + // Matching requirements + $manager->merge_metadata(array( + 'require' => array( + 'php' => '<=' . phpversion(), + 'phpbb' => '<=3.1.0', // config is set to 3.1.0 + ), + )); + + try + { + $this->assertEquals(true, $manager->validate_require_php()); + $this->assertEquals(true, $manager->validate_require_phpbb()); + } + catch(\phpbb\extension\exception $e) + { + $this->fail($e); + } + } + + /** + * Get an instance of the metadata manager + * + * @param string $ext_name + * @return phpbb_mock_metadata_manager + */ + private function get_metadata_manager($ext_name) + { + return new phpbb_mock_metadata_manager( + $ext_name, + $this->config, + $this->extension_manager, + $this->template, + $this->phpbb_root_path + ); + } +} diff --git a/tests/extension/modules_test.php b/tests/extension/modules_test.php new file mode 100644 index 0000000000..ef21c943c2 --- /dev/null +++ b/tests/extension/modules_test.php @@ -0,0 +1,194 @@ +<?php +/** +* +* @package testing +* @copyright (c) 2013 phpBB Group +* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 +* +*/ + +require_once dirname(__FILE__) . '/ext/foo/acp/a_info.php'; +require_once dirname(__FILE__) . '/ext/foo/mcp/a_info.php'; +require_once dirname(__FILE__) . '/ext/foo/acp/fail_info.php'; +require_once dirname(__FILE__) . '/ext/barfoo/acp/a_info.php'; +require_once dirname(__FILE__) . '/../../phpBB/includes/acp/acp_modules.php'; + +class phpbb_extension_modules_test extends phpbb_test_case +{ + protected $extension_manager; + protected $finder; + + public function setUp() + { + global $phpbb_extension_manager; + + $this->extension_manager = new phpbb_mock_extension_manager( + dirname(__FILE__) . '/', + array( + 'foo' => array( + 'ext_name' => 'foo', + 'ext_active' => '1', + 'ext_path' => 'ext/foo/', + ), + 'bar' => array( + 'ext_name' => 'bar', + 'ext_active' => '1', + 'ext_path' => 'ext/bar/', + ), + )); + $phpbb_extension_manager = $this->extension_manager; + + $this->acp_modules = new acp_modules(); + } + + public function test_get_module_infos() + { + global $phpbb_root_path; + +// $this->markTestIncomplete('Modules no speak namespace! Going to get rid of db modules altogether and fix this test after.'); + + // Correctly set the root path for this test to this directory, so the classes can be found + $phpbb_root_path = dirname(__FILE__) . '/'; + + // Find acp module info files + $this->acp_modules->module_class = 'acp'; + $acp_modules = $this->acp_modules->get_module_infos(); + $this->assertEquals(array( + 'foo\\acp\\a_module' => array( + 'filename' => 'foo\\acp\\a_module', + 'title' => 'Foobar', + 'version' => '3.1.0-dev', + 'modes' => array( + 'config' => array('title' => 'Config', 'auth' => '', 'cat' => array('ACP_MODS')), + ), + ), + 'acp_foobar' => array( + 'filename' => 'acp_foobar', + 'title' => 'ACP Foobar', + 'version' => '3.1.0-dev', + 'modes' => array( + 'test' => array('title' => 'Test', 'auth' => '', 'cat' => array('ACP_GENERAL')), + ), + ), + ), $acp_modules); + + // Find mcp module info files + $this->acp_modules->module_class = 'mcp'; + $acp_modules = $this->acp_modules->get_module_infos(); + $this->assertEquals(array( + 'foo\\mcp\\a_module' => array( + 'filename' => 'foo\\mcp\\a_module', + 'title' => 'Foobar', + 'version' => '3.1.0-dev', + 'modes' => array( + 'config' => array('title' => 'Config', 'auth' => '', 'cat' => array('MCP_MAIN')), + ), + ), + ), $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( + 'foo\\mcp\\a_module' => array( + 'filename' => 'foo\\mcp\\a_module', + 'title' => 'Foobar', + 'version' => '3.1.0-dev', + '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'); + $this->assertEquals(array( + 'foo\\mcp\\a_module' => array( + 'filename' => 'foo\\mcp\\a_module', + 'title' => 'Foobar', + 'version' => '3.1.0-dev', + 'modes' => array( + 'config' => array('title' => 'Config', 'auth' => '', 'cat' => array('MCP_MAIN')), + ), + ), + ), $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'); + $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(); + $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'); + $this->assertEquals(array( + 'foo\\acp\\a_module' => array ( + 'filename' => 'foo\\acp\\a_module', + 'title' => 'Foobar', + 'version' => '3.1.0-dev', + 'modes' => array ( + 'config' => array ('title' => 'Config', 'auth' => '', 'cat' => array ('ACP_MODS')), + ), + ), + ), $acp_modules); + + // No specific module and module class set to an incorrect name + $acp_modules = $this->acp_modules->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(); + $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 (barfoo) + $this->acp_modules->module_class = 'acp'; + $acp_modules = $this->acp_modules->get_module_infos('', false, true); + $this->assertEquals(array( + 'foo\\acp\\a_module' => array( + 'filename' => 'foo\\acp\\a_module', + 'title' => 'Foobar', + 'version' => '3.1.0-dev', + 'modes' => array( + 'config' => array('title' => 'Config', 'auth' => '', 'cat' => array('ACP_MODS')), + ), + ), + 'acp_foobar' => array( + 'filename' => 'acp_foobar', + 'title' => 'ACP Foobar', + 'version' => '3.1.0-dev', + 'modes' => array( + 'test' => array('title' => 'Test', 'auth' => '', 'cat' => array('ACP_GENERAL')), + ), + ), + 'barfoo\\acp\\a_module' => array( + 'filename' => 'barfoo\\acp\\a_module', + 'title' => 'Barfoo', + 'version' => '3.1.0-dev', + 'modes' => array( + 'config' => array('title' => 'Config', 'auth' => '', 'cat' => array('ACP_MODS')), + ), + ) + ), $acp_modules); + + // Specific module set to disabled extension + $acp_modules = $this->acp_modules->get_module_infos('barfoo_acp_a_module', 'acp', true); + $this->assertEquals(array( + 'barfoo\\acp\\a_module' => array( + 'filename' => 'barfoo\\acp\\a_module', + 'title' => 'Barfoo', + 'version' => '3.1.0-dev', + 'modes' => array( + 'config' => array('title' => 'Config', 'auth' => '', 'cat' => array('ACP_MODS')), + ), + ) + ), $acp_modules); + } +} diff --git a/tests/extension/phpbb/default/implementation.php b/tests/extension/phpbb/default/implementation.php new file mode 100644 index 0000000000..91d5f8aa2f --- /dev/null +++ b/tests/extension/phpbb/default/implementation.php @@ -0,0 +1,5 @@ +<?php + +class phpbb_default_impl_class implements phpbb_default_interface +{ +} |