diff options
Diffstat (limited to 'tests/extension')
40 files changed, 1661 insertions, 0 deletions
diff --git a/tests/extension/ext/barfoo/composer.json b/tests/extension/ext/barfoo/composer.json new file mode 100644 index 0000000000..05bb099707 --- /dev/null +++ b/tests/extension/ext/barfoo/composer.json @@ -0,0 +1,24 @@ +{ +	"name": "vendor/barfoo", +	"type": "phpbb-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", +	"license": "GNU GPL v2", +	"authors": [{ +			"name": "John Smith", +			"username": "JohnSmith27", +			"email": "email@phpbb.com", +			"homepage": "http://phpbb.com", +			"role": "N/A" +		}], +	"require": { +		"php": ">=5.3" +	}, +	"extra": { +		"display-name": "phpBB BarFoo Extension", +		"soft-require": { +			"phpbb/phpbb": "3.1.*@dev" +		} +	} +} diff --git a/tests/extension/ext/barfoo/ext.php b/tests/extension/ext/barfoo/ext.php new file mode 100644 index 0000000000..0de403424c --- /dev/null +++ b/tests/extension/ext/barfoo/ext.php @@ -0,0 +1,7 @@ +<?php + +namespace vendor\barfoo; + +class ext extends \phpbb\extension\base +{ +} diff --git a/tests/extension/ext/vendor/moo/composer.json b/tests/extension/ext/vendor/moo/composer.json new file mode 100644 index 0000000000..d49aab47cd --- /dev/null +++ b/tests/extension/ext/vendor/moo/composer.json @@ -0,0 +1,24 @@ +{ +	"name": "vendor/moo", +	"type": "phpbb-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", +	"license": "GNU GPL v2", +	"authors": [{ +			"name": "John Smith", +			"username": "JohnSmith27", +			"email": "email@phpbb.com", +			"homepage": "http://phpbb.com", +			"role": "N/A" +		}], +	"require": { +		"php": ">=5.3" +	}, +	"extra": { +		"display-name": "phpBB Moo Extension", +		"soft-require": { +			"phpbb/phpbb": "3.1.*@dev" +		} +	} +} 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/ext/vendor2/bar/acp/a_info.php b/tests/extension/ext/vendor2/bar/acp/a_info.php new file mode 100644 index 0000000000..8132df587f --- /dev/null +++ b/tests/extension/ext/vendor2/bar/acp/a_info.php @@ -0,0 +1,18 @@ +<?php + +namespace vendor2\bar\acp; + +class a_info +{ +	public function module() +	{ +		return array( +			'filename'	=> 'vendor2\\bar\\acp\\a_module', +			'title'		=> 'Bar', +			'version'	=> '3.1.0-dev', +			'modes'		=> array( +				'config'		=> array('title' => 'Config',	'auth' => '', 'cat' => array('ACP_MODS')), +			), +		); +	} +} diff --git a/tests/extension/ext/vendor2/bar/acp/a_module.php b/tests/extension/ext/vendor2/bar/acp/a_module.php new file mode 100644 index 0000000000..3a3d105790 --- /dev/null +++ b/tests/extension/ext/vendor2/bar/acp/a_module.php @@ -0,0 +1,7 @@ +<?php + +namespace vendor2\bar\acp; + +class a_module +{ +} diff --git a/tests/extension/ext/vendor2/bar/composer.json b/tests/extension/ext/vendor2/bar/composer.json new file mode 100644 index 0000000000..9d2ed86a0c --- /dev/null +++ b/tests/extension/ext/vendor2/bar/composer.json @@ -0,0 +1,23 @@ +{ +	"name": "vendor2/bar", +	"type": "phpbb-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", +	"license": "GPL-2.0", +	"authors": [{ +			"name": "John Smith", +			"email": "email@phpbb.com", +			"homepage": "http://phpbb.com", +			"role": "N/A" +		}], +	"require": { +		"php": ">=5.3" +	}, +	"extra": { +		"display-name": "phpBB Bar Extension", +		"soft-require": { +			"phpbb/phpbb": "3.1.*@dev" +		} +	} +} diff --git a/tests/extension/ext/vendor2/bar/ext.php b/tests/extension/ext/vendor2/bar/ext.php new file mode 100644 index 0000000000..f94ab9ad81 --- /dev/null +++ b/tests/extension/ext/vendor2/bar/ext.php @@ -0,0 +1,26 @@ +<?php + +namespace vendor2\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/vendor2/bar/migrations/migration.php b/tests/extension/ext/vendor2/bar/migrations/migration.php new file mode 100644 index 0000000000..71caa34fd9 --- /dev/null +++ b/tests/extension/ext/vendor2/bar/migrations/migration.php @@ -0,0 +1,18 @@ +<?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. +* +*/ + +namespace vendor2\bar\migrations; + +class migration extends \phpbb\db\migration\migration +{ +} diff --git a/tests/extension/ext/vendor2/foo/a_class.php b/tests/extension/ext/vendor2/foo/a_class.php new file mode 100644 index 0000000000..06278c0e0c --- /dev/null +++ b/tests/extension/ext/vendor2/foo/a_class.php @@ -0,0 +1,7 @@ +<?php + +namespace vendor2\foo; + +class a_class +{ +} diff --git a/tests/extension/ext/vendor2/foo/acp/a_info.php b/tests/extension/ext/vendor2/foo/acp/a_info.php new file mode 100644 index 0000000000..e1eaa340b7 --- /dev/null +++ b/tests/extension/ext/vendor2/foo/acp/a_info.php @@ -0,0 +1,18 @@ +<?php + +namespace vendor2\foo\acp; + +class a_info +{ +	public function module() +	{ +		return array( +			'filename'	=> 'vendor2\\foo\\acp\\a_module', +			'title'		=> 'Foobar', +			'version'	=> '3.1.0-dev', +			'modes'		=> array( +				'config'		=> array('title' => 'Config',	'auth' => 'ext_vendor2/foo', 'cat' => array('ACP_MODS')), +			), +		); +	} +} diff --git a/tests/extension/ext/vendor2/foo/acp/a_module.php b/tests/extension/ext/vendor2/foo/acp/a_module.php new file mode 100644 index 0000000000..78d91af2fe --- /dev/null +++ b/tests/extension/ext/vendor2/foo/acp/a_module.php @@ -0,0 +1,7 @@ +<?php + +namespace vendor2\foo\acp; + +class a_module +{ +} diff --git a/tests/extension/ext/vendor2/foo/acp/fail_info.php b/tests/extension/ext/vendor2/foo/acp/fail_info.php new file mode 100644 index 0000000000..d9b4353957 --- /dev/null +++ b/tests/extension/ext/vendor2/foo/acp/fail_info.php @@ -0,0 +1,22 @@ +<?php + +namespace vendor2\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'	=> 'vendor2\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/vendor2/foo/acp/fail_module.php b/tests/extension/ext/vendor2/foo/acp/fail_module.php new file mode 100644 index 0000000000..c8a5eae745 --- /dev/null +++ b/tests/extension/ext/vendor2/foo/acp/fail_module.php @@ -0,0 +1,11 @@ +<?php + +namespace vendor2\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/vendor2/foo/b_class.php b/tests/extension/ext/vendor2/foo/b_class.php new file mode 100644 index 0000000000..3d0f193908 --- /dev/null +++ b/tests/extension/ext/vendor2/foo/b_class.php @@ -0,0 +1,7 @@ +<?php + +namespace vendor2\foo; + +class b_class +{ +} diff --git a/tests/extension/ext/vendor2/foo/composer.json b/tests/extension/ext/vendor2/foo/composer.json new file mode 100644 index 0000000000..efcdfc338f --- /dev/null +++ b/tests/extension/ext/vendor2/foo/composer.json @@ -0,0 +1,23 @@ +{ +	"name": "vendor2/foo", +	"type": "phpbb-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", +	"license": "GPL-2.0", +	"authors": [{ +			"name": "John Smith", +			"email": "email@phpbb.com", +			"homepage": "http://phpbb.com", +			"role": "N/A" +		}], +	"require": { +		"php": ">=5.3" +	}, +	"extra": { +		"display-name": "phpBB Foo Extension", +		"soft-require": { +			"phpbb/phpbb": "3.1.*@dev" +		} +	} +} diff --git a/tests/extension/ext/vendor2/foo/ext.php b/tests/extension/ext/vendor2/foo/ext.php new file mode 100644 index 0000000000..15480fe92a --- /dev/null +++ b/tests/extension/ext/vendor2/foo/ext.php @@ -0,0 +1,15 @@ +<?php + +namespace vendor2\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/vendor2/foo/mcp/a_info.php b/tests/extension/ext/vendor2/foo/mcp/a_info.php new file mode 100644 index 0000000000..b5599fde65 --- /dev/null +++ b/tests/extension/ext/vendor2/foo/mcp/a_info.php @@ -0,0 +1,18 @@ +<?php + +namespace vendor2\foo\mcp; + +class a_info +{ +	public function module() +	{ +		return array( +			'filename'	=> 'vendor2\\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/vendor2/foo/mcp/a_module.php b/tests/extension/ext/vendor2/foo/mcp/a_module.php new file mode 100644 index 0000000000..fe29783827 --- /dev/null +++ b/tests/extension/ext/vendor2/foo/mcp/a_module.php @@ -0,0 +1,7 @@ +<?php + +namespace vendor2\foo\mcp; + +class a_module +{ +} diff --git a/tests/extension/ext/vendor2/foo/sub/type/alternative.php b/tests/extension/ext/vendor2/foo/sub/type/alternative.php new file mode 100644 index 0000000000..1eaf794609 --- /dev/null +++ b/tests/extension/ext/vendor2/foo/sub/type/alternative.php @@ -0,0 +1,7 @@ +<?php + +namespace foo\sub\type; + +class alternative +{ +} diff --git a/tests/extension/ext/vendor2/foo/type/alternative.php b/tests/extension/ext/vendor2/foo/type/alternative.php new file mode 100644 index 0000000000..8f753491ef --- /dev/null +++ b/tests/extension/ext/vendor2/foo/type/alternative.php @@ -0,0 +1,7 @@ +<?php + +namespace foo\type; + +class alternative +{ +} diff --git a/tests/extension/ext/vendor2/foo/type/dummy/empty.txt b/tests/extension/ext/vendor2/foo/type/dummy/empty.txt new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/tests/extension/ext/vendor2/foo/type/dummy/empty.txt diff --git a/tests/extension/ext/vendor2/foo/typewrong/error.php b/tests/extension/ext/vendor2/foo/typewrong/error.php new file mode 100644 index 0000000000..5020926043 --- /dev/null +++ b/tests/extension/ext/vendor2/foo/typewrong/error.php @@ -0,0 +1,7 @@ +<?php + +namespace foo\typewrong; + +class error +{ +} diff --git a/tests/extension/ext/vendor3/bar/ext.php b/tests/extension/ext/vendor3/bar/ext.php new file mode 100644 index 0000000000..37a5e92059 --- /dev/null +++ b/tests/extension/ext/vendor3/bar/ext.php @@ -0,0 +1,26 @@ +<?php + +namespace vendor3\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/vendor3/bar/my/hidden_class.php b/tests/extension/ext/vendor3/bar/my/hidden_class.php new file mode 100644 index 0000000000..38eb59aadf --- /dev/null +++ b/tests/extension/ext/vendor3/bar/my/hidden_class.php @@ -0,0 +1,7 @@ +<?php + +namespace vendor3\bar\my; + +class hidden_class +{ +} diff --git a/tests/extension/ext/vendor3/bar/styles/prosilver/template/foobar_body.html b/tests/extension/ext/vendor3/bar/styles/prosilver/template/foobar_body.html new file mode 100644 index 0000000000..00c2a84a18 --- /dev/null +++ b/tests/extension/ext/vendor3/bar/styles/prosilver/template/foobar_body.html @@ -0,0 +1 @@ +bertie rules! diff --git a/tests/extension/ext/vendor3/foo/composer.json b/tests/extension/ext/vendor3/foo/composer.json new file mode 100644 index 0000000000..b4b3e6f32f --- /dev/null +++ b/tests/extension/ext/vendor3/foo/composer.json @@ -0,0 +1,23 @@ +{ +	"name": "vendor3/foo", +	"type": "phpbb-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", +	"license": "GPL-2.0", +	"authors": [{ +			"name": "John Smith", +			"email": "email@phpbb.com", +			"homepage": "http://phpbb.com", +			"role": "N/A" +		}], +	"require": { +		"php": ">=5.3" +	}, +	"extra": { +		"display-name": "phpBB Bar Extension", +		"soft-require": { +			"phpbb/phpbb": "3.1.*@dev" +		} +	} +} diff --git a/tests/extension/ext/vendor3/foo/ext.php b/tests/extension/ext/vendor3/foo/ext.php new file mode 100644 index 0000000000..b52649d921 --- /dev/null +++ b/tests/extension/ext/vendor3/foo/ext.php @@ -0,0 +1,20 @@ +<?php + +namespace vendor3\foo; + +class ext extends \phpbb\extension\base +{ +	static public $enabled; + +	public function enable_step($old_state) +	{ +		self::$enabled = true; + +		return self::$enabled; +	} + +	public function is_enableable() +	{ +		return false; +	} +} diff --git a/tests/extension/ext/vendor4/bar/composer.json b/tests/extension/ext/vendor4/bar/composer.json new file mode 100644 index 0000000000..1a2fddc3f4 --- /dev/null +++ b/tests/extension/ext/vendor4/bar/composer.json @@ -0,0 +1,23 @@ +{ +	"name": "vendor4/bar", +	"type": "phpbb-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", +	"license": "GPL-2.0", +	"authors": [{ +			"name": "John Smith", +			"email": "email@phpbb.com", +			"homepage": "http://phpbb.com", +			"role": "N/A" +		}], +	"require": { +		"php": ">=5.3" +	}, +	"extra": { +		"display-name": "phpBB Bar Extension", +		"soft-require": { +			"phpbb/phpbb": "3.1.*@dev" +		} +	} +} diff --git a/tests/extension/ext/vendor4/bar/styles/all/template/foobar_body.html b/tests/extension/ext/vendor4/bar/styles/all/template/foobar_body.html new file mode 100644 index 0000000000..c8f8cf957e --- /dev/null +++ b/tests/extension/ext/vendor4/bar/styles/all/template/foobar_body.html @@ -0,0 +1 @@ +All folder diff --git a/tests/extension/extension_base_test.php b/tests/extension/extension_base_test.php new file mode 100644 index 0000000000..eee38186db --- /dev/null +++ b/tests/extension/extension_base_test.php @@ -0,0 +1,79 @@ +<?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. +* +*/ +require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php'; + +class phpbb_extension_extension_base_test extends phpbb_test_case +{ +	protected static $reflection_method_get_migration_file_list; + +	/** @var phpbb_mock_extension_manager */ +	protected $extension_manager; + +	public static function setUpBeforeClass() +	{ +		parent::setUpBeforeClass(); + +		$reflection_class = new ReflectionClass('\phpbb\extension\base'); +		self::$reflection_method_get_migration_file_list = $reflection_class->getMethod('get_migration_file_list'); +		self::$reflection_method_get_migration_file_list->setAccessible(true); +	} + +	public function setUp() +	{ +		$container = new phpbb_mock_container_builder(); +		$migrator = new phpbb_mock_migrator(); +		$container->set('migrator', $migrator); + +		$this->extension_manager = new phpbb_mock_extension_manager( +			dirname(__FILE__) . '/', +			array( +				'vendor2/foo' => array( +					'ext_name' => 'vendor2/foo', +					'ext_active' => '1', +					'ext_path' => 'ext/vendor2/foo/', +				), +				'vendor3/bar' => array( +					'ext_name' => 'vendor3/bar', +					'ext_active' => '1', +					'ext_path' => 'ext/vendor3/bar/', +				), +				'vendor2/bar' => array( +					'ext_name' => 'vendor2/bar', +					'ext_active' => '1', +					'ext_path' => 'ext/vendor2/bar/', +				), +			), +			$container); +	} + +	public function data_test_suffix_get_classes() +	{ +		return array( +			array( +				'vendor2/bar', +				array( +					'\vendor2\bar\migrations\migration', +				), +			), +		); +	} + +	/** +	* @dataProvider data_test_suffix_get_classes +	*/ +	public function test_suffix_get_classes($extension_name, $expected) +	{ +		$extension = $this->extension_manager->get_extension($extension_name); +		$this->assertEquals($expected, self::$reflection_method_get_migration_file_list->invoke($extension)); +	} +} diff --git a/tests/extension/finder_test.php b/tests/extension/finder_test.php new file mode 100644 index 0000000000..2116cc057b --- /dev/null +++ b/tests/extension/finder_test.php @@ -0,0 +1,309 @@ +<?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. +* +*/ +require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php'; + +class phpbb_extension_finder_test extends phpbb_test_case +{ +	/** @var \phpbb\extension\manager */ +	protected $extension_manager; +	/** @var \phpbb\finder */ +	protected $finder; + +	public function setUp() +	{ +		$this->extension_manager = new phpbb_mock_extension_manager( +			dirname(__FILE__) . '/', +			array( +				'vendor2/foo' => array( +					'ext_name' => 'vendor2/foo', +					'ext_active' => '1', +					'ext_path' => 'ext/vendor2/foo/', +				), +				'vendor3/bar' => array( +					'ext_name' => 'vendor3/bar', +					'ext_active' => '1', +					'ext_path' => 'ext/vendor3/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( +				'\phpbb\default\implementation', +				'\vendor2\foo\a_class', +				'\vendor2\foo\b_class', +				'\vendor3\bar\my\hidden_class', +			), +			$classes +		); +	} + +	public function set_extensions_data() +	{ +		return array( +			array( +				array(), +				array('\phpbb\default\implementation'), +			), +			array( +				array('vendor3/bar'), +				array( +					'\phpbb\default\implementation', +					'\vendor3\bar\my\hidden_class', +				), +			), +			array( +				array('vendor2/foo', 'vendor3/bar'), +				array( +					'\phpbb\default\implementation', +					'\vendor2\foo\a_class', +					'\vendor2\foo\b_class', +					'\vendor3\bar\my\hidden_class', +				), +			), +		); +	} + +	/** +	 * @dataProvider set_extensions_data +	 */ +	public function test_set_extensions($extensions, $expected) +	{ +		$classes = $this->finder +			->set_extensions($extensions) +			->core_path('phpbb/default/') +			->extension_suffix('_class') +			->get_classes(); + +		sort($classes); +		$this->assertEquals($expected, $classes); +	} + +	public function test_get_directories() +	{ +		$dirs = $this->finder +			->directory('/type') +			->get_directories(); + +		sort($dirs); +		$this->assertEquals(array( +			dirname(__FILE__) . '/ext/vendor2/foo/type/', +		), $dirs); +	} + +	public function test_prefix_get_directories() +	{ +		$dirs = $this->finder +			->prefix('ty') +			->get_directories(); + +		sort($dirs); +		$this->assertEquals(array( +			dirname(__FILE__) . '/ext/vendor2/foo/sub/type/', +			dirname(__FILE__) . '/ext/vendor2/foo/type/', +			dirname(__FILE__) . '/ext/vendor2/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( +				'\phpbb\default\implementation', +				'\vendor3\bar\my\hidden_class', +			), +			$classes +		); +	} + +	public function test_directory_get_classes() +	{ +		$classes = $this->finder +			->core_path('phpbb/default/') +			->extension_directory('type') +			->get_classes(); + +		sort($classes); +		$this->assertEquals( +			array( +				'\phpbb\default\implementation', +				'\vendor2\foo\sub\type\alternative', +				'\vendor2\foo\type\alternative', +			), +			$classes +		); +	} + +	public function test_absolute_directory_get_classes() +	{ +		$classes = $this->finder +			->directory('/type/') +			->get_classes(); + +		sort($classes); +		$this->assertEquals( +			array( +				'\vendor2\foo\type\alternative', +			), +			$classes +		); +	} + +	public function test_non_absolute_directory_get_classes() +	{ +		$classes = $this->finder +			->directory('type/') +			->get_classes(); + +		sort($classes); +		$this->assertEquals( +			array( +				'\vendor2\foo\sub\type\alternative', +				'\vendor2\foo\type\alternative', +			), +			$classes +		); +	} + +	public function test_sub_directory_get_classes() +	{ +		$classes = $this->finder +			->directory('/sub/type') +			->get_classes(); + +		sort($classes); +		$this->assertEquals( +			array( +				'\vendor2\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( +				'\vendor2\foo\sub\type\alternative', +			), +			$classes +		); +	} + +	public function test_find_from_extension() +	{ +		$files = $this->finder +			->extension_directory('/type') +			->find_from_extension('vendor2/foo', dirname(__FILE__) . '/ext/vendor2/foo/'); +		$classes = $this->finder->get_classes_from_files($files); + +		sort($classes); +		$this->assertEquals( +			array( +				'\vendor2\foo\type\alternative', +				'\vendor2\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\finder(new \phpbb\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(); + +		$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\finder( +			new \phpbb\filesystem(), +			dirname(__FILE__) . '/', +			new phpbb_mock_cache(array( +				'_ext_finder' => array( +					md5(serialize($query)) => array('file_name' => 'extension'), +				), +			)) +		); +		$finder->set_extensions(array_keys($this->extension_manager->all_enabled())); + +		$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..6846162f0f --- /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>vendor2/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..c4591cae07 --- /dev/null +++ b/tests/extension/includes/acp/acp_foobar.php @@ -0,0 +1,29 @@ +<?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. +* +*/ + +/** +* @ignore +*/ +if (!defined('IN_PHPBB')) +{ +	exit; +} + +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..870225ba4f --- /dev/null +++ b/tests/extension/includes/acp/info/acp_foobar.php @@ -0,0 +1,27 @@ +<?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 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..0eeb060936 --- /dev/null +++ b/tests/extension/manager_test.php @@ -0,0 +1,187 @@ +<?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. +* +*/ + +require_once dirname(__FILE__) . '/ext/vendor2/bar/ext.php'; +require_once dirname(__FILE__) . '/ext/vendor2/foo/ext.php'; +require_once dirname(__FILE__) . '/ext/vendor3/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_all_available() +	{ +		// barfoo and vendor3/bar should not listed due to missing composer.json. barfoo also has incorrect dir structure. +		$this->assertEquals(array('vendor/moo', 'vendor2/bar', 'vendor2/foo', 'vendor3/foo', 'vendor4/bar'), array_keys($this->extension_manager->all_available())); +	} + +	public function test_all_enabled() +	{ +		$this->assertEquals(array('vendor2/foo'), array_keys($this->extension_manager->all_enabled())); +	} + +	public function test_all_configured() +	{ +		$this->assertEquals(array('vendor/moo', 'vendor2/foo'), array_keys($this->extension_manager->all_configured())); +	} + +	public function test_is_enabled() +	{ +		$this->assertSame(true, $this->extension_manager->is_enabled('vendor2/foo')); +		$this->assertSame(false, $this->extension_manager->is_enabled('vendor/moo')); +		$this->assertSame(false, $this->extension_manager->is_enabled('vendor2/bar')); +		$this->assertSame(false, $this->extension_manager->is_enabled('bertie/worlddominationplan')); +	} + +	public function test_is_disabled() +	{ +		$this->assertSame(false, $this->extension_manager->is_disabled('vendor2/foo')); +		$this->assertSame(true, $this->extension_manager->is_disabled('vendor/moo')); +		$this->assertSame(false, $this->extension_manager->is_disabled('vendor2/bar')); +		$this->assertSame(false, $this->extension_manager->is_disabled('bertie/worlddominationplan')); +	} + +	public function test_is_purged() +	{ +		$this->assertSame(false, $this->extension_manager->is_purged('vendor2/foo')); +		$this->assertSame(false, $this->extension_manager->is_purged('vendor/moo')); +		$this->assertSame(true, $this->extension_manager->is_purged('vendor2/bar')); +		$this->assertSame(false, $this->extension_manager->is_purged('bertie/worlddominationplan')); +	} + +	public function test_is_configured() +	{ +		$this->assertSame(true, $this->extension_manager->is_configured('vendor2/foo')); +		$this->assertSame(true, $this->extension_manager->is_configured('vendor/moo')); +		$this->assertSame(false, $this->extension_manager->is_configured('vendor2/bar')); +		$this->assertSame(false, $this->extension_manager->is_configured('bertie/worlddominationplan')); +	} + +	public function test_is_available() +	{ +		$this->assertSame(true, $this->extension_manager->is_available('vendor2/foo')); +		$this->assertSame(true, $this->extension_manager->is_available('vendor/moo')); +		$this->assertSame(true, $this->extension_manager->is_available('vendor2/bar')); +		$this->assertSame(false, $this->extension_manager->is_available('bertie/worlddominationplan')); +	} + +	public function test_enable() +	{ +		vendor2\bar\ext::$state = 0; + +		$this->assertEquals(array('vendor2/foo'), array_keys($this->extension_manager->all_enabled())); +		$this->extension_manager->enable('vendor2/bar'); +		$this->assertEquals(array('vendor2/bar', 'vendor2/foo'), array_keys($this->extension_manager->all_enabled())); +		$this->assertEquals(array('vendor/moo', 'vendor2/bar', 'vendor2/foo'), array_keys($this->extension_manager->all_configured())); + +		$this->assertEquals(4, vendor2\bar\ext::$state); +	} + +	public function test_enable_not_enableable() +	{ +		vendor3\foo\ext::$enabled = false; + +		$this->assertEquals(array('vendor2/foo'), array_keys($this->extension_manager->all_enabled())); +		$this->extension_manager->enable('vendor3/foo'); +		$this->assertEquals(array('vendor2/foo'), array_keys($this->extension_manager->all_enabled())); +		$this->assertEquals(array('vendor/moo', 'vendor2/foo'), array_keys($this->extension_manager->all_configured())); + +		$this->assertSame(false, vendor3\foo\ext::$enabled); +	} + +	public function test_disable() +	{ +		vendor2\foo\ext::$disabled = false; + +		$this->assertEquals(array('vendor2/foo'), array_keys($this->extension_manager->all_enabled())); +		$this->extension_manager->disable('vendor2/foo'); +		$this->assertEquals(array(), array_keys($this->extension_manager->all_enabled())); +		$this->assertEquals(array('vendor/moo', 'vendor2/foo'), array_keys($this->extension_manager->all_configured())); + +		$this->assertTrue(vendor2\foo\ext::$disabled); +	} + +	public function test_purge() +	{ +		vendor\moo\ext::$purged = false; + +		$this->assertEquals(array('vendor2/foo'), array_keys($this->extension_manager->all_enabled())); +		$this->assertEquals(array('vendor/moo', 'vendor2/foo'), array_keys($this->extension_manager->all_configured())); +		$this->extension_manager->purge('vendor/moo'); +		$this->assertEquals(array('vendor2/foo'), array_keys($this->extension_manager->all_enabled())); +		$this->assertEquals(array('vendor2/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('vendor2/foo'), array_keys($extension_manager->all_enabled())); +	} + +	protected function create_extension_manager($with_cache = true) +	{ + +		$config = new \phpbb\config\config(array('version' => PHPBB_VERSION)); +		$db = $this->new_dbal(); +		$db_tools = new \phpbb\db\tools($db); +		$phpbb_root_path = __DIR__ . './../../phpBB/'; +		$php_ext = 'php'; +		$table_prefix = 'phpbb_'; +		$user = new \phpbb\user('\phpbb\user'); + +		$container = new phpbb_mock_container_builder(); + +		$migrator = new \phpbb\db\migrator( +			$container, +			$config, +			$db, +			$db_tools, +			'phpbb_migrations', +			$phpbb_root_path, +			$php_ext, +			$table_prefix, +			array(), +			new \phpbb\db\migration\helper() +		); +		$container->set('migrator', $migrator); + +		return new \phpbb\extension\manager( +			$container, +			$db, +			$config, +			new \phpbb\filesystem(), +			$user, +			'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..2a746d3792 --- /dev/null +++ b/tests/extension/metadata_manager_test.php @@ -0,0 +1,343 @@ +<?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 phpbb_extension_metadata_manager_test extends phpbb_database_test_case +{ +	protected $class_loader; +	protected $extension_manager; + +	protected $cache; +	protected $config; +	protected $db; +	protected $db_tools; +	protected $table_prefix; +	protected $phpbb_root_path; +	protected $phpEx; +	protected $migrator; +	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('\phpbb\datetime'); +		$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->getMock('\phpbb\request\request'), +				$this->phpbb_root_path, +				$this->phpEx +			), +			$this->config, +			$this->user, +			new \phpbb\template\context() +		); + +		$container = new phpbb_mock_container_builder(); + +		$this->migrator = new \phpbb\db\migrator( +			$container, +			$this->config, +			$this->db, +			$this->db_tools, +			'phpbb_migrations', +			$this->phpbb_root_path, +			'php', +			$this->table_prefix, +			array(), +			new \phpbb\db\migration\helper() +		); +		$container->set('migrator', $this->migrator); + +		$this->extension_manager = new \phpbb\extension\manager( +			$container, +			$this->db, +			$this->config, +			new \phpbb\filesystem(), +			$this->user, +			'phpbb_ext', +			$this->phpbb_root_path, +			$this->phpEx, +			$this->cache +		); +	} + +	// Should fail from missing composer.json +	public function test_bar() +	{ +		$ext_name = 'vendor3/bar'; + +		$manager = $this->get_metadata_manager($ext_name); + +		try +		{ +			$manager->get_metadata(); +		} +		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')); +		} +	} + +	// Should be the same as a direct json_decode of the composer.json file +	public function test_foo() +	{ +		$ext_name = 'vendor2/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/vendor2/foo/composer.json'), true); +		array_walk_recursive($json, array($manager, 'sanitize_json')); + +		$this->assertEquals($metadata, $json); +	} + +	public function validator_non_existing_data() +	{ +		return array( +			array('name'), +			array('type'), +			array('license'), +			array('version'), +		); +	} + +	/** +	* @dataProvider validator_non_existing_data +	*/ +	public function test_validator_non_existing($field_name) +	{ +		$manager = $this->get_metadata_manager('validator'); +		try +		{ +			$manager->validate($field_name); +			$this->fail('Exception not triggered'); +		} +		catch(\phpbb\extension\exception $e) +		{ +			$this->assertEquals((string) $e, $this->user->lang('META_FIELD_NOT_SET', $field_name)); +		} +	} + +	public function test_validator_non_existing_authors() +	{ +		$manager = $this->get_metadata_manager('validator'); +		try +		{ +			$manager->validate_authors(); +			$this->fail('Exception not triggered'); +		} +		catch (\phpbb\extension\exception $e) +		{ +			$this->assertEquals((string) $e, $this->user->lang('META_FIELD_NOT_SET', 'authors')); +		} + +		$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, $this->user->lang('META_FIELD_NOT_SET', 'author name')); +		} +	} + +	public function validator_invalid_data() +	{ +		return array( +			array('name', 'asdf'), +			array('type', 'asdf'), +			array('license', ''), +			array('version', ''), +		); +	} + +	/** +	 * @dataProvider validator_invalid_data +	 */ +	public function test_validator_invalid($field_name, $field_value) +	{ +		$manager = $this->get_metadata_manager('validator'); + +		// Invalid data +		$manager->set_metadata(array( +			$field_name		=> $field_value, +		)); + +		try +		{ +			$manager->validate($field_name); +			$this->fail('Exception not triggered'); +		} +		catch(\phpbb\extension\exception $e) +		{ +			$this->assertEquals((string) $e, $this->user->lang('META_FIELD_INVALID', $field_name)); +		} +	} + +	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'		=> 'phpbb-extension', +			'license'	=> 'GPL v2', +			'version'	=> '1.0.0', +		)); + +		try +		{ +			$this->assertEquals(true, $manager->validate('enable')); +		} +		catch(\phpbb\extension\exception $e) +		{ +			$this->fail($e); +		} +	} + +	public function validator_requirements_data() +	{ +		return array( +			array( +				'10.0.0', +				'100.2.0', +				false, +				false, +				'Versions are not compared at the moment', +			), +			array( +				'5.3.0', +				'3.1.0-beta', +				true, +				true, +			), +			array( +				'>' . phpversion(), +				'>3.1.0', +				false, +				false, +				'Versions are not compared at the moment', +			), +			array( +				'<' . phpversion(), +				'<3.1.0', +				false, +				false, +				'Versions are not compared at the moment', +			), +			array( +				phpversion(), +				'3.1.0', +				true, +				true, +			), +			array( +				'>=' . phpversion(), +				'>=3.1.0', +				true, +				true, +			), +			array( +				'<=' . phpversion(), +				'<=3.1.0', +				true, +				true, +			), +		); +	} + +	/** +	* @dataProvider validator_requirements_data +	*/ +	public function test_validator_requirements($php_version, $phpbb_version, $expected_php, $expected_phpbb, $incomplete_reason = '') +	{ +		if ($incomplete_reason) +		{ +			$this->markTestIncomplete($incomplete_reason); +		} + +		$ext_name = 'validator'; +		$manager = $this->get_metadata_manager($ext_name); +		// Too high of requirements +		$manager->merge_metadata(array( +			'require'		=> array( +				'php'		=> $php_version, +			), +			'extra'		=> array( +				'soft-require'	=> array( +					'phpbb/phpbb'		=> $phpbb_version, // config is set to 3.1.0 +				), +			), +		)); + +		$this->assertEquals($expected_php, $manager->validate_require_php()); +		$this->assertEquals($expected_phpbb, $manager->validate_require_phpbb()); +	} + +	/** +	* 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->user, +			$this->phpbb_root_path +		); +	} +} diff --git a/tests/extension/modules_test.php b/tests/extension/modules_test.php new file mode 100644 index 0000000000..21f1c6aca5 --- /dev/null +++ b/tests/extension/modules_test.php @@ -0,0 +1,238 @@ +<?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. +* +*/ + +require_once dirname(__FILE__) . '/ext/vendor2/foo/acp/a_info.php'; +require_once dirname(__FILE__) . '/ext/vendor2/foo/mcp/a_info.php'; +require_once dirname(__FILE__) . '/ext/vendor2/foo/acp/fail_info.php'; +require_once dirname(__FILE__) . '/ext/vendor2/bar/acp/a_info.php'; +require_once dirname(__FILE__) . '/../../phpBB/includes/acp/acp_modules.php'; +require_once dirname(__FILE__) . '/../../phpBB/includes/functions_module.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( +				'vendor2/foo' => array( +					'ext_name' => 'vendor2/foo', +					'ext_active' => '1', +					'ext_path' => 'ext/vendor2/foo/', +				), +				'vendor3/bar' => array( +					'ext_name' => 'vendor3/bar', +					'ext_active' => '1', +					'ext_path' => 'ext/vendor3/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( +				'vendor2\\foo\\acp\\a_module' => array( +					'filename'	=> 'vendor2\\foo\\acp\\a_module', +					'title'		=> 'Foobar', +					'version'	=> '3.1.0-dev', +					'modes'		=> array( +						'config'		=> array('title' => 'Config',	'auth' => 'ext_vendor2/foo', '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( +				'vendor2\\foo\\mcp\\a_module' => array( +					'filename'	=> 'vendor2\\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( +				'vendor2\\foo\\mcp\\a_module' => array( +					'filename'	=> 'vendor2\\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( +				'vendor2\\foo\\mcp\\a_module' => array( +					'filename'	=> 'vendor2\\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( +				'vendor2\\foo\\acp\\a_module' => array ( +					'filename' => 'vendor2\\foo\\acp\\a_module', +					'title' => 'Foobar', +					'version' => '3.1.0-dev', +					'modes' => array ( +						'config'		=> array ('title' => 'Config', 'auth' => 'ext_vendor2/foo', '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 (vendor2/bar) +		$this->acp_modules->module_class = 'acp'; +		$acp_modules = $this->acp_modules->get_module_infos('', false, true); +		$this->assertEquals(array( +				'vendor2\\foo\\acp\\a_module' => array( +					'filename'	=> 'vendor2\\foo\\acp\\a_module', +					'title'		=> 'Foobar', +					'version'	=> '3.1.0-dev', +					'modes'		=> array( +						'config'		=> array('title' => 'Config',	'auth' => 'ext_vendor2/foo', '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')), +					), +				), +				'vendor2\\bar\\acp\\a_module' => array( +					'filename'	=> 'vendor2\\bar\\acp\\a_module', +					'title'		=> 'Bar', +					'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('vendor2_bar_acp_a_module', 'acp', true); +		$this->assertEquals(array( +				'vendor2\\bar\\acp\\a_module' => array( +					'filename'	=> 'vendor2\\bar\\acp\\a_module', +					'title'		=> 'Bar', +					'version'	=> '3.1.0-dev', +					'modes'		=> array( +						'config'		=> array('title' => 'Config',	'auth' => '', 'cat' => array('ACP_MODS')), +					), +				) +			), $acp_modules); +	} + +	public function module_auth_test_data() +	{ +		return array( +			// module_auth, expected result +			array('ext_foo', false), +			array('ext_foo/bar', false), +			array('ext_vendor3/bar', false), +			array('ext_vendor2/foo', true), +		); +	} + +	/** +	* @dataProvider module_auth_test_data +	*/ +	public function test_modules_auth($module_auth, $expected) +	{ +		global $phpbb_extension_manager, $phpbb_dispatcher; + +		$phpbb_extension_manager = $this->extension_manager = new phpbb_mock_extension_manager( +			dirname(__FILE__) . '/', +			array( +				'vendor2/foo' => array( +					'ext_name' => 'vendor2/foo', +					'ext_active' => '1', +					'ext_path' => 'ext/vendor2/foo/', +				), +				'vendor3/bar' => array( +					'ext_name' => 'vendor3/bar', +					'ext_active' => '0', +					'ext_path' => 'ext/vendor3/bar/', +				), +			) +		); + +		$phpbb_dispatcher = new phpbb_mock_event_dispatcher(); + +		$this->assertEquals($expected, p_master::module_auth($module_auth, 0)); +	} +} 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 +{ +}  | 
