aboutsummaryrefslogtreecommitdiffstats
path: root/tests/extension
diff options
context:
space:
mode:
authorNils Adermann <naderman@naderman.de>2011-06-09 05:13:26 +0200
committerNils Adermann <naderman@naderman.de>2011-09-29 15:42:33 +0200
commit14f1e581faa3b66e7689c55c1e9c0485c0872b1e (patch)
tree437880dd3c80e47a6205beadb005c7ce27a1a960 /tests/extension
parent8377418466f861f6b3291ae92a71821f0a0be2d6 (diff)
downloadforums-14f1e581faa3b66e7689c55c1e9c0485c0872b1e.tar
forums-14f1e581faa3b66e7689c55c1e9c0485c0872b1e.tar.gz
forums-14f1e581faa3b66e7689c55c1e9c0485c0872b1e.tar.bz2
forums-14f1e581faa3b66e7689c55c1e9c0485c0872b1e.tar.xz
forums-14f1e581faa3b66e7689c55c1e9c0485c0872b1e.zip
[feature/extension-manager] Extension Manager & Finder
Extensions RFC: http://area51.phpbb.com/phpBB/viewtopic.php?f=84&t=41499 Ticket: http://tracker.phpbb.com/browse/PHPBB3-10323 PHPBB3-10323
Diffstat (limited to 'tests/extension')
-rw-r--r--tests/extension/ext/bar/my/hidden_class.php5
-rw-r--r--tests/extension/ext/foo/a_class.php5
-rw-r--r--tests/extension/ext/foo/b_class.php5
-rw-r--r--tests/extension/ext/foo/foo.php5
-rw-r--r--tests/extension/ext/foo/sub/type/alternative.php5
-rw-r--r--tests/extension/ext/foo/type/alternative.php5
-rw-r--r--tests/extension/ext/foo/typewrong/error.php5
-rw-r--r--tests/extension/ext/moo/feature_class.php5
-rw-r--r--tests/extension/finder_test.php133
-rw-r--r--tests/extension/fixtures/extensions.xml15
-rw-r--r--tests/extension/includes/default/implementation.php5
-rw-r--r--tests/extension/manager_test.php89
12 files changed, 282 insertions, 0 deletions
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()));
+ }
+}