예제 #1
0
 function test_restore_to_date()
 {
     $app =& Dataface_Application::getInstance();
     $record = df_get_record('HistoryToolTest', array('name' => 'Johnny'));
     $this->assertEquals('john.gif', $record->val('container_field'));
     $record->setValue('container_field', 'john2.gif');
     $record->save();
     $ht = new Dataface_HistoryTool();
     $hid = $ht->logRecord($record);
     $history1 = $ht->getRecordById('HistoryToolTest', $hid);
     $this->assertEquals(array('name' => 'Johnny', 'container_field' => 'john2.gif'), $history1->strvals(array('name', 'container_field')));
     $record->setValue('container_field', 'john3.gif');
     $record->save();
     $hid2 = $ht->logRecord($record);
     $history2 = $ht->getRecordById('HistoryToolTest', $hid2);
     $this->assertEquals(array('name' => 'Johnny', 'container_field' => 'john3.gif'), $history2->strvals(array('name', 'container_field')));
     $record2 = df_get_record('HistoryToolTest', array('name' => 'Johnny'));
     $this->assertEquals($record2->strvals(array('name', 'container_field')), $history2->strvals(array('name', 'container_field')));
     $sql = array();
     $sql[] = "update `HistoryToolTest__history` set `history__modified` = '2004-01-02' where `history__id` = '{$hid}'";
     foreach ($sql as $q) {
         $res = xf_db_query($q, $app->db());
         if (!$res) {
             trigger_error(xf_db_error($app->db()), E_USER_ERROR);
         }
     }
     $ht->restoreToDate($record, '2004-02-02');
     $record3 = df_get_record('HistoryToolTest', array('name' => 'Johnny'));
     $this->assertEquals(array('name' => 'Johnny', 'container_field' => 'john2.gif'), $record3->strvals(array('name', 'container_field')));
 }