aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoas Schilling <nickvergessen@gmx.de>2014-06-29 23:41:28 +0200
committerJoas Schilling <nickvergessen@gmx.de>2014-06-29 23:41:28 +0200
commit7ad88ba32b50e03a658166bffb628b39784db369 (patch)
tree6f484f7172afcf1dfaf51bdffcb402b2441181e8
parentfb3baba3e07813776bd0820667244ee61981a8a4 (diff)
parent5652f33ccca36b093a20033f17cb42ec79a581da (diff)
downloadforums-7ad88ba32b50e03a658166bffb628b39784db369.tar
forums-7ad88ba32b50e03a658166bffb628b39784db369.tar.gz
forums-7ad88ba32b50e03a658166bffb628b39784db369.tar.bz2
forums-7ad88ba32b50e03a658166bffb628b39784db369.tar.xz
forums-7ad88ba32b50e03a658166bffb628b39784db369.zip
Merge branch 'develop-ascraeus' into develop
* develop-ascraeus: [ticket/12777] Add tests for unavailable extension [ticket/12777] Add tests [ticket/12777] Add is_purged() [ticket/12777] Update doc block of is_configured() [ticket/12777] Rename extension status functions and add is_configured()
-rw-r--r--phpBB/includes/acp/acp_extensions.php12
-rw-r--r--phpBB/phpbb/console/command/extension/disable.php2
-rw-r--r--phpBB/phpbb/console/command/extension/enable.php2
-rw-r--r--phpBB/phpbb/console/command/extension/purge.php2
-rw-r--r--phpBB/phpbb/extension/manager.php42
-rw-r--r--tests/extension/manager_test.php46
6 files changed, 92 insertions, 14 deletions
diff --git a/phpBB/includes/acp/acp_extensions.php b/phpBB/includes/acp/acp_extensions.php
index b2a6820461..aba9caaece 100644
--- a/phpBB/includes/acp/acp_extensions.php
+++ b/phpBB/includes/acp/acp_extensions.php
@@ -137,7 +137,7 @@ class acp_extensions
trigger_error($user->lang['EXTENSION_NOT_AVAILABLE'] . adm_back_link($this->u_action), E_USER_WARNING);
}
- if ($phpbb_extension_manager->enabled($ext_name))
+ if ($phpbb_extension_manager->is_enabled($ext_name))
{
redirect($this->u_action);
}
@@ -162,7 +162,7 @@ class acp_extensions
trigger_error($user->lang['EXTENSION_NOT_AVAILABLE'] . adm_back_link($this->u_action), E_USER_WARNING);
}
- if ($phpbb_extension_manager->enabled($ext_name))
+ if ($phpbb_extension_manager->is_enabled($ext_name))
{
redirect($this->u_action);
}
@@ -194,7 +194,7 @@ class acp_extensions
break;
case 'disable_pre':
- if (!$phpbb_extension_manager->enabled($ext_name))
+ if (!$phpbb_extension_manager->is_enabled($ext_name))
{
redirect($this->u_action);
}
@@ -209,7 +209,7 @@ class acp_extensions
break;
case 'disable':
- if (!$phpbb_extension_manager->enabled($ext_name))
+ if (!$phpbb_extension_manager->is_enabled($ext_name))
{
redirect($this->u_action);
}
@@ -234,7 +234,7 @@ class acp_extensions
break;
case 'delete_data_pre':
- if ($phpbb_extension_manager->enabled($ext_name))
+ if ($phpbb_extension_manager->is_enabled($ext_name))
{
redirect($this->u_action);
}
@@ -248,7 +248,7 @@ class acp_extensions
break;
case 'delete_data':
- if ($phpbb_extension_manager->enabled($ext_name))
+ if ($phpbb_extension_manager->is_enabled($ext_name))
{
redirect($this->u_action);
}
diff --git a/phpBB/phpbb/console/command/extension/disable.php b/phpBB/phpbb/console/command/extension/disable.php
index 5f0e74b984..c04848aa01 100644
--- a/phpBB/phpbb/console/command/extension/disable.php
+++ b/phpBB/phpbb/console/command/extension/disable.php
@@ -37,7 +37,7 @@ class disable extends command
$this->manager->disable($name);
$this->manager->load_extensions();
- if ($this->manager->enabled($name))
+ if ($this->manager->is_enabled($name))
{
$output->writeln("<error>Could not disable extension $name</error>");
return 1;
diff --git a/phpBB/phpbb/console/command/extension/enable.php b/phpBB/phpbb/console/command/extension/enable.php
index 05e1d927c6..86a034cdf4 100644
--- a/phpBB/phpbb/console/command/extension/enable.php
+++ b/phpBB/phpbb/console/command/extension/enable.php
@@ -37,7 +37,7 @@ class enable extends command
$this->manager->enable($name);
$this->manager->load_extensions();
- if ($this->manager->enabled($name))
+ if ($this->manager->is_enabled($name))
{
$this->log->add('admin', ANONYMOUS, '', 'LOG_EXT_ENABLE', time(), array($name));
$output->writeln("<info>Successfully enabled extension $name</info>");
diff --git a/phpBB/phpbb/console/command/extension/purge.php b/phpBB/phpbb/console/command/extension/purge.php
index 4e57641d83..841598b90a 100644
--- a/phpBB/phpbb/console/command/extension/purge.php
+++ b/phpBB/phpbb/console/command/extension/purge.php
@@ -37,7 +37,7 @@ class purge extends command
$this->manager->purge($name);
$this->manager->load_extensions();
- if ($this->manager->enabled($name))
+ if ($this->manager->is_enabled($name))
{
$output->writeln("<error>Could not purge extension $name</error>");
return 1;
diff --git a/phpBB/phpbb/extension/manager.php b/phpBB/phpbb/extension/manager.php
index 4130e8455a..b19eb9f8a3 100644
--- a/phpBB/phpbb/extension/manager.php
+++ b/phpBB/phpbb/extension/manager.php
@@ -515,7 +515,7 @@ class manager
* @param string $name Extension name to check NOTE: Can be user input
* @return bool Depending on whether or not the extension is available
*/
- public function available($name)
+ public function is_available($name)
{
return file_exists($this->get_extension_path($name, true));
}
@@ -526,12 +526,50 @@ class manager
* @param string $name Extension name to check
* @return bool Depending on whether or not the extension is enabled
*/
- public function enabled($name)
+ public function is_enabled($name)
{
return isset($this->extensions[$name]) && $this->extensions[$name]['ext_active'];
}
/**
+ * Check to see if a given extension is disabled
+ *
+ * @param string $name Extension name to check
+ * @return bool Depending on whether or not the extension is disabled
+ */
+ public function is_disabled($name)
+ {
+ return isset($this->extensions[$name]) && !$this->extensions[$name]['ext_active'];
+ }
+
+ /**
+ * Check to see if a given extension is configured
+ *
+ * All enabled and disabled extensions are considered configured. A purged
+ * extension that is no longer in the database is not configured.
+ *
+ * @param string $name Extension name to check
+ * @return bool Depending on whether or not the extension is configured
+ */
+ public function is_configured($name)
+ {
+ return isset($this->extensions[$name]);
+ }
+
+ /**
+ * Check to see if a given extension is purged
+ *
+ * An extension is purged if it is available, not enabled and not disabled.
+ *
+ * @param string $name Extension name to check
+ * @return bool Depending on whether or not the extension is purged
+ */
+ public function is_purged($name)
+ {
+ return $this->is_available($name) && !$this->is_configured($name);
+ }
+
+ /**
* Instantiates a \phpbb\finder.
*
* @param bool $use_all_available Should we load all extensions, or just enabled ones
diff --git a/tests/extension/manager_test.php b/tests/extension/manager_test.php
index d9f8fbd1a4..230c90c7c7 100644
--- a/tests/extension/manager_test.php
+++ b/tests/extension/manager_test.php
@@ -32,22 +32,62 @@ class phpbb_extension_manager_test extends phpbb_database_test_case
$this->extension_manager = $this->create_extension_manager();
}
- public function test_available()
+ 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'), array_keys($this->extension_manager->all_available()));
}
- public function test_enabled()
+ public function test_all_enabled()
{
$this->assertEquals(array('vendor2/foo'), array_keys($this->extension_manager->all_enabled()));
}
- public function test_configured()
+ 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;