Skip to content
Snippets Groups Projects
Commit 1447d9d2 authored by mattwire's avatar mattwire
Browse files

Handle timezones in tests

parent 479c13f5
Branches
Tags
1 merge request!217Implement Stripe Checkout (with support for SEPA and ACH)
......@@ -175,6 +175,29 @@ abstract class CRM_Stripe_BaseTest extends \PHPUnit\Framework\TestCase implement
$this->createPaymentProcessor();
}
/**
* When storing DateTime in database we have to convert to local timezone when running tests
* Used for checking that available_on custom field is set.
*
* @param string $dateInUTCTimezone eg. '2023-06-10 20:05:05'
*
* @return string
* @throws \Exception
*/
public function getDateinCurrentTimezone(string $dateInUTCTimezone) {
// create a $dt object with the UTC timezone
$dt = new DateTime($dateInUTCTimezone, new DateTimeZone('UTC'));
// get the local timezone
$loc = (new DateTime)->getTimezone();
// change the timezone of the object without changing its time
$dt->setTimezone($loc);
// format the datetime
return $dt->format('Y-m-d H:i:s');
}
/**
* Submit to stripe
*
......
......@@ -332,7 +332,7 @@ class CRM_Stripe_IpnTest extends CRM_Stripe_BaseTest {
// Check we set some values on the FinancialTrxn (payment)
$this->checkFinancialTrxn([
'Payment_details.available_on' => '2023-06-10 21:05:05',
'Payment_details.available_on' => $this->getDateinCurrentTimezone('2023-06-10 20:05:05'),
'fee_amount' => 11.90,
'total_amount' => $this->total,
'order_reference' => 'ch_mock',
......@@ -747,7 +747,7 @@ class CRM_Stripe_IpnTest extends CRM_Stripe_BaseTest {
// Check we set some values on the FinancialTrxn (payment)
$this->checkFinancialTrxn([
'Payment_details.available_on' => '2023-06-10 21:05:05',
'Payment_details.available_on' => $this->getDateinCurrentTimezone('2023-06-10 20:05:05'),
'fee_amount' => 11.90,
'total_amount' => $this->total,
'order_reference' => 'in_mock_2',
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment