time component no longer a field
authordemeritcowboy <demeritcowboy@hotmail.com>
Thu, 14 Jan 2021 17:41:52 +0000 (12:41 -0500)
committerdemeritcowboy <demeritcowboy@hotmail.com>
Thu, 14 Jan 2021 17:41:52 +0000 (12:41 -0500)
CRM/Contribute/Form/AdditionalInfo.php
tests/phpunit/CRM/Contribute/Form/ContributionTest.php

index 29403fad6488d37fcf8e45f24d2381c657ca6fc8..f66501a2d3754ff1d2d9bb3fb7f63d51434cfac8 100644 (file)
@@ -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'])) {
index 37ba9509563cc6f58e0c826bd0550795a7921edd..4ab4943b6367c87757c57ef0015194dd9f4c8c41 100644 (file)
@@ -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&amp;action=add&amp;cid=1&amp;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&amp;action=add&amp;cid=1&amp;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&amp;action=add&amp;cid=1&amp;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' => [],
+        ],
+      ],
+    ];
+  }
+
 }