aboutsummaryrefslogtreecommitdiffstats
path: root/tests/extension
diff options
context:
space:
mode:
Diffstat (limited to 'tests/extension')
-rw-r--r--tests/extension/acp.php205
-rw-r--r--tests/extension/ext/bar/ext.php24
-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/composer.json22
-rw-r--r--tests/extension/ext/foo/ext.php13
-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/type/dummy/empty.txt0
-rw-r--r--tests/extension/ext/foo/typewrong/error.php5
-rw-r--r--tests/extension/ext/vendor/moo/composer.json22
-rw-r--r--tests/extension/ext/vendor/moo/ext.php13
-rw-r--r--tests/extension/ext/vendor/moo/feature_class.php5
-rw-r--r--tests/extension/finder_test.php203
-rw-r--r--tests/extension/fixtures/extensions.xml18
-rw-r--r--tests/extension/includes/default/implementation.php5
-rw-r--r--tests/extension/manager_test.php103
-rw-r--r--tests/extension/metadata_manager_test.php431
19 files changed, 1094 insertions, 0 deletions
diff --git a/tests/extension/acp.php b/tests/extension/acp.php
new file mode 100644
index 0000000000..790df77c0d
--- /dev/null
+++ b/tests/extension/acp.php
@@ -0,0 +1,205 @@
+<?php
+/**
+*
+* @package testing
+* @copyright (c) 2011 phpBB Group
+* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
+*
+*/
+
+class acp_test extends phpbb_functional_test_case
+{
+ static private $copied_files = array();
+ static private $helper;
+
+ /**
+ * This should only be called once before the tests are run.
+ * This is used to copy the extensions to the phpBB install
+ */
+ static public function setUpBeforeClass()
+ {
+ global $phpbb_root_path;
+
+ parent::setUpBeforeClass();
+
+ self::$helper = new phpbb_test_case_helpers(self);
+
+ // First, move any extensions setup on the board to a temp directory
+ self::$copied_files = self::$helper->copy_dir($phpbb_root_path . 'ext/', $phpbb_root_path . 'store/temp_ext/');
+
+ // Then empty the ext/ directory on the board (for accurate test cases)
+ self::$helper->empty_dir($phpbb_root_path . 'ext/');
+
+ // Copy our ext/ files from the test case to the board
+ self::$copied_files = array_merge(self::$copied_files, self::$helper->copy_dir(dirname(__FILE__) . '/ext/', $phpbb_root_path . 'ext/'));
+ }
+
+ public function setUp()
+ {
+ parent::setUp();
+
+ $this->get_db();
+
+ // Clear the phpbb_ext table
+ $this->db->sql_query('DELETE FROM phpbb_ext');
+
+ // Insert our base data
+ $insert_rows = array(
+ array(
+ 'ext_name' => 'foo',
+ 'ext_active' => true,
+ 'ext_state' => 'b:0;',
+ ),
+ array(
+ 'ext_name' => 'vendor/moo',
+ 'ext_active' => false,
+ 'ext_state' => 'b:0;',
+ ),
+
+ // do not exist
+ array(
+ 'ext_name' => 'test2',
+ 'ext_active' => true,
+ 'ext_state' => 'b:0;',
+ ),
+ array(
+ 'ext_name' => 'test3',
+ 'ext_active' => false,
+ 'ext_state' => 'b:0;',
+ ),
+ );
+ $this->db->sql_multi_insert('phpbb_ext', $insert_rows);
+
+ $this->login();
+ $this->admin_login();
+
+ $this->add_lang('acp/extensions');
+ }
+
+ /**
+ * This should only be called once after the tests are run.
+ * This is used to remove the files copied to the phpBB install
+ */
+ static public function tearDownAfterClass()
+ {
+ global $phpbb_root_path;
+
+ // Copy back the board installed extensions from the temp directory
+ self::$helper->copy_dir($phpbb_root_path . 'store/temp_ext/', $phpbb_root_path . 'ext/');
+
+ self::$copied_files[] = $phpbb_root_path . 'store/temp_ext/';
+
+ // Remove all of the files we copied around (from board ext -> temp_ext, from test ext -> board ext)
+ self::$helper->remove_files(self::$copied_files);
+ }
+
+ public function test_list()
+ {
+ $crawler = $this->request('GET', 'adm/index.php?i=acp_extensions&mode=main&sid=' . $this->sid);
+
+ $this->assertCount(1, $crawler->filter('.ext_enabled'));
+ $this->assertCount(4, $crawler->filter('.ext_disabled'));
+
+ $this->assertContains('phpBB Foo Extension', $crawler->filter('.ext_enabled')->eq(0)->text());
+ $this->assertContainsLang('PURGE', $crawler->filter('.ext_enabled')->eq(0)->text());
+
+ $this->assertContains('The "test2" extension is not valid.', $crawler->filter('.ext_disabled')->eq(0)->text());
+
+ $this->assertContains('The "test3" extension is not valid.', $crawler->filter('.ext_disabled')->eq(1)->text());
+
+ $this->assertContains('phpBB Moo Extension', $crawler->filter('.ext_disabled')->eq(2)->text());
+ $this->assertContainsLang('DETAILS', $crawler->filter('.ext_disabled')->eq(2)->text());
+ $this->assertContainsLang('ENABLE', $crawler->filter('.ext_disabled')->eq(2)->text());
+ $this->assertContainsLang('PURGE', $crawler->filter('.ext_disabled')->eq(2)->text());
+
+ $this->assertContains('The "bar" extension is not valid.', $crawler->filter('.ext_disabled')->eq(3)->text());
+ }
+
+ public function test_details()
+ {
+ $crawler = $this->request('GET', 'adm/index.php?i=acp_extensions&mode=main&action=details&ext_name=foo&sid=' . $this->sid);
+
+ $validation = array(
+ 'DISPLAY_NAME' => 'phpBB Foo Extension',
+ 'CLEAN_NAME' => 'foo/example',
+ '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',
+ 'PHPBB_VERSION' => '3.1.0-dev',
+ 'PHP_VERSION' => '>=5.3',
+ 'AUTHOR_NAME' => 'Nathan Guse',
+ 'AUTHOR_EMAIL' => 'email@phpbb.com',
+ 'AUTHOR_HOMEPAGE' => 'http://lithiumstudios.org',
+ 'AUTHOR_ROLE' => 'N/A',
+ );
+
+ for ($i = 0; $i < $crawler->filter('dl')->count(); $i++)
+ {
+ $text = $crawler->filter('dl')->eq($i)->text();
+
+ $match = false;
+
+ foreach ($validation as $language_key => $expected)
+ {
+ if (strpos($text, $this->lang($language_key)) === 0)
+ {
+ $match = true;
+
+ $this->assertContains($expected, $text);
+ }
+ }
+
+ if (!$match)
+ {
+ $this->fail('Unexpected field: "' . $text . '"');
+ }
+ }
+ }
+
+ public function test_enable_pre()
+ {
+ // Foo is already enabled (redirect to list)
+ $crawler = $this->request('GET', 'adm/index.php?i=acp_extensions&mode=main&action=enable_pre&ext_name=foo&sid=' . $this->sid);
+ $this->assertContainsLang('EXTENSION_NAME', $crawler->filter('html')->text());
+ $this->assertContainsLang('EXTENSION_OPTIONS', $crawler->filter('html')->text());
+ $this->assertContainsLang('EXTENSION_ACTIONS', $crawler->filter('html')->text());
+
+ $crawler = $this->request('GET', 'adm/index.php?i=acp_extensions&mode=main&action=enable_pre&ext_name=vendor%2Fmoo&sid=' . $this->sid);
+ $this->assertContainsLang('ENABLE_CONFIRM', $crawler->filter('html')->text());
+ }
+
+ public function test_disable_pre()
+ {
+ // Moo is not enabled (redirect to list)
+ $crawler = $this->request('GET', 'adm/index.php?i=acp_extensions&mode=main&action=disable_pre&ext_name=vendor%2Fmoo&sid=' . $this->sid);
+ $this->assertContainsLang('EXTENSION_NAME', $crawler->filter('html')->text());
+ $this->assertContainsLang('EXTENSION_OPTIONS', $crawler->filter('html')->text());
+ $this->assertContainsLang('EXTENSION_ACTIONS', $crawler->filter('html')->text());
+
+ $crawler = $this->request('GET', 'adm/index.php?i=acp_extensions&mode=main&action=disable_pre&ext_name=foo&sid=' . $this->sid);
+ $this->assertContainsLang('DISABLE_CONFIRM', $crawler->filter('html')->text());
+ }
+
+ public function test_purge_pre()
+ {
+ // test2 is not available (error)
+ $crawler = $this->request('GET', 'adm/index.php?i=acp_extensions&mode=main&action=purge_pre&ext_name=test2&sid=' . $this->sid);
+ $this->assertContains('The required file does not exist', $crawler->filter('html')->text());
+
+ $crawler = $this->request('GET', 'adm/index.php?i=acp_extensions&mode=main&action=purge_pre&ext_name=foo&sid=' . $this->sid);
+ $this->assertContainsLang('PURGE_CONFIRM', $crawler->filter('html')->text());
+ }
+
+ public function test_actions()
+ {
+ $crawler = $this->request('GET', 'adm/index.php?i=acp_extensions&mode=main&action=enable&ext_name=vendor%2Fmoo&sid=' . $this->sid);
+ $this->assertContainsLang('ENABLE_SUCCESS', $crawler->filter('html')->text());
+
+ $crawler = $this->request('GET', 'adm/index.php?i=acp_extensions&mode=main&action=disable&ext_name=vendor%2Fmoo&sid=' . $this->sid);
+ $this->assertContainsLang('DISABLE_SUCCESS', $crawler->filter('html')->text());
+
+ $crawler = $this->request('GET', 'adm/index.php?i=acp_extensions&mode=main&action=purge&ext_name=vendor%2Fmoo&sid=' . $this->sid);
+ $this->assertContainsLang('PURGE_SUCCESS', $crawler->filter('html')->text());
+ }
+} \ No newline at end of file
diff --git a/tests/extension/ext/bar/ext.php b/tests/extension/ext/bar/ext.php
new file mode 100644
index 0000000000..5585edf9ac
--- /dev/null
+++ b/tests/extension/ext/bar/ext.php
@@ -0,0 +1,24 @@
+<?php
+
+class phpbb_ext_bar_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..0261d7c59a
--- /dev/null
+++ b/tests/extension/ext/bar/my/hidden_class.php
@@ -0,0 +1,5 @@
+<?php
+
+class phpbb_ext_bar_my_hidden_class
+{
+}
diff --git a/tests/extension/ext/foo/a_class.php b/tests/extension/ext/foo/a_class.php
new file mode 100644
index 0000000000..b7be1ad654
--- /dev/null
+++ b/tests/extension/ext/foo/a_class.php
@@ -0,0 +1,5 @@
+<?php
+
+class phpbb_ext_foo_a_class
+{
+}
diff --git a/tests/extension/ext/foo/b_class.php b/tests/extension/ext/foo/b_class.php
new file mode 100644
index 0000000000..4645266122
--- /dev/null
+++ b/tests/extension/ext/foo/b_class.php
@@ -0,0 +1,5 @@
+<?php
+
+class phpbb_ext_foo_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..60b3ad1f16
--- /dev/null
+++ b/tests/extension/ext/foo/ext.php
@@ -0,0 +1,13 @@
+<?php
+
+class phpbb_ext_foo_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/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..404b66b965
--- /dev/null
+++ b/tests/extension/ext/foo/type/alternative.php
@@ -0,0 +1,5 @@
+<?php
+
+class phpbb_ext_foo_type_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..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/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..e0ac1a22cc
--- /dev/null
+++ b/tests/extension/ext/vendor/moo/ext.php
@@ -0,0 +1,13 @@
+<?php
+
+class phpbb_ext_vendor_moo_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..c3bcc4451c
--- /dev/null
+++ b/tests/extension/ext/vendor/moo/feature_class.php
@@ -0,0 +1,5 @@
+<?php
+
+class phpbb_ext_vendor_moo_feature_class
+{
+}
diff --git a/tests/extension/finder_test.php b/tests/extension/finder_test.php
new file mode 100644
index 0000000000..622f404786
--- /dev/null
+++ b/tests/extension/finder_test.php
@@ -0,0 +1,203 @@
+<?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_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('includes/default/')
+ ->extension_suffix('_class')
+ ->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_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('t')
+ ->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('includes/default/')
+ ->extension_prefix('hidden_')
+ ->get_classes();
+
+ sort($classes);
+ $this->assertEquals(
+ array(
+ 'phpbb_default_implementation',
+ 'phpbb_ext_bar_my_hidden_class',
+ ),
+ $classes
+ );
+ }
+
+ public function test_directory_get_classes()
+ {
+ $classes = $this->finder
+ ->core_path('includes/default/')
+ ->extension_directory('type')
+ ->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_get_classes_create_cache()
+ {
+ $cache = new phpbb_mock_cache;
+ $finder = new phpbb_extension_finder($this->extension_manager, 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' => 'includes/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, 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/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..5cde5bccdb
--- /dev/null
+++ b/tests/extension/manager_test.php
@@ -0,0 +1,103 @@
+<?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 = new phpbb_extension_manager(
+ $this->new_dbal(),
+ new phpbb_config(array()),
+ 'phpbb_ext',
+ dirname(__FILE__) . '/',
+ '.php',
+ new phpbb_mock_cache
+ );
+ }
+
+ public function test_available()
+ {
+ $this->assertEquals(array('bar', '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()
+ {
+ phpbb_ext_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, phpbb_ext_bar_ext::$state);
+ }
+
+ public function test_disable()
+ {
+ phpbb_ext_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(phpbb_ext_foo_ext::$disabled);
+ }
+
+ public function test_purge()
+ {
+ phpbb_ext_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(phpbb_ext_vendor_moo_ext::$purged);
+ }
+
+ public function test_enabled_no_cache()
+ {
+ $extension_manager = new phpbb_extension_manager(
+ $this->new_dbal(),
+ new phpbb_config(array()),
+ 'phpbb_ext',
+ dirname(__FILE__) . '/',
+ '.php'
+ );
+
+ $this->assertEquals(array('foo'), array_keys($extension_manager->all_enabled()));
+ }
+
+}
diff --git a/tests/extension/metadata_manager_test.php b/tests/extension/metadata_manager_test.php
new file mode 100644
index 0000000000..ce7be0dea5
--- /dev/null
+++ b/tests/extension/metadata_manager_test.php
@@ -0,0 +1,431 @@
+<?php
+/**
+*
+* @package testing
+* @copyright (c) 2011 phpBB Group
+* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
+*
+*/
+
+class 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(array(
+ 'version' => '3.1.0',
+ ));
+ $this->db = $this->new_dbal();
+ $this->phpbb_root_path = dirname(__FILE__) . '/';
+ $this->phpEx = '.php';
+ $this->user = new phpbb_user();
+
+ $this->template = new phpbb_template(
+ $this->phpbb_root_path,
+ $this->phpEx,
+ $this->config,
+ $this->user,
+ new phpbb_style_resource_locator(),
+ new phpbb_template_context()
+ );
+
+ $this->extension_manager = new phpbb_extension_manager(
+ $this->db,
+ $this->config,
+ '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_extension_metadata_manager_test
+ */
+ private function get_metadata_manager($ext_name)
+ {
+ return new phpbb_extension_metadata_manager_test(
+ $ext_name,
+ $this->db,
+ $this->extension_manager,
+ $this->phpbb_root_path,
+ $this->phpEx,
+ $this->template,
+ $this->config
+ );
+ }
+}
+
+class phpbb_extension_metadata_manager_test extends phpbb_extension_metadata_manager
+{
+ public function set_metadata($metadata)
+ {
+ $this->metadata = $metadata;
+ }
+
+ public function merge_metadata($metadata)
+ {
+ $this->metadata = array_merge($this->metadata, $metadata);
+ }
+} \ No newline at end of file