From aa9e580fd8ce5824d627bdaf797a3ccd6732f1a0 Mon Sep 17 00:00:00 2001 From: demeritcowboy Date: Thu, 14 Jan 2021 12:41:52 -0500 Subject: [PATCH] time component no longer a field --- CRM/Contribute/Form/AdditionalInfo.php | 6 +- .../CRM/Contribute/Form/ContributionTest.php | 267 ++++++++++++++++++ 2 files changed, 270 insertions(+), 3 deletions(-) diff --git a/CRM/Contribute/Form/AdditionalInfo.php b/CRM/Contribute/Form/AdditionalInfo.php index 29403fad64..f66501a2d3 100644 --- a/CRM/Contribute/Form/AdditionalInfo.php +++ b/CRM/Contribute/Form/AdditionalInfo.php @@ -271,11 +271,11 @@ class CRM_Contribute_Form_AdditionalInfo { $formatted[$f] = $params[$f] ?? NULL; } - if (!empty($params['thankyou_date']) && !CRM_Utils_System::isNull($params['thankyou_date'])) { - $formatted['thankyou_date'] = CRM_Utils_Date::processDate($params['thankyou_date'], $params['thankyou_date_time']); + if (!empty($params['thankyou_date'])) { + $formatted['thankyou_date'] = CRM_Utils_Date::processDate($params['thankyou_date']); } else { - $formatted['thankyou_date'] = 'null'; + $formatted['thankyou_date'] = NULL; } if (!empty($params['is_email_receipt'])) { diff --git a/tests/phpunit/CRM/Contribute/Form/ContributionTest.php b/tests/phpunit/CRM/Contribute/Form/ContributionTest.php index 37ba950956..4ab4943b63 100644 --- a/tests/phpunit/CRM/Contribute/Form/ContributionTest.php +++ b/tests/phpunit/CRM/Contribute/Form/ContributionTest.php @@ -1779,4 +1779,271 @@ Price Field - Price Field 1 1 $ 100.00 $ 100.00 $this->assertContains("mainTabContainer", $contents); } + /** + * Test AdditionalInfo::postProcessCommon + * @dataProvider additionalInfoProvider + * @param array $input + * @param array $expectedFormatted + */ + public function testAdditionalInfoPostProcessCommon(array $input, array $expectedFormatted) { + $formatted = []; + $dummy = new CRM_Contribute_Form_AdditionalInfo(); + CRM_Contribute_Form_AdditionalInfo::postProcessCommon($input, $formatted, $dummy); + $this->assertEquals($expectedFormatted, $formatted); + } + + /** + * Dataprovider for testAdditionalInfoPostProcessCommon + * @return array + */ + public function additionalInfoProvider(): array { + return [ + 'no-date' => [ + 'input' => [ + 'qfKey' => 'CRMContributeFormContributionu2pbzqqmz74oscck4ss4osccw4wgccc884wkk4ws0o8wgss4w_8953', + 'entryURL' => 'http://example.org/civicrm/contact/view/contribution?reset=1&action=add&cid=1&context=contribution', + 'check_number' => '', + 'frequency_interval' => '1', + 'hidden_AdditionalDetail' => '1', + 'contact_id' => '1', + 'financial_type_id' => '1', + 'payment_instrument_id' => '4', + 'trxn_id' => '', + 'from_email_address' => '2', + 'contribution_status_id' => '1', + // This is unused here but is iffy to put in a dataprovider + 'receive_date' => '2021-01-14 11:12:13', + 'receipt_date' => '', + 'cancel_date' => '', + 'cancel_reason' => '', + 'price_set_id' => '', + 'total_amount' => 10, + 'currency' => 'USD', + 'source' => 'a source', + 'soft_credit_contact_id' => [ + 1 => '', + 2 => '', + 3 => '', + 4 => '', + 5 => '', + 6 => '', + 7 => '', + 8 => '', + 9 => '', + 10 => '', + ], + 'soft_credit_amount' => [ + 1 => '', + 2 => '', + 3 => '', + 4 => '', + 5 => '', + 6 => '', + 7 => '', + 8 => '', + 9 => '', + 10 => '', + ], + 'soft_credit_type' => [ + 1 => '', + 2 => '', + 3 => '', + 4 => '', + 5 => '', + 6 => '', + 7 => '', + 8 => '', + 9 => '', + 10 => '', + ], + 'sct_default_id' => '3', + 'MAX_FILE_SIZE' => '2097152', + 'ip_address' => '127.0.0.1', + 'price_1' => [ + 1 => 1, + ], + 'amount' => 10, + ], + 'expected' => [ + 'non_deductible_amount' => NULL, + 'total_amount' => 10, + 'fee_amount' => NULL, + 'trxn_id' => '', + 'invoice_id' => NULL, + 'creditnote_id' => NULL, + 'campaign_id' => NULL, + 'contribution_page_id' => NULL, + 'thankyou_date' => NULL, + 'custom' => [], + ], + ], + + 'date-no-time' => [ + 'input' => [ + 'qfKey' => 'CRMContributeFormContributionu2pbzqqmz74oscck4ss4osccw4wgccc884wkk4ws0o8wgss4w_8953', + 'entryURL' => 'http://example.org/civicrm/contact/view/contribution?reset=1&action=add&cid=1&context=contribution', + 'id' => '40', + 'frequency_interval' => '1', + 'hidden_AdditionalDetail' => '1', + 'thankyou_date' => '2021-01-14', + 'non_deductible_amount' => '0.00', + 'fee_amount' => '0.00', + 'invoice_id' => '', + 'creditnote_id' => '', + 'contribution_page_id' => '', + 'note' => '', + 'contact_id' => '1', + 'financial_type_id' => '1', + 'from_email_address' => '2', + 'contribution_status_id' => '1', + // This is unused here but is iffy to put in a dataprovider + 'receive_date' => '2021-01-14 11:12:13', + 'receipt_date' => '', + 'cancel_date' => '', + 'cancel_reason' => '', + 'price_set_id' => '', + 'total_amount' => '10.00', + 'currency' => 'USD', + 'source' => 'a source', + 'soft_credit_contact_id' => [ + 1 => '', + 2 => '', + 3 => '', + 4 => '', + 5 => '', + 6 => '', + 7 => '', + 8 => '', + 9 => '', + 10 => '', + ], + 'soft_credit_amount' => [ + 1 => '', + 2 => '', + 3 => '', + 4 => '', + 5 => '', + 6 => '', + 7 => '', + 8 => '', + 9 => '', + 10 => '', + ], + 'soft_credit_type' => [ + 1 => '', + 2 => '', + 3 => '', + 4 => '', + 5 => '', + 6 => '', + 7 => '', + 8 => '', + 9 => '', + 10 => '', + ], + 'sct_default_id' => '3', + 'MAX_FILE_SIZE' => '2097152', + 'ip_address' => '127.0.0.1', + // leaving out since don't want to enforce string 'null' in a test + //'tax_amount' => 'null', + ], + 'expected' => [ + 'non_deductible_amount' => '0.00', + 'total_amount' => '10.00', + 'fee_amount' => '0.00', + 'trxn_id' => NULL, + 'invoice_id' => '', + 'creditnote_id' => '', + 'campaign_id' => NULL, + 'contribution_page_id' => NULL, + 'thankyou_date' => '20210114000000', + 'custom' => [], + ], + ], + + 'date-and-time' => [ + 'input' => [ + 'qfKey' => 'CRMContributeFormContributionu2pbzqqmz74oscck4ss4osccw4wgccc884wkk4ws0o8wgss4w_8953', + 'entryURL' => 'http://example.org/civicrm/contact/view/contribution?reset=1&action=add&cid=1&context=contribution', + 'id' => '40', + 'frequency_interval' => '1', + 'hidden_AdditionalDetail' => '1', + 'thankyou_date' => '2021-01-14 10:11:12', + 'non_deductible_amount' => '0.00', + 'fee_amount' => '0.00', + 'invoice_id' => '', + 'creditnote_id' => '', + 'contribution_page_id' => '', + 'note' => '', + 'contact_id' => '1', + 'financial_type_id' => '1', + 'from_email_address' => '2', + 'contribution_status_id' => '1', + // This is unused here but is iffy to put in a dataprovider + 'receive_date' => '2021-01-14 11:12:13', + 'receipt_date' => '', + 'cancel_date' => '', + 'cancel_reason' => '', + 'price_set_id' => '', + 'total_amount' => '10.00', + 'currency' => 'USD', + 'source' => 'a source', + 'soft_credit_contact_id' => [ + 1 => '', + 2 => '', + 3 => '', + 4 => '', + 5 => '', + 6 => '', + 7 => '', + 8 => '', + 9 => '', + 10 => '', + ], + 'soft_credit_amount' => [ + 1 => '', + 2 => '', + 3 => '', + 4 => '', + 5 => '', + 6 => '', + 7 => '', + 8 => '', + 9 => '', + 10 => '', + ], + 'soft_credit_type' => [ + 1 => '', + 2 => '', + 3 => '', + 4 => '', + 5 => '', + 6 => '', + 7 => '', + 8 => '', + 9 => '', + 10 => '', + ], + 'sct_default_id' => '3', + 'MAX_FILE_SIZE' => '2097152', + 'ip_address' => '127.0.0.1', + // leaving out since don't want to enforce string 'null' in a test + //'tax_amount' => 'null', + ], + 'expected' => [ + 'non_deductible_amount' => '0.00', + 'total_amount' => '10.00', + 'fee_amount' => '0.00', + 'trxn_id' => NULL, + 'invoice_id' => '', + 'creditnote_id' => '', + 'campaign_id' => NULL, + 'contribution_page_id' => NULL, + 'thankyou_date' => '20210114101112', + 'custom' => [], + ], + ], + ]; + } + } -- 2.25.1