Additional testing for Horde_Notification.
authorGunnar Wrobel <p@rdus.de>
Wed, 24 Feb 2010 13:08:16 +0000 (14:08 +0100)
committerGunnar Wrobel <p@rdus.de>
Wed, 24 Feb 2010 13:08:16 +0000 (14:08 +0100)
framework/Notification/test/Horde/Notification/Class/Notification/Event/StatusTest.php [new file with mode: 0644]
framework/Notification/test/Horde/Notification/Class/Notification/HandlerTest.php
framework/Notification/test/Horde/Notification/Class/Notification/Listener/StatusTest.php
framework/Notification/test/Horde/Notification/Class/Notification/ListenerTest.php

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 (file)
index 0000000..c853114
--- /dev/null
@@ -0,0 +1,49 @@
+<?php
+/**
+ * Test the status event class.
+ *
+ * @category Horde
+ * @package  Notification
+ * @author   Gunnar Wrobel <wrobel@pardus.de>
+ * @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 <wrobel@pardus.de>
+ * @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('<b>test</b>');
+        $this->assertEquals('&lt;b&gt;test&lt;/b&gt;', (string) $event);
+    }
+
+    public function testMethodTostringHasUnescapedResultIfContentRawFlagIsSet()
+    {
+        $event = new Horde_Notification_Event_Status('<b>test</b>', null, array('content.raw'));
+        $this->assertEquals('<b>test</b>', (string) $event);
+    }
+
+}
index 66854e4..94fa666 100644 (file)
@@ -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');
index 6a21776..71576b9 100644 (file)
@@ -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('<b>test</b>');
+        $messages = array($event);
+        $listener->notify($messages, array('mobile' => $mobile));
+    }
+
 }
index 4e42094..561a5e1 100644 (file)
@@ -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();