mirror of
https://github.com/phpbb/phpbb.git
synced 2025-08-01 14:30:32 +02:00
[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
This commit is contained in:
@@ -32,7 +32,7 @@ else
|
||||
require_once $phpbb_root_path . 'includes/constants.php';
|
||||
require_once $phpbb_root_path . 'includes/class_loader.' . $phpEx;
|
||||
|
||||
$class_loader = new phpbb_class_loader($phpbb_root_path, '.php');
|
||||
$class_loader = new phpbb_class_loader($phpbb_root_path . 'includes/', $phpbb_root_path . 'ext/', '.php');
|
||||
$class_loader->register();
|
||||
|
||||
require_once 'test_framework/phpbb_test_case_helpers.php';
|
||||
|
@@ -26,7 +26,7 @@ class phpbb_class_loader_test extends PHPUnit_Framework_TestCase
|
||||
public function test_resolve_path()
|
||||
{
|
||||
$prefix = dirname(__FILE__) . '/';
|
||||
$class_loader = new phpbb_class_loader($prefix);
|
||||
$class_loader = new phpbb_class_loader($prefix . 'includes/', $prefix . 'ext/');
|
||||
|
||||
$prefix .= 'includes/';
|
||||
|
||||
@@ -56,6 +56,11 @@ class phpbb_class_loader_test extends PHPUnit_Framework_TestCase
|
||||
$class_loader->resolve_path('phpbb_dir2'),
|
||||
'Class with name of dir within dir (short class name)'
|
||||
);
|
||||
$this->assertEquals(
|
||||
dirname(__FILE__) . '/ext/foo/class.php',
|
||||
$class_loader->resolve_path('phpbb_ext_foo_class'),
|
||||
'Extension class'
|
||||
);
|
||||
}
|
||||
|
||||
public function test_resolve_cached()
|
||||
@@ -64,7 +69,7 @@ class phpbb_class_loader_test extends PHPUnit_Framework_TestCase
|
||||
$cache = new phpbb_mock_cache($cacheMap);
|
||||
|
||||
$prefix = dirname(__FILE__) . '/';
|
||||
$class_loader = new phpbb_class_loader($prefix, '.php', $cache);
|
||||
$class_loader = new phpbb_class_loader($prefix . 'includes/', $prefix . 'ext/', '.php', $cache);
|
||||
|
||||
$prefix .= 'includes/';
|
||||
|
||||
|
6
tests/class_loader/ext/foo/class.php
Normal file
6
tests/class_loader/ext/foo/class.php
Normal file
@@ -0,0 +1,6 @@
|
||||
<?php
|
||||
|
||||
class phpbb_ext_foo_class
|
||||
{
|
||||
}
|
||||
|
5
tests/extension/ext/bar/my/hidden_class.php
Normal file
5
tests/extension/ext/bar/my/hidden_class.php
Normal file
@@ -0,0 +1,5 @@
|
||||
<?php
|
||||
|
||||
class phpbb_ext_bar_my_hidden_class
|
||||
{
|
||||
}
|
5
tests/extension/ext/foo/a_class.php
Normal file
5
tests/extension/ext/foo/a_class.php
Normal file
@@ -0,0 +1,5 @@
|
||||
<?php
|
||||
|
||||
class phpbb_ext_foo_a_class
|
||||
{
|
||||
}
|
5
tests/extension/ext/foo/b_class.php
Normal file
5
tests/extension/ext/foo/b_class.php
Normal file
@@ -0,0 +1,5 @@
|
||||
<?php
|
||||
|
||||
class phpbb_ext_foo_b_class
|
||||
{
|
||||
}
|
5
tests/extension/ext/foo/foo.php
Normal file
5
tests/extension/ext/foo/foo.php
Normal file
@@ -0,0 +1,5 @@
|
||||
<?php
|
||||
|
||||
class phpbb_ext_foo extends phpbb_extension_base
|
||||
{
|
||||
}
|
5
tests/extension/ext/foo/sub/type/alternative.php
Normal file
5
tests/extension/ext/foo/sub/type/alternative.php
Normal file
@@ -0,0 +1,5 @@
|
||||
<?php
|
||||
|
||||
class phpbb_ext_foo_sub_type_alternative
|
||||
{
|
||||
}
|
5
tests/extension/ext/foo/type/alternative.php
Normal file
5
tests/extension/ext/foo/type/alternative.php
Normal file
@@ -0,0 +1,5 @@
|
||||
<?php
|
||||
|
||||
class phpbb_ext_foo_type_alternative
|
||||
{
|
||||
}
|
5
tests/extension/ext/foo/typewrong/error.php
Normal file
5
tests/extension/ext/foo/typewrong/error.php
Normal file
@@ -0,0 +1,5 @@
|
||||
<?php
|
||||
|
||||
class phpbb_ext_foo_typewrong_error
|
||||
{
|
||||
}
|
5
tests/extension/ext/moo/feature_class.php
Normal file
5
tests/extension/ext/moo/feature_class.php
Normal file
@@ -0,0 +1,5 @@
|
||||
<?php
|
||||
|
||||
class phpbb_ext_moo_feature_class
|
||||
{
|
||||
}
|
133
tests/extension/finder_test.php
Normal file
133
tests/extension/finder_test.php
Normal file
@@ -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
|
||||
);
|
||||
}
|
||||
}
|
15
tests/extension/fixtures/extensions.xml
Normal file
15
tests/extension/fixtures/extensions.xml
Normal file
@@ -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>
|
5
tests/extension/includes/default/implementation.php
Normal file
5
tests/extension/includes/default/implementation.php
Normal file
@@ -0,0 +1,5 @@
|
||||
<?php
|
||||
|
||||
class phpbb_default_impl_class implements phpbb_default_interface
|
||||
{
|
||||
}
|
89
tests/extension/manager_test.php
Normal file
89
tests/extension/manager_test.php
Normal file
@@ -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()));
|
||||
}
|
||||
}
|
16
tests/mock/extension_manager.php
Normal file
16
tests/mock/extension_manager.php
Normal file
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* @package testing
|
||||
* @copyright (c) 2011 phpBB Group
|
||||
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
|
||||
*
|
||||
*/
|
||||
|
||||
class phpbb_mock_extension_manager extends phpbb_extension_manager
|
||||
{
|
||||
public function __construct($extensions = array())
|
||||
{
|
||||
$this->extensions = $extensions;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user