1
0
mirror of https://github.com/phpbb/phpbb.git synced 2025-08-06 08:47:45 +02:00

Merge remote-tracking branch 'naderman/feature/extension-manager' into develop

* naderman/feature/extension-manager: (67 commits)
  [feature/extension-manager] Removing now unused acp_search code
  [feature/extension-manager] Split disabling extensions up into steps as well
  [feature/extension-manager] Add documentation on caching in ext finder
  [feature/extension-manager] Reference correct new module basenames in install
  [feature/extension-manager] Rename default methods to core methods on finder.
  [feature/extension-manager] Document what the class loader stores in cache
  [feature/extension-manager] Add docblock to cached paths map in class loader
  [feature/extension-manager] Clear up docs of extension related template changes
  [feature/extension-manager] Use "core files" instead of "global files" in docs
  [feature/extension-manager] Add docblocks to new search backend methods
  [feature/extension-manager] Add docblocks to new methods in functions_module
  [feature/extension-manager] Clarify comment on ext meta class instantiator
  [feature/extension-manager] Add more info on suffixes in extension finder
  [feature/extension-manager] Clarify is_dir parameter description
  [feature/extension-manager] Clarify class finding method docblock
  [feature/extension-manager] Correct default path comment & remove double strlen
  [feature/extension-manager] Fix "disbale" typo in comment
  [feature/extension-manager] Properly remove old ACP language loading code
  [feature/extension-manager] Support extensions in subdirectories of ext/
  [feature/extension-manager] Add prefix to extension meta data / install classes
  ...
This commit is contained in:
Igor Wiedler
2011-11-19 01:20:22 +01:00
74 changed files with 2574 additions and 534 deletions

View File

@@ -32,8 +32,10 @@ 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->register();
$phpbb_class_loader_ext = new phpbb_class_loader('phpbb_ext_', $phpbb_root_path . 'ext/', ".php");
$phpbb_class_loader_ext->register();
$phpbb_class_loader = new phpbb_class_loader('phpbb_', $phpbb_root_path . 'includes/', ".php");
$phpbb_class_loader->register();
require_once 'test_framework/phpbb_test_case_helpers.php';
require_once 'test_framework/phpbb_test_case.php';

View File

@@ -13,20 +13,26 @@ class phpbb_class_loader_test extends PHPUnit_Framework_TestCase
{
public function setUp()
{
global $class_loader;
$class_loader->unregister();
global $phpbb_class_loader;
$phpbb_class_loader->unregister();
global $phpbb_class_loader_ext;
$phpbb_class_loader_ext->unregister();
}
public function tearDown()
{
global $class_loader;
$class_loader->register();
global $phpbb_class_loader_ext;
$phpbb_class_loader_ext->register();
global $phpbb_class_loader;
$phpbb_class_loader->register();
}
public function test_resolve_path()
{
$prefix = dirname(__FILE__) . '/';
$class_loader = new phpbb_class_loader($prefix);
$class_loader = new phpbb_class_loader('phpbb_', $prefix . 'includes/');
$prefix .= 'includes/';
@@ -60,11 +66,15 @@ class phpbb_class_loader_test extends PHPUnit_Framework_TestCase
public function test_resolve_cached()
{
$cacheMap = array('class_loader' => array('phpbb_a_cached_name' => 'a/cached_name'));
$cache = new phpbb_mock_cache($cacheMap);
$cache_map = array(
'class_loader_phpbb_' => array('phpbb_a_cached_name' => 'a/cached_name'),
'class_loader_phpbb_ext_' => array('phpbb_ext_foo' => 'foo'),
);
$cache = new phpbb_mock_cache($cache_map);
$prefix = dirname(__FILE__) . '/';
$class_loader = new phpbb_class_loader($prefix, '.php', $cache);
$class_loader = new phpbb_class_loader('phpbb_', $prefix . 'includes/', '.php', $cache);
$class_loader_ext = new phpbb_class_loader('phpbb_ext_', $prefix . 'includes/', '.php', $cache);
$prefix .= 'includes/';
@@ -74,13 +84,22 @@ class phpbb_class_loader_test extends PHPUnit_Framework_TestCase
'Class in a directory'
);
$this->assertFalse($class_loader->resolve_path('phpbb_ext_foo'));
$this->assertFalse($class_loader_ext->resolve_path('phpbb_a_cached_name'));
$this->assertEquals(
$prefix . 'a/cached_name.php',
$class_loader->resolve_path('phpbb_a_cached_name'),
'Class in a directory'
'Cached class found'
);
$cacheMap['class_loader']['phpbb_dir_class_name'] = 'dir/class_name';
$cache->check($this, $cacheMap);
$this->assertEquals(
$prefix . 'foo.php',
$class_loader_ext->resolve_path('phpbb_ext_foo'),
'Cached class found in alternative loader'
);
$cache_map['class_loader_phpbb_']['phpbb_dir_class_name'] = 'dir/class_name';
$cache->check($this, $cache_map);
}
}

