From: Michael M Slusarz Date: Tue, 18 May 2010 20:25:17 +0000 (-0600) Subject: Remove Core dependency in horde/LoginTasks X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=66468480ef1d7e115c15c3f45ebd83086c1155c7;p=horde.git Remove Core dependency in horde/LoginTasks Framework libs other than Core must contain NO horde dependencies, even if they are optional. For testing: unit tests in the framework libraries should only test whether the code contained in the library works. If we want to test things dependent on Horde (the application), these tests should be in Core. --- diff --git a/framework/Core/lib/Horde.php b/framework/Core/lib/Horde.php index dc1f655bb..fae51153a 100644 --- a/framework/Core/lib/Horde.php +++ b/framework/Core/lib/Horde.php @@ -442,7 +442,7 @@ HTML; * @param string $type The service to display. *
      * TODO
-     * 'ajax', 'cache', 'download', 'go', 'prefsapi'
+     * 'ajax', 'cache', 'download', 'go', 'logintasks', 'prefsapi'
      * 'help', 'problem', 'logout', 'login', 'options'
      * 
* @param string $app The name of the current Horde application. @@ -467,6 +467,9 @@ HTML; case 'login': return self::url($webroot . '/login.php'); + case 'logintasks': + return self::url($webroot . '/services/logintasks.php')->add('app', $app); + case 'options': case 'prefsapi': if (!in_array($GLOBALS['conf']['prefs']['driver'], array('', 'none'))) { diff --git a/framework/Core/lib/Horde/Core/Binder/LoginTasks.php b/framework/Core/lib/Horde/Core/Binder/LoginTasks.php new file mode 100644 index 000000000..304d8fde1 --- /dev/null +++ b/framework/Core/lib/Horde/Core/Binder/LoginTasks.php @@ -0,0 +1,17 @@ + + * @license http://www.fsf.org/copyleft/lgpl.html LGPL + * @link http://pear.horde.org/index.php?package=Core + */ + +/** + * A Horde_Injector:: based Horde_LoginTasks:: factory. + * + * Copyright 2010 The Horde Project (http://www.horde.org/) + * + * See the enclosed file COPYING for license information (LGPL). If you + * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html. + * + * @category Horde + * @package Core + * @author Michael Slusarz + * @license http://www.fsf.org/copyleft/lgpl.html LGPL + * @link http://pear.horde.org/index.php?package=Core + */ +class Horde_Core_Factory_LoginTasks +{ + /** + * Instances. + * + * @var array + */ + private $_instances = array(); + + /** + * The injector. + * + * @var Horde_Injector + */ + private $_injector; + + /** + * Constructor. + * + * @param Horde_Injector $injector The injector to use. + */ + public function __construct(Horde_Injector $injector) + { + $this->_injector = $injector; + } + + /** + * Return the Horde_LoginTasks:: instance. + * + * @param string $app The current application. + * + * @return Horde_LoginTasks The singleton instance. + */ + public function getOb($app) + { + if (!isset($this->_instances[$app])) { + $this->_instances[$app] = new Horde_LoginTasks(new Horde_Core_LoginTasks_Backend_Horde($app)); + } + + return $this->_instances[$app]; + } + +} diff --git a/framework/Core/lib/Horde/Core/LoginTasks/Backend/Horde.php b/framework/Core/lib/Horde/Core/LoginTasks/Backend/Horde.php new file mode 100644 index 000000000..816608a59 --- /dev/null +++ b/framework/Core/lib/Horde/Core/LoginTasks/Backend/Horde.php @@ -0,0 +1,172 @@ + + * @author Gunnar Wrobel + * @category Horde + * @package Core + */ +class Horde_Core_LoginTasks_Backend_Horde extends Horde_LoginTasks_Backend +{ + /** + * The Horde application that is currently active. + * + * @var string + */ + private $_app; + + /** + * Constructor. + * + * @param string $app The currently active Horde application. + */ + public function __construct($app) + { + $this->_app = $app; + } + + /** + * Is the current session authenticated? + * + * @return boolean True if the user is authenticated, false otherwise. + */ + public function isAuthenticated() + { + return (Horde_Auth::getAuth() !== false); + } + + /** + * Retrieve a cached tasklist if it exists. + * + * @return Horde_LoginTasks_Tasklist|boolean The cached task list or + * false if no task list was + * cached. + */ + public function getTasklistFromCache() + { + if (isset($_SESSION['horde_logintasks'][$this->_app])) { + return @unserialize($_SESSION['horde_logintasks'][$this->_app]); + } + return false; + } + + /** + * Store a login tasklist in the cache. + * + * @param Horde_LoginTasks_Tasklist|boolean $tasklist The tasklist to be + * stored. + */ + public function storeTasklistInCache($tasklist) + { + $_SESSION['horde_logintasks'][$this->_app] = serialize($tasklist); + } + + /** + * Register the shutdown handler. + * + * @param array $shutdown The shutdown function. + */ + public function registerShutdown($shutdown) + { + register_shutdown_function($shutdown); + } + + /** + * Get the class names of the task classes that need to be performed. + * + * @return array An array of class names. + */ + public function getTasks() + { + /* Add Horde tasks here if not yet run. */ + $app_list = array($this->_app); + if (($this->_app != 'horde') && + !isset($_SESSION['horde_logintasks']['horde'])) { + array_unshift($app_list, 'horde'); + } + + $tasks = array(); + + foreach ($app_list as $app) { + foreach (array_merge($GLOBALS['registry']->getAppDrivers($app, 'LoginTasks_SystemTask'), $GLOBALS['registry']->getAppDrivers($app, 'LoginTasks_Task')) as $val) { + $tasks[$val] = $app; + } + } + + return $tasks; + } + + /** + * Get the information about the last time the tasks were run. Array keys + * are app names, values are last run timestamps. Special key '_once' + * contains list of ONCE tasks previously run. + * + * @return array The information about the last time the tasks were run. + */ + public function getLastRun() + { + $lasttask_pref = @unserialize($GLOBALS['prefs']->getValue('last_logintasks')); + if (!is_array($lasttask_pref)) { + $lasttask_pref = array(); + } + + return $lasttask_pref; + } + + /** + * Store the information about the last time the tasks were run. + * + * @param array $last The information about the last time the tasks were + * run. + */ + public function setLastRun(array $last) + { + $GLOBALS['prefs']->setValue('last_logintasks', serialize($last)); + } + + /** + * Mark the current time as time the login tasks were run for the last + * time. + */ + public function markLastRun() + { + $lasttasks = $this->getLastRun(); + $lasttasks[$this->_app] = time(); + if (($this->_app != 'horde') && + !isset($_SESSION['horde_logintasks']['horde'])) { + $lasttasks['horde'] = time(); + $_SESSION['horde_logintasks']['horde'] = true; + } + $GLOBALS['prefs']->setValue('last_logintasks', serialize($lasttasks)); + } + + /** + * Redirect to the given URL. + * + * @param string $url The URL to redirect to. + */ + public function redirect($url) + { + header('Location: ' . $url); + exit; + } + + /** + * Return the URL of the login tasks view. + * + * @param array $tasks The tasks to be displayed next. + * + * @return string The URL of the login tasks view. + */ + public function getLoginTasksUrl(array $tasks = null) + { + return Horde::getServiceLink('logintasks', $this->_app); + } +} diff --git a/framework/Core/lib/Horde/Registry.php b/framework/Core/lib/Horde/Registry.php index 7014dca92..77aa287ad 100644 --- a/framework/Core/lib/Horde/Registry.php +++ b/framework/Core/lib/Horde/Registry.php @@ -240,6 +240,7 @@ class Horde_Registry 'Horde_History' => new Horde_Core_Binder_History(), 'Horde_Lock' => new Horde_Core_Binder_Lock(), 'Horde_Log_Logger' => new Horde_Core_Binder_Logger(), + 'Horde_LoginTasks' => new Horde_Core_Binder_LoginTasks(), 'Horde_Mail' => new Horde_Core_Binder_Mail(), 'Horde_Memcache' => new Horde_Core_Binder_Memcache(), 'Horde_Notification' => new Horde_Core_Binder_Notification(), @@ -1131,7 +1132,7 @@ class Horde_Registry /* Do login tasks. */ if ($checkPerms) { - $tasks = Horde_LoginTasks::singleton($app); + $tasks = $GLOBALS['injector']->getInstance('Horde_LoginTasks')->getOb($app); if (!empty($options['logintasks'])) { $tasks->runTasks(false, Horde::selfUrl(true, true, true)); } diff --git a/framework/Core/package.xml b/framework/Core/package.xml index 0239c9aad..17cb7c8a9 100644 --- a/framework/Core/package.xml +++ b/framework/Core/package.xml @@ -37,7 +37,8 @@ Application Framework. beta LGPL - * Import perms UI handling class from horde/Perms. + * Import Horde backend driver from horde/LoginTasks. + * Import perms UI handling class from horde/Perms. * Import prefs UI handling class from horde/Prefs. * Convert from PEAR Log to Horde_Log for logging. * Add Horde_Themes:: class. @@ -77,6 +78,7 @@ Application Framework. + @@ -96,10 +98,16 @@ Application Framework. + + + + + + @@ -183,6 +191,10 @@ Application Framework. pear.horde.org + LoginTasks + pear.horde.org + + Prefs pear.horde.org @@ -239,6 +251,7 @@ Application Framework. + @@ -256,7 +269,9 @@ Application Framework. + + diff --git a/framework/LoginTasks/lib/Horde/LoginTasks.php b/framework/LoginTasks/lib/Horde/LoginTasks.php index a28b96378..79e09329d 100644 --- a/framework/LoginTasks/lib/Horde/LoginTasks.php +++ b/framework/LoginTasks/lib/Horde/LoginTasks.php @@ -41,13 +41,6 @@ class Horde_LoginTasks const PRIORITY_NORMAL = 2; /** - * Singleton instance. - * - * @var array - */ - static protected $_instances = array(); - - /** * The Horde_LoginTasks_Backend object provides all utilities we need for * handling the login tasks. * @@ -63,36 +56,9 @@ class Horde_LoginTasks protected $_tasklist; /** - * Attempts to return a reference to a concrete Horde_LoginTasks - * instance based on $app. It will only create a new instance - * if no instance with the same parameters currently exists. - * - * This method must be invoked as: - * $var = Horde_LoginTasks::singleton($app[, $params]); - * - * @param string $app See self::__construct(). - * - * @return Horde_LoginTasks The singleton instance. - */ - static public function singleton($app) - { - if (empty(self::$_instances[$app])) { - self::$_instances[$app] = new self( - new Horde_LoginTasks_Backend_Horde( - $GLOBALS['registry'], - $GLOBALS['prefs'], - $app - ) - ); - } - - return self::$_instances[$app]; - } - - /** * Constructor. * - * @param string $app The name of the Horde application. + * @param Horde_LoginTasks_Backend $backend The backend to use. */ public function __construct(Horde_LoginTasks_Backend $backend) { diff --git a/framework/LoginTasks/lib/Horde/LoginTasks/Backend.php b/framework/LoginTasks/lib/Horde/LoginTasks/Backend.php index 3fa7c8b39..363a3bc31 100644 --- a/framework/LoginTasks/lib/Horde/LoginTasks/Backend.php +++ b/framework/LoginTasks/lib/Horde/LoginTasks/Backend.php @@ -18,40 +18,38 @@ abstract class Horde_LoginTasks_Backend /** * Is the current session authenticated? * - * @return boolean True if the user is authenticated, false otherwise. + * @return boolean True if the user is authenticated, false otherwise. */ abstract public function isAuthenticated(); /** * Retrieve a cached tasklist if it exists. * - * @return Horde_LoginTasks_Tasklist|boolean The cached task list or false - * if no task list was cached. + * @return Horde_LoginTasks_Tasklist|boolean The cached task list or + * false if no task list was + * cached. */ abstract public function getTasklistFromCache(); /** * Store a login tasklist in the cache. * - * @param Horde_LoginTasks_Tasklist|boolean The tasklist to be stored. - * - * @return NULL + * @param Horde_LoginTasks_Tasklist|boolean $tasklist The tasklist to be + * stored. */ abstract public function storeTasklistInCache($tasklist); /** * Register the shutdown handler. * - * @param array The shutdown function - * - * @return NULL + * @param array $shutdown The shutdown function. */ abstract public function registerShutdown($shutdown); /** * Get the class names of the task classes that need to be performed. * - * @return array An array of class names. + * @return array An array of class names. */ abstract public function getTasks(); @@ -60,41 +58,37 @@ abstract class Horde_LoginTasks_Backend * are app names, values are last run timestamps. Special key '_once' * contains list of ONCE tasks previously run. * - * @return array The information about the last time the tasks were run. + * @return array The information about the last time the tasks were run. */ abstract public function getLastRun(); /** * Store the information about the last time the tasks were run. * - * @param array $last The information about the last time the tasks were run. - * - * @return NULL + * @param array $last The information about the last time the tasks were + * run. */ abstract public function setLastRun(array $last); /** - * Mark the current time as time the login tasks were run for the last time. - * - * @return NULL + * Mark the current time as time the login tasks were run for the last + * time. */ abstract public function markLastRun(); /** * Redirect to the given URL. * - * @param string $url The URL to redirect to. - * - * @return NULL + * @param string $url The URL to redirect to. */ abstract public function redirect($url); /** * Return the URL of the login tasks view. * - * @param array $tasks The tasks to be displayed next. + * @param array $tasks The tasks to be displayed next. * - * @return string The URL of the login tasks view + * @return string The URL of the login tasks view */ abstract public function getLoginTasksUrl(array $tasks = null); -} \ No newline at end of file +} diff --git a/framework/LoginTasks/lib/Horde/LoginTasks/Backend/Horde.php b/framework/LoginTasks/lib/Horde/LoginTasks/Backend/Horde.php deleted file mode 100644 index 1ec6eee90..000000000 --- a/framework/LoginTasks/lib/Horde/LoginTasks/Backend/Horde.php +++ /dev/null @@ -1,195 +0,0 @@ - - * @author Gunnar Wrobel - * @package Horde_LoginTasks - */ -class Horde_LoginTasks_Backend_Horde -extends Horde_LoginTasks_Backend -{ - /** - * The Horde application that is currently active. - * - * @var string - */ - private $_app; - - /** - * The Horde registry. - * - * @var Horde_Registry - */ - private $_registry; - - /** - * The Horde preferences system - * - * @var Horde_Prefs - */ - private $_prefs; - - /** - * Constructor - * - * @param string $app The Horde application that is currently active. - */ - public function __construct( - Horde_Registry $registry, - Horde_Prefs $prefs, - $app - ) { - $this->_registry = $registry; - $this->_prefs = $prefs; - $this->_app = $app; - } - - /** - * Is the current session authenticated? - * - * @return boolean True if the user is authenticated, false otherwise. - */ - public function isAuthenticated() - { - return (Horde_Auth::getAuth() !== false); - } - - /** - * Retrieve a cached tasklist if it exists. - * - * @return Horde_LoginTasks_Tasklist|boolean The cached task list or false - * if no task list was cached. - */ - public function getTasklistFromCache() - { - if (isset($_SESSION['horde_logintasks'][$this->_app])) { - return @unserialize($_SESSION['horde_logintasks'][$this->_app]); - } - return false; - } - - /** - * Store a login tasklist in the cache. - * - * @param Horde_LoginTasks_Tasklist|boolean The tasklist to be stored. - * - * @return NULL - */ - public function storeTasklistInCache($tasklist) - { - $_SESSION['horde_logintasks'][$this->_app] = serialize($tasklist); - } - - /** - * Register the shutdown handler. - * - * @param array The shutdown function - * - * @return NULL - */ - public function registerShutdown($shutdown) - { - register_shutdown_function($shutdown); - } - - /** - * Get the class names of the task classes that need to be performed. - * - * @return array An array of class names. - */ - public function getTasks() - { - /* Add Horde tasks here if not yet run. */ - $app_list = array($this->_app); - if (($this->_app != 'horde') && - !isset($_SESSION['horde_logintasks']['horde'])) { - array_unshift($app_list, 'horde'); - } - - $tasks = array(); - - foreach ($app_list as $app) { - foreach (array_merge($this->_registry->getAppDrivers($app, 'LoginTasks_SystemTask'), $this->_registry->getAppDrivers($app, 'LoginTasks_Task')) as $val) { - $tasks[$val] = $app; - } - } - return $tasks; - } - - /** - * Get the information about the last time the tasks were run. Array keys - * are app names, values are last run timestamps. Special key '_once' - * contains list of ONCE tasks previously run. - * - * @return array The information about the last time the tasks were run. - */ - public function getLastRun() - { - $lasttask_pref = @unserialize($this->_prefs->getValue('last_logintasks')); - if (!is_array($lasttask_pref)) { - $lasttask_pref = array(); - } - return $lasttask_pref; - } - - /** - * Store the information about the last time the tasks were run. - * - * @param array $last The information about the last time the tasks were run. - * - * @return NULL - */ - public function setLastRun(array $last) - { - $this->_prefs->setValue('last_logintasks', serialize($last)); - } - - /** - * Mark the current time as time the login tasks were run for the last time. - * - * @return NULL - */ - public function markLastRun() - { - $lasttasks = $this->getLastRun(); - $lasttasks[$this->_app] = time(); - if (($this->_app != 'horde') && - !isset($_SESSION['horde_logintasks']['horde'])) { - $lasttasks['horde'] = time(); - $_SESSION['horde_logintasks']['horde'] = true; - } - $this->_prefs->setValue('last_logintasks', serialize($lasttasks)); - } - - /** - * Redirect to the given URL. - * - * @param string $url The URL to redirect to. - * - * @return NULL - */ - public function redirect($url) - { - header('Location: ' . $url); - exit; - } - - /** - * Return the URL of the login tasks view. - * - * @param array $tasks The tasks to be displayed next. - * - * @return string The URL of the login tasks view - */ - public function getLoginTasksUrl(array $tasks = null) - { - return Horde::url(Horde_Util::addParameter($this->_registry->get('webroot', 'horde') . '/services/logintasks.php', array('app' => $this->_app)), true); - } -} \ No newline at end of file diff --git a/framework/LoginTasks/package.xml b/framework/LoginTasks/package.xml index 646980c49..ba58dabae 100644 --- a/framework/LoginTasks/package.xml +++ b/framework/LoginTasks/package.xml @@ -21,8 +21,8 @@ beta LGPL - -* Added system tasks. + * Removed Core dependency. + * Added system tasks. * Added ONCE interval. * Renamed Maintenance:: -> Horde_LoginTasks::. * Initial Horde 4 package. @@ -32,9 +32,6 @@ - - - @@ -69,20 +66,6 @@ pear.horde.org - - - Auth - pear.horde.org - - - Core - pear.horde.org - - - Prefs - pear.horde.org - - @@ -91,7 +74,6 @@ - diff --git a/framework/LoginTasks/test/Horde/LoginTasks/LoginTasksTest.php b/framework/LoginTasks/test/Horde/LoginTasks/LoginTasksTest.php index 1f126bed5..f0a88e9c8 100644 --- a/framework/LoginTasks/test/Horde/LoginTasks/LoginTasksTest.php +++ b/framework/LoginTasks/test/Horde/LoginTasks/LoginTasksTest.php @@ -104,7 +104,6 @@ class Horde_LoginTasks_LoginTasksTest extends PHPUnit_Framework_TestCase $tasks = $this->_getLoginTasks( array('Horde_LoginTasks_Stub_Year'), true, $date ); - $tasks->runTasks(); $this->assertEquals( array(), Horde_LoginTasks_Stub_Task::$executed @@ -241,11 +240,9 @@ class Horde_LoginTasks_LoginTasksTest extends PHPUnit_Framework_TestCase public function testTasksThatRunOnceAreNotExecutedMoreThanOnce() { - $prefs = new Horde_LoginTasks_Stub_Prefs(); - Horde_LoginTasks_Stub_Once::$executed = array(); $tasks = $this->_getLoginTasks( - array('Horde_LoginTasks_Stub_Once'), true, false, $prefs + array('Horde_LoginTasks_Stub_Once'), true, false ); $tasks->runTasks(); $this->assertEquals( @@ -254,9 +251,8 @@ class Horde_LoginTasks_LoginTasksTest extends PHPUnit_Framework_TestCase ); Horde_LoginTasks_Stub_Task::$executed = array(); - $date = getdate(); $tasks = $this->_getLoginTasks( - array('Horde_LoginTasks_Stub_Once'), true, false, $prefs + array('Horde_LoginTasks_Stub_Once'), true, true ); $tasks->runTasks(); $this->assertEquals( @@ -267,7 +263,6 @@ class Horde_LoginTasks_LoginTasksTest extends PHPUnit_Framework_TestCase public function testAllTasksGetRunIfNoTasksRequiresDisplay() { - $prefs = new Horde_LoginTasks_Stub_Prefs(); Horde_LoginTasks_Stub_Task::$executed = array(); $tasks = $this->_getLoginTasks( array( @@ -275,17 +270,20 @@ class Horde_LoginTasks_LoginTasksTest extends PHPUnit_Framework_TestCase 'Horde_LoginTasks_Stub_High', ), true, - false, - $prefs + false ); $tasks->runTasks(); - $v = $prefs->getValue('last_logintasks'); - $this->assertTrue(!empty($v)); + $this->assertEquals( + array( + 'Horde_LoginTasks_Stub_High', + 'Horde_LoginTasks_Stub_Task' + ), + Horde_LoginTasks_Stub_Task::$executed + ); } public function testTheLastTimeOfCompletingTheLoginTasksWillBeStoredOnceAllTasksWereExcecuted() { - $prefs = new Horde_LoginTasks_Stub_Prefs(); Horde_LoginTasks_Stub_Task::$executed = array(); $tasks = $this->_getLoginTasks( array( @@ -293,12 +291,10 @@ class Horde_LoginTasks_LoginTasksTest extends PHPUnit_Framework_TestCase 'Horde_LoginTasks_Stub_High', ), true, - false, - $prefs + false ); $tasks->runTasks(); - $v = unserialize($prefs->getValue('last_logintasks')); - $this->assertTrue($v['horde'] > time() - 10); + $this->assertTrue(Horde_LoginTasks_Stub_Backend::$lastRun['test'] > time() - 10); } public function testAllTasksToBeRunBeforeTheFirstTaskRequiringDisplayGetExecutedInABatch() @@ -334,7 +330,7 @@ class Horde_LoginTasks_LoginTasksTest extends PHPUnit_Framework_TestCase true ); $this->assertContains( - 'http:///services/logintasks.php?app=test', + 'URL', (string) $tasks->runTasks(false, null) ); } @@ -423,7 +419,7 @@ class Horde_LoginTasks_LoginTasksTest extends PHPUnit_Framework_TestCase $tasks->runTasks(false, 'redirect'); $tasks->displayTasks(); $this->assertContains( - 'http:///services/logintasks.php?app=test', + 'URL', (string) $tasks->runTasks(true) ); $this->assertNull( @@ -431,7 +427,8 @@ class Horde_LoginTasks_LoginTasksTest extends PHPUnit_Framework_TestCase ); $tasks->displayTasks(); $this->assertEquals( - 'redirect', $tasks->runTasks(true) + 'redirect', + $tasks->runTasks(true) ); } @@ -452,7 +449,7 @@ class Horde_LoginTasks_LoginTasksTest extends PHPUnit_Framework_TestCase true ); $this->assertContains( - 'http:///services/logintasks.php?app=test', + 'URL', (string) $tasks->runTasks(false, 'redirect') ); $this->assertEquals( @@ -476,7 +473,7 @@ class Horde_LoginTasks_LoginTasksTest extends PHPUnit_Framework_TestCase $_POST['logintasks_confirm_0'] = true; $_POST['logintasks_confirm_1'] = true; $this->assertContains( - 'http:///services/logintasks.php?app=test', + 'URL', (string) $tasks->runTasks(true) ); $this->assertEquals( @@ -512,7 +509,7 @@ class Horde_LoginTasks_LoginTasksTest extends PHPUnit_Framework_TestCase $classes ); $this->assertContains( - 'http:///services/logintasks.php?app=test', + 'URL', (string) $tasks->runTasks(true) ); $this->assertEquals( @@ -538,7 +535,7 @@ class Horde_LoginTasks_LoginTasksTest extends PHPUnit_Framework_TestCase ); $_POST['logintasks_confirm_0'] = true; $this->assertContains( - 'http:///services/logintasks.php?app=test', + 'URL', (string) $tasks->runTasks(true) ); $this->assertEquals( @@ -567,7 +564,7 @@ class Horde_LoginTasks_LoginTasksTest extends PHPUnit_Framework_TestCase ); $_POST['logintasks_confirm_0'] = true; $this->assertContains( - 'http:///services/logintasks.php?app=test', + 'URL', (string) $tasks->runTasks(true) ); $this->assertEquals( @@ -614,49 +611,31 @@ class Horde_LoginTasks_LoginTasksTest extends PHPUnit_Framework_TestCase ); } - private function _getLoginTasks( - array $tasks = array(), - $authenticated = false, - $last_run = false, - $prefs = false - ) { - if ($authenticated) { - $_SESSION['horde_auth']['userId'] = 'test'; - } - $last_time = false; - if ($last_run) { - $last_time = mktime( - $last_run['hours'], - $last_run['minutes'], - $last_run['seconds'], - $last_run['mon'], - $last_run['mday'], - $last_run['year'] - ); - $last_time = serialize( - array( - 'test' => $last_time - ) + private function _getLoginTasks(array $tasks = array(), + $authenticated = false, $last_run = false) + { + $last_time = $last_run; + if ($last_time && !is_bool($last_time)) { + $last_time = array( + 'test' => mktime( + $last_run['hours'], + $last_run['minutes'], + $last_run['seconds'], + $last_run['mon'], + $last_run['mday'], + $last_run['year'] + ) ); } - if (empty($prefs)) { - $GLOBALS['prefs'] = $this->getMock('Horde_Prefs', array(), array(), '', false, false); - $GLOBALS['prefs']->expects($this->any()) - ->method('getValue') - ->will($this->returnValue($last_time)); - } else { - $GLOBALS['prefs'] = $prefs; + + $tasklist = array(); + foreach ($tasks as $val) { + $tasklist[$val] = 'test'; } - $GLOBALS['registry'] = $this->getMock('Horde_Registry', array(), array(), '', false, false); - $GLOBALS['registry']->expects($this->any()) - ->method('getAppDrivers') - ->will($this->returnValue($tasks)); + return new Horde_LoginTasks( - new Horde_LoginTasks_Stub_Backend( - $GLOBALS['registry'], - $GLOBALS['prefs'], - 'test' - ) + new Horde_LoginTasks_Stub_Backend($tasklist, $authenticated, $last_time) ); } + } diff --git a/framework/LoginTasks/test/Horde/LoginTasks/Stubs.php b/framework/LoginTasks/test/Horde/LoginTasks/Stubs.php index 0d7dd4a1f..013d32102 100644 --- a/framework/LoginTasks/test/Horde/LoginTasks/Stubs.php +++ b/framework/LoginTasks/test/Horde/LoginTasks/Stubs.php @@ -1,67 +1,72 @@ _tasklist = $tasks; + $this->_authenticated = $authenticated; + if ($last_run !== true) { + self::$lastRun = $last_run; } } -} -if (!class_exists('Horde_Registry')) { - class Horde_Registry { - public function get($parameter, $app = null) - { - } + public function isAuthenticated() + { + return $this->_authenticated; + } - public function getAppDrivers($app, $prefix) - { - } + public function getTasklistFromCache() + { + return $this->_tasklistCache; } -} -if (!class_exists('Horde')) { - class Horde { - static public function url($url) - { - $url = new Horde_Url($url); - return 'http://' . (string) $url; - } + public function storeTasklistInCache($tasklist) + { + $this->_tasklistCache = $tasklist; } -} -if (!class_exists('Horde_Auth')) { - class Horde_Auth { - static public function getAuth() - { - return empty($_SESSION['horde_auth']['userId']) - ? false - : $_SESSION['horde_auth']['userId']; - } + public function registerShutdown($shutdown) + { } -} -class Horde_LoginTasks_Stub_Prefs -extends Horde_Prefs -{ - private $_storage = array(); + public function getTasks() + { + return $this->_tasklist; + } + + public function getLastRun() + { + return self::$lastRun; + } + + public function setLastRun(array $last) + { + self::$lastRun = $last; + } - public function __construct() + public function markLastRun() { + $lasttasks = $this->getLastRun(); + $lasttasks['test'] = time(); + self::$lastRun = $lasttasks; } - public function setValue($pref, $val, $convert = true) + public function redirect($url) { - $this->_storage[$pref] = $val; + return $url; } - public function getValue($pref, $convert = true) + public function getLoginTasksUrl(array $tasks = null) { - return isset($this->_storage[$pref]) ? $this->_storage[$pref] : null; + return 'URL'; } } @@ -71,9 +76,7 @@ extends Horde_LoginTasks_Task static public $executed; public $interval = Horde_LoginTasks::EVERY; - public $display = Horde_LoginTasks::DISPLAY_NONE; - public $priority = Horde_LoginTasks::PRIORITY_NORMAL; public function execute() @@ -82,15 +85,6 @@ extends Horde_LoginTasks_Task } } -class Horde_LoginTasks_Stub_Backend -extends Horde_LoginTasks_Backend_Horde -{ - public function redirect($url) - { - return $url; - } -} - class Horde_LoginTasks_Stub_TaskTwo extends Horde_LoginTasks_Stub_Task { @@ -172,4 +166,4 @@ class Horde_LoginTasks_Stub_Year extends Horde_LoginTasks_Stub_Task { public $interval = Horde_LoginTasks::YEARLY; -} \ No newline at end of file +} diff --git a/horde/services/logintasks.php b/horde/services/logintasks.php index e0317a558..c1dbe0052 100644 --- a/horde/services/logintasks.php +++ b/horde/services/logintasks.php @@ -16,13 +16,13 @@ Horde_Registry::appInit('horde', array('nologintasks' => true)); /* If no 'module' parameter passed in, die with an error. */ if (!($app = basename(Horde_Util::getFormData('app')))) { - throw new Horde_Exception("Do not directly access logintasks.php"); + throw new Horde_Exception('Do not directly access logintasks.php.'); } $registry->pushApp($app, array('logintasks' => false)); -if (!($tasks = Horde_LoginTasks::singleton($app))) { - throw new Horde_Exception("The Horde_LoginTasks:: class did not load successfully"); +if (!($tasks = $injector->getInstance('Horde_LoginTasks')->getOb($app))) { + throw new Horde_Exception('The Horde_LoginTasks:: class did not load successfully.'); } /* If we are through with tasks, this call will redirect to application. */