Add test cases for alarm-related utility functions + select the correct alarm if multiple are defined
This commit is contained in:
parent
0463028a76
commit
44b67121b7
2 changed files with 89 additions and 1 deletions
|
@ -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;
|
||||
|
|
|
@ -28,6 +28,94 @@ class libcalendaring_test extends PHPUnit_Framework_TestCase
|
|||
require_once __DIR__ . '/../libcalendaring.php';
|
||||
}
|
||||
|
||||
/**
|
||||
* 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()
|
||||
*/
|
||||
|
|
Loading…
Add table
Reference in a new issue