From 2c6b0b4b53c5656d161a02f36ee7c40b1ca9150f Mon Sep 17 00:00:00 2001 From: Tim Otten Date: Thu, 27 Jul 2017 21:09:26 -0700 Subject: [PATCH] CRM-20958 - api_v3_CaseTest - Add test for timestamp management --- tests/phpunit/api/v3/CaseTest.php | 48 +++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/tests/phpunit/api/v3/CaseTest.php b/tests/phpunit/api/v3/CaseTest.php index 72ea596cf6cf..a1820df11ed5 100644 --- a/tests/phpunit/api/v3/CaseTest.php +++ b/tests/phpunit/api/v3/CaseTest.php @@ -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']); + } + }