View File

@@ -7,7 +7,7 @@
*
*/
class phpbb_cron_task_testmod_dummy_task extends phpbb_cron_task_base
class phpbb_ext_testext_cron_dummy_task extends phpbb_cron_task_base
{
public static $was_run = 0;

View File

@@ -0,0 +1,23 @@
<?php
/**
*
* @package testing
* @copyright (c) 2010 phpBB Group
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
*
*/
class phpbb_cron_task_core_dummy_task extends phpbb_cron_task_base
{
public static $was_run = 0;
public function run()
{
self::$was_run++;
}
public function should_run()
{
return true;
}
}

View File

@@ -7,7 +7,7 @@
*
*/
class phpbb_cron_task_testmod_second_dummy_task extends phpbb_cron_task_base
class phpbb_cron_task_core_second_dummy_task extends phpbb_cron_task_base
{
public static $was_run = 0;

View File

@@ -7,25 +7,24 @@
*
*/
require_once dirname(__FILE__) . '/../mock/cache.php';
require_once dirname(__FILE__) . '/task/testmod/dummy_task.php';
require_once dirname(__FILE__) . '/task/testmod/second_dummy_task.php';
require_once dirname(__FILE__) . '/task2/testmod/simple_ready.php';
require_once dirname(__FILE__) . '/task2/testmod/simple_not_runnable.php';
require_once dirname(__FILE__) . '/task2/testmod/simple_should_not_run.php';
require_once dirname(__FILE__) . '/../mock/extension_manager.php';
require_once dirname(__FILE__) . '/includes/cron/task/core/dummy_task.php';
require_once dirname(__FILE__) . '/includes/cron/task/core/second_dummy_task.php';
require_once dirname(__FILE__) . '/ext/testext/cron/dummy_task.php';
require_once dirname(__FILE__) . '/tasks/simple_ready.php';
require_once dirname(__FILE__) . '/tasks/simple_not_runnable.php';
require_once dirname(__FILE__) . '/tasks/simple_should_not_run.php';
class phpbb_cron_manager_test extends PHPUnit_Framework_TestCase
{
public function setUp()
{
$this->manager = new phpbb_cron_manager(dirname(__FILE__) . '/task/', 'php');
$this->task_name = 'phpbb_cron_task_testmod_dummy_task';
}
public function test_manager_finds_shipped_tasks()
{
$tasks = $this->manager->find_cron_task_names();
$this->assertEquals(2, sizeof($tasks));
$this->manager = new phpbb_cron_manager(array(
'phpbb_cron_task_core_dummy_task',
'phpbb_cron_task_core_second_dummy_task',
'phpbb_ext_testext_cron_dummy_task',
));
$this->task_name = 'phpbb_cron_task_core_dummy_task';
}
public function test_manager_finds_shipped_task_by_name()
@@ -45,7 +44,7 @@ class phpbb_cron_manager_test extends PHPUnit_Framework_TestCase
public function test_manager_finds_all_ready_tasks()
{
$tasks = $this->manager->find_all_ready_tasks();
$this->assertEquals(2, sizeof($tasks));
$this->assertEquals(3, sizeof($tasks));
}
public function test_manager_finds_one_ready_task()
@@ -54,21 +53,16 @@ class phpbb_cron_manager_test extends PHPUnit_Framework_TestCase
$this->assertInstanceOf('phpbb_cron_task_wrapper', $task);
}
public function test_manager_finds_all_ready_tasks_cached()
{
$cache = new phpbb_mock_cache(array('_cron_tasks' => array($this->task_name)));
$manager = new phpbb_cron_manager(dirname(__FILE__) . '/../../phpBB/', 'php', $cache);
$tasks = $manager->find_all_ready_tasks();
$this->assertEquals(1, sizeof($tasks));
}
public function test_manager_finds_only_ready_tasks()
{
$manager = new phpbb_cron_manager(dirname(__FILE__) . '/task2/', 'php');
$manager = new phpbb_cron_manager(array(
'phpbb_cron_task_core_simple_ready',
'phpbb_cron_task_core_simple_not_runnable',
'phpbb_cron_task_core_simple_should_not_run',
));
$tasks = $manager->find_all_ready_tasks();
$task_names = $this->tasks_to_names($tasks);
$this->assertEquals(array('phpbb_cron_task_testmod_simple_ready'), $task_names);
$this->assertEquals(array('phpbb_cron_task_core_simple_ready'), $task_names);
}
private function tasks_to_names($tasks)

View File

@@ -1,8 +0,0 @@
<?php
class phpbb_cron_task_testmod_simple_ready extends phpbb_cron_task_base
{
public function run()
{
}
}

View File

@@ -0,0 +1,43 @@
<?php
/**
*
* @package testing
* @copyright (c) 2010 phpBB Group
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
*
*/
require_once dirname(__FILE__) . '/../mock/extension_manager.php';
class phpbb_cron_task_provider_test extends PHPUnit_Framework_TestCase
{
public function setUp()
{
$this->extension_manager = new phpbb_mock_extension_manager(
dirname(__FILE__) . '/',
array(
'testext' => array(
'ext_name' => 'testext',
'ext_active' => true,
'ext_path' => 'ext/testext/'
),
));
$this->provider = new phpbb_cron_task_provider($this->extension_manager);
}
public function test_manager_finds_shipped_tasks()
{
$tasks = array();
foreach ($this->provider as $task)
{
$tasks[] = $task;
}
sort($tasks);
$this->assertEquals(array(
'phpbb_cron_task_core_dummy_task',
'phpbb_cron_task_core_second_dummy_task',
'phpbb_ext_testext_cron_dummy_task',
), $tasks);
}
}

View File

@@ -1,6 +1,6 @@
<?php
class phpbb_cron_task_testmod_simple_not_runnable extends phpbb_cron_task_base
class phpbb_cron_task_core_simple_not_runnable extends phpbb_cron_task_base
{
public function run()
{

View File

@@ -0,0 +1,8 @@
<?php
class phpbb_cron_task_core_simple_ready extends phpbb_cron_task_base
{
public function run()
{
}
}

View File

@@ -1,6 +1,6 @@
<?php
class phpbb_cron_task_testmod_simple_should_not_run extends phpbb_cron_task_base
class phpbb_cron_task_core_simple_should_not_run extends phpbb_cron_task_base
{
public function run()
{

View File

@@ -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;
}
}

View File

@@ -0,0 +1,5 @@
<?php
class phpbb_ext_bar_my_hidden_class
{
}

View File

@@ -0,0 +1,5 @@
<?php
class phpbb_ext_foo_a_class
{
}

View File

@@ -0,0 +1,5 @@
<?php
class phpbb_ext_foo_b_class
{
}

View File

@@ -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;
}
}

View File

@@ -0,0 +1,5 @@
<?php
class phpbb_ext_foo_sub_type_alternative
{
}

View File

@@ -0,0 +1,5 @@
<?php
class phpbb_ext_foo_type_alternative
{
}

View File

@@ -0,0 +1,5 @@
<?php
class phpbb_ext_foo_typewrong_error
{
}

13
tests/extension/ext/vendor/moo/ext.php vendored Normal file
View File

@@ -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;
}
}

