From d13e02c7b100ac43943f11912a8f4acb740f69b6 Mon Sep 17 00:00:00 2001
From: Tristan Darricau <github@nicofuma.fr>
Date: Fri, 27 Jun 2014 10:49:13 +0200
Subject: [PATCH 1/5] [ticket/12777] Rename extension status functions and add
 is_configured()

PHPBB3-12777
---
 phpBB/includes/acp/acp_extensions.php         | 12 ++++-----
 .../console/command/extension/disable.php     |  2 +-
 .../console/command/extension/enable.php      |  2 +-
 .../phpbb/console/command/extension/purge.php |  2 +-
 phpBB/phpbb/extension/manager.php             | 27 +++++++++++++++++--
 5 files changed, 34 insertions(+), 11 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 0cdf26d4db..d0d0c9f1cc 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_EXTENSION_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..580960ca01 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,11 +526,34 @@ 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
+	*
+	* @param string $name Extension name to check
+	* @return bool Depending on whether or not the extension is configured
+	* @see all_configured()
+	*/
+	public function is_configured($name)
+	{
+		return isset($this->extensions[$name]);
+	}
+
 	/**
 	* Instantiates a \phpbb\finder.
 	*

From 4d9e451f6037924329336ae3b01990fc7ef5828b Mon Sep 17 00:00:00 2001
From: Tristan Darricau <github@nicofuma.fr>
Date: Fri, 27 Jun 2014 11:23:11 +0200
Subject: [PATCH 2/5] [ticket/12777] Update doc block of is_configured()

PHPBB3-12777
---
 phpBB/phpbb/extension/manager.php | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/phpBB/phpbb/extension/manager.php b/phpBB/phpbb/extension/manager.php
index 580960ca01..95496926eb 100644
--- a/phpBB/phpbb/extension/manager.php
+++ b/phpBB/phpbb/extension/manager.php
@@ -545,9 +545,11 @@ class manager
 	/**
 	* 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
-	* @see all_configured()
 	*/
 	public function is_configured($name)
 	{

From 8e8b493fae59aba59e1ea732c1f93d66f59fb640 Mon Sep 17 00:00:00 2001
From: Tristan Darricau <github@nicofuma.fr>
Date: Fri, 27 Jun 2014 11:28:13 +0200
Subject: [PATCH 3/5] [ticket/12777] Add is_purged()

PHPBB3-12777
---
 phpBB/phpbb/extension/manager.php | 13 +++++++++++++
 1 file changed, 13 insertions(+)

diff --git a/phpBB/phpbb/extension/manager.php b/phpBB/phpbb/extension/manager.php
index 95496926eb..b19eb9f8a3 100644
--- a/phpBB/phpbb/extension/manager.php
+++ b/phpBB/phpbb/extension/manager.php
@@ -556,6 +556,19 @@ class manager
 		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.
 	*

From e6b8ae6bd5eb211cc61b19f09c96cf7641f8491f Mon Sep 17 00:00:00 2001
From: Tristan Darricau <github@nicofuma.fr>
Date: Fri, 27 Jun 2014 16:53:14 +0200
Subject: [PATCH 4/5] [ticket/12777] Add tests

PHPBB3-12777
---
 tests/extension/manager_test.php | 41 +++++++++++++++++++++++++++++---
 1 file changed, 38 insertions(+), 3 deletions(-)

diff --git a/tests/extension/manager_test.php b/tests/extension/manager_test.php
index d9f8fbd1a4..de7afdee65 100644
--- a/tests/extension/manager_test.php
+++ b/tests/extension/manager_test.php
@@ -32,22 +32,57 @@ 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'));
+	}
+
+	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'));
+	}
+
+	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'));
+	}
+
+	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'));
+	}
+
+	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'));
+	}
+
 	public function test_enable()
 	{
 		vendor2\bar\ext::$state = 0;

From daeb635d6c27d94fe2f7135ab4d921da5d870447 Mon Sep 17 00:00:00 2001
From: Tristan Darricau <github@nicofuma.fr>
Date: Fri, 27 Jun 2014 18:35:35 +0200
Subject: [PATCH 5/5] [ticket/12777] Add tests for unavailable extension

PHPBB3-12777
---
 tests/extension/manager_test.php | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/tests/extension/manager_test.php b/tests/extension/manager_test.php
index de7afdee65..230c90c7c7 100644
--- a/tests/extension/manager_test.php
+++ b/tests/extension/manager_test.php
@@ -53,6 +53,7 @@ class phpbb_extension_manager_test extends phpbb_database_test_case
 		$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()
@@ -60,6 +61,7 @@ class phpbb_extension_manager_test extends phpbb_database_test_case
 		$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()
@@ -67,6 +69,7 @@ class phpbb_extension_manager_test extends phpbb_database_test_case
 		$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()
@@ -74,6 +77,7 @@ class phpbb_extension_manager_test extends phpbb_database_test_case
 		$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()
@@ -81,6 +85,7 @@ class phpbb_extension_manager_test extends phpbb_database_test_case
 		$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()