Add test for null driver.
authorJan Schneider <jan@horde.org>
Fri, 7 May 2010 12:43:24 +0000 (14:43 +0200)
committerJan Schneider <jan@horde.org>
Fri, 7 May 2010 12:43:24 +0000 (14:43 +0200)
framework/Alarm/lib/Horde/Alarm/Null.php
framework/Alarm/test/Horde/Alarm/NullTest.php [new file with mode: 0644]

index c027abb..ca25a58 100644 (file)
@@ -42,7 +42,7 @@ class Horde_Alarm_Null extends Horde_Alarm
      */
     protected function _get($id, $user)
     {
-        return array();
+        throw new Horde_Alarm_Exception('Alarm not found');
     }
 
     /**
diff --git a/framework/Alarm/test/Horde/Alarm/NullTest.php b/framework/Alarm/test/Horde/Alarm/NullTest.php
new file mode 100644 (file)
index 0000000..a054a64
--- /dev/null
@@ -0,0 +1,122 @@
+<?php
+/**
+ * @author     Jan Schneider <jan@horde.org>
+ * @license    http://www.fsf.org/copyleft/lgpl.html LGPL
+ * @category   Horde
+ * @package    Horde_Alarm
+ * @subpackage UnitTests
+ */
+
+class Horde_Alarm_NullTest extends PHPUnit_Framework_TestCase
+{
+    protected static $alarm;
+    protected static $date;
+    protected static $end;
+
+    public function testFactory()
+    {
+        self::$alarm = Horde_Alarm::factory('Null');
+    }
+
+    /**
+     * @depends testFactory
+     */
+    public function testSet()
+    {
+        $now = time();
+        self::$date = new Horde_Date($now);
+        self::$end = new Horde_Date($now + 3600);
+        $hash = array('id' => 'personalalarm',
+                      'user' => 'john',
+                      'start' => self::$date,
+                      'end' => self::$end,
+                      'methods' => array(),
+                      'params' => array(),
+                      'title' => 'This is a personal alarm.');
+        self::$alarm->set($hash);
+    }
+
+    /**
+     * @depends testFactory
+     */
+    public function testExists()
+    {
+        $this->assertFalse(self::$alarm->exists('personalalarm', 'john'));
+    }
+
+    /**
+     * @depends testFactory
+     * @expectedException Horde_Alarm_Exception
+     */
+    public function testGet()
+    {
+        $alarm = self::$alarm->get('personalalarm', 'john');
+    }
+
+    /**
+     * @depends testFactory
+     */
+    public function testListAlarms()
+    {
+        self::$alarm->set(array('id' => 'publicalarm',
+                                'start' => self::$date,
+                                'end' => self::$end,
+                                'methods' => array(),
+                                'params' => array(),
+                                'title' => 'This is a public alarm.'));
+        self::$date->min--;
+        $list = self::$alarm->listAlarms('john');
+        $this->assertEquals(0, count($list));
+    }
+
+    /**
+     * @depends testFactory
+     */
+    public function testDelete()
+    {
+        self::$alarm->delete('publicalarm', '');
+        $list = self::$alarm->listAlarms('john');
+        $this->assertEquals(0, count($list));
+    }
+
+    /**
+     * @depends testFactory
+     * @expectedException Horde_Alarm_Exception
+     */
+    public function testSnoozeException()
+    {
+        self::$alarm->snooze('personalalarm', 'jane', 30);
+    }
+
+    /**
+     * @depends testFactory
+     */
+    public function testSnooze()
+    {
+        $this->assertFalse(self::$alarm->isSnoozed('personalalarm', 'john'));
+    }
+
+    /**
+     * @depends testFactory
+     */
+    public function testAlarmWithoutEnd()
+    {
+        self::$alarm->set(array('id' => 'noend',
+                                'user' => 'john',
+                                'start' => self::$date,
+                                'methods' => array('notify'),
+                                'params' => array(),
+                                'title' => 'This is an alarm without end.'));
+        $list = self::$alarm->listAlarms('john', self::$end);
+        $this->assertEquals(0, count($list));
+    }
+
+    /**
+     * @depends testFactory
+     */
+    public function testCleanUp()
+    {
+        self::$alarm->delete('noend', 'john');
+        self::$alarm->delete('personalalarm', 'john');
+    }
+}