aboutsummaryrefslogtreecommitdiffstats
path: root/tests/cron
diff options
context:
space:
mode:
authorOleg Pudeyev <oleg@bsdpower.com>2012-11-06 11:11:27 -0500
committerOleg Pudeyev <oleg@bsdpower.com>2012-11-06 11:11:27 -0500
commit87ea50948ea53c0d1beab5b44badebeae4292d1a (patch)
treedbc99fde4dfc62b84bae60c7e4ab5c02ddbe8a3c /tests/cron
parent5b48df41685da785b082612318ebe7a8012c4149 (diff)
parent44ff9d020fd218cbdb2f07a0d7f85a630367e3c2 (diff)
downloadforums-87ea50948ea53c0d1beab5b44badebeae4292d1a.tar
forums-87ea50948ea53c0d1beab5b44badebeae4292d1a.tar.gz
forums-87ea50948ea53c0d1beab5b44badebeae4292d1a.tar.bz2
forums-87ea50948ea53c0d1beab5b44badebeae4292d1a.tar.xz
forums-87ea50948ea53c0d1beab5b44badebeae4292d1a.zip
Merge remote-tracking branch 'upstream/develop' into feature/prune-users
* upstream/develop: (2171 commits) [ticket/11164] Update composer.phar [ticket/10933] Use inheritDoc, eliminate copy pasted docblocks. [ticket/10933] Dependency inject template context. [ticket/10933] Expanded prose documentation for phpbb_extension_provider. [ticket/10933] Specify empty template path for absolute includephp test. [ticket/10933] Useful documentation for template locate function [ticket/10933] Typo fixes [ticket/10933] Initialize template context when template is constructed. [ticket/11099] Mark acp_ban::display_ban_options() as static. [ticket/11158] Require acl_u_sig for ucp signature module. [ticket/11158] Revert old fix in PHPBB3-10186. [ticket/11159] static public is the currently approved order. [ticket/11157] static public is the currently approved order. [ticket/11157] Fix remaining captcha spam. [ticket/11157] get_captcha_types is an instance method. [ticket/11156] Delete "Misc" tab of forum based permissions + move items [ticket/10848] Move include up. [ticket/11014] Fix old pagination assignment [ticket/11018] Fix several paginations in ACP [ticket/11014] Fix IF statements for new template pagination ... Conflicts: phpBB/includes/functions_user.php
Diffstat (limited to 'tests/cron')
-rw-r--r--tests/cron/ext/testext/cron/dummy_task.php28
-rw-r--r--tests/cron/includes/cron/task/core/dummy_task.php28
-rw-r--r--tests/cron/includes/cron/task/core/second_dummy_task.php28
-rw-r--r--tests/cron/manager_test.php63
-rw-r--r--tests/cron/task/testmod/dummy_task.php23
-rw-r--r--tests/cron/task/testmod/second_dummy_task.php23
-rw-r--r--tests/cron/task2/testmod/simple_not_runnable.php13
-rw-r--r--tests/cron/task2/testmod/simple_ready.php8
-rw-r--r--tests/cron/task2/testmod/simple_should_not_run.php13
-rw-r--r--tests/cron/task_provider_test.php50
-rw-r--r--tests/cron/tasks/simple_not_runnable.php18
-rw-r--r--tests/cron/tasks/simple_ready.php13
-rw-r--r--tests/cron/tasks/simple_should_not_run.php18
13 files changed, 211 insertions, 115 deletions
diff --git a/tests/cron/ext/testext/cron/dummy_task.php b/tests/cron/ext/testext/cron/dummy_task.php
new file mode 100644
index 0000000000..a31806c1b1
--- /dev/null
+++ b/tests/cron/ext/testext/cron/dummy_task.php
@@ -0,0 +1,28 @@
+<?php
+/**
+*
+* @package testing
+* @copyright (c) 2010 phpBB Group
+* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
+*
+*/
+
+class phpbb_ext_testext_cron_dummy_task extends phpbb_cron_task_base
+{
+ public static $was_run = 0;
+
+ public function get_name()
+ {
+ return get_class($this);
+ }
+
+ public function run()
+ {
+ self::$was_run++;
+ }
+
+ public function should_run()
+ {
+ return true;
+ }
+}
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..ce3e91a9ba
--- /dev/null
+++ b/tests/cron/includes/cron/task/core/dummy_task.php
@@ -0,0 +1,28 @@
+<?php
+/**
+*
+* @package testing
+* @copyright (c) 2010 phpBB Group
+* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
+*
+*/
+
+class phpbb_cron_task_core_dummy_task extends phpbb_cron_task_base
+{
+ public static $was_run = 0;
+
+ public function get_name()
+ {
+ return get_class($this);
+ }
+
+ public function run()
+ {
+ self::$was_run++;
+ }
+
+ public function should_run()
+ {
+ return true;
+ }
+}
diff --git a/tests/cron/includes/cron/task/core/second_dummy_task.php b/tests/cron/includes/cron/task/core/second_dummy_task.php
new file mode 100644
index 0000000000..76a55588f9
--- /dev/null
+++ b/tests/cron/includes/cron/task/core/second_dummy_task.php
@@ -0,0 +1,28 @@
+<?php
+/**
+*
+* @package testing
+* @copyright (c) 2010 phpBB Group
+* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
+*
+*/
+
+class phpbb_cron_task_core_second_dummy_task extends phpbb_cron_task_base
+{
+ public static $was_run = 0;
+
+ public function get_name()
+ {
+ return get_class($this);
+ }
+
+ public function run()
+ {
+ self::$was_run++;
+ }
+
+ public function should_run()
+ {
+ return true;
+ }
+}
diff --git a/tests/cron/manager_test.php b/tests/cron/manager_test.php
index 65d8360fbb..3c541be2a6 100644
--- a/tests/cron/manager_test.php
+++ b/tests/cron/manager_test.php
@@ -3,29 +3,27 @@
*
* @package testing
* @copyright (c) 2010 phpBB Group
-* @license http://opensource.org/licenses/gpl-license.php GNU Public License
+* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
*
*/
-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__) . '/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 = $this->create_cron_manager(array(
+ new phpbb_cron_task_core_dummy_task(),
+ new phpbb_cron_task_core_second_dummy_task(),
+ new phpbb_ext_testext_cron_dummy_task(),
+ ));
+ $this->task_name = 'phpbb_cron_task_core_dummy_task';
}
public function test_manager_finds_shipped_task_by_name()
@@ -35,17 +33,10 @@ class phpbb_cron_manager_test extends PHPUnit_Framework_TestCase
$this->assertEquals($this->task_name, $task->get_name());
}
- public function test_manager_instantiates_task_by_name()
- {
- $task = $this->manager->instantiate_task($this->task_name, array());
- $this->assertInstanceOf('phpbb_cron_task_wrapper', $task);
- $this->assertEquals($this->task_name, $task->get_name());
- }
-
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 +45,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 = $this->create_cron_manager(array(
+ new phpbb_cron_task_core_simple_ready(),
+ new phpbb_cron_task_core_simple_not_runnable(),
+ new 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)
@@ -76,8 +62,15 @@ class phpbb_cron_manager_test extends PHPUnit_Framework_TestCase
$names = array();
foreach ($tasks as $task)
{
- $names[] = get_class($task->task);
+ $names[] = $task->get_name();
}
return $names;
}
+
+ private function create_cron_manager($tasks)
+ {
+ global $phpbb_root_path, $phpEx;
+
+ return new phpbb_cron_manager($tasks, $phpbb_root_path, $phpEx);
+ }
}
diff --git a/tests/cron/task/testmod/dummy_task.php b/tests/cron/task/testmod/dummy_task.php
deleted file mode 100644
index 5941157589..0000000000
--- a/tests/cron/task/testmod/dummy_task.php
+++ /dev/null
@@ -1,23 +0,0 @@
-<?php
-/**
-*
-* @package testing
-* @copyright (c) 2010 phpBB Group
-* @license http://opensource.org/licenses/gpl-license.php GNU Public License
-*
-*/
-
-class phpbb_cron_task_testmod_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/task/testmod/second_dummy_task.php
deleted file mode 100644
index 7118b2ebe7..0000000000
--- a/tests/cron/task/testmod/second_dummy_task.php
+++ /dev/null
@@ -1,23 +0,0 @@
-<?php
-/**
-*
-* @package testing
-* @copyright (c) 2010 phpBB Group
-* @license http://opensource.org/licenses/gpl-license.php GNU Public License
-*
-*/
-
-class phpbb_cron_task_testmod_second_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/task2/testmod/simple_not_runnable.php b/tests/cron/task2/testmod/simple_not_runnable.php
deleted file mode 100644
index 54869fa1cc..0000000000
--- a/tests/cron/task2/testmod/simple_not_runnable.php
+++ /dev/null
@@ -1,13 +0,0 @@
-<?php
-
-class phpbb_cron_task_testmod_simple_not_runnable extends phpbb_cron_task_base
-{
- public function run()
- {
- }
-
- public function is_runnable()
- {
- return false;
- }
-}
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/task2/testmod/simple_should_not_run.php b/tests/cron/task2/testmod/simple_should_not_run.php
deleted file mode 100644
index 14ba4cdbd3..0000000000
--- a/tests/cron/task2/testmod/simple_should_not_run.php
+++ /dev/null
@@ -1,13 +0,0 @@
-<?php
-
-class phpbb_cron_task_testmod_simple_should_not_run extends phpbb_cron_task_base
-{
- public function run()
- {
- }
-
- public function should_run()
- {
- return false;
- }
-}
diff --git a/tests/cron/task_provider_test.php b/tests/cron/task_provider_test.php
new file mode 100644
index 0000000000..ec853bb3ba
--- /dev/null
+++ b/tests/cron/task_provider_test.php
@@ -0,0 +1,50 @@
+<?php
+/**
+*
+* @package testing
+* @copyright (c) 2010 phpBB Group
+* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
+*
+*/
+
+class phpbb_cron_task_provider_test extends PHPUnit_Framework_TestCase
+{
+ public function setUp()
+ {
+ $this->tasks = array(
+ 'phpbb_cron_task_core_dummy_task',
+ 'phpbb_cron_task_core_second_dummy_task',
+ 'phpbb_ext_testext_cron_dummy_task',
+ );
+
+ $container = $this->getMock('Symfony\Component\DependencyInjection\TaggedContainerInterface');
+ $container
+ ->expects($this->once())
+ ->method('findTaggedServiceIds')
+ ->will($this->returnValue(array_flip($this->tasks)));
+ $container
+ ->expects($this->any())
+ ->method('get')
+ ->will($this->returnCallback(function ($name) {
+ return new $name;
+ }));
+
+ $this->provider = new phpbb_cron_task_provider($container);
+ }
+
+ public function test_manager_finds_shipped_tasks()
+ {
+ $task_names = array();
+ foreach ($this->provider as $task)
+ {
+ $task_names[] = $task->get_name();
+ }
+ sort($task_names);
+
+ $this->assertEquals(array(
+ 'phpbb_cron_task_core_dummy_task',
+ 'phpbb_cron_task_core_second_dummy_task',
+ 'phpbb_ext_testext_cron_dummy_task',
+ ), $task_names);
+ }
+}
diff --git a/tests/cron/tasks/simple_not_runnable.php b/tests/cron/tasks/simple_not_runnable.php
new file mode 100644
index 0000000000..56d484eacd
--- /dev/null
+++ b/tests/cron/tasks/simple_not_runnable.php
@@ -0,0 +1,18 @@
+<?php
+
+class phpbb_cron_task_core_simple_not_runnable extends phpbb_cron_task_base
+{
+ public function get_name()
+ {
+ return get_class($this);
+ }
+
+ public function run()
+ {
+ }
+
+ public function is_runnable()
+ {
+ return false;
+ }
+}
diff --git a/tests/cron/tasks/simple_ready.php b/tests/cron/tasks/simple_ready.php
new file mode 100644
index 0000000000..8aa0507406
--- /dev/null
+++ b/tests/cron/tasks/simple_ready.php
@@ -0,0 +1,13 @@
+<?php
+
+class phpbb_cron_task_core_simple_ready extends phpbb_cron_task_base
+{
+ public function get_name()
+ {
+ return get_class($this);
+ }
+
+ public function run()
+ {
+ }
+}
diff --git a/tests/cron/tasks/simple_should_not_run.php b/tests/cron/tasks/simple_should_not_run.php
new file mode 100644
index 0000000000..58f6df2616
--- /dev/null
+++ b/tests/cron/tasks/simple_should_not_run.php
@@ -0,0 +1,18 @@
+<?php
+
+class phpbb_cron_task_core_simple_should_not_run extends phpbb_cron_task_base
+{
+ public function get_name()
+ {
+ return get_class($this);
+ }
+
+ public function run()
+ {
+ }
+
+ public function should_run()
+ {
+ return false;
+ }
+}