From: Gunnar Wrobel Date: Wed, 24 Feb 2010 13:08:16 +0000 (+0100) Subject: Additional testing for Horde_Notification. X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=232433f7554e11c3f023a34509c0c344e2239908;p=horde.git Additional testing for Horde_Notification. --- diff --git a/framework/Notification/test/Horde/Notification/Class/Notification/Event/StatusTest.php b/framework/Notification/test/Horde/Notification/Class/Notification/Event/StatusTest.php new file mode 100644 index 000000000..c853114ef --- /dev/null +++ b/framework/Notification/test/Horde/Notification/Class/Notification/Event/StatusTest.php @@ -0,0 +1,49 @@ + + * @license http://www.fsf.org/copyleft/lgpl.html LGPL + * @link http://pear.horde.org/index.php?package=Notification + */ + +/** + * Prepare the test setup. + */ +require_once dirname(__FILE__) . '/../../../Autoload.php'; + +/** + * Test the status event class. + * + * Copyright 2009-2010 The Horde Project (http://www.horde.org/) + * + * See the enclosed file COPYING for license information (LGPL). If you + * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html. + * + * @category Horde + * @package Notification + * @author Gunnar Wrobel + * @license http://www.fsf.org/copyleft/lgpl.html LGPL + * @link http://pear.horde.org/index.php?package=Notification + */ +class Horde_Notification_Class_Notification_Event_StatusTest extends PHPUnit_Framework_TestCase +{ + public function testMethodTostringHasResultTheTextOfTheEvent() + { + if (!class_exists('Horde_Nls')) { + $this->markTestSkipped('The Horde_Nls class is not available!'); + } + Horde_Nls::setCharset('ISO-8859-1'); + $event = new Horde_Notification_Event_Status('test'); + $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); + } + +} diff --git a/framework/Notification/test/Horde/Notification/Class/Notification/HandlerTest.php b/framework/Notification/test/Horde/Notification/Class/Notification/HandlerTest.php index 66854e4c7..94fa66623 100644 --- a/framework/Notification/test/Horde/Notification/Class/Notification/HandlerTest.php +++ b/framework/Notification/test/Horde/Notification/Class/Notification/HandlerTest.php @@ -106,6 +106,61 @@ class Horde_Notification_Class_Notification_HandlerTest extends PHPUnit_Framewor } } + 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'); diff --git a/framework/Notification/test/Horde/Notification/Class/Notification/Listener/StatusTest.php b/framework/Notification/test/Horde/Notification/Class/Notification/Listener/StatusTest.php index 6a2177621..71576b92d 100644 --- a/framework/Notification/test/Horde/Notification/Class/Notification/Listener/StatusTest.php +++ b/framework/Notification/test/Horde/Notification/Class/Notification/Listener/StatusTest.php @@ -60,4 +60,19 @@ class Horde_Notification_Class_Notification_Listener_StatusTest extends PHPUnit_ $listener->notify($messages); } + public function testMethodNotifyHasMobileOutputIfTheMobileOptionWasSet() + { + if (!class_exists('Horde_Mobile')) { + $this->markTestSkipped('The Horde_Mobile package is not installed!'); + } + $mobile = $this->getMock('Horde_Mobile', array(), array(), '', false, false); + $mobile->expects($this->once()) + ->method('add') + ->with($this->isInstanceOf('Horde_Mobile_Text')); + $listener = new Horde_Notification_Listener_Status(); + $event = new Horde_Notification_Event('test'); + $messages = array($event); + $listener->notify($messages, array('mobile' => $mobile)); + } + } diff --git a/framework/Notification/test/Horde/Notification/Class/Notification/ListenerTest.php b/framework/Notification/test/Horde/Notification/Class/Notification/ListenerTest.php index 4e42094bc..561a5e1d1 100644 --- a/framework/Notification/test/Horde/Notification/Class/Notification/ListenerTest.php +++ b/framework/Notification/test/Horde/Notification/Class/Notification/ListenerTest.php @@ -49,6 +49,13 @@ class Horde_Notification_Class_Notification_ListenerTest extends PHPUnit_Framewo $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();