mirror of
https://github.com/phpbb/phpbb.git
synced 2025-08-06 16:56:44 +02:00
[ticket/16891] Do not change an extension status in the middle of a request
When enabling an extension, it should be considered as not being enabled for the entire request as if the "enabled" flag is switch during the request, the extension will stay not loaded (same when disabling an extension). Example when it can be an issue today : if the router is called for the first time after enabling the extension and if the extension uses a custom route loader (like phpbb/pages) then the router will fail because the custom route will be found but the custom loader will not be loaded and available. PHPBB3-16891
This commit is contained in:
@@ -80,6 +80,7 @@ class phpbb_dbal_migrator_test extends phpbb_database_test_case
|
||||
$this->db,
|
||||
$this->config,
|
||||
new phpbb\filesystem\filesystem(),
|
||||
new phpbb_mock_dummy_router(),
|
||||
'phpbb_ext',
|
||||
__DIR__ . '/../../phpBB/',
|
||||
'php',
|
||||
|
@@ -30,6 +30,7 @@ class phpbb_extension_manager_test extends phpbb_database_test_case
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->db = null;
|
||||
$this->extension_manager = $this->create_extension_manager();
|
||||
}
|
||||
|
||||
@@ -95,7 +96,12 @@ class phpbb_extension_manager_test extends phpbb_database_test_case
|
||||
|
||||
$this->assertEquals(array('vendor2/foo'), array_keys($this->extension_manager->all_enabled()));
|
||||
$this->extension_manager->enable('vendor2/bar');
|
||||
$this->assertEquals(array('vendor2/bar', 'vendor2/foo'), array_keys($this->extension_manager->all_enabled()));
|
||||
|
||||
// We should not display the extension as being enabled in the same request
|
||||
$this->assertEquals(array('vendor2/foo'), array_keys($this->extension_manager->all_enabled()));
|
||||
// With a different request we should see the extension as being disabled
|
||||
$this->assertEquals(array('vendor2/bar', 'vendor2/foo'), array_keys($this->create_extension_manager()->all_enabled()));
|
||||
|
||||
$this->assertEquals(array('vendor/moo', 'vendor2/bar', 'vendor2/foo'), array_keys($this->extension_manager->all_configured()));
|
||||
|
||||
$this->assertEquals(4, vendor2\bar\ext::$state);
|
||||
@@ -119,7 +125,12 @@ class phpbb_extension_manager_test extends phpbb_database_test_case
|
||||
|
||||
$this->assertEquals(array('vendor2/foo'), array_keys($this->extension_manager->all_enabled()));
|
||||
$this->extension_manager->disable('vendor2/foo');
|
||||
$this->assertEquals(array(), array_keys($this->extension_manager->all_enabled()));
|
||||
|
||||
// We should still display the extension as being enabled in the current request
|
||||
$this->assertEquals(array('vendor2/foo'), array_keys($this->extension_manager->all_enabled()));
|
||||
// With a different request we should see the extension as being disabled
|
||||
$this->assertEquals(array(), array_keys($this->create_extension_manager()->all_enabled()));
|
||||
|
||||
$this->assertEquals(array('vendor/moo', 'vendor2/foo'), array_keys($this->extension_manager->all_configured()));
|
||||
|
||||
$this->assertTrue(vendor2\foo\ext::$disabled);
|
||||
@@ -147,7 +158,6 @@ class phpbb_extension_manager_test extends phpbb_database_test_case
|
||||
|
||||
protected function create_extension_manager($with_cache = true)
|
||||
{
|
||||
|
||||
$config = new \phpbb\config\config(array('version' => PHPBB_VERSION));
|
||||
$db = $this->new_dbal();
|
||||
$factory = new \phpbb\db\tools\factory();
|
||||
@@ -177,6 +187,7 @@ class phpbb_extension_manager_test extends phpbb_database_test_case
|
||||
$db,
|
||||
$config,
|
||||
new \phpbb\filesystem\filesystem(),
|
||||
new phpbb_mock_dummy_router(),
|
||||
'phpbb_ext',
|
||||
__DIR__ . '/',
|
||||
$php_ext,
|
||||
|
@@ -98,6 +98,7 @@ class phpbb_extension_metadata_manager_test extends phpbb_database_test_case
|
||||
$this->db,
|
||||
$this->config,
|
||||
new \phpbb\filesystem\filesystem(),
|
||||
new phpbb_mock_dummy_router(),
|
||||
'phpbb_ext',
|
||||
$this->phpbb_root_path,
|
||||
$this->phpEx,
|
||||
|
31
tests/mock/dummy_router.php
Normal file
31
tests/mock/dummy_router.php
Normal file
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* This file is part of the phpBB Forum Software package.
|
||||
*
|
||||
* @copyright (c) phpBB Limited <https://www.phpbb.com>
|
||||
* @license GNU General Public License, version 2 (GPL-2.0)
|
||||
*
|
||||
* For full copyright and license information, please see
|
||||
* the docs/CREDITS.txt file.
|
||||
*
|
||||
*/
|
||||
|
||||
class phpbb_mock_dummy_router extends phpbb_mock_router
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
}
|
||||
|
||||
public function get_matcher()
|
||||
{
|
||||
$this->create_new_url_matcher();
|
||||
return parent::get_matcher();
|
||||
}
|
||||
|
||||
public function get_generator()
|
||||
{
|
||||
$this->create_new_url_generator();
|
||||
return parent::get_generator();
|
||||
}
|
||||
}
|
@@ -11,6 +11,7 @@
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
class phpbb_mock_extension_manager extends \phpbb\extension\manager
|
||||
{
|
||||
public function __construct($phpbb_root_path, $extensions = array(), $container = null)
|
||||
@@ -25,5 +26,6 @@ class phpbb_mock_extension_manager extends \phpbb\extension\manager
|
||||
$this->container = $container;
|
||||
$this->config = new \phpbb\config\config(array());
|
||||
$this->user = new \phpbb\user($lang,'\phpbb\datetime');
|
||||
$this->router = new phpbb_mock_dummy_router();
|
||||
}
|
||||
}
|
||||
|
@@ -261,6 +261,7 @@ class phpbb_functional_test_case extends phpbb_test_case
|
||||
$db,
|
||||
$config,
|
||||
new phpbb\filesystem\filesystem(),
|
||||
new phpbb_mock_dummy_router(),
|
||||
self::$config['table_prefix'] . 'ext',
|
||||
__DIR__ . '/',
|
||||
$phpEx,
|
||||
|
Reference in New Issue
Block a user