View File

@@ -0,0 +1,5 @@
<?php
class phpbb_ext_vendor_moo_feature_class
{
}

View File

@@ -0,0 +1,206 @@
<?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(
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
);
}
}

View 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>vendor/moo</value>
<value>0</value>
</row>
</table>
</dataset>

View File

@@ -0,0 +1,5 @@
<?php
class phpbb_default_impl_class implements phpbb_default_interface
{
}

View File

@@ -0,0 +1,102 @@
<?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__) . '/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(),
'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(),
'phpbb_ext',
dirname(__FILE__) . '/',
'.php'
);
$this->assertEquals(array('foo'), array_keys($extension_manager->all_enabled()));
}
}

View File

@@ -59,6 +59,21 @@ class phpbb_mock_cache implements phpbb_cache_driver_interface
$test->assertEquals($data, $this->data[$var_name]);
}
public function checkAssociativeVar(PHPUnit_Framework_Assert $test, $var_name, $data, $sort = true)
{
$test->assertTrue(isset($this->data[$var_name]));
if ($sort)
{
foreach ($this->data[$var_name] as &$content)
{
sort($content);
}
}
$test->assertEquals($data, $this->data[$var_name]);
}
public function checkVarUnset(PHPUnit_Framework_Assert $test, $var_name)
{
$test->assertFalse(isset($this->data[$var_name]));

View File

@@ -0,0 +1,18 @@
<?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($phpbb_root_path, $extensions = array())
{
$this->phpbb_root_path = $phpbb_root_path;
$this->phpEx = '.php';
$this->extensions = $extensions;
}
}

