/usr/share/php/tests/Horde_Alarm/Horde/Alarm/SqlTest.php is in php-horde-alarm 2.0.5-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 | <?php
/**
* @author Jan Schneider <jan@horde.org>
* @license http://www.horde.org/licenses/lgpl21 LGPL 2.1
* @category Horde
* @package Alarm
* @subpackage UnitTests
*/
class Horde_Alarm_SqlTest extends Horde_Test_Case
{
protected static $skip = false;
protected static $db;
protected static $migrator;
protected static $alarm;
protected static $date;
protected static $end;
public static function setUpBeforeClass()
{
// @fixme
$GLOBALS['language'] = 'en_US';
$conf = self::getConfig('ALARM_TEST_CONFIG');
if (!isset($conf['alarm']['test'])) {
self::$skip = true;
return;
}
$adapter = str_replace(' ', '_' , ucwords(str_replace('_', ' ', basename($conf['alarm']['test']['horde']['adapter']))));
$class = 'Horde_Db_Adapter_' . $adapter;
self::$db = new $class($conf['alarm']['test']['horde']);
self::$migrator = new Horde_Db_Migration_Migrator(self::$db, null, array('migrationsPath' => dirname(dirname(dirname(__DIR__))) . '/migration/Horde/Alarm'));
self::$migrator->up();
}
public static function tearDownAfterClass()
{
if (self::$migrator) {
self::$migrator->down();
}
}
public function setUp()
{
if (self::$skip) {
$this->markTestSkipped('No configuration for Horde_Alarm test.');
}
}
public function testFactory()
{
self::$alarm = new Horde_Alarm_Sql(array('db' => self::$db, 'charset' => 'UTF-8'));
self::$alarm->initialize();
self::$alarm->gc(true);
}
/**
* @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 testSet
*/
public function testExists()
{
$this->assertTrue(self::$alarm->exists('personalalarm', 'john'));
}
/**
* @depends testExists
*/
public function testGet()
{
$alarm = self::$alarm->get('personalalarm', 'john');
$this->assertInternalType('array', $alarm);
$this->assertEquals('personalalarm', $alarm['id']);
$this->assertEquals('john', $alarm['user']);
$this->assertEquals(array(), $alarm['methods']);
$this->assertEquals(array(), $alarm['params']);
$this->assertEquals('This is a personal alarm.', $alarm['title']);
$this->assertNull($alarm['text']);
$this->assertNull($alarm['snooze']);
$this->assertNull($alarm['internal']);
$this->assertThat($alarm['start'], $this->isInstanceOf('Horde_Date'));
$this->assertThat($alarm['end'], $this->isInstanceOf('Horde_Date'));
$this->assertEquals(0, $alarm['start']->compareDateTime(self::$date));
return $alarm;
}
/**
* @depends testGet
*/
public function testUpdate($alarm)
{
$alarm['title'] = 'Changed alarm text';
self::$alarm->set($alarm);
}
/**
* @depends testUpdate
*/
public function testListAlarms()
{
self::$date->min--;
self::$alarm->set(array('id' => 'publicalarm',
'start' => self::$date,
'end' => self::$end,
'methods' => array(),
'params' => array(),
'title' => 'This is a public alarm.'));
$list = self::$alarm->listAlarms('john');
$this->assertEquals(2, count($list));
$this->assertEquals('publicalarm', $list[0]['id']);
$this->assertEquals('personalalarm', $list[1]['id']);
}
/**
* @depends testListAlarms
*/
public function testDelete()
{
self::$alarm->delete('publicalarm', '');
$list = self::$alarm->listAlarms('john');
$this->assertEquals(1, count($list));
$this->assertEquals('personalalarm', $list[0]['id']);
}
/**
* @depends testDelete
* @expectedException Horde_Alarm_Exception
*/
public function testSnoozeException()
{
self::$alarm->snooze('personalalarm', 'jane', 30);
}
/**
* @depends testDelete
*/
public function testSnooze()
{
self::$alarm->snooze('personalalarm', 'john', 30);
$this->assertTrue(self::$alarm->isSnoozed('personalalarm', 'john'));
$list = self::$alarm->listAlarms('john');
$this->assertEquals(0, count($list));
$list = self::$alarm->listAlarms('john', self::$end);
$this->assertEquals(1, count($list));
$this->assertEquals('personalalarm', $list[0]['id']);
/* Test resetting snooze after changing the alarm. */
$alarm = self::$alarm->get('personalalarm', 'john');
self::$alarm->set($alarm, true);
$this->assertTrue(self::$alarm->isSnoozed('personalalarm', 'john'));
self::$alarm->set($alarm);
$this->assertFalse(self::$alarm->isSnoozed('personalalarm', 'john'));
}
/**
* @depends testSnooze
*/
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(2, count($list));
$this->assertEquals('noend', $list[0]['id']);
$this->assertEquals('personalalarm', $list[1]['id']);
}
/**
* @depends testAlarmWithoutEnd
*/
public function testCleanUp()
{
self::$alarm->delete('noend', 'john');
self::$alarm->delete('personalalarm', 'john');
}
}
|