From e48b8a54fc54a179be749967a6a8b6b73cc1162e Mon Sep 17 00:00:00 2001 From: Michael M Slusarz Date: Mon, 15 Feb 2010 23:27:31 -0700 Subject: [PATCH] Another Notification rewrite. First, fix Bug #8870. Fixed by removing Nag specific event type (nag.alarm). However, this was just a symptom of a larger problem. The problem: using application specific Notification handlers to handle application specific event types. The problem comes when switching between applications. Since these application handlers don't have any knowledge of each other, events created by one handler may not be able to be displayed when notify() was eventually called, because another status handler had replaced the original handler. The solution: all notifications need to be handled by a single, centralized source - namely, the horde-level handlers. Application specific details are instead injected into the horde-level handler to extend behavior. While reworking the code, also provided opportunity to remove all application-specific code from Notification. Horde-specific instantiation (i.e. adding Horde logging and Alarm decorators) is now done in Horde_Core rather than in the base Notification object. Additionally, rework some of the complexity added to the package. I believe the goal of the recent Notification changes was to make the Notification package testable and/or usable outside of a base Horde install. But these changes also made the code unreadable, redundant, and overly complex. e.g. using interfaces where simple class extensions make much more sense (IMHO - there are very few cases where an interface makes more sense than an abstract class. Using interfaces for the Handler class was simply overkill. Out of the 10 methods defined, there are only 2 methods useful for decorator purposes - push() and notify(). And any given decorator won't even use both of these. Having to contort code to do things like chaining handlers to achieve this in an interface pattern was almost impossible to follow. It is much simpler to simply add decorators directly to the base handler object. --- framework/Ajax/lib/Horde/Ajax/Application/Base.php | 18 +- framework/Core/lib/Horde.php | 13 +- .../Core/lib/Horde/Core/Binder/Notification.php | 22 ++ .../Core/lib/Horde/Core/Notification/Status.php | 109 ++++++++++ framework/Core/lib/Horde/Registry.php | 15 +- framework/Core/package.xml | 6 + framework/Notification/lib/Horde/Notification.php | 8 +- .../Notification/lib/Horde/Notification/Event.php | 16 +- .../lib/Horde/Notification/Event/Status.php | 32 +++ .../Notification/{Handler/Base.php => Handler.php} | 234 +++++++++++++++------ .../Horde/Notification/Handler/Decorator/Alarm.php | 155 ++------------ .../Horde/Notification/Handler/Decorator/Base.php | 39 ++++ .../Notification/Handler/Decorator/Hordelog.php | 153 +------------- .../Horde/Notification/Handler/Decorator/Log.php | 169 ++------------- .../lib/Horde/Notification/Handler/Interface.php | 118 ----------- .../lib/Horde/Notification/Listener.php | 47 +++-- .../lib/Horde/Notification/Listener/Audio.php | 29 +-- .../lib/Horde/Notification/Listener/Javascript.php | 47 ++--- .../lib/Horde/Notification/Listener/Mobile.php | 86 -------- .../lib/Horde/Notification/Listener/Status.php | 149 ++----------- framework/Notification/package.xml | 33 ++- .../test/Horde/Notification/Autoload.php | 3 + .../Notification/Class/Notification/EventTest.php | 6 +- .../Notification/Handler/Decorator/AlarmTest.php | 92 +------- .../Handler/Decorator/HordelogTest.php | 103 +-------- .../Notification/Handler/Decorator/LogTest.php | 90 +------- .../{Handler/BaseTest.php => HandlerTest.php} | 93 ++++---- .../Class/Notification/Listener/AudioTest.php | 4 +- .../Class/Notification/Listener/JavascriptTest.php | 10 +- .../Class/Notification/Listener/MobileTest.php | 122 ----------- .../Class/Notification/Listener/StatusTest.php | 42 +--- .../Class/Notification/ListenerTest.php | 146 +------------ .../Horde/Notification/Class/NotificationTest.php | 16 +- framework/Prefs/lib/Horde/Prefs/Ui.php | 1 - horde/services/ajax.php | 4 +- horde/services/prefs.php | 5 - imp/compose-dimp.php | 5 +- imp/js/DimpCore.js | 6 +- imp/lib/Ajax/Application.php | 18 +- imp/lib/Application.php | 45 ++-- imp/lib/Auth.php | 9 +- imp/lib/Dimp.php | 15 -- imp/lib/Notification/Event/Status.php | 45 ++++ imp/lib/Notification/Handler/Decorator/Imap.php | 34 +++ imp/lib/Notification/Listener/AjaxStatus.php | 34 +++ imp/lib/Notification/Listener/Status.php | 94 --------- imp/lib/Notification/Listener/StatusMobile.php | 34 --- imp/message-dimp.php | 4 +- imp/message-mimp.php | 3 +- imp/templates/compose/compose-mimp.inc | 3 +- imp/templates/compose/redirect-mimp.inc | 3 +- imp/templates/folders/folders-mimp.inc | 3 +- imp/templates/mailbox/mailbox-mimp.inc | 3 +- imp/templates/mailbox/search-mimp.inc | 3 +- kronolith/lib/Ajax/Application.php | 10 +- nag/lib/Application.php | 2 - nag/lib/Nag.php | 4 +- nag/lib/Notification/Listener/Status.php | 25 --- 58 files changed, 769 insertions(+), 1868 deletions(-) create mode 100644 framework/Core/lib/Horde/Core/Binder/Notification.php create mode 100644 framework/Core/lib/Horde/Core/Notification/Status.php create mode 100644 framework/Notification/lib/Horde/Notification/Event/Status.php rename framework/Notification/lib/Horde/Notification/{Handler/Base.php => Handler.php} (57%) create mode 100644 framework/Notification/lib/Horde/Notification/Handler/Decorator/Base.php delete mode 100644 framework/Notification/lib/Horde/Notification/Handler/Interface.php delete mode 100644 framework/Notification/lib/Horde/Notification/Listener/Mobile.php rename framework/Notification/test/Horde/Notification/Class/Notification/{Handler/BaseTest.php => HandlerTest.php} (68%) delete mode 100644 framework/Notification/test/Horde/Notification/Class/Notification/Listener/MobileTest.php create mode 100644 imp/lib/Notification/Event/Status.php create mode 100644 imp/lib/Notification/Handler/Decorator/Imap.php create mode 100644 imp/lib/Notification/Listener/AjaxStatus.php delete mode 100644 imp/lib/Notification/Listener/Status.php delete mode 100644 imp/lib/Notification/Listener/StatusMobile.php delete mode 100644 nag/lib/Notification/Listener/Status.php diff --git a/framework/Ajax/lib/Horde/Ajax/Application/Base.php b/framework/Ajax/lib/Horde/Ajax/Application/Base.php index 6eda893b0..9acc00c9a 100644 --- a/framework/Ajax/lib/Horde/Ajax/Application/Base.php +++ b/framework/Ajax/lib/Horde/Ajax/Application/Base.php @@ -13,6 +13,13 @@ abstract class Horde_Ajax_Application_Base { /** + * Determines if notification information is sent in response. + * + * @var boolean + */ + public $notify = false; + + /** * The Horde application. * * @var string @@ -88,17 +95,6 @@ abstract class Horde_Ajax_Application_Base } /** - * Returns a notification handler object to use to output any - * notification messages triggered by the AJAX action. - * - * @return Horde_Notification_Handler_Base The notification handler. - */ - public function notificationHandler() - { - return null; - } - - /** * Determines the HTTP response output type. * * @see Horde::sendHTTPResponse(). diff --git a/framework/Core/lib/Horde.php b/framework/Core/lib/Horde.php index ebbc071ab..60d1445b6 100644 --- a/framework/Core/lib/Horde.php +++ b/framework/Core/lib/Horde.php @@ -607,17 +607,16 @@ HTML; /** * Returns a stdClass response object with added notification information. * - * @param mixed $data The 'response' data. - * @param Notification_Listener $listener If set, adds notification - * information to object. + * @param mixed $data The 'response' data. + * @param boolean $notify If true, adds notification info to object. */ - static public function prepareResponse($data = null, $listener = null) + static public function prepareResponse($data = null, $notify = false) { $response = new stdClass(); $response->response = $data; - if ($listener) { - $GLOBALS['notification']->notify(array('listeners' => 'status', 'store' => true)); - $stack = $listener->getStack(); + + if ($notify) { + $stack = $GLOBALS['notification']->notify(array('listeners' => 'status', 'raw' => true)); if (!empty($stack)) { $response->msgs = $stack; } diff --git a/framework/Core/lib/Horde/Core/Binder/Notification.php b/framework/Core/lib/Horde/Core/Binder/Notification.php new file mode 100644 index 000000000..780dda7af --- /dev/null +++ b/framework/Core/lib/Horde/Core/Binder/Notification.php @@ -0,0 +1,22 @@ +addType('default', '*', 'Horde_Core_Notification_Status'); + $notify->addType('status', 'horde.*', 'Horde_Core_Notification_Status'); + + $notify->addDecorator(new Horde_Notification_Handler_Decorator_Alarm(Horde_Alarm::factory(), Horde_Auth::getAuth())); + $notify->addDecorator(new Horde_Notification_Handler_Decorator_Hordelog()); + + return $notify; + } + + public function equals(Horde_Injector_Binder $binder) + { + return false; + } + +} diff --git a/framework/Core/lib/Horde/Core/Notification/Status.php b/framework/Core/lib/Horde/Core/Notification/Status.php new file mode 100644 index 000000000..676e41991 --- /dev/null +++ b/framework/Core/lib/Horde/Core/Notification/Status.php @@ -0,0 +1,109 @@ + + * @package Horde_Core + */ +class Horde_Core_Notification_Status extends Horde_Notification_Event_Status +{ + /** + * Constructor. + * + * @param mixed $data Message: either a string or an Exception or + * PEAR_Error object. + * @param string $type The event type. + * @param array $flags The flag array. + */ + public function __construct($data, $type = null, array $flags = array()) + { + if (is_null($type)) { + $type = ($data instanceof PEAR_Error || $data instanceof Exception) + ? 'horde.error' + : (is_string($data) ? 'horde.message' : 'horde.error'); + } + + parent::__construct($data, $type, $flags); + } + + /** + * String representation of this object. + * + * @return string String representation. + */ + public function __toString() + { + $text = null; + + switch ($this->type) { + case 'horde.alarm': + $alarm = $this->flags['alarm']; + $text = $alarm['title']; + + if (!empty($alarm['params']['notify']['show'])) { + $text = Horde::link(Horde::url($GLOBALS['registry']->linkByPackage($alarm['params']['notify']['show']['__app'], 'show', $alarm['params']['notify']['show'])), $alarm['text']) . $text . ''; + } + + if (!empty($alarm['user']) && + $GLOBALS['browser']->hasFeature('xmlhttpreq')) { + Horde::addScriptFile('prototype.js', 'horde'); + $url = Horde::url($GLOBALS['registry']->get('webroot', 'horde') . '/services/snooze.php', true); + $opts = array( + '-1' => _("Dismiss"), + '5' => _("5 minutes"), + '15' => _("15 minutes"), + '60' => _("1 hour"), + '360' => _("6 hours"), + '1440' => _("1 day") + ); + $id = 'snooze_' . md5($alarm['id']); + $text .= ' [' . _("Snooze...") . ']'; + } + + $img = 'alerts/alarm.png'; + $label = _("Alarm"); + break; + + case 'horde.error': + $img = 'alerts/error.png'; + $label = _("Error"); + $text = parent::__toString($this->message); + break; + + case 'horde.message': + $img = 'alerts/message.png'; + $label = _("Message"); + $text = parent::__toString($this->message); + break; + + case 'horde.success': + $img = 'alerts/success.png'; + $label = _("Success"); + $text = parent::__toString($this->message); + break; + + case 'horde.warning': + $img = 'alerts/warning.png'; + $label = _("Warning"); + $text = parent::__toString($this->message); + break; + } + + return Horde::img($img, $label, null, $GLOBALS['registry']->getImageDir('horde')) . $text; + } + +} diff --git a/framework/Core/lib/Horde/Registry.php b/framework/Core/lib/Horde/Registry.php index 7c58e3a51..f905cf97d 100644 --- a/framework/Core/lib/Horde/Registry.php +++ b/framework/Core/lib/Horde/Registry.php @@ -232,6 +232,7 @@ class Horde_Registry $injector->addBinder('Horde_Db_Adapter_Base', new Horde_Core_Binder_Db('reader')); $injector->addBinder('Horde_Log_Logger', new Horde_Core_Binder_Logger()); $injector->addBinder('Horde_Memcache', new Horde_Core_Binder_Memcache()); + $injector->addBinder('Horde_Notification', new Horde_Core_Binder_Notification()); $injector->addBinder('Horde_Perms', new Horde_Core_Binder_Perms()); $injector->addBinder('Horde_Template', new Horde_Core_Binder_Template()); $injector->addBinder('Net_DNS_Resolver', new Horde_Core_Binder_Dns()); @@ -315,11 +316,15 @@ class Horde_Registry } /* Initialize notification object. Always attach status listener by - * default. */ - $GLOBALS['notification'] = Horde_Notification::singleton(); - $statusListener = $GLOBALS['notification']->attach('status'); - $injector->setInstance('Horde_Notification', $GLOBALS['notification']); - $injector->setInstance('Horde_Notification_Listener', $statusListener); + * default. Default status listener can be overriden through the + * $_SESSION['horde_notification']['override'] variable. */ + $GLOBALS['notification'] = $injector->getInstance('Horde_Notification'); + if (isset($_SESSION['horde_notification']['override'])) { + require_once $_SESSION['horde_notification']['override'][0]; + $GLOBALS['notification']->attach('status', null, $_SESSION['horde_notification']['override'][1]); + } else { + $GLOBALS['notification']->attach('status'); + } } /** diff --git a/framework/Core/package.xml b/framework/Core/package.xml index c7c868176..9e6ccbc07 100644 --- a/framework/Core/package.xml +++ b/framework/Core/package.xml @@ -66,9 +66,13 @@ Application Framework. + + + + @@ -156,8 +160,10 @@ Application Framework. + + diff --git a/framework/Notification/lib/Horde/Notification.php b/framework/Notification/lib/Horde/Notification.php index 976a8244d..ecb261097 100644 --- a/framework/Notification/lib/Horde/Notification.php +++ b/framework/Notification/lib/Horde/Notification.php @@ -35,13 +35,7 @@ class Horde_Notification static public function singleton($stack = 'horde_notification_stacks') { if (!isset(self::$_instances[$stack])) { - $storage = new Horde_Notification_Storage_Session($stack); - - $handler = new Horde_Notification_Handler_Base($storage); - $handler = new Horde_Notification_Handler_Decorator_Hordelog($handler); - $handler = new Horde_Notification_Handler_Decorator_Alarm($handler, Horde_Alarm::factory()); - - self::$_instances[$stack] = $handler; + self::$_instances[$stack] = new Horde_Notification_Handler(new Horde_Notification_Storage_Session($stack)); } return self::$_instances[$stack]; diff --git a/framework/Notification/lib/Horde/Notification/Event.php b/framework/Notification/lib/Horde/Notification/Event.php index eb09147b1..fa593ae3d 100644 --- a/framework/Notification/lib/Horde/Notification/Event.php +++ b/framework/Notification/lib/Horde/Notification/Event.php @@ -45,6 +45,10 @@ class Horde_Notification_Event { $this->flags = $flags; + $this->type = empty($type) + ? 'status' + : $type; + if ($data instanceof PEAR_Error) { // DEPRECATED if (($userinfo = $data->getUserInfo()) && @@ -66,25 +70,13 @@ class Horde_Notification_Event } else { $this->message = $data->getMessage(); } - - if (is_null($type)) { - $type = 'horde.error'; - } } elseif ($data instanceof Exception) { // Exception $this->message = $data->getMessage(); - if (is_null($type)) { - $type = 'horde.error'; - } } else { // String or object $this->message = strval($data); - if (is_null($type)) { - $type = is_string($data) ? 'horde.message' : 'horde.error'; - } } - - $this->type = $type; } /** diff --git a/framework/Notification/lib/Horde/Notification/Event/Status.php b/framework/Notification/lib/Horde/Notification/Event/Status.php new file mode 100644 index 000000000..f4fb39caf --- /dev/null +++ b/framework/Notification/lib/Horde/Notification/Event/Status.php @@ -0,0 +1,32 @@ + + * @package Horde_Notification + */ +class Horde_Notification_Event_Status extends Horde_Notification_Event +{ + /** + * String representation of this object. + * + * @return string String representation. + */ + public function __toString() + { + $text = $this->message; + + if (!in_array('content.raw', $this->flags)) { + $text = htmlspecialchars($text, ENT_COMPAT, Horde_Nls::getCharset()); + } + + return $text; + } + +} diff --git a/framework/Notification/lib/Horde/Notification/Handler/Base.php b/framework/Notification/lib/Horde/Notification/Handler.php similarity index 57% rename from framework/Notification/lib/Horde/Notification/Handler/Base.php rename to framework/Notification/lib/Horde/Notification/Handler.php index 22381371c..ed93bfbf0 100644 --- a/framework/Notification/lib/Horde/Notification/Handler/Base.php +++ b/framework/Notification/lib/Horde/Notification/Handler.php @@ -12,8 +12,7 @@ * @author Jan Schneider * @package Horde_Notification */ -class Horde_Notification_Handler_Base -implements Horde_Notification_Handler_Interface +class Horde_Notification_Handler { /** * Hash containing all attached listener objects. @@ -23,24 +22,34 @@ implements Horde_Notification_Handler_Interface protected $_listeners = array(); /** - * The storage location where we store the messages. + * Decorators. * - * @var Horde_Notification_Storage + * @var array */ - protected $_storage; + protected $_decorators = array(); + + /** + * Additional handle definitions. + * + * @var array + */ + protected $_handles = array( + 'default' => array( + '*' => 'Horde_Notification_Event' + ) + ); /** - * A Horde_Alarm instance. + * The storage location where we store the messages. * - * @var Horde_Alarm + * @var Horde_Notification_Storage */ - protected $_alarm; + protected $_storage; /** * Initialize the notification system. * - * @param Horde_Notification_Storage $storage The storage location to - * use. + * @param Horde_Notification_Storage $storage The storage object to use. */ public function __construct(Horde_Notification_Storage_Interface $storage) { @@ -62,20 +71,19 @@ implements Horde_Notification_Handler_Interface * you have to include the library file * containing this class yourself. This is useful * if you want the listener driver to be - * overriden by an application's implementation. + * overriden by an application's implementation * * @return Horde_Notification_Listener The listener object. * @throws Horde_Exception */ public function attach($listener, $params = null, $class = null) { - $listener = Horde_String::lower(basename($listener)); - if (!empty($this->_listeners[$listener])) { - return $this->_listeners[$listener]; + if ($ob = $this->getListener($listener)) { + return $ob; } if (is_null($class)) { - $class = 'Horde_Notification_Listener_' . Horde_String::ucfirst($listener); + $class = 'Horde_Notification_Listener_' . Horde_String::ucfirst(Horde_String::lower($listener)); } if (class_exists($class)) { @@ -83,6 +91,7 @@ implements Horde_Notification_Handler_Interface if (!$this->_storage->exists($listener)) { $this->_storage->set($listener, array()); } + $this->_addTypes($listener); return $this->_listeners[$listener]; } @@ -98,57 +107,111 @@ implements Horde_Notification_Handler_Interface */ public function detach($listener) { - $listener = Horde_String::lower(basename($listener)); - if (isset($this->_listeners[$listener])) { - unset($this->_listeners[$listener]); + if ($ob = $this->getListener($listener)) { + unset($this->_listeners[$ob->getName()]); + $this->_storage->clear($ob->getName()); } else { throw new Horde_Exception(sprintf('Notification listener %s not found.', $listener)); } } /** - * Replaces a listener in the notification list. If the listener does not - * exist, the new listener will be added automatically. + * Clear any notification events that may exist in a listener. + * + * @param string $listener The name of the listener to flush. If null, + * clears all unattached events. + */ + public function clear($listener = null) + { + if (is_null($listener)) { + $this->_storage->clear('_unattached'); + } elseif ($ob = $this->getListener($listener)) { + $this->_storage->clear($ob->getName()); + } + } + + /** + * Returns the current Listener object for a given listener type. * - * @param string $listener See attach(). - * @param array $params See attach(). - * @param string $class See attach(). + * @param string $type The listener type. * - * @return Horde_Notification_Listener See attach(). + * @return mixed A Horde_Notification_Listener object, or null if + * $type listener is not attached. */ - public function replace($listener, array $params = array(), $class = null) + public function get($type) { - try { - $this->detach($listener); - } catch (Horde_Exception $e) {} + foreach ($this->_listeners as $listener) { + if ($listener->handles($type)) { + return $listener; + } + } - return $this->attach($listener, $params, $class); + return null; } /** - * Clear any notification events that may exist in a listener. + * Returns a listener object given a listener name. * - * @param string $listener The name of the listener to flush. If null, - * clears all unattached events. + * @param string $listener The listener name. + * + * @return mixed Either a Horde_Notification_Listener or null. */ - public function clear($listener = null) + public function getListener($listener) { - if (is_null($listener)) { - $this->_storage->clear('_unattached'); - } else { - $listener = Horde_String::lower(basename($listener)); - if (isset($this->_listeners[$listener])) { - $this->_storage->clear($this->_listeners[$listener]->getName()); + $listener = Horde_String::lower(basename($listener)); + return empty($this->_listeners[$listener]) + ? null + : $this->_listeners[$listener]; + } + + /** + * Adds a type handler to a given Listener. + * To change the default listener, use the following: + *
+     *   $ob->addType('default', '*', $classname);
+     * 
+ * + * @param string $listener The listener name. + * @param string $type The listener type. + * @param string $class The Event class to use. + */ + public function addType($listener, $type, $class) + { + $this->_handles[$listener][$type] = $class; + + if (isset($this->_listeners[$listener])) { + $this->_addTypes($listener); + } + } + + /** + * Adds any additional listener types to a given Listener. + * + * @param string $listener The listener name. + */ + protected function _addTypes($listener) + { + if (isset($this->_handles[$listener])) { + foreach ($this->_handles[$listener] as $type => $class) { + $this->_listeners[$listener]->addType($type, $class); } } } /** - * Add an event to the Horde message stack. + * Add a decorator. * - * The event type parameter should begin with 'horde.' unless the - * application defines its own Horde_Notification_Listener subclass that - * handles additional codes. + * @param Horde_Notification_Handler_Decorator_Base $decorator The + * Decorator + * object. + */ + public function addDecorator(Horde_Notification_Handler_Decorator_Base $decorator) + { + $this->_decorators[] = $decorator; + } + + /** + * Add an event to the Horde message stack. * * @param mixed $event Horde_Notification_Event object or message * string. @@ -171,17 +234,23 @@ implements Horde_Notification_Handler_Interface $event->flags = $flags; $event->type = $type; } else { + $class = (!is_null($type) && ($listener = $this->get($type))) + ? $listener->handles($type) + : $this->_handles['default']['*']; + /* Transparently create a Horde_Notification_Event object. */ - $event = new Horde_Notification_Event($event, $type, $flags); + $event = new $class($event, $type, $flags); + } + + foreach ($this->_decorators as $decorator) { + $decorator->push($event, $options); } if (empty($options['immediate'])) { $this->_storage->push('_unattached', $event); } else { - foreach ($this->_listeners as $listener) { - if ($listener->handles($event->type)) { - $this->_storage->push($listener->getName(), $event); - } + if ($listener = $this->get($event->type)) { + $this->_storage->push($listener->getName(), $event); } } } @@ -191,15 +260,23 @@ implements Horde_Notification_Handler_Interface * handle their messages. * * @param array $options An array containing display options for the - * listeners. + * listeners. Any options not contained in this + * list will be passed to the listeners. *
-     * 'listeners' - The list of listeners to notify.
+     * 'listeners' - (array) The list of listeners to notify.
+     * 'raw' - (boolean) If true, does not call the listener's notify()
+     *         function.
      * 
