From 3e4a9d6208d5cdec779b80517db1a52d9829a933 Mon Sep 17 00:00:00 2001 From: Jan Schneider Date: Mon, 10 May 2010 12:06:27 +0200 Subject: [PATCH] We have to set up the handlers all at once first, to avoid them being loaded automatically on demand. --- .../Alarm/lib/Horde/Alarm/Handler/Desktop.php | 6 +-- framework/Alarm/lib/Horde/Alarm/Handler/Notify.php | 2 +- framework/Alarm/test/Horde/Alarm/HandlerTest.php | 51 +++++++++++++--------- framework/Core/lib/Horde/Core/Binder/Alarm.php | 4 ++ 4 files changed, 38 insertions(+), 25 deletions(-) diff --git a/framework/Alarm/lib/Horde/Alarm/Handler/Desktop.php b/framework/Alarm/lib/Horde/Alarm/Handler/Desktop.php index d7a7f247f..549d110c7 100644 --- a/framework/Alarm/lib/Horde/Alarm/Handler/Desktop.php +++ b/framework/Alarm/lib/Horde/Alarm/Handler/Desktop.php @@ -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'); } /** diff --git a/framework/Alarm/lib/Horde/Alarm/Handler/Notify.php b/framework/Alarm/lib/Horde/Alarm/Handler/Notify.php index d2470ad25..f3ac2c764 100644 --- a/framework/Alarm/lib/Horde/Alarm/Handler/Notify.php +++ b/framework/Alarm/lib/Horde/Alarm/Handler/Notify.php @@ -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'); } /** diff --git a/framework/Alarm/test/Horde/Alarm/HandlerTest.php b/framework/Alarm/test/Horde/Alarm/HandlerTest.php index 4c12bfa9d..f8638062f 100644 --- a/framework/Alarm/test/Horde/Alarm/HandlerTest.php +++ b/framework/Alarm/test/Horde/Alarm/HandlerTest.php @@ -10,9 +10,20 @@ 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 = <<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); } } diff --git a/framework/Core/lib/Horde/Core/Binder/Alarm.php b/framework/Core/lib/Horde/Core/Binder/Alarm.php index 658cba8af..56b24b53a 100644 --- a/framework/Core/lib/Horde/Core/Binder/Alarm.php +++ b/framework/Core/lib/Horde/Core/Binder/Alarm.php @@ -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'), -- 2.11.0