plugins/libcalendaring

Thomas Brüderli bruederli at kolabsys.com
Thu Jan 8 15:39:43 CET 2015


 plugins/libcalendaring/libcalendaring.php       |    2 
 plugins/libcalendaring/tests/libcalendaring.php |   88 ++++++++++++++++++++++++
 2 files changed, 89 insertions(+), 1 deletion(-)

New commits:
commit 44b67121b7e41a6a54ae26e264d0ff0a0adbf36e
Author: Thomas Bruederli <bruederli at kolabsys.com>
Date:   Thu Jan 8 15:39:39 2015 +0100

    Add test cases for alarm-related utility functions + select the correct alarm if multiple are defined

diff --git a/plugins/libcalendaring/libcalendaring.php b/plugins/libcalendaring/libcalendaring.php
index 7506336..49ef40a 100644
--- a/plugins/libcalendaring/libcalendaring.php
+++ b/plugins/libcalendaring/libcalendaring.php
@@ -609,7 +609,7 @@ class libcalendaring extends rcube_plugin
                 }
             }
 
-            if ($notify_time && (!$notify_at || ($notify_time < $notify_at && $notify_time > $expires))) {
+            if ($notify_time && (!$notify_at || ($notify_time > $notify_at && $notify_time > $expires))) {
                 $notify_at = $notify_time;
                 $action = $alarm['action'];
                 $alarm_prop = $alarm;
diff --git a/plugins/libcalendaring/tests/libcalendaring.php b/plugins/libcalendaring/tests/libcalendaring.php
index 3d0eb86..6b52617 100644
--- a/plugins/libcalendaring/tests/libcalendaring.php
+++ b/plugins/libcalendaring/tests/libcalendaring.php
@@ -29,6 +29,94 @@ class libcalendaring_test extends PHPUnit_Framework_TestCase
     }
 
     /**
+     * libcalendaring::parse_alaram_value()
+     */
+    function test_parse_alaram_value()
+    {
+        $alarm = libcalendaring::parse_alaram_value('-15M');
+        $this->assertEquals('15', $alarm[0]);
+        $this->assertEquals('-M', $alarm[1]);
+        $this->assertEquals('-PT15M', $alarm[3]);
+
+        $alarm = libcalendaring::parse_alaram_value('-PT5H');
+        $this->assertEquals('5',  $alarm[0]);
+        $this->assertEquals('-H', $alarm[1]);
+
+        $alarm = libcalendaring::parse_alaram_value('P0DT1H0M0S');
+        $this->assertEquals('1',  $alarm[0]);
+        $this->assertEquals('+H', $alarm[1]);
+
+        // FIXME: this should return something like (1140 + 120 + 30)M
+        $alarm = libcalendaring::parse_alaram_value('-P1DT2H30M');
+        // $this->assertEquals('1590', $alarm[0]);
+        // $this->assertEquals('-M',   $alarm[1]);
+
+        $alarm = libcalendaring::parse_alaram_value('@1420722000');
+        $this->assertInstanceOf('DateTime', $alarm[0]);
+    }
+
+    /**
+     * libcalendaring::get_next_alarm()
+     */
+    function test_get_next_alarm()
+    {
+        // alarm 10 minutes before event
+        $date = date('Ymd', strtotime('today + 2 days'));
+        $event = array(
+            'start' => new DateTime($date . 'T160000Z'),
+            'end'   => new DateTime($date . 'T180000Z'),
+            'valarms' => array(
+                array(
+                    'trigger' => '-PT10M',
+                    'action'  => 'DISPLAY',
+                ),
+            ),
+        );
+        $alarm = libcalendaring::get_next_alarm($event);
+        $this->assertEquals($event['valarms'][0]['action'], $alarm['action']);
+        $this->assertEquals(strtotime($date . 'T155000Z'), $alarm['time']);
+
+        // alarm 1 hour after before event
+        $event['valarms'] = array(
+            array(
+                'trigger' => '+PT1H',
+            ),
+        );
+        $alarm = libcalendaring::get_next_alarm($event);
+        $this->assertEquals('DISPLAY', $alarm['action']);
+        $this->assertEquals(strtotime($date . 'T190000Z'), $alarm['time']);
+
+        // ignore past alarms
+        $event['start'] = new DateTime('today 22:00:00');
+        $event['end']   = new DateTime('today 23:00:00');
+        $event['valarms'] = array(
+            array(
+                'trigger' => '-P2D',
+                'action'  => 'EMAIL',
+            ),
+            array(
+                'trigger' => '-PT30M',
+                'action'  => 'DISPLAY',
+            ),
+        );
+        $alarm = libcalendaring::get_next_alarm($event);
+        $this->assertEquals('DISPLAY', $alarm['action']);
+        $this->assertEquals(strtotime('today 21:30:00'), $alarm['time']);
+
+        // absolute alarm date/time
+        $event['valarms'] = array(
+            array('trigger' => new DateTime('today 20:00:00'))
+        );
+        $alarm = libcalendaring::get_next_alarm($event);
+        $this->assertEquals($event['valarms'][0]['trigger']->format('U'), $alarm['time']);
+
+        // no alarms for cancelled events
+        $event['status'] = 'CANCELLED';
+        $alarm = libcalendaring::get_next_alarm($event);
+        $this->assertEquals(null, $alarm);
+    }
+
+    /**
      * libcalendaring::part_is_vcalendar()
      */
     function test_part_is_vcalendar()




More information about the commits mailing list