* @category Horde
* @license http://www.horde.org/licenses/lgpl21 LGPL 2.1
* @package Notification
*/
class Horde_Notification_Handler
{
/**
* Decorators.
*
* @var array
*/
protected $_decorators = array();
/**
* Forces immediate attachment of a notification to a listener.
*
* @var boolean
*/
protected $_forceAttach = false;
/**
* Additional handle definitions.
*
* @var array
*/
protected $_handles = array(
'default' => array(
'*' => 'Horde_Notification_Event'
)
);
/**
* Hash containing all attached listener objects.
*
* @var array
*/
protected $_listeners = array();
/**
* The storage location where we store the messages.
*
* @var Horde_Notification_Storage
*/
protected $_storage;
/**
* Initialize the notification system.
*
* @param Horde_Notification_Storage $storage The storage object to use.
*/
public function __construct(Horde_Notification_Storage_Interface $storage)
{
$this->_storage = $storage;
}
/**
* 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)
{
if ($ob = $this->getListener($listener)) {
return $ob;
}
if (is_null($class)) {
$class = 'Horde_Notification_Listener_' . Horde_String::ucfirst(Horde_String::lower($listener));
}
if (class_exists($class)) {
$this->_listeners[$listener] = new $class($params);
if (!$this->_storage->exists($listener)) {
$this->_storage->set($listener, array());
}
$this->_addTypes($listener);
return $this->_listeners[$listener];
}
throw new Horde_Exception(sprintf('Notification listener %s not found.', $class));
}
/**
* Remove a listener from the notification list.
*
* @param string $listner The name of the listener to detach.
*
* @throws Horde_Exception
*/
public function detach($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));
}
}
/**
* 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 $type The listener type.
*
* @return mixed A Horde_Notification_Listener object, or null if
* $type listener is not attached.
*/
public function get($type)
{
foreach ($this->_listeners as $listener) {
if ($listener->handles($type)) {
return $listener;
}
}
return null;
}
/**
* Returns a listener object given a listener name.
*
* @param string $listener The listener name.
*
* @return mixed Either a Horde_Notification_Listener or null.
*/
public function getListener($listener)
{
$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 a decorator.
*
* @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.
* @param string $type The type of message.
* @param array $flags Array of optional flags that will be passed to
* the registered listeners.
* @param array $options Additional options:
*
* 'immediate' - (boolean) If true, immediately tries to attach to a
* listener. If no listener exists for this type, the
* message will be dropped.
* DEFAULT: false (message will be attached to available
* handler at the time notify() is called).
*
*/
public function push($event, $type = null, array $flags = array(),
$options = array())
{
if ($event instanceof Horde_Notification_Event) {
$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 $class($event, $type, $flags);
}
foreach ($this->_decorators as $decorator) {
$decorator->push($event, $options);
}
if (!$this->_forceAttach && empty($options['immediate'])) {
$this->_storage->push('_unattached', $event);
} else {
if ($listener = $this->get($event->type)) {
$this->_storage->push($listener->getName(), $event);
}
}
}
/**
* 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. Any options not contained in this
* list will be passed to the listeners.
*
* 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())
{
/* Convert the 'listeners' option into the format expected by the
* notification handler. */
if (!isset($options['listeners'])) {
$listeners = array_keys($this->_listeners);
} elseif (!is_array($options['listeners'])) {
$listeners = array($options['listeners']);
} else {
$listeners = $options['listeners'];
}
$events = array();
$unattached = $this->_storage->exists('_unattached')
? $this->_storage->get('_unattached')
: array();
/* Pass the message stack to all listeners and asks them to handle
* their messages. */
foreach ($listeners as $listener) {
$listener = Horde_String::lower($listener);
if (isset($this->_listeners[$listener])) {
$instance = $this->_listeners[$listener];
$name = $instance->getName();
foreach (array_keys($unattached) as $val) {
if ($unattached[$val] instanceof Horde_Notification_Event
&& $instance->handles($unattached[$val]->type)) {
$this->_storage->push($name, $unattached[$val]);
unset($unattached[$val]);
}
}
foreach ($this->_decorators as $decorator) {
$this->_forceAttach = true;
try {
$decorator->notify($this, $instance);
} catch (Horde_Notification_Exception $e) {
$this->push($e);
}
$this->_forceAttach = false;
}
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);
}
}
if (empty($unattached)) {
$this->_storage->clear('_unattached');
} else {
$this->_storage->set('_unattached', $unattached);
}
return $events;
}
/**
* 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)
{
$count = 0;
if (!is_null($my_listener)) {
if ($ob = $this->get($my_listener)) {
$count = count($this->_storage->get($ob->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()));
}
}
}
return $count;
}
}
Horde_Notification-2.0.4/lib/Horde/Notification/Listener.php 0000664 0001750 0001750 00000004474 12653752150 022142 0 ustar jan jan
* @category Horde
* @license http://www.horde.org/licenses/lgpl21 LGPL 2.1
* @package Notification
*/
abstract class Horde_Notification_Listener
{
/**
* The base type of this listener.
*
* @var string
*/
protected $_name;
/**
* 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
*/
protected $_handles = array();
/**
* Does this listener handle a certain type of message?
*
* @param string $type The message type in question.
*
* @return mixed False if this listener does not handle, the default
* event class if it does handle the type.
*/
public function 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;
}
/**
* Return a unique identifier for this listener.
*
* @return string Unique id.
*/
public function getName()
{
return $this->_name;
}
/**
* Outputs the status line, sends emails, pages, etc., if there
* are any messages on this listener's message stack.
*
* @param array $events The list of events to handle.
* @param array $options An array of options.
*/
abstract public function notify($events, $options = array());
}
Horde_Notification-2.0.4/lib/Horde/Notification.php 0000664 0001750 0001750 00000002571 12653752150 020351 0 ustar jan jan
* @category Horde
* @license http://www.horde.org/licenses/lgpl21 LGPL 2.1
* @package Notification
*/
class Horde_Notification
{
/**
* Horde_Notification instances.
*
* @var Horde_Notification
*/
protected static $_instances = array();
/**
* Returns a reference to the global notification handler, only
* creating it if it doesn't already exist.
*
* This method must be invoked as:
* $notification = Horde_Notification::singleton([$stack]);
*
* @param string $stack The name of the message stack to use.
*
* return Horde_Notification_Handler The Horde Notification handler.
*/
public static function singleton($stack = 'horde_notification_stacks')
{
if (!isset(self::$_instances[$stack])) {
self::$_instances[$stack] = new Horde_Notification_Handler(new Horde_Notification_Storage_Session($stack));
}
return self::$_instances[$stack];
}
}
Horde_Notification-2.0.4/test/Horde/Notification/Class/Notification/Event/StatusTest.php 0000664 0001750 0001750 00000002466 12653752150 027464 0 ustar jan jan
* @license http://www.horde.org/licenses/lgpl21 LGPL 2.1
* @link http://pear.horde.org/index.php?package=Notification
*/
/**
* Test the status event class.
*
* Copyright 2009-2016 Horde LLC (http://www.horde.org/)
*
* See the enclosed file COPYING for license information (LGPL). If you
* did not receive this file, see http://www.horde.org/licenses/lgpl21.
*
* @category Horde
* @package Notification
* @author Gunnar Wrobel
* @license http://www.horde.org/licenses/lgpl21 LGPL 2.1
* @link http://pear.horde.org/index.php?package=Notification
*/
class Horde_Notification_Class_Notification_Event_StatusTest extends Horde_Test_Case
{
public function testMethodTostringHasResultTheTextOfTheEvent()
{
$event = new Horde_Notification_Event_Status('test');
$event->charset = 'ISO-8859-1';
$this->assertEquals('<b>test</b>', (string) $event);
}
public function testMethodTostringHasUnescapedResultIfContentRawFlagIsSet()
{
$event = new Horde_Notification_Event_Status('test', null, array('content.raw'));
$this->assertEquals('test', (string) $event);
}
}
Horde_Notification-2.0.4/test/Horde/Notification/Class/Notification/Handler/Decorator/AlarmTest.php 0000664 0001750 0001750 00000003071 12653752150 031444 0 ustar jan jan
* @license http://www.horde.org/licenses/lgpl21 LGPL 2.1
* @link http://pear.horde.org/index.php?package=Notification
*/
/**
* Test the alarm notification handler class.
*
* Copyright 2009-2016 Horde LLC (http://www.horde.org/)
*
* See the enclosed file COPYING for license information (LGPL). If you
* did not receive this file, see http://www.horde.org/licenses/lgpl21.
*
* @category Horde
* @package Notification
* @author Gunnar Wrobel
* @license http://www.horde.org/licenses/lgpl21 LGPL 2.1
* @link http://pear.horde.org/index.php?package=Notification
*/
class Horde_Notification_Class_Notification_Handler_Decorator_AlarmTest
extends Horde_Test_Case
{
public function setUp()
{
$this->markTestIncomplete('Currently broken');
if (!class_exists('Horde_Alarm')) {
$this->markTestSkipped('The Horde_Alarm package is not installed!');
}
$this->alarm = $this->getMockForAbstractClass('Horde_Alarm');
$this->alarm_handler = new Horde_Notification_Handler_Decorator_Alarm(
$this->alarm, null
);
}
public function testMethodNotifyHasPostconditionThatTheAlarmSystemGotNotifiedIfTheStatusListenerShouldBeNotified()
{
$this->alarm->expects($this->once())
->method('notify')
->with('');
$this->alarm_handler->notify(array('listeners' => array('status')));
}
}
././@LongLink 0 0 0 146 0 003737 L Horde_Notification-2.0.4/test/Horde/Notification/Class/Notification/Handler/Decorator/HordelogTest.php Horde_Notification-2.0.4/test/Horde/Notification/Class/Notification/Handler/Decorator/HordelogTest.p0000664 0001750 0001750 00000002014 12653752150 031617 0 ustar jan jan
* @license http://www.horde.org/licenses/lgpl21 LGPL 2.1
* @link http://pear.horde.org/index.php?package=Notification
*/
/**
* Test the notification handler class that logs to the horde log.
*
* Copyright 2009-2016 Horde LLC (http://www.horde.org/)
*
* See the enclosed file COPYING for license information (LGPL). If you
* did not receive this file, see http://www.horde.org/licenses/lgpl21.
*
* @category Horde
* @package Notification
* @author Gunnar Wrobel
* @license http://www.horde.org/licenses/lgpl21 LGPL 2.1
* @link http://pear.horde.org/index.php?package=Notification
*/
class Horde_Notification_Class_Notification_Handler_Decorator_HordelogTest
extends Horde_Test_Case
{
public function testNoneAvailable()
{
// No tests
$this->markTestIncomplete('No tests available.');
}
}
Horde_Notification-2.0.4/test/Horde/Notification/Class/Notification/Handler/Decorator/LogTest.php 0000664 0001750 0001750 00000003035 12653752150 031131 0 ustar jan jan
* @license http://www.horde.org/licenses/lgpl21 LGPL 2.1
* @link http://pear.horde.org/index.php?package=Notification
*/
/**
* Test the logging notification handler class.
*
* Copyright 2009-2016 Horde LLC (http://www.horde.org/)
*
* See the enclosed file COPYING for license information (LGPL). If you
* did not receive this file, see http://www.horde.org/licenses/lgpl21.
*
* @category Horde
* @package Notification
* @author Gunnar Wrobel
* @license http://www.horde.org/licenses/lgpl21 LGPL 2.1
* @link http://pear.horde.org/index.php?package=Notification
*/
class Horde_Notification_Class_Notification_Handler_Decorator_LogTest
extends Horde_Test_Case
{
public function setUp()
{
if (!class_exists('Horde_Log_Logger')) {
$this->markTestSkipped('The Horde_Log package is not installed!');
}
$this->logger = $this->getMock('Horde_Log_Logger');
$this->log = new Horde_Notification_Handler_Decorator_Log(
$this->logger
);
}
public function testMethodPushHasPostconditionThattheEventGotLoggedIfTheEventWasAnError()
{
$exception = new Horde_Notification_Event(new Exception('test'));
$this->logger->expects($this->once())
->method('__call')
->with('debug', $this->isType('array'));
$this->log->push($exception, array());
}
}
Horde_Notification-2.0.4/test/Horde/Notification/Class/Notification/Listener/AudioTest.php 0000664 0001750 0001750 00000003135 12653752150 027740 0 ustar jan jan
* @license http://www.horde.org/licenses/lgpl21 LGPL 2.1
* @link http://pear.horde.org/index.php?package=Notification
*/
/**
* Test the audio listener class.
*
* Copyright 2009-2016 Horde LLC (http://www.horde.org/)
*
* See the enclosed file COPYING for license information (LGPL). If you
* did not receive this file, see http://www.horde.org/licenses/lgpl21.
*
* @category Horde
* @package Notification
* @author Gunnar Wrobel
* @license http://www.horde.org/licenses/lgpl21 LGPL 2.1
* @link http://pear.horde.org/index.php?package=Notification
*/
class Horde_Notification_Class_Notification_Listener_AudioTest extends Horde_Test_Case
{
public function testMethodHandleHasEventClassForAudioMessages()
{
$listener = new Horde_Notification_Listener_Audio();
$this->assertEquals('Horde_Notification_Event', $listener->handles('audio'));
}
public function testMethodGetnameHasResultStringAudio()
{
$listener = new Horde_Notification_Listener_Audio();
$this->assertEquals('audio', $listener->getName());
}
public function testMethodNotifyHasOutputEventMessage()
{
$listener = new Horde_Notification_Listener_Audio();
$event = new Horde_Notification_Event('test');
$messages = array($event);
$this->expectOutputString(
''
);
$listener->notify($messages);
}
}
Horde_Notification-2.0.4/test/Horde/Notification/Class/Notification/Listener/StatusTest.php 0000664 0001750 0001750 00000003506 12653752150 030164 0 ustar jan jan
* @license http://www.horde.org/licenses/lgpl21 LGPL 2.1
* @link http://pear.horde.org/index.php?package=Notification
*/
/**
* Test the status listener class.
*
* Copyright 2009-2016 Horde LLC (http://www.horde.org/)
*
* See the enclosed file COPYING for license information (LGPL). If you
* did not receive this file, see http://www.horde.org/licenses/lgpl21.
*
* @category Horde
* @package Notification
* @author Gunnar Wrobel
* @license http://www.horde.org/licenses/lgpl21 LGPL 2.1
* @link http://pear.horde.org/index.php?package=Notification
*/
class Horde_Notification_Class_Notification_Listener_StatusTest extends Horde_Test_Case
{
public function testMethodHandleHasEventClassForHordeMessages()
{
$listener = new Horde_Notification_Listener_Status();
$this->assertEquals('Horde_Notification_Event_Status', $listener->handles('status'));
}
public function testMethodGetnameHasResultStringStatus()
{
$listener = new Horde_Notification_Listener_Status();
$this->assertEquals('status', $listener->getName());
}
public function testMethodNotifyHasNoOutputIfTheMessageStackIsEmpty()
{
$listener = new Horde_Notification_Listener_Status();
$messages = array();
$listener->notify($messages);
}
public function testMethodNotifyHasOutputEventMessagesEmbeddedInUlElement()
{
$listener = new Horde_Notification_Listener_Status();
$event = new Horde_Notification_Event('test');
$messages = array($event);
$this->expectOutputString(
''
);
$listener->notify($messages);
}
}
Horde_Notification-2.0.4/test/Horde/Notification/Class/Notification/EventTest.php 0000664 0001750 0001750 00000002657 12653752150 026203 0 ustar jan jan
* @license http://www.horde.org/licenses/lgpl21 LGPL 2.1
* @link http://pear.horde.org/index.php?package=Notification
*/
/**
* Test the basic event class.
*
* Copyright 2009-2016 Horde LLC (http://www.horde.org/)
*
* See the enclosed file COPYING for license information (LGPL). If you
* did not receive this file, see http://www.horde.org/licenses/lgpl21.
*
* @category Horde
* @package Notification
* @author Gunnar Wrobel
* @license http://www.horde.org/licenses/lgpl21 LGPL 2.1
* @link http://pear.horde.org/index.php?package=Notification
*/
class Horde_Notification_Class_Notification_EventTest extends Horde_Test_Case
{
public function testMethodConstructHasPostconditionThatTheGivenMessageWasSavedIfItWasNotNull()
{
$event = new Horde_Notification_Event('test');
$this->assertEquals('test', $event->message);
}
public function testMethodGetmessageHasResultStringTheStoredMessage()
{
$event = new Horde_Notification_Event('');
$event->message = 'test';
$this->assertEquals('test', $event->message);
}
public function testMethodGetmessageHasResultStringEmptyIfNoMessageWasStored()
{
$event = new Horde_Notification_Event('');
$this->assertEquals('', $event->message);
}
}
Horde_Notification-2.0.4/test/Horde/Notification/Class/Notification/HandlerTest.php 0000664 0001750 0001750 00000022372 12653752150 026473 0 ustar jan jan
* @license http://www.horde.org/licenses/lgpl21 LGPL 2.1
* @link http://pear.horde.org/index.php?package=Notification
*/
/**
* Test the basic notification handler class.
*
* Copyright 2009-2016 Horde LLC (http://www.horde.org/)
*
* See the enclosed file COPYING for license information (LGPL). If you
* did not receive this file, see http://www.horde.org/licenses/lgpl21.
*
* @category Horde
* @package Notification
* @author Gunnar Wrobel
* @license http://www.horde.org/licenses/lgpl21 LGPL 2.1
* @link http://pear.horde.org/index.php?package=Notification
*/
class Horde_Notification_Class_Notification_HandlerTest extends Horde_Test_Case
{
public function setUp()
{
$this->storage = new Horde_Notification_Storage_Session('test');
$this->handler = new Horde_Notification_Handler($this->storage);
}
public function tearDown()
{
unset($_SESSION);
}
public function testMethodAttachHasResultNotificationlistener()
{
$this->assertInstanceOf(
'Horde_Notification_Listener_Audio',
$this->handler->attach('audio')
);
}
public function testMethodAttachHasResultNotificationlistenerTheSameListenerAsBeforeIfThisListenerHasAlreadyBeenAttached()
{
$listener = $this->handler->attach('audio');
$this->assertSame($listener, $this->handler->attach('audio'));
}
public function testMethodAttachHasResultNotificationlistenerClassAsSpecifiedInParameterClass()
{
$this->assertInstanceOf(
'Horde_Notification_Listener_Audio',
$this->handler->attach(
'MyAudio', array(), 'Horde_Notification_Listener_Audio'
)
);
}
public function testMethodAttachHasPostconditionThatTheListenerGotInitializedWithTheProvidedParmeters()
{
$listener = $this->handler->attach('dummy', array('test'));
$this->assertEquals(array('test'), $listener->params);
}
public function testMethodAttachHasPostconditionThatTheListenerStackGotInitializedAsArray()
{
$this->handler->attach('audio');
$this->assertEquals(array(), $_SESSION['test']['audio']);
}
public function testMethodAttachThrowsExceptionIfTheListenerTypeIsUnknown()
{
try {
$this->handler->attach('MyAudio');
$this->fail('No exception!');
} catch (Horde_Exception $e) {
$this->assertEquals(
'Notification listener Horde_Notification_Listener_Myaudio not found.',
$e->getMessage()
);
}
}
public function testMethodDetachHasPostconditionThatTheListenerStackGotUnset()
{
$this->handler->attach('audio');
$this->handler->detach('audio');
$this->assertFalse(isset($_SESSION['test']['audio']));
}
public function testMethodDetachThrowsExceptionIfTheListenerIsUnset()
{
try {
$this->handler->detach('MyAudio');
$this->fail('No exception!');
} catch (Horde_Exception $e) {
$this->assertEquals(
'Notification listener MyAudio not found.',
$e->getMessage()
);
}
}
public function testMethodClearHasPostconditionThatTheStorageOfTheSpecifiedListenerWasCleared()
{
$storage = $this->getMock('Horde_Notification_Storage_Interface');
$storage->expects($this->once())
->method('clear')
->with('dummy');
$handler = new Horde_Notification_Handler($storage);
$handler->attach('dummy');
$handler->clear('dummy');
}
public function testMethodClearHasPostconditionThatAllUnattachedEventsHaveBeenClearedFromStorageIfNoListenerWasSpecified()
{
$storage = $this->getMock('Horde_Notification_Storage_Interface');
$storage->expects($this->once())
->method('clear')
->with('_unattached');
$handler = new Horde_Notification_Handler($storage);
$handler->clear();
}
public function testMethodGetHasResultNullIfTheSpecifiedListenerIsNotAttached()
{
$this->assertNull($this->handler->get('not attached'));
}
public function testMethodAddtypeHasPostconditionThatTheSpecifiedListenerHandlesTheGivenMessageType()
{
$this->handler->attach('dummy');
$this->handler->addType('dummy', 'newtype', 'NewType');
$this->assertEquals('NewType', $this->handler->getListener('dummy')->handles('newtype'));
}
public function testMethodAdddecoratorHasPostconditionThatTheGivenDecoratorWasAddedToTheHandlerAndReceivesPushCalls()
{
$decorator = $this->getMock('Horde_Notification_Handler_Decorator_Base');
$decorator->expects($this->once())
->method('push')
->with($this->isInstanceOf('Horde_Notification_Event'));
$event = new Horde_Notification_Event('test');
$this->handler->attach('audio');
$this->handler->addDecorator($decorator);
$this->handler->push($event, 'audio');
}
public function testMethodAdddecoratorHasPostconditionThatTheGivenDecoratorWasAddedToTheHandlerAndReceivesNotifyCalls()
{
$decorator = $this->getMock('Horde_Notification_Handler_Decorator_Base');
$decorator->expects($this->once())
->method('notify');
$this->handler->attach('audio');
$this->handler->addDecorator($decorator);
$this->handler->notify();
}
public function testMethodPushHasPostconditionThatTheEventGotSavedInAllAttachedListenerStacksHandlingTheEvent()
{
$event = new Horde_Notification_Event('test');
$this->handler->attach('audio');
$this->handler->push('test', 'audio', array(), array('immediate' => true));
$result = array_shift($_SESSION['test']['audio']);
$this->assertNotNull($result);
$this->assertInstanceOf('Horde_Notification_Event', $result);
$this->assertEquals(array(), $result->flags);
$this->assertEquals('audio', $result->type);
}
public function testMethodPushHasPostconditionThatAnExceptionGetsMarkedAsTypeStatusIfTheTypeWasUnset()
{
$this->handler->attach('dummy');
$this->handler->push(new Exception('test'), null, array(), array('immediate' => true));
$result = array_shift($_SESSION['test']['dummy']);
$this->assertNotNull($result);
$this->assertInstanceOf('Horde_Notification_Event', $result);
$this->assertEquals(array(), $result->flags);
$this->assertEquals('status', $result->type);
}
public function testMethodPushHasPostconditionThatEventsWithoutTypeGetMarkedAsTypeStatus()
{
$this->handler->attach('dummy');
$this->handler->push('test', null, array(), array('immediate' => true));
$result = array_shift($_SESSION['test']['dummy']);
$this->assertNotNull($result);
$this->assertInstanceOf('Horde_Notification_Event', $result);
$this->assertEquals(array(), $result->flags);
$this->assertEquals('status', $result->type);
}
public function testMethodNotifyHasPostconditionThatAllListenersWereNotified()
{
$dummy = $this->handler->attach('dummy');
$this->handler->push('test', 'dummy');
$this->handler->notify();
$result = array_shift($dummy->events);
$this->assertNotNull($result);
$this->assertInstanceOf('Horde_Notification_Event', $result);
$this->assertEquals(array(), $result->flags);
$this->assertEquals('dummy', $result->type);
}
public function testMethodNotifyHasPostconditionThatTheSpecifiedListenersWereNotified()
{
$dummy = $this->handler->attach('dummy');
$this->handler->push('test', 'dummy');
$this->handler->notify(array('listeners' => 'dummy'));
$result = array_shift($dummy->events);
$this->assertNotNull($result);
$this->assertInstanceOf('Horde_Notification_Event', $result);
$this->assertEquals(array(), $result->flags);
$this->assertEquals('dummy', $result->type);
}
public function testMethodCountHasResultTheTotalNumberOfEventsInTheStack()
{
$this->handler->attach('audio');
$this->handler->attach('dummy');
$this->handler->push('test', 'audio');
$this->handler->push('test', 'dummy');
$this->assertEquals(2, $this->handler->count());
}
public function testMethodCountHasResultTheEventNumberForASpecificListenerIfTheListenerHasBeenSpecified()
{
$this->handler->attach('audio');
$this->handler->attach('dummy');
$this->handler->push('test', 'audio');
$this->assertEquals(1, $this->handler->count('audio'));
}
}
class Horde_Notification_Listener_Dummy extends Horde_Notification_Listener
{
public $events;
public $params;
public function __construct($params)
{
$this->params = $params;
$this->_name = 'dummy';
$this->_handles = array(
'dummy' => 'Horde_Notification_Event',
'status' => 'Horde_Notification_Event'
);
}
public function notify($events, $options = array())
{
$this->events = $events;
}
}
Horde_Notification-2.0.4/test/Horde/Notification/Class/Notification/ListenerTest.php 0000664 0001750 0001750 00000004123 12653752150 026675 0 ustar jan jan
* @license http://www.horde.org/licenses/lgpl21 LGPL 2.1
* @link http://pear.horde.org/index.php?package=Notification
*/
/**
* Test the basic listener class.
*
* Copyright 2009-2016 Horde LLC (http://www.horde.org/)
*
* See the enclosed file COPYING for license information (LGPL). If you
* did not receive this file, see http://www.horde.org/licenses/lgpl21.
*
* @category Horde
* @package Notification
* @author Gunnar Wrobel
* @license http://www.horde.org/licenses/lgpl21 LGPL 2.1
* @link http://pear.horde.org/index.php?package=Notification
*/
class Horde_Notification_Class_Notification_ListenerTest extends Horde_Test_Case
{
public function setUp()
{
if (!class_exists('PEAR_Error')) {
$this->markTestSkipped('The PEAR_Error class is not available!');
}
}
public function testMethodHandleHasResultBooleanFalse()
{
$listener = new Horde_Notification_Listener_Mock();
$this->assertFalse($listener->handles('test'));
}
public function testMethodHandleHasEventClassName()
{
$listener = new Horde_Notification_Listener_Mock();
$this->assertEquals('Horde_Notification_Event', $listener->handles('mock'));
}
public function testMethodHandleHasEventClassNameIfItMatchesAsteriskExpression()
{
$listener = new Horde_Notification_Listener_Mock();
$listener->addType('t*', 'Test_Event');
$this->assertEquals('Test_Event', $listener->handles('test'));
}
public function testMethodGetnameHasResultStringTheNameOfTheListener()
{
$listener = new Horde_Notification_Listener_Mock();
$this->assertEquals('mock', $listener->getName());
}
}
class Horde_Notification_Listener_Mock extends Horde_Notification_Listener
{
protected $_handles = array('mock' => 'Horde_Notification_Event');
protected $_name = 'mock';
public function notify($events, $options = array())
{
}
}
Horde_Notification-2.0.4/test/Horde/Notification/Class/NotificationTest.php 0000664 0001750 0001750 00000003172 12653752150 025113 0 ustar jan jan
* @license http://www.horde.org/licenses/lgpl21 LGPL 2.1
* @link http://pear.horde.org/index.php?package=Notification
*/
/**
* Test the notification class.
*
* Copyright 2009-2016 Horde LLC (http://www.horde.org/)
*
* See the enclosed file COPYING for license information (LGPL). If you
* did not receive this file, see http://www.horde.org/licenses/lgpl21.
*
* @category Horde
* @package Notification
* @author Gunnar Wrobel
* @license http://www.horde.org/licenses/lgpl21 LGPL 2.1
* @link http://pear.horde.org/index.php?package=Notification
*/
class Horde_Notification_Class_NotificationTest extends Horde_Test_Case
{
public function tearDown()
{
unset($_SESSION);
}
public function testMethodSingletonReturnsAlwaysTheSameInstanceForTheSameStackName()
{
$notification1 = Horde_Notification::singleton('test');
$notification2 = Horde_Notification::singleton('test');
$this->assertSame($notification1, $notification2);
}
public function testMethodConstructHasPostconditionThatTheSessionStackGotInitializedAsArray()
{
$notification = Horde_Notification_Instance::newInstance('test');
$this->assertEquals(array(), $_SESSION['test']);
}
}
class Horde_Notification_Instance extends Horde_Notification
{
public static function newInstance($stack)
{
$storage = new Horde_Notification_Storage_Session($stack);
return new Horde_Notification_Handler($storage);
}
}
Horde_Notification-2.0.4/test/Horde/Notification/AllTests.php 0000664 0001750 0001750 00000000132 12653752150 022304 0 ustar jan jan run();
Horde_Notification-2.0.4/test/Horde/Notification/Autoload.php 0000664 0001750 0001750 00000000506 12653752150 022326 0 ustar jan jan
* @license http://www.horde.org/licenses/lgpl21 LGPL 2.1
* @link http://pear.horde.org/index.php?package=Notification
*/
/** Needed for PEAR_Error. */
@include_once 'PEAR.php';
Horde_Notification-2.0.4/test/Horde/Notification/bootstrap.php 0000664 0001750 0001750 00000000143 12653752150 022570 0 ustar jan jan
../../../lib