public function log($guid, array $attributes = array(),
$replaceAction = false)
{
+ if (!is_string($guid)) {
+ throw new InvalidArgumentException('The guid needs to be a string!');
+ }
+
$history = $this->getHistory($guid);
if (!isset($attributes['who'])) {
*/
public function getHistory($guid)
{
+ if (!is_string($guid)) {
+ throw new InvalidArgumentException('The guid needs to be a string!');
+ }
+ return $this->_getHistory($guid);
+ }
+
+ /**
+ * Returns a Horde_HistoryObject corresponding to the named history
+ * entry, with the data retrieved appropriately.
+ *
+ * @param string $guid The name of the history entry to retrieve.
+ *
+ * @return Horde_HistoryObject A Horde_HistoryObject
+ *
+ * @throws Horde_Exception
+ */
+ public function _getHistory($guid)
+ {
throw new Horde_Exception('Not implemented!');
}
public function getByTimestamp($cmp, $ts, array $filters = array(),
$parent = null)
{
+ if (!is_string($cmp)) {
+ throw new InvalidArgumentException('The comparison operator needs to be a string!');
+ }
+ if (!is_integer($ts)) {
+ throw new InvalidArgumentException('The timestamp needs to be an integer!');
+ }
+ return $this->_getByTimestamp($cmp, $ts, $filters, $parent);
+ }
+
+ /**
+ * Finds history objects by timestamp, and optionally filter on other
+ * fields as well.
+ *
+ * @param string $cmp The comparison operator (<, >, <=, >=, or =) to
+ * check the timestamps with.
+ * @param integer $ts The timestamp to compare against.
+ * @param array $filters An array of additional (ANDed) criteria.
+ * Each array value should be an array with 3
+ * entries:
+ * <pre>
+ * 'field' - the history field being compared (i.e. 'action').
+ * 'op' - the operator to compare this field with.
+ * 'value' - the value to check for (i.e. 'add').
+ * </pre>
+ * @param string $parent The parent history to start searching at. If
+ * non-empty, will be searched for with a LIKE
+ * '$parent:%' clause.
+ *
+ * @return array An array of history object ids, or an empty array if
+ * none matched the criteria.
+ *
+ * @throws Horde_Exception
+ */
+ public function _getByTimestamp($cmp, $ts, array $filters = array(),
+ $parent = null)
+ {
throw new Horde_Exception('Not implemented!');
}
*
* @return integer The timestamp, or 0 if no matching entry is found.
*
+ * @throws InvalidArgumentException If the input parameters are not of
+ * type string.
* @throws Horde_Exception
*/
public function getActionTimestamp($guid, $action)
{
+ if (!is_string($guid) || !is_string($action)) {
+ throw new InvalidArgumentException('$guid and $action need to be strings!');
+ }
+
/* This implementation still works, but we should be able to
* get much faster now with a SELECT MAX(history_ts)
* ... query. */
}
return $injector;
}
+
/**
* Return the history handler for the specified environment.
*
public function testMethodLogHasPostConditionThatTimestampAndActorAreAlwaysRecorded()
{
- //@todo: More complex
foreach ($this->getEnvironments() as $environment) {
$history = $this->getHistory($environment);
$history->log('test', array('action' => 'test'));
public function testMethodLogHasPostConditionThatTheGivenEventHasBeenRecorded()
{
- //@todo: More complex
foreach ($this->getEnvironments() as $environment) {
$history = $this->getHistory($environment);
$history->log('test', array('who' => 'me', 'ts' => 1000, 'action' => 'test'));
public function testMethodLogHasParameterStringGuid()
{
- //@todo: Add a check for the type.
- }
-
- public function testMethodLogHasArrayParameterAttributes()
- {
- //@todo: type hint the array
+ foreach ($this->getEnvironments() as $environment) {
+ $history = $this->getHistory($environment);
+ try {
+ $history->log(array());
+ $this->fail('No exception!');
+ } catch (InvalidArgumentException $e) {
+ }
+ }
}
public function testMethodLogHasArrayParameterBooleanReplaceaction()
public function testMethodGethistoryHasParameterStringGuid()
{
- //@todo: Add a check for the type.
+ foreach ($this->getEnvironments() as $environment) {
+ $history = $this->getHistory($environment);
+ try {
+ $history->getHistory(array());
+ $this->fail('No exception!');
+ } catch (InvalidArgumentException $e) {
+ }
+ }
}
public function testMethodGethistoryHasResultHordehistoryobjectRepresentingTheHistoryLogMatchingTheGivenGuid()
public function testMethodGetbytimestampHasParameterStringCmp()
{
+ foreach ($this->getEnvironments() as $environment) {
+ $history = $this->getHistory($environment);
+ try {
+ $history->getByTimestamp(array(), 1);
+ $this->fail('No exception!');
+ } catch (InvalidArgumentException $e) {
+ }
+ }
}
public function testMethodGetbytimestampHasParameterIntegerTs()
{
+ foreach ($this->getEnvironments() as $environment) {
+ $history = $this->getHistory($environment);
+ try {
+ $history->getByTimestamp('>', 'hello');
+ $this->fail('No exception!');
+ } catch (InvalidArgumentException $e) {
+ }
+ }
}
public function testMethodGetbytimestampHasParameterArrayFilters()
public function testMethodGetbytimestampHasResultArrayContainingTheMatchingEventIds()
{
- //@todo: More complex
foreach ($this->getEnvironments() as $environment) {
$history = $this->getHistory($environment);
$history->log('test', array('who' => 'me', 'ts' => 1000, 'action' => 'test'));
$history->log('test', array('who' => 'me', 'ts' => 1000, 'action' => 'test'));
$history->log('test', array('who' => 'you', 'ts' => 2000, 'action' => 'yours', 'extra' => array('a' => 'a')));
+ $result = $history->getByTimestamp('<=', 1000);
+ $this->assertEquals(array('test' => 2), $result);
$result = $history->getByTimestamp('<', 1001);
$this->assertEquals(array('test' => 2), $result);
+ $result = $history->getByTimestamp('>', 1001);
+ $this->assertEquals(array('test' => 3), $result);
+ $result = $history->getByTimestamp('>=', 2000);
+ $this->assertEquals(array('test' => 3), $result);
+ $result = $history->getByTimestamp('=', 2000);
+ $this->assertEquals(array('test' => 3), $result);
+ $result = $history->getByTimestamp('>', 2000);
+ $this->assertEquals(array(), $result);
}
}
public function testMethodGetactiontimestampHasParameterStringGuid()
{
- //@todo: Add a check for the type.
+ foreach ($this->getEnvironments() as $environment) {
+ $history = $this->getHistory($environment);
+ try {
+ $history->getActionTimestamp(array(), 'test');
+ $this->fail('No exception!');
+ } catch (InvalidArgumentException $e) {
+ }
+ }
}
public function testMethodGetactiontimestampHasParameterStringAction()
{
- //@todo: Add a check for the type.
+ foreach ($this->getEnvironments() as $environment) {
+ $history = $this->getHistory($environment);
+ try {
+ $history->getActionTimestamp('test', array());
+ $this->fail('No exception!');
+ } catch (InvalidArgumentException $e) {
+ }
+ }
}
public function testMethodGetactiontimestampHasResultIntegerZeroIfGethistoryReturnsAnError()
{
- //@todo: test
+ $injector = $this->initializeEnvironment(self::ENVIRONMENT_DB);
+ $mock = new Dummy_Db();
+ $injector->setInstance('DB_common_write', $mock);
+ $history = $injector->getInstance('Horde_History');
+ $this->assertEquals(0, $history->getActionTimestamp('test', 'test'));
}
public function testMethodGetactiontimestampHasResultIntegerZeroIfThereIsNoMatchingRecord()