Unit test for CRM-21436
authorJitendra Purohit <jitendra@fuzion.co.nz>
Tue, 28 Nov 2017 02:47:45 +0000 (08:17 +0530)
committerJitendra Purohit <jitendra@fuzion.co.nz>
Thu, 30 Nov 2017 12:28:15 +0000 (17:58 +0530)
tests/phpunit/CRM/Contribute/Form/ContributionTest.php

index 77547e14f536b394b97534916524b4de55224611..ed9892f4037d56c87e7699ab6687c86c087970c9 100644 (file)
@@ -1324,6 +1324,55 @@ Price Field - Price Field 1        1   $ 100.00      $ 100.00
     $this->assertEquals(CRM_Utils_Array::value('pan_truncation', $financialTrxn), 4567);
   }
 
+  /**
+   * Check payment processor is correctly assigned for a contribution page.
+   */
+  public function testContributionBasePreProcess() {
+    //Create contribution page with only pay later enabled.
+    $params = array(
+      'title' => "Test Contribution Page",
+      'financial_type_id' => 1,
+      'currency' => 'NZD',
+      'goal_amount' => 100,
+      'is_pay_later' => 1,
+      'is_monetary' => TRUE,
+      'is_active' => TRUE,
+      'is_email_receipt' => TRUE,
+      'receipt_from_email' => 'yourconscience@donate.com',
+      'receipt_from_name' => 'Ego Freud',
+    );
+
+    $page1 = $this->callAPISuccess("contribution_page", 'create', $params);
+
+    //Execute CRM_Contribute_Form_ContributionBase preProcess
+    //and check the assignment of payment processors
+    $form = new CRM_Contribute_Form_ContributionBase();
+    $form->controller = new CRM_Core_Controller();
+    $form->set('id', $page1['id']);
+    $_REQUEST['id'] = $page1['id'];
+
+    $form->preProcess();
+    $this->assertEquals($form->_paymentProcessor['name'], 'pay_later');
+
+    //Disable all the payment processor for the contribution page.
+    $params['is_pay_later'] = 0;
+    $page2 = $this->callAPISuccess("contribution_page", 'create', $params);
+
+    //Assert an exception is thrown on loading the contribution page.
+    $form = new CRM_Contribute_Form_ContributionBase();
+    $form->controller = new CRM_Core_Controller();
+    $_REQUEST['id'] = $page2['id'];
+    $form->set('id', $page2['id']);
+    try {
+      $form->preProcess();
+    }
+    catch (CRM_Core_Exception $e) {
+      $this->assertContains("A payment processor configured for this page might be disabled (contact the site administrator for assistance).", $e->getMessage());
+      return;
+    }
+    $this->fail('Exception was expected');
+  }
+
   /**
    * function to test card_type and pan truncation.
    */