aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/bootstrap.php6
-rw-r--r--tests/class_loader/class_loader_test.php41
-rw-r--r--tests/cron/ext/testext/cron/dummy_task.php (renamed from tests/cron/task/testmod/dummy_task.php)2
-rw-r--r--tests/cron/includes/cron/task/core/dummy_task.php23
-rw-r--r--tests/cron/includes/cron/task/core/second_dummy_task.php (renamed from tests/cron/task/testmod/second_dummy_task.php)2
-rw-r--r--tests/cron/manager_test.php46
-rw-r--r--tests/cron/task2/testmod/simple_ready.php8
-rw-r--r--tests/cron/task_provider_test.php43
-rw-r--r--tests/cron/tasks/simple_not_runnable.php (renamed from tests/cron/task2/testmod/simple_not_runnable.php)2
-rw-r--r--tests/cron/tasks/simple_ready.php8
-rw-r--r--tests/cron/tasks/simple_should_not_run.php (renamed from tests/cron/task2/testmod/simple_should_not_run.php)2
-rw-r--r--tests/extension/ext/bar/ext.php24
-rw-r--r--tests/extension/ext/bar/my/hidden_class.php5
-rw-r--r--tests/extension/ext/foo/a_class.php5
-rw-r--r--tests/extension/ext/foo/b_class.php5
-rw-r--r--tests/extension/ext/foo/ext.php13
-rw-r--r--tests/extension/ext/foo/sub/type/alternative.php5
-rw-r--r--tests/extension/ext/foo/type/alternative.php5
-rw-r--r--tests/extension/ext/foo/typewrong/error.php5
-rw-r--r--tests/extension/ext/vendor/moo/ext.php13
-rw-r--r--tests/extension/ext/vendor/moo/feature_class.php5
-rw-r--r--tests/extension/finder_test.php206
-rw-r--r--tests/extension/fixtures/extensions.xml15
-rw-r--r--tests/extension/includes/default/implementation.php5
-rw-r--r--tests/extension/manager_test.php102
-rw-r--r--tests/mock/cache.php15
-rw-r--r--tests/mock/extension_manager.php18
-rw-r--r--tests/template/template_inheritance_test.php3
-rw-r--r--tests/template/template_test.php2
-rw-r--r--tests/template/template_test_case.php5
30 files changed, 585 insertions, 54 deletions
diff --git a/tests/bootstrap.php b/tests/bootstrap.php
index 855ea1ce1f..838230a499 100644
--- a/tests/bootstrap.php
+++ b/tests/bootstrap.php
@@ -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';
diff --git a/tests/class_loader/class_loader_test.php b/tests/class_loader/class_loader_test.php
index 0c7fe3f97a..9744a1c703 100644
--- a/tests/class_loader/class_loader_test.php
+++ b/tests/class_loader/class_loader_test.php
@@ -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'
+ );
+
+ $this->assertEquals(
+ $prefix . 'foo.php',
+ $class_loader_ext->resolve_path('phpbb_ext_foo'),
+ 'Cached class found in alternative loader'
);
- $cacheMap['class_loader']['phpbb_dir_class_name'] = 'dir/class_name';
- $cache->check($this, $cacheMap);
+ $cache_map['class_loader_phpbb_']['phpbb_dir_class_name'] = 'dir/class_name';
+ $cache->check($this, $cache_map);
}
}
diff --git a/tests/cron/task/testmod/dummy_task.php b/tests/cron/ext/testext/cron/dummy_task.php
index 5941157589..06546ada05 100644
--- a/tests/cron/task/testmod/dummy_task.php
+++ b/tests/cron/ext/testext/cron/dummy_task.php
@@ -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;
diff --git a/tests/cron/includes/cron/task/core/dummy_task.php b/tests/cron/includes/cron/task/core/dummy_task.php
new file mode 100644
index 0000000000..ddaf6a9b7c
--- /dev/null
+++ b/tests/cron/includes/cron/task/core/dummy_task.php
@@ -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;
+ }
+}
diff --git a/tests/cron/task/testmod/second_dummy_task.php b/tests/cron/includes/cron/task/core/second_dummy_task.php
index 7118b2ebe7..36c3912c30 100644
--- a/tests/cron/task/testmod/second_dummy_task.php
+++ b/tests/cron/includes/cron/task/core/second_dummy_task.php
@@ -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;
diff --git a/tests/cron/manager_test.php b/tests/cron/manager_test.php
index 65d8360fbb..80c92e234b 100644
--- a/tests/cron/manager_test.php
+++ b/tests/cron/manager_test.php
@@ -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)
diff --git a/tests/cron/task2/testmod/simple_ready.php b/tests/cron/task2/testmod/simple_ready.php
deleted file mode 100644
index e407441e90..0000000000
--- a/tests/cron/task2/testmod/simple_ready.php
+++ /dev/null
@@ -1,8 +0,0 @@
-<?php
-
-class phpbb_cron_task_testmod_simple_ready extends phpbb_cron_task_base
-{
- public function run()
- {
- }
-}
diff --git a/tests/cron/task_provider_test.php b/tests/cron/task_provider_test.php
new file mode 100644
index 0000000000..5565d0f64c
--- /dev/null
+++ b/tests/cron/task_provider_test.php
@@ -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);
+ }
+}
diff --git a/tests/cron/task2/testmod/simple_not_runnable.php b/tests/cron/tasks/simple_not_runnable.php
index 54869fa1cc..837f28f1c0 100644
--- a/tests/cron/task2/testmod/simple_not_runnable.php
+++ b/tests/cron/tasks/simple_not_runnable.php
@@ -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()
{
diff --git a/tests/cron/tasks/simple_ready.php b/tests/cron/tasks/simple_ready.php
new file mode 100644
index 0000000000..de5f10e491
--- /dev/null
+++ b/tests/cron/tasks/simple_ready.php
@@ -0,0 +1,8 @@
+<?php
+
+class phpbb_cron_task_core_simple_ready extends phpbb_cron_task_base
+{
+ public function run()
+ {
+ }
+}
diff --git a/tests/cron/task2/testmod/simple_should_not_run.php b/tests/cron/tasks/simple_should_not_run.php
index 14ba4cdbd3..c2a41616f6 100644
--- a/tests/cron/task2/testmod/simple_should_not_run.php
+++ b/tests/cron/tasks/simple_should_not_run.php
@@ -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()
{
diff --git a/tests/extension/ext/bar/ext.php b/tests/extension/ext/bar/ext.php
new file mode 100644
index 0000000000..5585edf9ac
--- /dev/null
+++ b/tests/extension/ext/bar/ext.php
@@ -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;
+ }
+}
diff --git a/tests/extension/ext/bar/my/hidden_class.php b/tests/extension/ext/bar/my/hidden_class.php
new file mode 100644
index 0000000000..0261d7c59a
--- /dev/null
+++ b/tests/extension/ext/bar/my/hidden_class.php
@@ -0,0 +1,5 @@
+<?php
+
+class phpbb_ext_bar_my_hidden_class
+{
+}
diff --git a/tests/extension/ext/foo/a_class.php b/tests/extension/ext/foo/a_class.php
new file mode 100644
index 0000000000..b7be1ad654
--- /dev/null
+++ b/tests/extension/ext/foo/a_class.php
@@ -0,0 +1,5 @@
+<?php
+
+class phpbb_ext_foo_a_class
+{
+}
diff --git a/tests/extension/ext/foo/b_class.php b/tests/extension/ext/foo/b_class.php
new file mode 100644
index 0000000000..4645266122
--- /dev/null
+++ b/tests/extension/ext/foo/b_class.php
@@ -0,0 +1,5 @@
+<?php
+
+class phpbb_ext_foo_b_class
+{
+}
diff --git a/tests/extension/ext/foo/ext.php b/tests/extension/ext/foo/ext.php
new file mode 100644
index 0000000000..60b3ad1f16
--- /dev/null
+++ b/tests/extension/ext/foo/ext.php
@@ -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;
+ }
+}
diff --git a/tests/extension/ext/foo/sub/type/alternative.php b/tests/extension/ext/foo/sub/type/alternative.php
new file mode 100644
index 0000000000..2ea7353f4b
--- /dev/null
+++ b/tests/extension/ext/foo/sub/type/alternative.php
@@ -0,0 +1,5 @@
+<?php
+
+class phpbb_ext_foo_sub_type_alternative
+{
+}
diff --git a/tests/extension/ext/foo/type/alternative.php b/tests/extension/ext/foo/type/alternative.php
new file mode 100644
index 0000000000..404b66b965
--- /dev/null
+++ b/tests/extension/ext/foo/type/alternative.php
@@ -0,0 +1,5 @@
+<?php
+
+class phpbb_ext_foo_type_alternative
+{
+}
diff --git a/tests/extension/ext/foo/typewrong/error.php b/tests/extension/ext/foo/typewrong/error.php
new file mode 100644
index 0000000000..ba22cfae9a
--- /dev/null
+++ b/tests/extension/ext/foo/typewrong/error.php
@@ -0,0 +1,5 @@
+<?php
+
+class phpbb_ext_foo_typewrong_error
+{
+}
diff --git a/tests/extension/ext/vendor/moo/ext.php b/tests/extension/ext/vendor/moo/ext.php
new file mode 100644
index 0000000000..e0ac1a22cc
--- /dev/null
+++ b/tests/extension/ext/vendor/moo/ext.php
@@ -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;
+ }
+}
diff --git a/tests/extension/ext/vendor/moo/feature_class.php b/tests/extension/ext/vendor/moo/feature_class.php
new file mode 100644
index 0000000000..c3bcc4451c
--- /dev/null
+++ b/tests/extension/ext/vendor/moo/feature_class.php
@@ -0,0 +1,5 @@
+<?php
+
+class phpbb_ext_vendor_moo_feature_class
+{
+}
diff --git a/tests/extension/finder_test.php b/tests/extension/finder_test.php
new file mode 100644
index 0000000000..03615bbfc0
--- /dev/null
+++ b/tests/extension/finder_test.php
@@ -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
+ );
+ }
+}
diff --git a/tests/extension/fixtures/extensions.xml b/tests/extension/fixtures/extensions.xml
new file mode 100644
index 0000000000..65cb71c7a4
--- /dev/null
+++ b/tests/extension/fixtures/extensions.xml
@@ -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>
diff --git a/tests/extension/includes/default/implementation.php b/tests/extension/includes/default/implementation.php
new file mode 100644
index 0000000000..91d5f8aa2f
--- /dev/null
+++ b/tests/extension/includes/default/implementation.php
@@ -0,0 +1,5 @@
+<?php
+
+class phpbb_default_impl_class implements phpbb_default_interface
+{
+}
diff --git a/tests/extension/manager_test.php b/tests/extension/manager_test.php
new file mode 100644
index 0000000000..891f1b287a
--- /dev/null
+++ b/tests/extension/manager_test.php
@@ -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()));
+ }
+
+}
diff --git a/tests/mock/cache.php b/tests/mock/cache.php
index 989180c256..0f174ea449 100644
--- a/tests/mock/cache.php
+++ b/tests/mock/cache.php
@@ -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]));
diff --git a/tests/mock/extension_manager.php b/tests/mock/extension_manager.php
new file mode 100644
index 0000000000..5155716181
--- /dev/null
+++ b/tests/mock/extension_manager.php
@@ -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;
+ }
+}
diff --git a/tests/template/template_inheritance_test.php b/tests/template/template_inheritance_test.php
index d62562ff0d..93b01ae381 100644
--- a/tests/template/template_inheritance_test.php
+++ b/tests/template/template_inheritance_test.php
@@ -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);
}
}
diff --git a/tests/template/template_test.php b/tests/template/template_test.php
index 86ff2e9ec6..35297b212d 100644
--- a/tests/template/template_test.php
+++ b/tests/template/template_test.php
@@ -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');
diff --git a/tests/template/template_test_case.php b/tests/template/template_test_case.php
index 0e1f960f61..4e36912e01 100644
--- a/tests/template/template_test_case.php
+++ b/tests/template/template_test_case.php
@@ -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');
}