View File

@@ -69,7 +69,8 @@ class phpbb_template_template_inheritance_test extends phpbb_template_template_t
$this->template_path = dirname(__FILE__) . '/templates';
$this->parent_template_path = dirname(__FILE__) . '/parent_templates';
$this->template_locator = new phpbb_template_locator();
$this->template = new phpbb_template($phpbb_root_path, $phpEx, $config, $user, $this->template_locator);
$this->template_provider = new phpbb_template_path_provider();
$this->template = new phpbb_template($phpbb_root_path, $phpEx, $config, $user, $this->template_locator, $this->template_provider);
$this->template->set_custom_template($this->template_path, 'tests', $this->parent_template_path);
}
}

View File

@@ -277,7 +277,7 @@ class phpbb_template_template_test extends phpbb_template_template_test_case
$this->template->set_filenames(array('test' => $filename));
$this->assertFileNotExists($this->template_path . '/' . $filename, 'Testing missing file, file cannot exist');
$expecting = sprintf('template locator: File %s does not exist', realpath($this->template_path . '/../') . '/templates/' . $filename);
$expecting = sprintf('template locator: File for handle test does not exist. Could not find: %s', realpath($this->template_path . '/../') . '/templates/' . $filename);
$this->setExpectedTriggerError(E_USER_ERROR, $expecting);
$this->display('test');

View File

@@ -8,12 +8,14 @@
*/
require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php';
require_once dirname(__FILE__) . '/../mock/extension_manager.php';
class phpbb_template_template_test_case extends phpbb_test_case
{
protected $template;
protected $template_path;
protected $template_locator;
protected $template_provider;
// Keep the contents of the cache for debugging?
const PRESERVE_CACHE = true;
@@ -57,7 +59,8 @@ class phpbb_template_template_test_case extends phpbb_test_case
$this->template_path = dirname(__FILE__) . '/templates';
$this->template_locator = new phpbb_template_locator();
$this->template = new phpbb_template($phpbb_root_path, $phpEx, $config, $user, $this->template_locator);
$this->template_provider = new phpbb_template_path_provider();
$this->template = new phpbb_template($phpbb_root_path, $phpEx, $config, $user, $this->template_locator, $this->template_provider);
$this->template->set_custom_template($this->template_path, 'tests');
}