[Ref] [Test] Update Authorize.net test to use the trait
authoreileen <emcnaughton@wikimedia.org>
Mon, 10 Aug 2020 05:38:30 +0000 (17:38 +1200)
committereileen <emcnaughton@wikimedia.org>
Mon, 10 Aug 2020 07:32:13 +0000 (19:32 +1200)
tests/phpunit/CRM/Core/Payment/AuthorizeNetTest.php
tests/phpunit/CRM/Mailing/Form/Task/AdhocMailingTest.php

index 3ef5c7ef9b814536cedd848ef5815a0308fabef2..0959ad2af15f4d7c299e86e537deb1bfd76d739d 100644 (file)
@@ -17,12 +17,7 @@ use Civi\Payment\PropertyBag;
  */
 class CRM_Core_Payment_AuthorizeNetTest extends CiviUnitTestCase {
 
-  use \Civi\Test\GuzzleTestTrait;
-
-  /**
-   * @var \CRM_Core_Payment_AuthorizeNet
-   */
-  protected $processor;
+  use CRM_Core_Payment_AuthorizeNetTrait;
 
   public function setUp() {
     parent::setUp();
@@ -44,44 +39,24 @@ class CRM_Core_Payment_AuthorizeNetTest extends CiviUnitTestCase {
    * Test doing a one-off payment.
    *
    * @throws \Civi\Payment\Exception\PaymentProcessorException
+   * @throws \CiviCRM_API3_Exception
    */
   public function testSinglePayment() {
-    $this->createMockHandler([$this->getExpectedSinglePaymentResponse()]);
-    $this->setUpClientWithHistoryContainer();
-    $this->processor->setGuzzleClient($this->getGuzzleClient());
+    $this->setupMockHandler();
     $params = $this->getBillingParams();
     $params['amount'] = 5.24;
     $this->processor->doPayment($params);
     $this->assertEquals($this->getExpectedSinglePaymentRequest(), $this->getRequestBodies()[0]);
   }
 
-  /**
-   * Get the expected response from Authorize.net.
-   *
-   * @return string
-   */
-  public function getExpectedSinglePaymentResponse() {
-    return '"1","1","1","(TESTMODE) This transaction has been approved.","000000","P","0","","","5.24","CC","auth_capture","","John","O&#39;Connor","","","","","","","","","","","","","","","","","","","","","","","",""';
-  }
-
-  /**
-   *  Get the expected request from Authorize.net.
-   *
-   * @return string
-   */
-  public function getExpectedSinglePaymentRequest() {
-    return 'x_login=4y5BfuW7jm&x_tran_key=4cAmW927n8uLf5J8&x_email_customer=&x_first_name=John&x_last_name=O%27Connor&x_address=&x_city=&x_state=&x_zip=&x_country=&x_customer_ip=&x_email=&x_invoice_num=&x_amount=5.24&x_currency_code=&x_description=&x_cust_id=&x_relay_response=FALSE&x_delim_data=TRUE&x_delim_char=%2C&x_encap_char=%22&x_card_num=4444333322221111&x_card_code=123&x_exp_date=10%2F2022&x_test_request=TRUE';
-  }
-
   /**
    * Create a single post dated payment as a recurring transaction.
    *
    * Test works but not both due to some form of caching going on in the SmartySingleton
    */
   public function testCreateSingleNowDated() {
-    $this->createMockHandler([$this->getExpectedResponse()]);
-    $this->setUpClientWithHistoryContainer();
-    $this->processor->setGuzzleClient($this->getGuzzleClient());
+    $this->isRecur = TRUE;
+    $this->setupMockHandler();
     $firstName = 'John';
     $lastName = "O\'Connor";
     $nameParams = ['first_name' => 'John', 'last_name' => $lastName];
@@ -203,9 +178,8 @@ class CRM_Core_Payment_AuthorizeNetTest extends CiviUnitTestCase {
    * Create a single post dated payment as a recurring transaction.
    */
   public function testCreateSinglePostDated() {
-    $this->createMockHandler([$this->getExpectedResponse()]);
-    $this->setUpClientWithHistoryContainer();
-    $this->processor->setGuzzleClient($this->getGuzzleClient());
+    $this->isRecur = TRUE;
+    $this->setupMockHandler();
     $start_date = date('Ymd', strtotime('+ 1 week'));
 
     $firstName = 'John';
@@ -329,7 +303,7 @@ class CRM_Core_Payment_AuthorizeNetTest extends CiviUnitTestCase {
     );
 
     $response = $this->getResponseBodies();
-    $this->assertEquals($this->getExpectedResponse(), $response[0], 3);
+    $this->assertEquals($this->getExpectedRecurResponse(), $response[0], 3);
     $requests = $this->getRequestBodies();
     $this->assertEquals($this->getExpectedRequest($contactId, date('Y-m-d', strtotime($start_date)), 70.23, 3, 4007000000027, '2022-10'), $requests[0]);
   }
@@ -392,15 +366,6 @@ class CRM_Core_Payment_AuthorizeNetTest extends CiviUnitTestCase {
 ';
   }
 
-  /**
-   * Get a successful response to setting up a recurring.
-   *
-   * @return string
-   */
-  public function getExpectedResponse() {
-    return '<?xml version="1.0" encoding="utf-8"?><ARBCreateSubscriptionResponse xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="AnetApi/xml/v1/schema/AnetApiSchema.xsd"><refId>8d468ca1b1dd5c2b56c7</refId><messages><resultCode>Ok</resultCode><message><code>I00001</code><text>Successful.</text></message></messages><subscriptionId>6632052</subscriptionId><profile><customerProfileId>1512023280</customerProfileId><customerPaymentProfileId>1512027350</customerPaymentProfileId></profile></ARBCreateSubscriptionResponse>';
-  }
-
   /**
    * Get some basic billing parameters.
    *
index 2f427ee905993f7813f3c606bb7c5483074e8b8d..c579c87d26fc79804f9769c41bb8195cd28a4cfb 100644 (file)
@@ -40,7 +40,6 @@ class CRM_Mailing_Form_Task_AdhocMailingTest extends CiviUnitTestCase {
   public function testCreateHiddenGroupFromSearchBuilder() {
     $this->createLoggedInUser();
     $formValues = [
-      'qfKey' => 'dde96a85ddebb90fb66de44859404aeb_2077',
       'entryURL' => 'http://dmaster.local/civicrm/contact/search/builder?reset=1',
       'mapper' => [1 => [['Individual']]],
       'operator' => [1 => ['=']],