Move redirection into the backend.
authorGunnar Wrobel <p@rdus.de>
Wed, 3 Mar 2010 13:36:24 +0000 (14:36 +0100)
committerGunnar Wrobel <p@rdus.de>
Wed, 3 Mar 2010 13:36:24 +0000 (14:36 +0100)
framework/LoginTasks/lib/Horde/LoginTasks.php
framework/LoginTasks/lib/Horde/LoginTasks/Backend.php
framework/LoginTasks/lib/Horde/LoginTasks/Backend/Horde.php
framework/LoginTasks/test/Horde/LoginTasks/LoginTasksTest.php
framework/LoginTasks/test/Horde/LoginTasks/Stubs.php

index feecd1c..e62af95 100644 (file)
@@ -82,8 +82,7 @@ class Horde_LoginTasks
                     $GLOBALS['registry'],
                     $GLOBALS['prefs'],
                     $app
-                ),
-                $app
+                )
             );
         }
 
@@ -95,14 +94,10 @@ class Horde_LoginTasks
      *
      * @param string $app  The name of the Horde application.
      */
-    protected function __construct(
-        Horde_LoginTasks_Backend $backend,
-        $app
-    ) {
+    public function __construct(Horde_LoginTasks_Backend $backend)
+    {
         $this->_backend = $backend;
 
-        $this->_app = $app;
-
         if (!$this->_backend->isAuthenticated()) {
             return;
         }
@@ -217,7 +212,7 @@ class Horde_LoginTasks
      *                            have been confirmed by the user.
      * @param string $url         The URL to redirect to when finished.
      */
-    public function runTasks($confirmed = false, $url = null, $no_redirect = false)
+    public function runTasks($confirmed = false, $url = null)
     {
         if (!isset($this->_tasklist) ||
             ($this->_tasklist === true)) {
@@ -250,13 +245,9 @@ class Horde_LoginTasks
 
         if (!$processed && $need_display) {
             $this->_tasklist->target = $url;
-            if ($no_redirect) return $this->getLoginTasksUrl();
-            header('Location: ' . $this->getLoginTasksUrl());
-            exit;
+            return $this->_backend->redirect($this->getLoginTasksUrl());
         } elseif ($processed && !$need_display) {
-            if ($no_redirect) return $tasklist_target;
-            header('Location: ' . $tasklist_target);
-            exit;
+            return $this->_backend->redirect($tasklist_target);
         }
     }
 
index 56cfe90..93dc64e 100644 (file)
@@ -81,6 +81,15 @@ abstract class Horde_LoginTasks_Backend
     abstract public function markLastRun();
 
     /**
+     * Redirect to the given URL.
+     *
+     * @param string $url The URL to redirect to.
+     *
+     * @return NULL
+     */
+    abstract public function redirect($url);
+
+    /**
      * Return the URL of the login tasks view.
      *
      * @return string The URL of the login tasks view
index c34d190..b95be3d 100644 (file)
@@ -169,6 +169,19 @@ extends Horde_LoginTasks_Backend
     }
 
     /**
+     * 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.
      *
      * @return string The URL of the login tasks view
index edf7abd..9ff3a22 100644 (file)
@@ -31,8 +31,6 @@ require_once dirname(__FILE__) . '/Autoload.php';
 
 class Horde_LoginTasks_Class_LoginTasksTest extends PHPUnit_Framework_TestCase
 {
-    static private $_singleton_counter = 0;
-
     public function testNoTasksAreRanIfNoUserIsAuthenticated()
     {
         Horde_LoginTasks_Stub_Task::$executed = array();
@@ -523,7 +521,7 @@ class Horde_LoginTasks_Class_LoginTasksTest extends PHPUnit_Framework_TestCase
             );
             $last_time = serialize(
                 array(
-                    'test' . self::$_singleton_counter => $last_time
+                    'test' => $last_time
                 )
             );
         }
@@ -539,6 +537,12 @@ class Horde_LoginTasks_Class_LoginTasksTest extends PHPUnit_Framework_TestCase
         $GLOBALS['registry']->expects($this->any())
             ->method('getAppDrivers')
             ->will($this->returnValue($tasks));
-        return Horde_LoginTasks::singleton('test' . self::$_singleton_counter++);
+        return new Horde_LoginTasks(
+            new Horde_LoginTasks_Stub_Backend(
+                $GLOBALS['registry'],
+                $GLOBALS['prefs'],
+                'test'
+            )
+        );
     }
 }
index 73e034e..da18568 100644 (file)
@@ -37,6 +37,15 @@ 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
 {