コード例 #1
0
 public function testGetModifications()
 {
     $testBase = array('record_id' => '5dea69be9c72ea3d263613277c3b02d529fbd8bc', 'type' => 'TestType', 'backend' => 'TestBackend');
     $firstModificationTime = $this->_persistantLogEntries[0]->modification_time;
     $lastModificationTime = $this->_persistantLogEntries[count($this->_persistantLogEntries) - 1]->modification_time;
     $toTest[] = $testBase + array('from_add' => 'addDay,-3', 'until_add' => 'addDay,1', 'nums' => 6);
     $toTest[] = $testBase + array('nums' => 4);
     $toTest[] = $testBase + array('account' => 999, 'nums' => 0);
     foreach ($toTest as $params) {
         $from = clone $firstModificationTime;
         $until = clone $lastModificationTime;
         if (isset($params['from_add'])) {
             list($fn, $p) = explode(',', $params['from_add']);
             $from->{$fn}($p);
         }
         if (isset($params['until_add'])) {
             list($fn, $p) = explode(',', $params['until_add']);
             $until->{$fn}($p);
         }
         $account = isset($params['account']) ? $params['account'] : NULL;
         $diffs = $this->_modLogClass->getModifications('Tinebase', $params['record_id'], $params['type'], $params['backend'], $from, $until, $account);
         $count = 0;
         foreach ($diffs as $diff) {
             if ($diff->record_id == $params['record_id']) {
                 $count++;
             }
         }
         $this->assertEquals($params['nums'], $count);
     }
 }
 /**
  * test modlog undo
  * 
  * @see 0006252: allow to undo history items (modlog)
  * @see 0000554: modlog: records can't be updated in less than 1 second intervals
  */
 public function testUndo()
 {
     // create a record
     $contact = Addressbook_Controller_Contact::getInstance()->create(new Addressbook_Model_Contact(array('n_family' => 'tester', 'tel_cell' => '+491234')));
     // change something using the record controller
     $contact->tel_cell = NULL;
     $contact = Addressbook_Controller_Contact::getInstance()->update($contact);
     // fetch modlog and test seq
     $modlog = $this->_modLogClass->getModifications('Addressbook', $contact->getId(), NULL, 'Sql', Tinebase_DateTime::now()->subSecond(5), Tinebase_DateTime::now())->getFirstRecord();
     $this->assertTrue($modlog !== NULL);
     $this->assertEquals(2, $modlog->seq);
     $this->assertEquals('+491234', $modlog->old_value);
     $filter = new Tinebase_Model_ModificationLogFilter(array(array('field' => 'record_type', 'operator' => 'equals', 'value' => 'Addressbook_Model_Contact'), array('field' => 'record_id', 'operator' => 'equals', 'value' => $contact->getId()), array('field' => 'modification_time', 'operator' => 'within', 'value' => 'weekThis')));
     $result = $this->_modLogClass->undo($filter);
     $this->assertEquals(1, $result['totalcount'], 'did not get 1 undone modlog: ' . print_r($result, TRUE));
     $this->assertEquals('+491234', $result['undoneModlogs']->getFirstRecord()->old_value);
     // check record after undo
     $contact = Addressbook_Controller_Contact::getInstance()->get($contact);
     $this->assertEquals('+491234', $contact->tel_cell);
 }