diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/bootstrap.php | 2 | ||||
-rw-r--r-- | tests/class_loader/class_loader_test.php | 9 | ||||
-rw-r--r-- | tests/class_loader/ext/foo/class.php | 6 | ||||
-rw-r--r-- | tests/extension/ext/bar/my/hidden_class.php | 5 | ||||
-rw-r--r-- | tests/extension/ext/foo/a_class.php | 5 | ||||
-rw-r--r-- | tests/extension/ext/foo/b_class.php | 5 | ||||
-rw-r--r-- | tests/extension/ext/foo/foo.php | 5 | ||||
-rw-r--r-- | tests/extension/ext/foo/sub/type/alternative.php | 5 | ||||
-rw-r--r-- | tests/extension/ext/foo/type/alternative.php | 5 | ||||
-rw-r--r-- | tests/extension/ext/foo/typewrong/error.php | 5 | ||||
-rw-r--r-- | tests/extension/ext/moo/feature_class.php | 5 | ||||
-rw-r--r-- | tests/extension/finder_test.php | 133 | ||||
-rw-r--r-- | tests/extension/fixtures/extensions.xml | 15 | ||||
-rw-r--r-- | tests/extension/includes/default/implementation.php | 5 | ||||
-rw-r--r-- | tests/extension/manager_test.php | 89 | ||||
-rw-r--r-- | tests/mock/extension_manager.php | 16 |
16 files changed, 312 insertions, 3 deletions
diff --git a/tests/bootstrap.php b/tests/bootstrap.php index b7c3534cde..fbe23c1835 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -32,7 +32,7 @@ else require_once $phpbb_root_path . 'includes/constants.php'; require_once $phpbb_root_path . 'includes/class_loader.' . $phpEx; -$class_loader = new phpbb_class_loader($phpbb_root_path, '.php'); +$class_loader = new phpbb_class_loader($phpbb_root_path . 'includes/', $phpbb_root_path . 'ext/', '.php'); $class_loader->register(); require_once 'test_framework/phpbb_test_case_helpers.php'; diff --git a/tests/class_loader/class_loader_test.php b/tests/class_loader/class_loader_test.php index 0c7fe3f97a..7d5f57aac3 100644 --- a/tests/class_loader/class_loader_test.php +++ b/tests/class_loader/class_loader_test.php @@ -26,7 +26,7 @@ class phpbb_class_loader_test extends PHPUnit_Framework_TestCase public function test_resolve_path() { $prefix = dirname(__FILE__) . '/'; - $class_loader = new phpbb_class_loader($prefix); + $class_loader = new phpbb_class_loader($prefix . 'includes/', $prefix . 'ext/'); $prefix .= 'includes/'; @@ -56,6 +56,11 @@ class phpbb_class_loader_test extends PHPUnit_Framework_TestCase $class_loader->resolve_path('phpbb_dir2'), 'Class with name of dir within dir (short class name)' ); + $this->assertEquals( + dirname(__FILE__) . '/ext/foo/class.php', + $class_loader->resolve_path('phpbb_ext_foo_class'), + 'Extension class' + ); } public function test_resolve_cached() @@ -64,7 +69,7 @@ class phpbb_class_loader_test extends PHPUnit_Framework_TestCase $cache = new phpbb_mock_cache($cacheMap); $prefix = dirname(__FILE__) . '/'; - $class_loader = new phpbb_class_loader($prefix, '.php', $cache); + $class_loader = new phpbb_class_loader($prefix . 'includes/', $prefix . 'ext/', '.php', $cache); $prefix .= 'includes/'; diff --git a/tests/class_loader/ext/foo/class.php b/tests/class_loader/ext/foo/class.php new file mode 100644 index 0000000000..7b1555c98d --- /dev/null +++ b/tests/class_loader/ext/foo/class.php @@ -0,0 +1,6 @@ +<?php + +class phpbb_ext_foo_class +{ +} + 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..b3c910a8c2 --- /dev/null +++ b/tests/extension/ext/bar/my/hidden_class.php @@ -0,0 +1,5 @@ +<?php + +class phpbb_ext_bar_my_hidden_class +{ +}
\ No newline at end of file diff --git a/tests/extension/ext/foo/a_class.php b/tests/extension/ext/foo/a_class.php new file mode 100644 index 0000000000..03253139f9 --- /dev/null +++ b/tests/extension/ext/foo/a_class.php @@ -0,0 +1,5 @@ +<?php + +class phpbb_ext_foo_a_class +{ +}
\ No newline at end of file diff --git a/tests/extension/ext/foo/b_class.php b/tests/extension/ext/foo/b_class.php new file mode 100644 index 0000000000..04644a9d9d --- /dev/null +++ b/tests/extension/ext/foo/b_class.php @@ -0,0 +1,5 @@ +<?php + +class phpbb_ext_foo_b_class +{ +}
\ No newline at end of file diff --git a/tests/extension/ext/foo/foo.php b/tests/extension/ext/foo/foo.php new file mode 100644 index 0000000000..78a8c95f65 --- /dev/null +++ b/tests/extension/ext/foo/foo.php @@ -0,0 +1,5 @@ +<?php + +class phpbb_ext_foo extends phpbb_extension_base +{ +}
\ No newline at end of file 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..2ea7353f4b --- /dev/null +++ b/tests/extension/ext/foo/sub/type/alternative.php @@ -0,0 +1,5 @@ +<?php + +class phpbb_ext_foo_sub_type_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..b43a293b1d --- /dev/null +++ b/tests/extension/ext/foo/type/alternative.php @@ -0,0 +1,5 @@ +<?php + +class phpbb_ext_foo_type_alternative +{ +}
\ No newline at end of file diff --git a/tests/extension/ext/foo/typewrong/error.php b/tests/extension/ext/foo/typewrong/error.php new file mode 100644 index 0000000000..ba22cfae9a --- /dev/null +++ b/tests/extension/ext/foo/typewrong/error.php @@ -0,0 +1,5 @@ +<?php + +class phpbb_ext_foo_typewrong_error +{ +} diff --git a/tests/extension/ext/moo/feature_class.php b/tests/extension/ext/moo/feature_class.php new file mode 100644 index 0000000000..20ea13054f --- /dev/null +++ b/tests/extension/ext/moo/feature_class.php @@ -0,0 +1,5 @@ +<?php + +class phpbb_ext_moo_feature_class +{ +}
\ No newline at end of file diff --git a/tests/extension/finder_test.php b/tests/extension/finder_test.php new file mode 100644 index 0000000000..a1b216face --- /dev/null +++ b/tests/extension/finder_test.php @@ -0,0 +1,133 @@ +<?php +/** +* +* @package testing +* @copyright (c) 2011 phpBB Group +* @license http://opensource.org/licenses/gpl-license.php GNU Public License +* +*/ + +require_once dirname(__FILE__) . '/../mock/cache.php'; +require_once dirname(__FILE__) . '/../mock/extension_manager.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(array( + 'foo' => array( + 'ext_name' => 'foo', + 'ext_active' => '1', + 'ext_path' => dirname(__FILE__) . '/ext/foo/', + ), + 'bar' => array( + 'ext_name' => 'bar', + 'ext_active' => '1', + 'ext_path' => dirname(__FILE__) . '/ext/bar/', + ), + )); + + $this->finder = new phpbb_extension_finder($this->extension_manager, dirname(__FILE__) . '/'); + } + + public function test_suffix_get_classes() + { + $classes = $this->finder + ->default_path('includes/default/') + ->suffix('_class') + ->default_suffix('') + ->get_classes(); + + sort($classes); + $this->assertEquals( + array( + 'phpbb_default_implementation', + 'phpbb_ext_bar_my_hidden_class', + 'phpbb_ext_foo_a_class', + 'phpbb_ext_foo_b_class', + ), + $classes + ); + } + + public function test_directory_get_classes() + { + $classes = $this->finder + ->default_path('includes/default/') + ->directory('type') + ->default_directory('') + ->get_classes(); + + sort($classes); + $this->assertEquals( + array( + 'phpbb_default_implementation', + 'phpbb_ext_foo_sub_type_alternative', + 'phpbb_ext_foo_type_alternative', + ), + $classes + ); + } + + public function test_absolute_directory_get_classes() + { + $classes = $this->finder + ->directory('/type/') + ->get_classes(); + + sort($classes); + $this->assertEquals( + array( + 'phpbb_ext_foo_type_alternative', + ), + $classes + ); + } + + public function test_sub_directory_get_classes() + { + $classes = $this->finder + ->directory('/sub/type') + ->get_classes(); + + sort($classes); + $this->assertEquals( + array( + 'phpbb_ext_foo_sub_type_alternative', + ), + $classes + ); + } + + public function test_cached_get_files() + { + $query = array( + 'default_path' => 'includes/foo', + 'default_suffix' => false, + 'default_directory' => 'bar', + 'suffix' => false, + 'directory' => false, + ); + + + $finder = new phpbb_extension_finder($this->extension_manager, dirname(__FILE__) . '/includes/', new phpbb_mock_cache(array( + '_extension_finder' => array( + md5(serialize($query)) => array('file_name'), + ), + ))); + + $classes = $finder + ->default_path($query['default_path']) + ->default_directory($query['default_directory']) + ->get_files(); + + sort($classes); + $this->assertEquals( + array('file_name'), + $classes + ); + } +} diff --git a/tests/extension/fixtures/extensions.xml b/tests/extension/fixtures/extensions.xml new file mode 100644 index 0000000000..f3acdd2575 --- /dev/null +++ b/tests/extension/fixtures/extensions.xml @@ -0,0 +1,15 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<dataset> + <table name="phpbb_ext"> + <column>ext_name</column> + <column>ext_active</column> + <row> + <value>foo</value> + <value>1</value> + </row> + <row> + <value>moo</value> + <value>0</value> + </row> + </table> +</dataset> diff --git a/tests/extension/includes/default/implementation.php b/tests/extension/includes/default/implementation.php new file mode 100644 index 0000000000..91d5f8aa2f --- /dev/null +++ b/tests/extension/includes/default/implementation.php @@ -0,0 +1,5 @@ +<?php + +class phpbb_default_impl_class implements phpbb_default_interface +{ +} diff --git a/tests/extension/manager_test.php b/tests/extension/manager_test.php new file mode 100644 index 0000000000..ebd92a728d --- /dev/null +++ b/tests/extension/manager_test.php @@ -0,0 +1,89 @@ +<?php +/** +* +* @package testing +* @copyright (c) 2011 phpBB Group +* @license http://opensource.org/licenses/gpl-license.php GNU Public License +* +*/ + +require_once dirname(__FILE__) . '/../mock/cache.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(); + + // disable the regular class loader to replace it with one that loads + // test extensions + global $class_loader; + $class_loader->unregister(); + + $prefix = dirname(__FILE__) . '/'; + $this->class_loader = new phpbb_class_loader($prefix . '../../phpBB/includes/', $prefix . 'ext/'); + $this->class_loader->register(); + + $this->extension_manager = new phpbb_extension_manager( + $this->new_dbal(), + 'phpbb_ext', + $prefix, + '.php', + new phpbb_mock_cache + ); + } + + protected function tearDown() + { + global $class_loader; + $class_loader->register(); + } + + public function test_available() + { + $this->assertEquals(array('bar', 'foo', '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', 'moo'), array_keys($this->extension_manager->all_configured())); + } + + public function test_enable() + { + $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', 'moo'), array_keys($this->extension_manager->all_configured())); + } + + public function test_disable() + { + $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', 'moo'), array_keys($this->extension_manager->all_configured())); + } + + public function test_purge() + { + $this->assertEquals(array('foo'), array_keys($this->extension_manager->all_enabled())); + $this->assertEquals(array('foo', 'moo'), array_keys($this->extension_manager->all_configured())); + $this->extension_manager->purge('moo'); + $this->assertEquals(array('foo'), array_keys($this->extension_manager->all_enabled())); + $this->assertEquals(array('foo'), array_keys($this->extension_manager->all_configured())); + } +} diff --git a/tests/mock/extension_manager.php b/tests/mock/extension_manager.php new file mode 100644 index 0000000000..49d727db37 --- /dev/null +++ b/tests/mock/extension_manager.php @@ -0,0 +1,16 @@ +<?php +/** +* +* @package testing +* @copyright (c) 2011 phpBB Group +* @license http://opensource.org/licenses/gpl-license.php GNU Public License +* +*/ + +class phpbb_mock_extension_manager extends phpbb_extension_manager +{ + public function __construct($extensions = array()) + { + $this->extensions = $extensions; + } +} |