/** * 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); }