public function setUp() {
parent::setUp();
- timecop_travel(mktime(1, 0, 0, 8, 1, 2020));
+ // NOTE: This will mock time for PHP. However, some values populated by MySQL ("modified_date") may leak through.
+ CRM_Utils_Time::setTime('2020-08-01 01:00:00');
$this->_individualId = $this->individualCreate();
$this->_paymentProcessorID = $this->processorCreate();
foreach ($this->ids['contact'] as $contactID) {
$this->callAPISuccess('contact', 'delete', ['id' => $contactID, 'skip_undelete' => TRUE]);
}
- timecop_return();
+ CRM_Utils_Time::resetTime();
}
/**
$membership = $this->callAPISuccessGetSingle('Membership', ['contact_id' => $this->_individualId]);
$this->assertEquals($newMembershipTypeID, $membership['membership_type_id']);
// The date (31 Dec this year) should be progressed by 2 months to 28 Dec next year.
- $this->assertEquals(date('Y', strtotime($membershipBefore['end_date'])) + 1 . '-02-28', $membership['end_date']);
+ $this->assertEquals(CRM_Utils_Time::date('Y', strtotime($membershipBefore['end_date'])) + 1 . '-02-28', $membership['end_date']);
}
/**
$params = [
'cid' => $this->_individualId,
'price_set_id' => 0,
- 'join_date' => date('m/d/Y'),
+ 'join_date' => CRM_Utils_Time::date('m/d/Y'),
'start_date' => '',
'end_date' => '',
'campaign_id' => '',
'cvv2' => '123',
'credit_card_exp_date' => [
'M' => '9',
- 'Y' => date('Y') + 1,
+ 'Y' => CRM_Utils_Time::date('Y') + 1,
],
'credit_card_type' => 'Visa',
'billing_first_name' => 'Test',
$contributionRecur = $this->callAPISuccessGetSingle('ContributionRecur', ['contact_id' => $this->_individualId]);
$this->assertEquals(1, $contributionRecur['is_email_receipt']);
$this->assertEquals(date('Y-m-d'), date('Y-m-d', strtotime($contributionRecur['modified_date'])));
- $this->assertEquals(date('Y-m-d'), date('Y-m-d', strtotime($contributionRecur['modified_date'])));
$this->assertNotEmpty($contributionRecur['invoice_id']);
$this->assertEquals(CRM_Core_PseudoConstant::getKey('CRM_Contribute_BAO_Contribution', 'contribution_status_id',
'Pending'), $contributionRecur['contribution_status_id']);
$form->testSubmit($params);
$membership = $this->callAPISuccessGetSingle('Membership', ['contact_id' => $this->_individualId]);
$this->assertEquals('2020-04-13', $membership['join_date']);
- $this->assertEquals(date('Y-01-01'), $membership['start_date']);
- $nextYear = date('Y') + 1;
- $this->assertEquals(date($nextYear . '-01-31'), $membership['end_date']);
- $expectedStatus = (strtotime(date('Y-07-14')) > time()) ? 'New' : 'Current';
+ $this->assertEquals(CRM_Utils_Time::date('Y-01-01'), $membership['start_date']);
+ $nextYear = CRM_Utils_Time::date('Y') + 1;
+ $this->assertEquals(CRM_Utils_Time::date($nextYear . '-01-31'), $membership['end_date']);
+ $expectedStatus = (strtotime(CRM_Utils_Time::date('Y-07-14')) > CRM_Utils_Time::time()) ? 'New' : 'Current';
$this->assertEquals(CRM_Core_PseudoConstant::getKey('CRM_Member_BAO_Membership', 'status_id', $expectedStatus), $membership['status_id']);
$this->assertNotEmpty($membership['contribution_recur_id']);
$this->assertNotEmpty('original_source', $membership['source']);
$log = $this->callAPISuccessGetSingle('MembershipLog', ['membership_id' => $membership['id'], 'options' => ['limit' => 1, 'sort' => 'id DESC']]);
- $this->assertEquals(date($nextYear . '-01-01'), $log['start_date']);
- $this->assertEquals(date($nextYear . '-01-31'), $log['end_date']);
- $this->assertEquals(date('Y-m-d'), $log['modified_date']);
+ $this->assertEquals(CRM_Utils_Time::date($nextYear . '-01-01'), $log['start_date']);
+ $this->assertEquals(CRM_Utils_Time::date($nextYear . '-01-31'), $log['end_date']);
+ $this->assertEquals(CRM_Utils_Time::date('Y-m-d'), $log['modified_date']);
$contributionRecur = $this->callAPISuccessGetSingle('ContributionRecur', ['contact_id' => $this->_individualId]);
$this->assertEquals($contributionRecur['id'], $membership['contribution_recur_id']);
$this->assertEquals(0, $contributionRecur['is_email_receipt']);
- $this->assertEquals(date('Y-m-d'), date('Y-m-d', strtotime($contributionRecur['modified_date'])));
+ $this->assertEquals(date('Y-m-d'), CRM_Utils_Time::date('Y-m-d', strtotime($contributionRecur['modified_date'])));
$this->assertNotEmpty($contributionRecur['invoice_id']);
// @todo fix this part!
/*
$originalMembership = $this->callAPISuccessGetSingle('membership', []);
$params = [
'cid' => $this->_individualId,
- 'join_date' => date('m/d/Y'),
+ 'join_date' => CRM_Utils_Time::date('m/d/Y'),
'start_date' => '',
'end_date' => '',
// This format reflects the 23 being the organisation & the 25 being the type.
$originalMembership = $this->callAPISuccessGetSingle('membership', []);
$params = [
'cid' => $this->_individualId,
- 'join_date' => date('m/d/Y'),
+ 'join_date' => CRM_Utils_Time::date('m/d/Y'),
'start_date' => '',
'end_date' => '',
// This format reflects the 23 being the organisation & the 25 being the type.
'cvv2' => '123',
'credit_card_exp_date' => [
'M' => '9',
- 'Y' => date('Y') + 1,
+ 'Y' => CRM_Utils_Time::date('Y') + 1,
],
'credit_card_type' => 'Visa',
'billing_first_name' => 'Test',
$form->testSubmit($params);
$renewedMembership = $this->callAPISuccessGetSingle('Membership', ['id' => $originalMembership['id']]);
$this->assertEquals('sauce', $renewedMembership['source']);
- $this->assertEquals(date('Y-01-01'), $renewedMembership['start_date']);
- $this->assertEquals(date('2019-03-01'), $renewedMembership['join_date']);
- $this->assertEquals(date('Y-12-31'), $renewedMembership['end_date']);
+ $this->assertEquals(CRM_Utils_Time::date('Y-01-01'), $renewedMembership['start_date']);
+ $this->assertEquals(CRM_Utils_Time::date('2019-03-01'), $renewedMembership['join_date']);
+ $this->assertEquals(CRM_Utils_Time::date('Y-12-31'), $renewedMembership['end_date']);
$log = $this->callAPISuccessGetSingle('MembershipLog', ['membership_id' => $renewedMembership['id'], 'options' => ['limit' => 1, 'sort' => 'id DESC']]);
- $this->assertEquals(date('Y-01-01'), $log['start_date']);
- $this->assertEquals(date('Y-12-31'), $log['end_date']);
- $this->assertEquals(date('Y-m-d'), $log['modified_date']);
+ $this->assertEquals(CRM_Utils_Time::date('Y-01-01'), $log['start_date']);
+ $this->assertEquals(CRM_Utils_Time::date('Y-12-31'), $log['end_date']);
+ $this->assertEquals(CRM_Utils_Time::date('Y-m-d'), $log['modified_date']);
$this->assertEquals(CRM_Core_PseudoConstant::getKey('CRM_Member_BAO_Membership', 'status_id', 'Current'), $log['status_id']);
}