/usr/share/php/tests/Horde_History/Horde/History/TestBase.php is in php-horde-history 2.2.1-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 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 | <?php
/**
* Copyright 2010-2013 Horde LLC (http://www.horde.org/)
*
* @author Michael J Rubinsky <mrubinsk@horde.org>
* @category Horde
* @package History
* @subpackage UnitTests
* @license http://www.horde.org/licenses/lgpl21 LGPL 2.1
*/
class Horde_History_TestBase extends Horde_Test_Case
{
protected static $history;
public function testMethodLogHasPostConditionThatTimestampAndActorAreAlwaysRecorded()
{
self::$history->log('test_uid', array('who' => 'me', 'action' => 'test_action'));
$this->assertTrue(self::$history->getActionTimestamp('test_uid', 'test_action') > 0);
$data = self::$history->getHistory('test_uid');
$this->assertTrue(isset($data[0]['who']));
}
public function testMethodLogHasPostConditionThatTheGivenEventHasBeenRecorded()
{
self::$history->log('test_uid', array('who' => 'me', 'ts' => 1000, 'action' => 'test_action'));
$this->assertEquals(1000, self::$history->getActionTimestamp('test_uid', 'test_action'));
}
public function testMethodLogHasParameterStringGuid()
{
try {
self::$history->log(array());
$this->fail('No exception!');
} catch (InvalidArgumentException $e) {
}
}
public function testMethodLogHasArrayParameterBooleanReplaceaction()
{
self::$history->log('test_uid', array('who' => 'me', 'ts' => 1000, 'action' => 'test_action'));
self::$history->log('test_uid', array('who' => 'me', 'ts' => 1000, 'action' => 'test_action'), false);
self::$history->log('test_uid', array('who' => 'you', 'ts' => 2000, 'action' => 'yours_action'));
self::$history->log('test_uid', array('who' => 'you', 'ts' => 2000, 'action' => 'yours_action'), true);
$expect = array(
1 => array(
'action' => 'test_action',
'desc' => null,
'who' => 'me',
'ts' => 1000,
),
2 => array(
'action' => 'test_action',
'desc' => null,
'who' => 'me',
'ts' => 1000,
),
4 => array(
'action' => 'yours_action',
'desc' => '',
'who' => 'you',
'ts' => 2000,
),
);
$data = self::$history->getHistory('test_uid');
foreach ($data as $log) {
foreach ($expect[$log['modseq']] as $key => $value) {
$this->assertEquals($value, $log[$key]);
}
}
}
public function testMethodGethistoryHasParameterStringGuid()
{
try {
self::$history->getHistory(array());
$this->fail('No exception!');
} catch (Horde_History_Exception $e) {
}
}
public function testMethodGethistoryHasResultHordehistorylogRepresentingTheHistoryLogMatchingTheGivenGuid()
{
self::$history->log('test_uid', array('who' => 'me', 'ts' => 1000, 'action' => 'test_action'));
self::$history->log('test_uid', array('who' => 'you', 'ts' => 2000, 'action' => 'yours_action', 'extra' => array('a' => 'a')));
$expect = array(
1 => array(
'action' => 'test_action',
'desc' => '',
'who' => 'me',
'ts' => 1000,
),
2 => array(
'action' => 'yours_action',
'desc' => '',
'who' => 'you',
'ts' => 2000,
'extra' => array('a' => 'a'),
),
);
$data = self::$history->getHistory('test_uid');
foreach ($data as $log) {
foreach ($expect[$log['modseq']] as $key => $value) {
$this->assertEquals($value, $log[$key]);
}
}
}
public function testMethodGetbytimestampHasParameterStringCmp()
{
try {
self::$history->getByTimestamp(array(), 1);
$this->fail('No exception!');
} catch (Horde_History_Exception $e) {
}
}
public function testMethodGetbytimestampHasParameterIntegerTs()
{
try {
self::$history->getByTimestamp('>', 'hello');
$this->fail('No exception!');
} catch (Horde_History_Exception $e) {
}
}
public function testMethodGetbytimestampHasParameterArrayFilters()
{
self::$history->log('test_uid', array('who' => 'me', 'ts' => 1000, 'action' => 'test_action'));
self::$history->log('test_uid', array('who' => 'you', 'ts' => 2000, 'action' => 'yours_action', 'extra' => array('a' => 'a')));
$result = self::$history->getByTimestamp('>', 1, array(array('field' => 'who', 'op' => '=', 'value' => 'you')));
$this->assertEquals(array('test_uid' => 2), $result);
}
public function testMethodGetbytimestampHasParameterStringParent()
{
self::$history->log('test_uid:a_uid', array('who' => 'me', 'ts' => 1000, 'action' => 'test_action'));
self::$history->log('test_uid:b_uid', array('who' => 'you', 'ts' => 2000, 'action' => 'yours_action'));
self::$history->log('yours_uid', array('who' => 'you', 'ts' => 3000, 'action' => 'yours_action'));
$result = self::$history->getByTimestamp('>', 1, array(), 'test_uid');
$this->assertEquals(array('test_uid:a_uid' => 1, 'test_uid:b_uid' => 2), $result);
}
public function testMethodGetbytimestampHasResultArrayContainingTheMatchingEventIds()
{
self::$history->log('test_uid', array('who' => 'me', 'ts' => 1000, 'action' => 'test_action'));
self::$history->log('test_uid', array('who' => 'me', 'ts' => 1000, 'action' => 'test_action'));
self::$history->log('test_uid', array('who' => 'you', 'ts' => 2000, 'action' => 'yours_action', 'extra' => array('a' => 'a')));
$result = self::$history->getByTimestamp('<=', 1000);
$this->assertEquals(array('test_uid' => 2), $result);
$result = self::$history->getByTimestamp('<', 1001);
$this->assertEquals(array('test_uid' => 2), $result);
$result = self::$history->getByTimestamp('>', 1001);
$this->assertEquals(array('test_uid' => 3), $result);
$result = self::$history->getByTimestamp('>=', 2000);
$this->assertEquals(array('test_uid' => 3), $result);
$result = self::$history->getByTimestamp('=', 2000);
$this->assertEquals(array('test_uid' => 3), $result);
$result = self::$history->getByTimestamp('>', 2000);
$this->assertEquals(array(), $result);
}
public function testMethodGetactiontimestampHasParameterStringGuid()
{
try {
self::$history->getActionTimestamp(array(), 'test');
$this->fail('No exception!');
} catch (Horde_History_Exception $e) {
}
}
public function testMethodGetactiontimestampHasParameterStringAction()
{
try {
self::$history->getActionTimestamp('test', array());
$this->fail('No exception!');
} catch (Horde_History_Exception $e) {
}
}
public function testMethodGetactiontimestampHasResultIntegerZeroIfGethistoryReturnsAnError()
{
$this->assertEquals(0, self::$history->getActionTimestamp('test', 'test'));
}
public function testMethodGetactiontimestampHasResultIntegerZeroIfThereIsNoMatchingRecord()
{
$this->assertEquals(0, self::$history->getActionTimestamp('test', 'test'));
}
public function testMethodGetactiontimestampHasResultIntegerTimestampOfTheMatchingRecord()
{
self::$history->log('test_uid', array('who' => 'me', 'ts' => 1, 'action' => 'test_action'));
self::$history->log('test_uid', array('who' => 'me', 'ts' => 2, 'action' => 'test_action'));
$this->assertEquals(2, self::$history->getActionTimestamp('test_uid', 'test_action'));
self::$history->log('test_uid', array('who' => 'me', 'ts' => 3, 'action' => 'test_action'));
$this->assertEquals(3, self::$history->getActionTimestamp('test_uid', 'test_action'));
}
public function testMethodRemovebynamesHasPostconditionThatAllNamedRevordsHaveBeenRemoved()
{
self::$history->log('test_uid', array('who' => 'me', 'ts' => 1000, 'action' => 'test_action'));
self::$history->log('test_uid', array('who' => 'me', 'ts' => 1000, 'action' => 'test_action'), false);
self::$history->log('yours_uid', array('who' => 'you', 'ts' => 2000, 'action' => 'yours_action'));
self::$history->log('yours_uid', array('who' => 'you', 'ts' => 2000, 'action' => 'yours_action'), true);
self::$history->removeByNames(array('test_uid'));
$data = self::$history->getHistory('test_uid');
$this->assertEquals(0, count($data));
$data = self::$history->getHistory('yours_uid');
$expect = array(
'action' => 'yours_action',
'desc' => null,
'who' => 'you',
'id' => 3,
'ts' => 2000,
'modseq' => 4
);
$this->assertEquals($expect, $data[0]);
self::$history->removeByNames(array('yours_uid'));
$data = self::$history->getHistory('yours_uid');
$this->assertEquals(0, count($data));
}
public function testMethodRemovebynamesHasParameterArrayNames()
{
self::$history->log('test_uid', array('who' => 'me', 'ts' => 1000, 'action' => 'test_action'));
self::$history->log('test_uid', array('who' => 'me', 'ts' => 1000, 'action' => 'test_action'), false);
self::$history->log('yours_uid', array('who' => 'you', 'ts' => 2000, 'action' => 'yours_action'));
self::$history->log('yours_uid', array('who' => 'you', 'ts' => 2000, 'action' => 'yours_action'), true);
self::$history->removeByNames(array('test_uid', 'yours_uid'));
$data = self::$history->getHistory('test_uid');
$this->assertEquals(0, count($data));
$data = self::$history->getHistory('yours_uid');
$this->assertEquals(0, count($data));
}
public function testMethodRemovebynamesSucceedsIfParameterNamesIsEmpty()
{
self::$history->log('test_uid', array('who' => 'me', 'ts' => 1000, 'action' => 'test_action'));
self::$history->log('test_uid', array('who' => 'me', 'ts' => 1000, 'action' => 'test_action'), false);
self::$history->log('test_uid', array('who' => 'you', 'ts' => 2000, 'action' => 'yours_action'));
self::$history->log('test_uid', array('who' => 'you', 'ts' => 2000, 'action' => 'yours_action'), true);
self::$history->removeByNames(array());
}
public function testConditionThatEmptyHistoryReturnsAFalseHighestModSeq()
{
$this->assertFalse(self::$history->getHighestModSeq());
}
public function testModSeqMethodsHavePostConditionThatMaxModSeqIncrements()
{
self::$history->log('test_uid', array('who' => 'me', 'action' => 'test_action'));
$this->assertEquals(self::$history->getHighestModSeq(), 1);
self::$history->log('test_uid', array('who' => 'me', 'action' => 'test_other_action'));
$this->assertEquals(self::$history->getHighestModSeq(), 2);
}
public function testMethodLogHasPostConditionThatModSeqIsRecorded()
{
self::$history->log('test_uid', array('who' => 'me', 'action' => 'test_action'));
$data = self::$history->getHistory('test_uid');
$this->assertEquals($data[0]['modseq'], 1);
self::$history->log('test_uid', array('who' => 'you', 'action' => 'your_action'));
$expect = array(
1 => array(
'who' => 'me',
'action' => 'test_action'
),
2 => array(
'who' => 'you',
'action' => 'your_action'
)
);
$data = self::$history->getHistory('test_uid');
foreach ($data as $log) {
foreach ($expect[$log['modseq']] as $key => $value) {
$this->assertEquals($value, $log[$key]);
}
}
}
public function testMethodLogHasPostConditionThatModSeqIsRecordedWhenLogIsOverwritten()
{
self::$history->log('test_uid', array('who' => 'me', 'action' => 'test_action'));
$data = self::$history->getHistory('test_uid');
$this->assertEquals($data[0]['modseq'], 1);
self::$history->log('test_uid', array('who' => 'me', 'action' => 'test_action'), true);
$data = self::$history->getHistory('test_uid');
$this->assertEquals($data[0]['modseq'], 2);
$this->assertTrue(empty($data[1]));
}
public function testMethodGetActionModSeqHasResultMatchingRequestedEntry()
{
self::$history->log('test_uid', array('who' => 'me', 'ts' => 1, 'action' => 'test_action'));
self::$history->log('test_uid', array('who' => 'me', 'ts' => 2, 'action' => 'test_action'));
self::$history->log('test_uid', array('who' => 'me', 'ts' => 3, 'action' => 'test_otheraction'));
$this->assertEquals(self::$history->getActionModSeq('test_uid', 'test_action'), 2);
self::$history->log('test_otheruid', array('who' => 'me', 'ts' => 3, 'action' => 'test_action'));
$this->assertEquals(self::$history->getActionModSeq('test_uid', 'test_action'), 2);
self::$history->log('test_uid', array('who' => 'you', 'ts' => 5, 'action' => 'test_action'), true);
$this->assertEquals(self::$history->getActionModSeq('test_uid', 'test_action'), 5);
}
public function testMethodGetbymodseqHasResultArrayContainingTheMatchingEventIds()
{
self::$history->log('appone:test_uid', array('who' => 'me', 'ts' => 1000, 'action' => 'test_action')); // 1
self::$history->log('appone:test_uid', array('who' => 'me', 'ts' => 1001, 'action' => 'test_action')); // 2
self::$history->log('apptwo:test_uid', array('who' => 'you', 'ts' => 1002, 'action' => 'test_special_action')); // 3
self::$history->log('apptwo:test_uid', array('who' => 'me', 'ts' => 1003, 'action' => 'test_action')); // 4
self::$history->log('appone:test_uid', array('who' => 'me', 'ts' => 1004, 'action' => 'test_action')); // 5
self::$history->log('appone:test_uid', array('who' => 'you', 'ts' => 2000, 'action' => 'yours_action', 'extra' => array('a' => 'a'))); // 6
self::$history->log('appone:test_uid', array('who' => 'you', 'ts' => 2000, 'action' => 'yours_action', 'extra' => array('a' => 'a'))); // 7
self::$history->log('appone:test_uid', array('who' => 'you', 'ts' => 2000, 'action' => 'yours_action', 'extra' => array('a' => 'a'))); // 8
// Only have two unique UIDS.
$result = self::$history->getByModSeq(0, 5);
$this->assertCount(2, $result);
$this->assertArrayHasKey('appone:test_uid', $result);
$this->assertArrayHasKey('apptwo:test_uid', $result);
$result = self::$history->getByModSeq(4, 8);
$this->assertCount(1, $result);
$this->assertArrayHasKey('appone:test_uid', $result);
// Test using action filter.
$filter = array(array('op' => '=', 'field' => 'action', 'value' => 'test_special_action'));
$result = self::$history->getByModSeq(0, 5, $filter);
$this->assertCount(1, $result);
$this->assertArrayHasKey('apptwo:test_uid', $result);
// Test using parent
$result = self::$history->getByModSeq(0, 5, array(), 'apptwo');
$this->assertCount(1, $result);
$this->assertArrayHasKey('apptwo:test_uid', $result);
// Test parent AND filter
$result = self::$history->getByModSeq(0, 5, $filter, 'apptwo');
$this->assertCount(1, $result);
$this->assertArrayHasKey('apptwo:test_uid', $result);
}
public function testConditionThatHigestModSeqPersistsAfterLogDeletion()
{
self::$history->log('appone:test_uid', array('who' => 'me', 'ts' => 1000, 'action' => 'test_action'));
self::$history->log('appone:test_uid', array('who' => 'me', 'ts' => 1001, 'action' => 'test_action'));
$this->assertEquals(2, self::$history->getHighestModSeq());
// Removes all entries
self::$history->removeByNames(array('appone:test_uid'));
$this->assertEquals(2, self::$history->getHighestModSeq());
self::$history->log('appone:test_uid', array('who' => 'me', 'ts' => 1001, 'action' => 'test_action'));
self::$history->log('appone:test_uid2', array('who' => 'me', 'ts' => 1002, 'action' => 'test_action'));
$this->assertEquals(4, self::$history->getHighestModSeq());
// Remove the highest modseq entry
// @todo Currently fails if we delete the existing highest modseq
// the modseq is incremented properly on the next addition though.
//self::$history->removeByNames(array('appone:test_uid2'));
//$this->assertEquals(4, self::$history->getHighestModSeq());
}
public function testMethodGetHighestModSeqWithParentFilterReturnsFilteredResults()
{
self::$history->log('appone:test_uid', array('who' => 'me', 'ts' => 1000, 'action' => 'test_action'));
self::$history->log('appone:test_uid', array('who' => 'me', 'ts' => 1001, 'action' => 'test_action'));
self::$history->log('apptwo:test_uid', array('who' => 'me', 'ts' => 1000, 'action' => 'test_action'));
$this->assertEquals(2, self::$history->getHighestModSeq('appone'));
$this->assertEquals(3, self::$history->getHighestModSeq('apptwo'));
$this->assertEquals(3, self::$history->getHighestModSeq());
}
}
|