[Test] fix test setup on ANet tests
authoreileen <emcnaughton@wikimedia.org>
Thu, 21 Nov 2019 09:42:40 +0000 (22:42 +1300)
committereileen <emcnaughton@wikimedia.org>
Fri, 29 Nov 2019 23:04:03 +0000 (12:04 +1300)
Per https://github.com/civicrm/civicrm-core/pull/15706 the setup for this test
is creating invalid transactions. This fixes - I had to do an order fix in the process

CRM/Member/BAO/Membership.php
api/v3/Order.php
tests/phpunit/CRM/Core/Payment/PayPalProIPNTest.php
tests/phpunit/CiviTest/CiviUnitTestCase.php

index 78e7edbad9bde6f703887c42426c53ac889ef70e..ea752975c93a020cf5182e17aa91301aca07b712 100644 (file)
@@ -364,7 +364,8 @@ class CRM_Member_BAO_Membership extends CRM_Member_DAO_Membership {
     if (empty($ids['contribution']) && !empty($ids['membership'])) {
       CRM_Price_BAO_LineItem::deleteLineItems($ids['membership'], 'civicrm_membership');
     }
-
+    // @todo - we should ONLY do the below if a contribution is created. Let's
+    // get some deprecation notices in here & see where it's hit & work to eliminate.
     // This could happen if there is no contribution or we are in one of many
     // weird and wonderful flows. This is scary code. Keep adding tests.
     if (!empty($params['line_item']) && empty($ids['contribution']) && empty($params['contribution_id'])) {
index 19b4eaefe2065075d74ce04eaeebd02781c1940b..88236aa0113ac69ea3e505a5a275e55ce596e142 100644 (file)
@@ -117,6 +117,9 @@ function civicrm_api3_order_create($params) {
     }
   }
   $contributionParams = $params;
+  // If this is nested we need to set sequential to 0 as sequential handling is done
+  // in create_success & id will be miscalculated...
+  $contributionParams['sequential'] = 0;
   foreach ($contributionParams as $key => $value) {
     // Unset chained keys so the code does not attempt to do this chaining twice.
     // e.g if calling 'api.Payment.create' We want to finish creating the order first.
index 19b3e601139dfa7aae82d7bd69a5fd45fdad8ff2..7e97b7b77f1f75aa8ac42cc73013fc74afb26dc9 100644 (file)
@@ -83,6 +83,8 @@ class CRM_Core_Payment_PayPalProIPNTest extends CiviUnitTestCase {
 
   /**
    * Test IPN response updates contribution_recur & contribution for first & second contribution.
+   *
+   * @throws \CRM_Core_Exception
    */
   public function testIPNPaymentMembershipRecurSuccess() {
     $durationUnit = 'year';
index 5d7c20e89b3cfd4f3f01dc31f83da7412e95fa38..59d1f8f51c04999612f33829326cdebd6bc70ab4 100644 (file)
@@ -2467,10 +2467,10 @@ AND    ( TABLE_NAME LIKE 'civicrm_value_%' )
       'payment_processor_id' => $this->_paymentProcessorID,
       // processor provided ID - use contact ID as proxy.
       'processor_id' => $this->_contactID,
-      'api.contribution.create' => $contributionParams,
-    ], $recurParams));
+      'api.Order.create' => $contributionParams,
+    ], $recurParams))['values'][0];
     $this->_contributionRecurID = $contributionRecur['id'];
-    $this->_contributionID = $contributionRecur['values']['0']['api.contribution.create']['id'];
+    $this->_contributionID = $contributionRecur['api.Order.create']['id'];
     $this->ids['Contribution'][0] = $this->_contributionID;
   }
 
@@ -2492,7 +2492,7 @@ AND    ( TABLE_NAME LIKE 'civicrm_value_%' )
 
     $this->ids['membership_type'] = $this->membershipTypeCreate($membershipParams);
     //create a contribution so our membership & contribution don't both have id = 1
-    if ($this->callAPISuccess('Contribution', 'getcount', []) == 0) {
+    if ($this->callAPISuccess('Contribution', 'getcount', []) === 0) {
       $this->contributionCreate([
         'contact_id' => $this->_contactID,
         'is_test' => 1,
@@ -2502,42 +2502,42 @@ AND    ( TABLE_NAME LIKE 'civicrm_value_%' )
         'receive_date' => '2019-07-25 07:34:23',
       ]);
     }
-    $this->setupRecurringPaymentProcessorTransaction($recurParams);
 
-    $this->ids['membership'] = $this->callAPISuccess('membership', 'create', [
+    $this->ids['membership'] = $this->callAPISuccess('Membership', 'create', [
       'contact_id' => $this->_contactID,
       'membership_type_id' => $this->ids['membership_type'],
-      'contribution_recur_id' => $this->_contributionRecurID,
       'format.only_id' => TRUE,
       'source' => 'Payment',
+      'skipLineItem' => TRUE,
     ]);
-    //CRM-15055 creates line items we don't want so get rid of them so we can set up our own line items
-    CRM_Core_DAO::executeQuery("TRUNCATE civicrm_line_item");
-
-    $this->callAPISuccess('line_item', 'create', [
-      'entity_table' => 'civicrm_membership',
-      'entity_id' => $this->ids['membership'],
-      'contribution_id' => $this->_contributionID,
-      'label' => 'General',
-      'qty' => 1,
-      'unit_price' => 200,
-      'line_total' => 200,
-      'financial_type_id' => 1,
-      'price_field_id' => $this->callAPISuccess('price_field', 'getvalue', [
-        'return' => 'id',
-        'label' => 'Membership Amount',
-        'options' => ['limit' => 1, 'sort' => 'id DESC'],
-      ]),
-      'price_field_value_id' => $this->callAPISuccess('price_field_value', 'getvalue', [
-        'return' => 'id',
-        'label' => 'General',
-        'options' => ['limit' => 1, 'sort' => 'id DESC'],
-      ]),
-    ]);
-    $this->callAPISuccess('membership_payment', 'create', [
-      'contribution_id' => $this->_contributionID,
-      'membership_id' => $this->ids['membership'],
+    $this->setupRecurringPaymentProcessorTransaction($recurParams, [
+      'line_items' => [
+        [
+          'line_item' => [
+            [
+              'entity_table' => 'civicrm_membership',
+              'entity_id' => $this->ids['membership'],
+              'label' => 'General',
+              'qty' => 1,
+              'unit_price' => 200,
+              'line_total' => 200,
+              'financial_type_id' => 1,
+              'price_field_id' => $this->callAPISuccess('price_field', 'getvalue', [
+                'return' => 'id',
+                'label' => 'Membership Amount',
+                'options' => ['limit' => 1, 'sort' => 'id DESC'],
+              ]),
+              'price_field_value_id' => $this->callAPISuccess('price_field_value', 'getvalue', [
+                'return' => 'id',
+                'label' => 'General',
+                'options' => ['limit' => 1, 'sort' => 'id DESC'],
+              ]),
+            ],
+          ],
+        ],
+      ],
     ]);
+    $this->callAPISuccess('Membership', 'create', ['id' => $this->ids['membership'], 'contribution_recur_id' => $this->_contributionRecurID]);
   }
 
   /**