Skip to content

Commit

Permalink
CRM-20958 - api_v3_CaseTest - Add test for timestamp management
Browse files Browse the repository at this point in the history
  • Loading branch information
totten committed Sep 6, 2017
1 parent 3a03a3f commit 2c6b0b4
Showing 1 changed file with 48 additions and 0 deletions.
48 changes: 48 additions & 0 deletions tests/phpunit/api/v3/CaseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -849,4 +849,52 @@ public function caseActivityRevisionExamples() {
return $examples;
}

public function testTimestamps() {
$params = $this->_params;
$case_created = $this->callAPISuccess('case', 'create', $params);

$case_1 = $this->callAPISuccess('Case', 'getsingle', array(
'id' => $case_created['id'],
));
$this->assertRegExp(';^\d\d\d\d-\d\d-\d\d \d\d:\d\d;', $case_1['created_date']);
$this->assertRegExp(';^\d\d\d\d-\d\d-\d\d \d\d:\d\d;', $case_1['modified_date']);
$this->assertApproxEquals(strtotime($case_1['created_date']), strtotime($case_1['modified_date']), 2);

$activity_1 = $this->callAPISuccess('activity', 'getsingle', array(
'case_id' => $case_created['id'],
'options' => array(
'limit' => 1,
),
));
$this->assertRegExp(';^\d\d\d\d-\d\d-\d\d \d\d:\d\d;', $activity_1['created_date']);
$this->assertRegExp(';^\d\d\d\d-\d\d-\d\d \d\d:\d\d;', $activity_1['modified_date']);
$this->assertApproxEquals(strtotime($activity_1['created_date']), strtotime($activity_1['modified_date']), 2);

usleep(1.5 * 1000000);
$this->callAPISuccess('activity', 'create', array(
'id' => $activity_1['id'],
'subject' => 'Make cheese',
));

$activity_2 = $this->callAPISuccess('activity', 'getsingle', array(
'id' => $activity_1['id'],
));
$this->assertRegExp(';^\d\d\d\d-\d\d-\d\d \d\d:\d\d;', $activity_2['created_date']);
$this->assertRegExp(';^\d\d\d\d-\d\d-\d\d \d\d:\d\d;', $activity_2['modified_date']);
$this->assertNotEquals($activity_2['created_date'], $activity_2['modified_date']);

$this->assertEquals($activity_1['created_date'], $activity_2['created_date']);
$this->assertNotEquals($activity_1['modified_date'], $activity_2['modified_date']);
$this->assertLessThan($activity_2['modified_date'], $activity_1['modified_date'],
sprintf("Original modification time (%s) should predate later modification time (%s)", $activity_1['modified_date'], $activity_2['modified_date']));

$case_2 = $this->callAPISuccess('Case', 'getsingle', array(
'id' => $case_created['id'],
));
$this->assertRegExp(';^\d\d\d\d-\d\d-\d\d \d\d:\d\d;', $case_2['created_date']);
$this->assertRegExp(';^\d\d\d\d-\d\d-\d\d \d\d:\d\d;', $case_2['modified_date']);
$this->assertEquals($case_1['created_date'], $case_2['created_date']);
$this->assertNotEquals($case_2['created_date'], $case_2['modified_date']);
}

}

0 comments on commit 2c6b0b4

Please sign in to comment.