We have to set up the handlers all at once first, to avoid them being loaded automati...
authorJan Schneider <jan@horde.org>
Mon, 10 May 2010 10:06:27 +0000 (12:06 +0200)
committerJan Schneider <jan@horde.org>
Mon, 10 May 2010 12:04:31 +0000 (14:04 +0200)
framework/Alarm/lib/Horde/Alarm/Handler/Desktop.php
framework/Alarm/lib/Horde/Alarm/Handler/Notify.php
framework/Alarm/test/Horde/Alarm/HandlerTest.php
framework/Core/lib/Horde/Core/Binder/Alarm.php

index d7a7f24..549d110 100644 (file)
@@ -52,11 +52,11 @@ class Horde_Alarm_Handler_Desktop extends Horde_Alarm_Handler
         }
         $this->_notification = $params['notification'];
         if (isset($params['icon'])) {
-            $this->_icon = $param['icon'];
+            $this->_icon = $params['icon'];
         }
         */
-        $this->_notification = $GLOBALS['injector']->getInstance('Horde_Notification');
-        $this->_icon = (string)Horde_Themes::img('alerts/alarm.png');
+        $this->_notification = isset($params['notification']) ? $params['notification'] : $GLOBALS['injector']->getInstance('Horde_Notification');
+        $this->_icon = isset($params['icon']) ? $params['icon'] : (string)Horde_Themes::img('alerts/alarm.png');
     }
 
     /**
index d2470ad..f3ac2c7 100644 (file)
@@ -50,7 +50,7 @@ class Horde_Alarm_Handler_Notify extends Horde_Alarm_Handler
         }
         $this->_notification = $params['notification'];
         */
-        $this->_notification = $GLOBALS['injector']->getInstance('Horde_Notification');
+        $this->_notification = isset($params['notification']) ? $params['notification'] : $GLOBALS['injector']->getInstance('Horde_Notification');
     }
 
     /**
index 4c12bfa..f863806 100644 (file)
 class Horde_Alarm_HandlerTest extends PHPUnit_Framework_TestCase
 {
     protected static $alarm;
+    protected static $storage;
+    protected static $mail;
 
     public function setUp()
     {
+        if (!class_exists('Horde_Notification')) {
+            $this->markTestSkipped('Horde_Notification not installed');
+            return;
+        }
+        if (!class_exists('Mail')) {
+            $this->markTestSkipped('Mail not installed');
+            return;
+        }
+
         self::$alarm = Horde_Alarm::factory('Object');
         $now = time();
         $hash = array('id' => 'personalalarm',
@@ -24,40 +35,38 @@ class Horde_Alarm_HandlerTest extends PHPUnit_Framework_TestCase
                       'title' => 'This is a personal alarm.',
                       'text' => 'Action is required.');
         self::$alarm->set($hash);
+
+        self::$storage = new Horde_Notification_Storage_Object();
+        $notification = new Horde_Notification_Handler(self::$storage);
+        $handler = new Horde_Alarm_Handler_Notify(array('notification' => $notification));
+        self::$alarm->addHandler('notify', $handler);
+
+        $handler = new Horde_Alarm_Handler_Desktop(array('notification' => $notification, 'icon' => 'test.png'));
+        self::$alarm->addHandler('desktop', $handler);
+
+        self::$mail = new Horde_Alarm_HandlerTest_Mail();
+        $factory = new Horde_Alarm_HandlerTest_IdentityFactory();
+        $handler = new Horde_Alarm_Handler_Mail(array('mail' => self::$mail, 'identity' => $factory, 'charset' => 'us-ascii'));
+        self::$alarm->addHandler('mail', $handler);
     }
 
     public function testNotify()
     {
-        if (!class_exists('Horde_Notification')) {
-            $this->markTestSkipped('Horde_Notification not installed');
-            return;
-        }
         $alarm = self::$alarm->get('personalalarm', 'john');
         $alarm['methods'] = array('notify');
         self::$alarm->set($alarm);
-        $storage = new Horde_Notification_Storage_Object();
-        $handler = new Horde_Alarm_Handler_Notify(array('notification' => new Horde_Notification_Handler($storage)));
-        self::$alarm->addHandler('notify', $handler);
         self::$alarm->notify('john', false);
 
-        $this->assertEquals(1, count($storage->notifications['_unattached']));
-        $this->assertEquals('This is a personal alarm.', $storage->notifications['_unattached'][0]->message);
-        $this->assertEquals('horde.alarm', $storage->notifications['_unattached'][0]->type);
+        $this->assertEquals(1, count(self::$storage->notifications['_unattached']));
+        $this->assertEquals('This is a personal alarm.', self::$storage->notifications['_unattached'][0]->message);
+        $this->assertEquals('horde.alarm', self::$storage->notifications['_unattached'][0]->type);
     }
 
     public function testMail()
     {
-        if (!class_exists('Mail')) {
-            $this->markTestSkipped('Mail not installed');
-            return;
-        }
         $alarm = self::$alarm->get('personalalarm', 'john');
         $alarm['methods'] = array('mail');
         self::$alarm->set($alarm);
-        $mail = new Horde_Alarm_HandlerTest_Mail();
-        $factory = new Horde_Alarm_HandlerTest_IdentityFactory();
-        $handler = new Horde_Alarm_Handler_Mail(array('mail' => $mail, 'identity' => $factory, 'charset' => 'us-ascii'));
-        self::$alarm->addHandler('mail', $handler);
         self::$alarm->notify('john', false);
         $regexp = <<<EOR
 Subject: This is a personal alarm\.
@@ -75,10 +84,10 @@ Action is required\.
 
 EOR;
 
-        $this->assertRegExp('/' . trim(str_replace("\r\n", "\n", $regexp)) . '/', trim(str_replace("\r\n", "\n", $mail->sentOutput)));
-        $mail->sentOutput = null;
+        $this->assertRegExp('/' . trim(str_replace("\r\n", "\n", $regexp)) . '/', trim(str_replace("\r\n", "\n", self::$mail->sentOutput)));
+        self::$mail->sentOutput = null;
         self::$alarm->notify('john', false);
-        $this->assertNull($mail->sentOutput);
+        $this->assertNull(self::$mail->sentOutput);
     }
 }
 
index 658cba8..56b24b5 100644 (file)
@@ -23,6 +23,10 @@ class Horde_Core_Binder_Alarm implements Horde_Injector_Binder
         $handler_params = array(
             'notification' => $injector->getInstance('Horde_Notification'));
         $alarm->addHandler('notify', new Horde_Alarm_Handler_Notification($handler_params));
+        $handler_params = array(
+            'notification' => $injector->getInstance('Horde_Notification'),
+            'icon' => (string)Horde_Themes::img('alerts/alarm.png'));
+        $alarm->addHandler('desktop', new Horde_Alarm_Handler_Desktop($handler_params));
         */
         $handler_params = array(
             'identity' => $injector->getInstance('Horde_Prefs_Identity'),