*/ public function notify(array $options = array()) { $options = $this->setNotificationListeners($options); - $this->notifyListeners($options); + + foreach ($this->_decorators as $decorator) { + $decorator->notify($options); + } + + return $this->notifyListeners($options); } /** @@ -207,7 +284,8 @@ implements Horde_Notification_Handler_Interface * notification handler. * * @param array $options An array containing display options for the - * listeners. + * listeners. See self::notify() for the valid + * keys. * * @return array The list of listeners to notify. */ @@ -218,6 +296,7 @@ implements Horde_Notification_Handler_Interface } elseif (!is_array($options['listeners'])) { $options['listeners'] = array($options['listeners']); } + $options['listeners'] = array_map(array('Horde_String', 'lower'), $options['listeners']); return $options; @@ -230,7 +309,10 @@ implements Horde_Notification_Handler_Interface * @param array $options An array containing display options for the * listeners. This array is required to contain the * correct lowercased listener names as array in the - * entry 'listeners'. + * entry 'listeners'. See self::notify() for the + * other valid keys. + * + * @return array The list of events that were sent to the listeners. */ public function notifyListeners(array $options) { @@ -238,18 +320,31 @@ implements Horde_Notification_Handler_Interface ? $this->_storage->get('_unattached') : array(); + $events = array(); + foreach ($options['listeners'] as $listener) { if (isset($this->_listeners[$listener])) { $instance = $this->_listeners[$listener]; + $name = $instance->getName(); foreach (array_keys($unattached) as $val) { if ($instance->handles($unattached[$val]->type)) { - $this->_storage->push($instance->getName(), $unattached[$val]); + $this->_storage->push($name, $unattached[$val]); unset($unattached[$val]); } } - $instance->notify($this->_storage->get($instance->getName()), $options); + if (!$this->_storage->exists($name)) { + continue; + } + + $tmp = $this->_storage->get($name); + if (empty($options['raw'])) { + $instance->notify($tmp, $options); + } + $this->_storage->clear($name); + + $events = array_merge($events, $tmp); } } @@ -258,6 +353,8 @@ implements Horde_Notification_Handler_Interface } else { $this->_storage->set('_unattached', $unattached); } + + return $events; } /** @@ -271,14 +368,29 @@ implements Horde_Notification_Handler_Interface */ public function count($my_listener = null) { + $count = 0; + if (!is_null($my_listener)) { - return @count($this->_storage->get($this->_listeners[Horde_String::lower($my_listener)]->getName())); - } + if ($ob = $this->get($my_listener)) { + $count = count($this->_storage->get($ob->getName())); - $count = 0; - foreach (array_merge($this->_listeners, array('_unattached')) as $val) { - if ($this->_storage->exists($val->getName())) { - $count += count($this->_storage->get($val->getName())); + if ($this->_storage->exists('_unattached')) { + foreach ($this->_storage->get('_unattached') as $val) { + if ($ob->handles($val->type)) { + ++$count; + } + } + } + } + } else { + if ($this->_storage->exists('_unattached')) { + $count = count($this->_storage->get('_unattached')); + } + + foreach ($this->_listeners as $val) { + if ($this->_storage->exists($val->getName())) { + $count += count($this->_storage->get($val->getName())); + } } } diff --git a/framework/Notification/lib/Horde/Notification/Handler/Decorator/Alarm.php b/framework/Notification/lib/Horde/Notification/Handler/Decorator/Alarm.php index efab2c2ee..0189abf6a 100644 --- a/framework/Notification/lib/Horde/Notification/Handler/Decorator/Alarm.php +++ b/framework/Notification/lib/Horde/Notification/Handler/Decorator/Alarm.php @@ -1,6 +1,7 @@ _handler = $handler; - $this->_alarm = $alarm; - } - - /** - * Registers a listener with the notification object and includes - * the necessary library file dynamically. - * - * @param string $listener The name of the listener to attach. These - * names must be unique; further listeners with - * the same name will be ignored. - * @param array $params A hash containing any additional configuration - * or connection parameters a listener driver - * might need. - * @param string $class The class name from which the driver was - * instantiated if not the default one. If given - * you have to include the library file - * containing this class yourself. This is useful - * if you want the listener driver to be - * overriden by an application's implementation. - * - * @return Horde_Notification_Listener The listener object. - * @throws Horde_Exception - */ - public function attach($listener, $params = null, $class = null) - { - return $this->_handler->attach($listener, $params, $class); - } - - /** - * Remove a listener from the notification list. This will discard any - * notifications in this listeners stack. - * - * @param string $listner The name of the listener to detach. + * The current user. * - * @throws Horde_Exception + * @var string */ - public function detach($listener) - { - $this->_handler->detach($listener); - } + protected $_user; /** - * Replaces a listener in the notification list. This preserves all - * notifications in this listeners stack. If the listener does not exist, - * the new listener will be added automatically. - * - * @param string $listener See attach(). - * @param array $params See attach(). - * @param string $class See attach(). - * - * @return Horde_Notification_Listener See attach() - * @throws Horde_Exception - */ - public function replace($listener, array $params = array(), $class = null) - { - return $this->_handler->replace($listener, $params, $class); - } - - /** - * Add an event to the Horde message stack. - * - * The event type parameter should begin with 'horde.' unless the - * application defines its own Horde_Notification_Listener subclass that - * handles additional codes. + * Initialize the notification system, set up any needed session + * variables, etc. * - * @param mixed $event Horde_Notification_Event object or message string. - * @param integer $type The type of message: 'horde.error', - * 'horde.warning', 'horde.success', or - * 'horde.message'. - * @param array $flags Array of optional flags that will be passed to the - * registered listeners. + * @param Horde_Alarm $alarm The alarm system to notify. + * @param string $user The current username. */ - public function push($event, $type = null, array $flags = array()) + public function __construct(Horde_Alarm $alarm, $user) { - $this->_handler->push($event, $type, $flags); + $this->_alarm = $alarm; + $this->_user = $user; } /** - * Passes the message stack to all listeners and asks them to - * handle their messages. + * Listeners are handling their messages. * * @param array $options An array containing display options for the - * listeners. + * listeners (see Horde_Notification_Handler for + * details). */ - public function notify(array $options = array()) + public function notify($options) { - $options = $this->_handler->setNotificationListeners($options); - if (in_array('status', $options['listeners'])) { - $this->_alarm->notify(Horde_Auth::getAuth()); + $this->_alarm->notify($this->_user); } - - $this->_handler->notifyListeners($options); - } - - /** - * Convert the 'listeners' option into the format expected by the - * notification handler. - * - * @param array $options An array containing display options for the - * listeners. - */ - public function setNotificationListeners(array $options) - { - return $this->_handler->setNotificationListeners($options); - } - - /** - * Passes the message stack to all listeners and asks them to - * handle their messages. - * - * @param array $options An array containing display options for the - * listeners. This array is required to contain the - * correct lowercased listener names as array in the - * entry 'listeners'. - */ - public function notifyListeners(array $options) - { - $this->_handler->notifyListeners($options); - } - - /** - * Return the number of notification messages in the stack. - * - * @author David Ulevitch - * - * @param string $my_listener The name of the listener. - * - * @return integer The number of messages in the stack. - */ - public function count($my_listener = null) - { - return $this->_handler->count($my_listener); } } diff --git a/framework/Notification/lib/Horde/Notification/Handler/Decorator/Base.php b/framework/Notification/lib/Horde/Notification/Handler/Decorator/Base.php new file mode 100644 index 000000000..454127f79 --- /dev/null +++ b/framework/Notification/lib/Horde/Notification/Handler/Decorator/Base.php @@ -0,0 +1,39 @@ + + * @author Michael Slusarz + * @package Horde_Notification + */ +class Horde_Notification_Handler_Decorator_Base +{ + /** + * Event is being added to the Horde message stack. + * + * @param Horde_Notification_Event $event Event object. + * @param array $options Additional options (see + * Horde_Notification_Handler for + * details). + */ + public function push(Horde_Notification_Event $event, $options) + { + } + + /** + * Listeners are handling their messages. + * + * @param array $options An array containing display options for the + * listeners (see Horde_Notification_Handler for + * details). + */ + public function notify($options) + { + } + +} diff --git a/framework/Notification/lib/Horde/Notification/Handler/Decorator/Hordelog.php b/framework/Notification/lib/Horde/Notification/Handler/Decorator/Hordelog.php index 506017c87..380c3dd05 100644 --- a/framework/Notification/lib/Horde/Notification/Handler/Decorator/Hordelog.php +++ b/framework/Notification/lib/Horde/Notification/Handler/Decorator/Hordelog.php @@ -1,7 +1,6 @@ _handler = $handler; + Horde::logMessage($event->message, __FILE__, __LINE__, PEAR_LOG_DEBUG); } - /** - * Registers a listener with the notification object and includes - * the necessary library file dynamically. - * - * @param string $listener The name of the listener to attach. These - * names must be unique; further listeners with - * the same name will be ignored. - * @param array $params A hash containing any additional configuration - * or connection parameters a listener driver - * might need. - * @param string $class The class name from which the driver was - * instantiated if not the default one. If given - * you have to include the library file - * containing this class yourself. This is useful - * if you want the listener driver to be - * overriden by an application's implementation. - * - * @return Horde_Notification_Listener The listener object. - * @throws Horde_Exception - */ - public function attach($listener, $params = null, $class = null) - { - return $this->_handler->attach($listener, $params, $class); - } - - /** - * Remove a listener from the notification list. This will discard any - * notifications in this listeners stack. - * - * @param string $listner The name of the listener to detach. - * - * @throws Horde_Exception - */ - public function detach($listener) - { - $this->_handler->detach($listener); - } - - /** - * Replaces a listener in the notification list. This preserves all - * notifications in this listeners stack. If the listener does not exist, - * the new listener will be added automatically. - * - * @param string $listener See attach(). - * @param array $params See attach(). - * @param string $class See attach(). - * - * @return Horde_Notification_Listener See attach() - * @throws Horde_Exception - */ - public function replace($listener, array $params = array(), $class = null) - { - return $this->_handler->replace($listener, $params, $class); - } - - /** - * Add an event to the Horde message stack. - * - * The event type parameter should begin with 'horde.' unless the - * application defines its own Horde_Notification_Listener subclass that - * handles additional codes. - * - * @param mixed $event Horde_Notification_Event object or message string. - * @param integer $type The type of message: 'horde.error', - * 'horde.warning', 'horde.success', or - * 'horde.message'. - * @param array $flags Array of optional flags that will be passed to the - * registered listeners. - */ - public function push($event, $type = null, array $flags = array()) - { - if ($event instanceof PEAR_Error || $event instanceof Exception) { - Horde::logMessage($event, __FILE__, __LINE__, PEAR_LOG_DEBUG); - } - $this->_handler->push($event, $type, $flags); - } - - /** - * Passes the message stack to all listeners and asks them to - * handle their messages. - * - * @param array $options An array containing display options for the - * listeners. - */ - public function notify(array $options = array()) - { - $this->_handler->notify($options); - } - - /** - * Convert the 'listeners' option into the format expected by the - * notification handler. - * - * @param array $options An array containing display options for the - * listeners. - */ - public function setNotificationListeners(array $options) - { - return $this->_handler->setNotificationListeners($options); - } - - /** - * Passes the message stack to all listeners and asks them to - * handle their messages. - * - * @param array $options An array containing display options for the - * listeners. This array is required to contain the - * correct lowercased listener names as array in the - * entry 'listeners'. - */ - public function notifyListeners(array $options) - { - $this->_handler->notifyListeners($options); - } - - /** - * Return the number of notification messages in the stack. - * - * @author David Ulevitch - * - * @param string $my_listener The name of the listener. - * - * @return integer The number of messages in the stack. - */ - public function count($my_listener = null) - { - return $this->_handler->count($my_listener); - } } diff --git a/framework/Notification/lib/Horde/Notification/Handler/Decorator/Log.php b/framework/Notification/lib/Horde/Notification/Handler/Decorator/Log.php index bd0c395fd..f7181a6e3 100644 --- a/framework/Notification/lib/Horde/Notification/Handler/Decorator/Log.php +++ b/framework/Notification/lib/Horde/Notification/Handler/Decorator/Log.php @@ -1,7 +1,6 @@ _handler = $handler; $this->_logger = $logger; } /** - * Registers a listener with the notification object and includes - * the necessary library file dynamically. - * - * @param string $listener The name of the listener to attach. These - * names must be unique; further listeners with - * the same name will be ignored. - * @param array $params A hash containing any additional configuration - * or connection parameters a listener driver - * might need. - * @param string $class The class name from which the driver was - * instantiated if not the default one. If given - * you have to include the library file - * containing this class yourself. This is useful - * if you want the listener driver to be - * overriden by an application's implementation. - * - * @return Horde_Notification_Listener The listener object. - * @throws Horde_Exception - */ - public function attach($listener, $params = null, $class = null) - { - return $this->_handler->attach($listener, $params, $class); - } - - /** - * Remove a listener from the notification list. This will discard any - * notifications in this listeners stack. - * - * @param string $listner The name of the listener to detach. - * - * @throws Horde_Exception - */ - public function detach($listener) - { - $this->_handler->detach($listener); - } - - /** - * Replaces a listener in the notification list. This preserves all - * notifications in this listeners stack. If the listener does not exist, - * the new listener will be added automatically. - * - * @param string $listener See attach(). - * @param array $params See attach(). - * @param string $class See attach(). - * - * @return Horde_Notification_Listener See attach() - * @throws Horde_Exception - */ - public function replace($listener, array $params = array(), $class = null) - { - return $this->_handler->replace($listener, $params, $class); - } - - /** - * Add an event to the Horde message stack. - * - * The event type parameter should begin with 'horde.' unless the - * application defines its own Horde_Notification_Listener subclass that - * handles additional codes. - * - * @param mixed $event Horde_Notification_Event object or message string. - * @param integer $type The type of message: 'horde.error', - * 'horde.warning', 'horde.success', or - * 'horde.message'. - * @param array $flags Array of optional flags that will be passed to the - * registered listeners. - */ - public function push($event, $type = null, array $flags = array()) - { - if ($event instanceof PEAR_Error || $event instanceof Exception) { - /* Some loggers only accept string messages. As both PEAR_Error - * and Exception accept being casted into a string we can ensure - * that the logger receives a string here. */ - $this->_logger->debug((string) $event); - } - $this->_handler->push($event, $type, $flags); - } - - /** - * Passes the message stack to all listeners and asks them to - * handle their messages. - * - * @param array $options An array containing display options for the - * listeners. - */ - public function notify(array $options = array()) - { - $this->_handler->notify($options); - } - - /** - * Convert the 'listeners' option into the format expected by the - * notification handler. - * - * @param array $options An array containing display options for the - * listeners. - */ - public function setNotificationListeners(array $options) - { - return $this->_handler->setNotificationListeners($options); - } - - /** - * Passes the message stack to all listeners and asks them to - * handle their messages. - * - * @param array $options An array containing display options for the - * listeners. This array is required to contain the - * correct lowercased listener names as array in the - * entry 'listeners'. - */ - public function notifyListeners(array $options) - { - $this->_handler->notifyListeners($options); - } - - /** - * Return the number of notification messages in the stack. - * - * @author David Ulevitch - * - * @param string $my_listener The name of the listener. + * Event is being added to the Horde message stack. * - * @return integer The number of messages in the stack. + * @param Horde_Notification_Event $event Event object. + * @param array $options Additional options (see + * Horde_Notification_Handler for + * details). */ - public function count($my_listener = null) + public function push(Horde_Notification_Event $event, $options) { - return $this->_handler->count($my_listener); + $this->_logger->debug($event->message); } } diff --git a/framework/Notification/lib/Horde/Notification/Handler/Interface.php b/framework/Notification/lib/Horde/Notification/Handler/Interface.php deleted file mode 100644 index b3bb26d29..000000000 --- a/framework/Notification/lib/Horde/Notification/Handler/Interface.php +++ /dev/null @@ -1,118 +0,0 @@ - - * @package Horde_Notification - */ -interface Horde_Notification_Handler_Interface -{ - /** - * Registers a listener with the notification object and includes - * the necessary library file dynamically. - * - * @param string $listener The name of the listener to attach. These - * names must be unique; further listeners with - * the same name will be ignored. - * @param array $params A hash containing any additional configuration - * or connection parameters a listener driver - * might need. - * @param string $class The class name from which the driver was - * instantiated if not the default one. If given - * you have to include the library file - * containing this class yourself. This is useful - * if you want the listener driver to be - * overriden by an application's implementation. - * - * @return Horde_Notification_Listener The listener object. - * @throws Horde_Exception - */ - public function attach($listener, $params = null, $class = null); - - /** - * Remove a listener from the notification list. This will discard any - * notifications in this listeners stack. - * - * @param string $listner The name of the listener to detach. - * - * @throws Horde_Exception - */ - public function detach($listener); - - /** - * Replaces a listener in the notification list. This preserves all - * notifications in this listeners stack. If the listener does not exist, - * the new listener will be added automatically. - * - * @param string $listener See attach(). - * @param array $params See attach(). - * @param string $class See attach(). - * - * @return Horde_Notification_Listener See attach() - * @throws Horde_Exception - */ - public function replace($listener, array $params = array(), $class = null); - - /** - * Add an event to the Horde message stack. - * - * The event type parameter should begin with 'horde.' unless the - * application defines its own Horde_Notification_Listener subclass that - * handles additional codes. - * - * @param mixed $event Horde_Notification_Event object or message string. - * @param integer $type The type of message: 'horde.error', - * 'horde.warning', 'horde.success', or - * 'horde.message'. - * @param array $flags Array of optional flags that will be passed to the - * registered listeners. - */ - public function push($event, $type = null, array $flags = array()); - - /** - * Passes the message stack to all listeners and asks them to - * handle their messages. - * - * @param array $options An array containing display options for the - * listeners. - */ - public function notify(array $options = array()); - - /** - * Convert the 'listeners' option into the format expected by the - * notification handler. - * - * @param array $options An array containing display options for the - * listeners. - */ - public function setNotificationListeners(array $options); - - /** - * Passes the message stack to all listeners and asks them to - * handle their messages. - * - * @param array $options An array containing display options for the - * listeners. This array is required to contain the - * correct lowercased listener names as array in the - * entry 'listeners'. - */ - public function notifyListeners(array $options); - - /** - * Return the number of notification messages in the stack. - * - * @author David Ulevitch - * - * @param string $my_listener The name of the listener. - * - * @return integer The number of messages in the stack. - */ - public function count($my_listener = null); - -} diff --git a/framework/Notification/lib/Horde/Notification/Listener.php b/framework/Notification/lib/Horde/Notification/Listener.php index 17fbfc49e..e3bd2a330 100644 --- a/framework/Notification/lib/Horde/Notification/Listener.php +++ b/framework/Notification/lib/Horde/Notification/Listener.php @@ -22,6 +22,8 @@ abstract class Horde_Notification_Listener /** * Array of message types that this listener handles. + * Key is the type, value is the default class name of the Event type to + * use. * * @var array */ @@ -32,11 +34,35 @@ abstract class Horde_Notification_Listener * * @param string $type The message type in question. * - * @return boolean Whether this listener handles the type. + * @return mixed False if this listener does not handle, the default + * event class if it does handle the type. */ public function handles($type) { - return isset($this->_handles[$type]); + if (isset($this->_handles[$type])) { + return $this->_handles[$type]; + } + + /* Search for '*' entries. */ + foreach (array_keys($this->_handles) as $key) { + if ((substr($key, -1) == '*') && + (strpos($type, substr($key, 0, -1)) === 0)) { + return $this->_handles[$key]; + } + } + + return false; + } + + /** + * Adds message type handler. + * + * @param string $type The type identifier. + * @param string $class A classname. + */ + public function addType($type, $class) + { + $this->_handles[$type] = $class; } /** @@ -53,20 +79,9 @@ abstract class Horde_Notification_Listener * Outputs the status line, sends emails, pages, etc., if there * are any messages on this listener's message stack. * - * @param array &$messageStack The stack of messages. - * @param array $options An array of options. - */ - abstract public function notify(&$messageStacks, $options = array()); - - /** - * Processes one message from the message stack. - * - * @param Horde_Notification_Event $event One event object from the - * stack. - * @param array $options An array of options. - * - * @return mixed The formatted message. + * @param array $events The list of events to handle. + * @param array $options An array of options. */ - abstract public function getMessage($event, $options = array()); + abstract public function notify($events, $options = array()); } diff --git a/framework/Notification/lib/Horde/Notification/Listener/Audio.php b/framework/Notification/lib/Horde/Notification/Listener/Audio.php index 3aebf9148..c6ff8816c 100644 --- a/framework/Notification/lib/Horde/Notification/Listener/Audio.php +++ b/framework/Notification/lib/Horde/Notification/Listener/Audio.php @@ -18,9 +18,7 @@ class Horde_Notification_Listener_Audio extends Horde_Notification_Listener */ public function __construct() { - $this->_handles = array( - 'audio' => '' - ); + $this->_handles['audio'] = 'Horde_Notification_Event'; $this->_name = 'audio'; } @@ -28,29 +26,14 @@ class Horde_Notification_Listener_Audio extends Horde_Notification_Listener * Outputs the embedded audio code if there are any messages on the * 'audio' message stack. * - * @param array &$messageStack The stack of messages. - * @param array $options An array of options (not used). + * @param array $events The list of events to handle. + * @param array $options An array of options (not used). */ - public function notify(&$messageStack, $options = array()) + public function notify($events, $options = array()) { - if (count($messageStack)) { - while ($message = array_shift($messageStack)) { - echo $this->getMessage($message); - } + foreach ($events as $event) { + echo ''; } } - /** - * Processes one message from the message stack. - * - * @param Horde_Notification_Event $event An event object. - * @param array $options An array of options (not used). - * - * @return mixed The formatted message. - */ - public function getMessage($event, $options = array()) - { - return ''; - } - } diff --git a/framework/Notification/lib/Horde/Notification/Listener/Javascript.php b/framework/Notification/lib/Horde/Notification/Listener/Javascript.php index edf4a23fd..2f653f218 100644 --- a/framework/Notification/lib/Horde/Notification/Listener/Javascript.php +++ b/framework/Notification/lib/Horde/Notification/Listener/Javascript.php @@ -18,10 +18,8 @@ class Horde_Notification_Listener_Javascript extends Horde_Notification_Listener */ public function __construct() { - $this->_handles = array( - 'javascript' => '', - 'javascript-file' => '' - ); + $this->_handles['javascript'] = 'Horde_Notification_Event'; + $this->_handles['javascript-file'] = 'Horde_Notification_Event'; $this->_name = 'javascript'; } @@ -29,26 +27,24 @@ class Horde_Notification_Listener_Javascript extends Horde_Notification_Listener * Outputs the javascript code if there are any messages on the * 'javascript' message stack and if the 'notify_javascript' option is set. * - * @param array &$messageStack The stack of messages. - * @param array $options An array of options. Options: 'noscript' + * @param array $events The list of events to handle. + * @param array $options An array of options: + *
+     * 'noscript' - TODO
+     * 
*/ - public function notify(&$messageStack, $options = array()) + public function notify($events, $options = array()) { - if (!count($messageStack)) { - return; - } - $files = $js_text = array(); - while ($message = array_shift($messageStack)) { - $event = $this->getMessage($message); + foreach ($events as $event) { switch ($event->type) { case 'javascript': - $js_text[] = $event->message . "\n"; + $js_text[] = strval($event); break; case 'javascript-file': - $files[] = $event->message; + $files[] = strval($event); break; } } @@ -61,28 +57,13 @@ class Horde_Notification_Listener_Javascript extends Horde_Notification_Listener if (empty($options['noscript'])) { if (!empty($js_text)) { - echo "//]]>\n"; + echo "\n//]]>\n"; } - if (count($files)) { - foreach ($files as $file) { - echo '' . "\n"; - } + foreach ($files as $file) { + echo '\n"; } } } - /** - * Processes one message from the message stack. - * - * @param Horde_Notification_Event $event An event object. - * @param array $options An array of options (not used). - * - * @return mixed The formatted message. - */ - public function getMessage($event, $options = array()) - { - return $event->message; - } - } diff --git a/framework/Notification/lib/Horde/Notification/Listener/Mobile.php b/framework/Notification/lib/Horde/Notification/Listener/Mobile.php deleted file mode 100644 index 610dc9729..000000000 --- a/framework/Notification/lib/Horde/Notification/Listener/Mobile.php +++ /dev/null @@ -1,86 +0,0 @@ - - * @package Horde_Notification - */ -class Horde_Notification_Listener_Mobile extends Horde_Notification_Listener_Status -{ - /** - * The Horde_Mobile:: object that status lines should be added to. - * - * @var Horde_Mobile - */ - protected $_mobile; - - /** - * Constructor. - */ - public function __construct() - { - $this->_handles = array( - 'horde.error' => _("ERR"), - 'horde.success' => _("SUCCESS"), - 'horde.warning' => _("WARN"), - 'horde.message' => _("MSG") - ); - $this->_name = 'status'; - } - - /** - * Associate a Horde_Mobile:: object with the listener. - * - * @param Horde_Mobile The Horde_Mobile:: object to send status lines to. - */ - public function setMobileObject($mobile) - { - $this->_mobile = $mobile; - } - - /** - * Outputs the status line if there are any messages on the 'mobile' - * message stack. - * - * @param array &$messageStack The stack of messages. - * @param array $options An array of options. - */ - public function notify(&$messageStack, $options = array()) - { - if (!$this->_mobile) { - $p = new Horde_Notification_Listener_Status(); - return $p->notify($messageStack, $options); - } - - if (count($messageStack)) { - while ($message = array_shift($messageStack)) { - $this->getMessage($message); - } - } - } - - /** - * Processes one message from the message stack. - * - * @param Horde_Notification_Event $event An event object. - * @param array $options An array of options (not used). - * - * @return mixed The formatted message. - */ - public function getMessage($event, $options = array()) - { - if (!$this->_mobile) { - $p = new Horde_Notification_Listener_Status(); - return $p->getMessage($event, $options); - } - - $this->_mobile->add(new Horde_Mobile_text($this->_handles[$event->type] . ': ' . strip_tags($event->message))); - } - -} diff --git a/framework/Notification/lib/Horde/Notification/Listener/Status.php b/framework/Notification/lib/Horde/Notification/Listener/Status.php index e91aa69aa..0178b9a59 100644 --- a/framework/Notification/lib/Horde/Notification/Listener/Status.php +++ b/framework/Notification/lib/Horde/Notification/Listener/Status.php @@ -14,26 +14,11 @@ class Horde_Notification_Listener_Status extends Horde_Notification_Listener { /** - * The notified message stack. - * - * @var array - */ - protected $_notifiedStack = array(); - - /** * Constructor. */ public function __construct() { - $image_dir = $GLOBALS['registry']->getImageDir('horde'); - - $this->_handles = array( - 'horde.error' => array($image_dir . '/alerts/error.png', _("Error")), - 'horde.success' => array($image_dir . '/alerts/success.png', _("Success")), - 'horde.warning' => array($image_dir . '/alerts/warning.png', _("Warning")), - 'horde.message' => array($image_dir . '/alerts/message.png', _("Message")), - 'horde.alarm' => array($image_dir . '/alerts/alarm.png', _("Alarm")) - ); + $this->_handles['status'] = 'Horde_Notification_Event_Status'; $this->_name = 'status'; } @@ -41,138 +26,32 @@ class Horde_Notification_Listener_Status extends Horde_Notification_Listener * Outputs the status line if there are any messages on the 'status' * message stack. * - * @param array &$messageStack The stack of messages. - * @param array $options An array of options. + * @param array $events The list of events to handle. + * @param array $options An array of options: *
-     * 'store' - (boolean) If false, outputs message stack to page. If true,
-     *                     stores the message stack for subsequent retrieval
-     *                     via getStack(). DEFAULT: false
+     * 'mobile' - (Horde_Mobile) The mobile object to send status lines to.
      * 
*/ - public function notify(&$messageStack, $options = array()) + public function notify($events, $options = array()) { - if (!count($messageStack)) { + if (!count($events)) { return; } - $store = !empty($options['store']); - - if (!$store) { - echo '
    '; - } - - while ($message = array_shift($messageStack)) { - $message = $this->getMessage($message, array('data' => $store)); - if ($store) { - $this->_notifiedStack[] = $message; - } else { - echo $message; - } - } - - if (!$store) { - echo '
'; - } - } - - /** - * Processes one message from the message stack. - * - * @param Horde_Notification_Event $event An event object. - * @param array $options An array of options: - *
-     * 'data' - (boolean) If false, returns HTML code. If true, returns an
-     *                    array of message information. DEFAULT: false
-     * 
- * - * @return mixed TODO - */ - public function getMessage($event, $options = array()) - { - $result = array('type' => $event->type); - - if ($event->type == 'horde.alarm') { - if (empty($options['data'])) { - $text = $this->_getAlarm($event->flags['alarm']); - } else { - $result['alarm'] = $event->flags['alarm']; - if (!empty($result['alarm']['params']['notify']['ajax'])) { - $result['alarm']['ajax'] = $result['alarm']['params']['notify']['ajax']; - } elseif (!empty($result['alarm']['params']['notify']['show'])) { - $result['alarm']['url'] = (string)Horde::url($GLOBALS['registry']->linkByPackage($result['alarm']['params']['notify']['show']['__app'], 'show', $result['alarm']['params']['notify']['show']), true); - } - unset($result['alarm']['params']['notify'], - $result['alarm']['methods']); - } - } else { - $text = $event->message; - if (!empty($options['data'])) { - $result['message'] = $text; - } - if (!in_array('content.raw', $event->flags)) { - $text = htmlspecialchars($text, ENT_COMPAT, Horde_Nls::getCharset()); + if (!empty($options['mobile'])) { + foreach ($events as $event) { + $options['mobile']->add(new Horde_Mobile_Text(strip_tags($event))); } + return; } - return empty($options['data']) - ? '
  • ' . Horde::img($this->_handles[$event->type][0], $this->_handles[$event->type][1], '', '') . $text . '
  • ' - : $result; - } + echo '
      '; - /** - * Renders the interface for an alarm notification. - * - * @param array $alarm An alarm hash. - * - * @return string The generated HTML code for the alarm notification. - */ - protected function _getAlarm(array $alarm) - { - $message = htmlspecialchars($alarm['title']); - - if (!empty($alarm['params']['notify']['show'])) { - $message = Horde::link(Horde::url($GLOBALS['registry']->linkByPackage($alarm['params']['notify']['show']['__app'], 'show', $alarm['params']['notify']['show'])), $alarm['text']) . $message . ''; + foreach ($events as $event) { + echo '
    • ' . $event . '
    • '; } - if (!empty($alarm['user']) && $GLOBALS['browser']->hasFeature('xmlhttpreq')) { - Horde::addScriptFile('prototype.js', 'horde'); - $url = Horde::url($GLOBALS['registry']->get('webroot', 'horde') . '/services/snooze.php', true); - $opts = array('-1' => _("Dismiss"), - '5' => _("5 minutes"), - '15' => _("15 minutes"), - '60' => _("1 hour"), - '360' => _("6 hours"), - '1440' => _("1 day")); - $id = 'snooze_' . md5($alarm['id']); - $message .= ' [' . _("Snooze...") . ']'; - } - - return $message; - } - - /** - * Returns all status messages stored via the 'store' option to notify(). - * - * @param boolean $clear Clear the entries off the internal stack? - * - * @return array An array of data items. - */ - public function getStack($clear = true) - { - $info = $this->_notifiedStack; - if ($clear) { - $this->_notifiedStack = array(); - } - return $info; + echo '
    '; } } diff --git a/framework/Notification/package.xml b/framework/Notification/package.xml index 58600fca8..da34162ba 100644 --- a/framework/Notification/package.xml +++ b/framework/Notification/package.xml @@ -33,27 +33,29 @@ http://pear.php.net/dtd/package-2.0.xsd"> + + + - + - - - - + + + @@ -63,23 +65,23 @@ http://pear.php.net/dtd/package-2.0.xsd"> + - + - @@ -110,40 +112,35 @@ http://pear.php.net/dtd/package-2.0.xsd"> Alarm pear.horde.org - - Auth - pear.horde.org - - + + - - - - + + + + - - diff --git a/framework/Notification/test/Horde/Notification/Autoload.php b/framework/Notification/test/Horde/Notification/Autoload.php index f7390dba9..89d906ac5 100644 --- a/framework/Notification/test/Horde/Notification/Autoload.php +++ b/framework/Notification/test/Horde/Notification/Autoload.php @@ -24,3 +24,6 @@ if (!spl_autoload_functions()) { /** Catch strict standards */ error_reporting(E_ALL | E_STRICT); + +/** Needed for PEAR_Error. */ +@require_once 'PEAR.php'; diff --git a/framework/Notification/test/Horde/Notification/Class/Notification/EventTest.php b/framework/Notification/test/Horde/Notification/Class/Notification/EventTest.php index 9d394cd15..b4880606b 100644 --- a/framework/Notification/test/Horde/Notification/Class/Notification/EventTest.php +++ b/framework/Notification/test/Horde/Notification/Class/Notification/EventTest.php @@ -38,14 +38,14 @@ class Horde_Notification_Class_Notification_EventTest extends PHPUnit_Framework_ public function testMethodGetmessageHasResultStringTheStoredMessage() { - $event = new Horde_Notification_Event(); - $event->message = test; + $event = new Horde_Notification_Event(''); + $event->message = 'test'; $this->assertEquals('test', $event->message); } public function testMethodGetmessageHasResultStringEmptyIfNoMessageWasStored() { - $event = new Horde_Notification_Event(); + $event = new Horde_Notification_Event(''); $this->assertEquals('', $event->message); } } diff --git a/framework/Notification/test/Horde/Notification/Class/Notification/Handler/Decorator/AlarmTest.php b/framework/Notification/test/Horde/Notification/Class/Notification/Handler/Decorator/AlarmTest.php index 7037488f7..c103718cd 100644 --- a/framework/Notification/test/Horde/Notification/Class/Notification/Handler/Decorator/AlarmTest.php +++ b/framework/Notification/test/Horde/Notification/Class/Notification/Handler/Decorator/AlarmTest.php @@ -38,12 +38,9 @@ extends PHPUnit_Framework_TestCase $this->markTestSkipped('The Horde_Alarm package is not installed!'); } - $this->handler = $this->getMock( - 'Horde_Notification_Handler_Base', array(), array(), '', false, false - ); - $this->alarm = $this->getMock('Horde_Alarm'); + $this->alarm = $this->getMock('Horde_Alarm'); $this->alarm_handler = new Horde_Notification_Handler_Decorator_Alarm( - $this->handler, $this->alarm + $this->alarm, null ); } @@ -52,92 +49,7 @@ extends PHPUnit_Framework_TestCase $this->alarm->expects($this->once()) ->method('notify') ->with(''); - $this->handler->expects($this->once()) - ->method('setNotificationListeners') - ->with(array('listeners' => array('status'))) - ->will($this->returnValue(array('listeners' => array('status')))); - $this->handler->expects($this->once()) - ->method('notifyListeners') - ->with(array('listeners' => array('status'))); $this->alarm_handler->notify(array('listeners' => array('status'))); } - public function testMethodAttachGetsDelegated() - { - $this->handler->expects($this->once()) - ->method('attach') - ->with('listener', array(), 'class') - ->will($this->returnValue('instance')); - $this->assertEquals( - 'instance', - $this->alarm_handler->attach('listener', array(), 'class') - ); - } - - public function testMethodDetachGetsDelegated() - { - $this->handler->expects($this->once()) - ->method('detach') - ->with('listener'); - $this->alarm_handler->detach('listener'); - } - - public function testMethodReplaceGetsDelegated() - { - $this->handler->expects($this->once()) - ->method('replace') - ->with('listener', array(), 'class') - ->will($this->returnValue('instance')); - $this->assertEquals( - 'instance', - $this->alarm_handler->replace('listener', array(), 'class') - ); - } - - public function testMethodPushGetsDelegated() - { - $this->handler->expects($this->once()) - ->method('push') - ->with('event', 'type', array()); - $this->alarm_handler->push('event', 'type', array()); - } - - public function testMethodNotifyGetsDelegated() - { - $this->handler->expects($this->once()) - ->method('setNotificationListeners') - ->with(array('listeners' => array('test'))) - ->will($this->returnValue(array('listeners' => array('test')))); - $this->handler->expects($this->once()) - ->method('notifyListeners') - ->with(array('listeners' => array('test'))); - $this->alarm_handler->notify(array('listeners' => array('test'))); - } - - public function testMethodSetnotificationlistenersGetsDelegated() - { - $this->handler->expects($this->once()) - ->method('setNotificationListeners') - ->with(array()); - $array = array(); - $this->alarm_handler->setNotificationListeners($array); - } - - public function testMethodNotifylistenersGetsDelegated() - { - $this->handler->expects($this->once()) - ->method('notifyListeners') - ->with(array()); - $this->alarm_handler->notifyListeners(array()); - } - - public function testMethodCountGetsDelegated() - { - $this->handler->expects($this->once()) - ->method('count') - ->with('listener') - ->will($this->returnValue(1)); - $this->assertEquals(1, $this->alarm_handler->count('listener')); - } - } diff --git a/framework/Notification/test/Horde/Notification/Class/Notification/Handler/Decorator/HordelogTest.php b/framework/Notification/test/Horde/Notification/Class/Notification/Handler/Decorator/HordelogTest.php index bf4750ce1..98fdf2cb1 100644 --- a/framework/Notification/test/Horde/Notification/Class/Notification/Handler/Decorator/HordelogTest.php +++ b/framework/Notification/test/Horde/Notification/Class/Notification/Handler/Decorator/HordelogTest.php @@ -32,106 +32,9 @@ require_once dirname(__FILE__) . '/../../../../Autoload.php'; class Horde_Notification_Class_Notification_Handler_Decorator_HordelogTest extends PHPUnit_Framework_TestCase { - public function setUp() + public function testNoneAvailable() { - if (!class_exists('Log')) { - $this->markTestSkipped('The PEAR Log package is not installed!'); - } - - @include_once 'Log.php'; - if (!defined('PEAR_LOG_DEBUG')) { - $this->markTestSkipped('The PEAR_LOG_DEBUG constant is not available!'); - } - - $this->handler = $this->getMock( - 'Horde_Notification_Handler_Base', array(), array(), '', false, false - ); - $this->logged_handler = new Horde_Notification_Handler_Decorator_Hordelog( - $this->handler - ); - } - - public function testMethodPushHasPostconditionThattheEventGotLoggedIfTheEventWasAnError() - { - $exception = new Exception('test'); - $this->handler->expects($this->once()) - ->method('push') - ->with($exception); - $this->logged_handler->push($exception); - } - - public function testMethodAttachGetsDelegated() - { - $this->handler->expects($this->once()) - ->method('attach') - ->with('listener', array(), 'class') - ->will($this->returnValue('instance')); - $this->assertEquals( - 'instance', - $this->logged_handler->attach('listener', array(), 'class') - ); - } - - public function testMethodDetachGetsDelegated() - { - $this->handler->expects($this->once()) - ->method('detach') - ->with('listener'); - $this->logged_handler->detach('listener'); - } - - public function testMethodReplaceGetsDelegated() - { - $this->handler->expects($this->once()) - ->method('replace') - ->with('listener', array(), 'class') - ->will($this->returnValue('instance')); - $this->assertEquals( - 'instance', - $this->logged_handler->replace('listener', array(), 'class') - ); - } - - public function testMethodPushGetsDelegated() - { - $this->handler->expects($this->once()) - ->method('push') - ->with('event', 'type', array()); - $this->logged_handler->push('event', 'type', array()); - } - - public function testMethodNotifyGetsDelegated() - { - $this->handler->expects($this->once()) - ->method('notify') - ->with(array('listeners' => array('test'))); - $this->logged_handler->notify(array('listeners' => array('test'))); - } - - public function testMethodSetnotificationlistenersGetsDelegated() - { - $this->handler->expects($this->once()) - ->method('setNotificationListeners') - ->with(array()); - $array = array(); - $this->logged_handler->setNotificationListeners($array); + // No tests + $this->markTestIncomplete('No tests available.'); } - - public function testMethodNotifylistenersGetsDelegated() - { - $this->handler->expects($this->once()) - ->method('notifyListeners') - ->with(array()); - $this->logged_handler->notifyListeners(array()); - } - - public function testMethodCountGetsDelegated() - { - $this->handler->expects($this->once()) - ->method('count') - ->with('listener') - ->will($this->returnValue(1)); - $this->assertEquals(1, $this->logged_handler->count('listener')); - } - } diff --git a/framework/Notification/test/Horde/Notification/Class/Notification/Handler/Decorator/LogTest.php b/framework/Notification/test/Horde/Notification/Class/Notification/Handler/Decorator/LogTest.php index 056abfbc0..933b5128a 100644 --- a/framework/Notification/test/Horde/Notification/Class/Notification/Handler/Decorator/LogTest.php +++ b/framework/Notification/test/Horde/Notification/Class/Notification/Handler/Decorator/LogTest.php @@ -38,99 +38,19 @@ extends PHPUnit_Framework_TestCase $this->markTestSkipped('The Horde_Log package is not installed!'); } - $this->handler = $this->getMock( - 'Horde_Notification_Handler_Base', array(), array(), '', false, false - ); - $this->logger = $this->getMock('Horde_Log_Logger'); - $this->logged_handler = new Horde_Notification_Handler_Decorator_Log( - $this->handler, $this->logger + $this->logger = $this->getMock('Horde_Log_Logger'); + $this->log = new Horde_Notification_Handler_Decorator_Log( + $this->logger ); } public function testMethodPushHasPostconditionThattheEventGotLoggedIfTheEventWasAnError() { - $exception = new Exception('test'); + $exception = new Horde_Notification_Event(new Exception('test')); $this->logger->expects($this->once()) ->method('__call') ->with('debug', $this->isType('array')); - $this->handler->expects($this->once()) - ->method('push') - ->with($exception); - $this->logged_handler->push($exception); - } - - public function testMethodAttachGetsDelegated() - { - $this->handler->expects($this->once()) - ->method('attach') - ->with('listener', array(), 'class') - ->will($this->returnValue('instance')); - $this->assertEquals( - 'instance', - $this->logged_handler->attach('listener', array(), 'class') - ); - } - - public function testMethodDetachGetsDelegated() - { - $this->handler->expects($this->once()) - ->method('detach') - ->with('listener'); - $this->logged_handler->detach('listener'); - } - - public function testMethodReplaceGetsDelegated() - { - $this->handler->expects($this->once()) - ->method('replace') - ->with('listener', array(), 'class') - ->will($this->returnValue('instance')); - $this->assertEquals( - 'instance', - $this->logged_handler->replace('listener', array(), 'class') - ); - } - - public function testMethodPushGetsDelegated() - { - $this->handler->expects($this->once()) - ->method('push') - ->with('event', 'type', array()); - $this->logged_handler->push('event', 'type', array()); - } - - public function testMethodNotifyGetsDelegated() - { - $this->handler->expects($this->once()) - ->method('notify') - ->with(array('listeners' => array('test'))); - $this->logged_handler->notify(array('listeners' => array('test'))); - } - - public function testMethodSetnotificationlistenersGetsDelegated() - { - $this->handler->expects($this->once()) - ->method('setNotificationListeners') - ->with(array()); - $array = array(); - $this->logged_handler->setNotificationListeners($array); - } - - public function testMethodNotifylistenersGetsDelegated() - { - $this->handler->expects($this->once()) - ->method('notifyListeners') - ->with(array()); - $this->logged_handler->notifyListeners(array()); - } - - public function testMethodCountGetsDelegated() - { - $this->handler->expects($this->once()) - ->method('count') - ->with('listener') - ->will($this->returnValue(1)); - $this->assertEquals(1, $this->logged_handler->count('listener')); + $this->log->push($exception, array()); } } diff --git a/framework/Notification/test/Horde/Notification/Class/Notification/Handler/BaseTest.php b/framework/Notification/test/Horde/Notification/Class/Notification/HandlerTest.php similarity index 68% rename from framework/Notification/test/Horde/Notification/Class/Notification/Handler/BaseTest.php rename to framework/Notification/test/Horde/Notification/Class/Notification/HandlerTest.php index 93323e6c1..66854e4c7 100644 --- a/framework/Notification/test/Horde/Notification/Class/Notification/Handler/BaseTest.php +++ b/framework/Notification/test/Horde/Notification/Class/Notification/HandlerTest.php @@ -12,7 +12,7 @@ /** * Prepare the test setup. */ -require_once dirname(__FILE__) . '/../../../Autoload.php'; +require_once dirname(__FILE__) . '/../../Autoload.php'; /** * Test the basic notification handler class. @@ -29,12 +29,12 @@ require_once dirname(__FILE__) . '/../../../Autoload.php'; * @link http://pear.horde.org/index.php?package=Notification */ -class Horde_Notification_Class_Notification_Handler_BaseTest extends PHPUnit_Framework_TestCase +class Horde_Notification_Class_Notification_HandlerTest extends PHPUnit_Framework_TestCase { public function setUp() { $this->storage = new Horde_Notification_Storage_Session('test'); - $this->handler = new Horde_Notification_Handler_Base($this->storage); + $this->handler = new Horde_Notification_Handler($this->storage); } public function testMethodAttachHasResultNotificationlistener() @@ -73,7 +73,7 @@ class Horde_Notification_Class_Notification_Handler_BaseTest extends PHPUnit_Fra $this->assertEquals(array(), $_SESSION['test']['audio']); } - public function testMethodAttachThrowsExceptionIfTheListenerTypeIsUnkown() + public function testMethodAttachThrowsExceptionIfTheListenerTypeIsUnknown() { try { $this->handler->attach('MyAudio'); @@ -86,19 +86,6 @@ class Horde_Notification_Class_Notification_Handler_BaseTest extends PHPUnit_Fra } } - public function testMethodReplaceHasResultNotificationlistener() - { - $this->handler->attach( - 'test', array(), 'Horde_Notification_Listener_Audio' - ); - $this->assertType( - 'Horde_Notification_Listener_Dummy', - $this->handler->replace( - 'test', array(), 'Horde_Notification_Listener_Dummy' - ) - ); - } - public function testMethodDetachHasPostconditionThatTheListenerStackGotUnset() { $this->handler->attach('audio'); @@ -113,7 +100,7 @@ class Horde_Notification_Class_Notification_Handler_BaseTest extends PHPUnit_Fra $this->fail('No exception!'); } catch (Horde_Exception $e) { $this->assertEquals( - 'Notification listener myaudio not found.', + 'Notification listener MyAudio not found.', $e->getMessage() ); } @@ -122,55 +109,59 @@ class Horde_Notification_Class_Notification_Handler_BaseTest extends PHPUnit_Fra public function testMethodPushHasPostconditionThatTheEventGotSavedInAllAttachedListenerStacksHandlingTheEvent() { $event = new Horde_Notification_Event('test'); - $flags= array(); $this->handler->attach('audio'); - $this->handler->push('test', 'audio'); + $this->handler->push('test', 'audio', array(), array('immediate' => true)); $result = array_shift($_SESSION['test']['audio']); - $this->assertEquals('Horde_Notification_Event', $result['class']); - $this->assertEquals(serialize($event), $result['event']); - $this->assertEquals(serialize($flags), $result['flags']); - $this->assertEquals('audio', $result['type']); + $this->assertNotNull($result); + $this->assertType('Horde_Notification_Event', $result); + $this->assertEquals(array(), $result->flags); + $this->assertEquals('audio', $result->type); } - public function testMethodPushHasPostconditionThatAnExceptionGetsMarkedAsTypeErrorIfTheTypeWasUnset() + public function testMethodPushHasPostconditionThatAnExceptionGetsMarkedAsTypeStatusIfTheTypeWasUnset() { $this->handler->attach('dummy'); - $this->handler->push(new Exception('test')); + $this->handler->push(new Exception('test'), null, array(), array('immediate' => true)); $result = array_shift($_SESSION['test']['dummy']); - $this->assertEquals('horde.error', $result['type']); + $this->assertNotNull($result); + $this->assertType('Horde_Notification_Event', $result); + $this->assertEquals(array(), $result->flags); + $this->assertEquals('status', $result->type); } - public function testMethodPushHasPostconditionThatEventsWithoutTypeGetMarkedAsTypeMessage() + public function testMethodPushHasPostconditionThatEventsWithoutTypeGetMarkedAsTypeStatus() { $this->handler->attach('dummy'); - $this->handler->push('test'); + $this->handler->push('test', null, array(), array('immediate' => true)); $result = array_shift($_SESSION['test']['dummy']); - $this->assertEquals('horde.message', $result['type']); + $this->assertNotNull($result); + $this->assertType('Horde_Notification_Event', $result); + $this->assertEquals(array(), $result->flags); + $this->assertEquals('status', $result->type); } public function testMethodNotifyHasPostconditionThatAllListenersWereNotified() { - $event = new Horde_Notification_Event('test'); $dummy = $this->handler->attach('dummy'); - $flags= array(); - $this->handler->push('test'); + $this->handler->push('test', 'dummy'); $this->handler->notify(); - $result = array_shift($dummy->notifications); - $this->assertEquals('Horde_Notification_Event', $result['class']); - $this->assertEquals(serialize($event), $result['event']); - $this->assertEquals(serialize($flags), $result['flags']); - $this->assertEquals('horde.message', $result['type']); + $result = array_shift($dummy->events); + $this->assertNotNull($result); + $this->assertType('Horde_Notification_Event', $result); + $this->assertEquals(array(), $result->flags); + $this->assertEquals('dummy', $result->type); } public function testMethodNotifyHasPostconditionThatTheSpecifiedListenersWereNotified() { - $event = new Horde_Notification_Event('test'); $dummy = $this->handler->attach('dummy'); - $flags= array(); - $this->handler->push('test'); + $this->handler->push('test', 'dummy'); $this->handler->notify(array('listeners' => 'dummy')); - $result = array_shift($dummy->notifications); - $this->assertEquals(serialize($event), $result['event']); + $result = array_shift($dummy->events); + $this->assertNotNull($result); + $this->assertType('Horde_Notification_Event', $result); + $this->assertEquals(array(), $result->flags); + $this->assertEquals('dummy', $result->type); } public function testMethodCountHasResultTheTotalNumberOfEventsInTheStack() @@ -178,6 +169,7 @@ class Horde_Notification_Class_Notification_Handler_BaseTest extends PHPUnit_Fra $this->handler->attach('audio'); $this->handler->attach('dummy'); $this->handler->push('test', 'audio'); + $this->handler->push('test', 'dummy'); $this->assertEquals(2, $this->handler->count()); } @@ -193,27 +185,22 @@ class Horde_Notification_Class_Notification_Handler_BaseTest extends PHPUnit_Fra class Horde_Notification_Listener_Dummy extends Horde_Notification_Listener { + public $events; public $params; - public $notifications; - public function __construct($params) { $this->params = $params; $this->_name = 'dummy'; $this->_handles = array( - 'audio' => '', - 'horde.error' => '', - 'horde.message' => '', + 'dummy' => 'Horde_Notification_Event', + 'status' => 'Horde_Notification_Event' ); } - public function notify(&$messageStacks, $options = array()) + public function notify($events, $options = array()) { - $this->notifications = $messageStacks; + $this->events = $events; } - public function getMessage($message, $options = array()) - { - } } diff --git a/framework/Notification/test/Horde/Notification/Class/Notification/Listener/AudioTest.php b/framework/Notification/test/Horde/Notification/Class/Notification/Listener/AudioTest.php index d5efc6538..ee7bec13c 100644 --- a/framework/Notification/test/Horde/Notification/Class/Notification/Listener/AudioTest.php +++ b/framework/Notification/test/Horde/Notification/Class/Notification/Listener/AudioTest.php @@ -30,10 +30,10 @@ require_once dirname(__FILE__) . '/../../../Autoload.php'; */ class Horde_Notification_Class_Notification_Listener_AudioTest extends PHPUnit_Extensions_OutputTestCase { - public function testMethodHandleHasResultBooleanTrueForAudioMessages() + public function testMethodHandleHasEventClassForAudioMessages() { $listener = new Horde_Notification_Listener_Audio(); - $this->assertTrue($listener->handles('audio')); + $this->assertEquals('Horde_Notification_Event', $listener->handles('audio')); } public function testMethodGetnameHasResultStringAudio() diff --git a/framework/Notification/test/Horde/Notification/Class/Notification/Listener/JavascriptTest.php b/framework/Notification/test/Horde/Notification/Class/Notification/Listener/JavascriptTest.php index 2761bbafa..3f11306a1 100644 --- a/framework/Notification/test/Horde/Notification/Class/Notification/Listener/JavascriptTest.php +++ b/framework/Notification/test/Horde/Notification/Class/Notification/Listener/JavascriptTest.php @@ -30,10 +30,10 @@ require_once dirname(__FILE__) . '/../../../Autoload.php'; */ class Horde_Notification_Class_Notification_Listener_JavascriptTest extends PHPUnit_Extensions_OutputTestCase { - public function testMethodHandleHasResultBooleanTrueForjavascriptMessages() + public function testMethodHandleHasEventClassForjavascriptMessages() { $listener = new Horde_Notification_Listener_Javascript(); - $this->assertTrue($listener->handles('javascript')); + $this->assertEquals('Horde_Notification_Event', $listener->handles('javascript')); } public function testMethodGetnameHasResultStringJavascript() @@ -52,7 +52,7 @@ class Horde_Notification_Class_Notification_Listener_JavascriptTest extends PHPU public function testMethodNotifyHasOutputEventMessageEmbeddedInScriptElement() { $listener = new Horde_Notification_Listener_Javascript(); - $event = new Horde_Notification_Event('test'); + $event = new Horde_Notification_Event('test', 'javascript'); $messages = array($event); $this->expectOutputString( '