Unit test for https://github.com/civicrm/civicrm-core/pull/16860
authoreileen <emcnaughton@wikimedia.org>
Tue, 14 Jul 2020 06:42:05 +0000 (18:42 +1200)
committereileen <emcnaughton@wikimedia.org>
Thu, 16 Jul 2020 07:02:09 +0000 (19:02 +1200)
tests/phpunit/CRM/Financial/BAO/PaymentProcessorTest.php

index 6c84e1e1e0648de9e0a025ef51f0ea3df1cfda40..f9b02b641c584283560bbc404860467bc404e9cd 100644 (file)
@@ -9,6 +9,7 @@
  +--------------------------------------------------------------------+
  */
 
+use Civi\Api4\PaymentProcessor;
 /**
  * Class CRM_Financial_BAO_PaymentProcessorTypeTest
  * @group headless
@@ -50,7 +51,9 @@ class CRM_Financial_BAO_PaymentProcessorTest extends CiviUnitTestCase {
   /**
    * Test the processor retrieval function.
    *
+   * @throws \API_Exception
    * @throws \CiviCRM_API3_Exception
+   * @throws \Civi\API\Exception\UnauthorizedException
    */
   public function testGetProcessors() {
     $testProcessor = $this->dummyProcessorCreate();
@@ -71,6 +74,21 @@ class CRM_Financial_BAO_PaymentProcessorTest extends CiviUnitTestCase {
 
     $processors = CRM_Financial_BAO_PaymentProcessor::getPaymentProcessors(['BackOffice', 'LiveMode'], [$liveProcessorID]);
     $this->assertEquals([$liveProcessorID], array_keys($processors), 'Only the Live processor should be returned');
+
+    PaymentProcessor::update()->addWhere('id', 'IS NOT NULL')->setValues(['domain_id' => 2])->execute();
+    $processors = CRM_Financial_BAO_PaymentProcessor::getPaymentProcessors(['BackOffice', 'LiveMode'], [$liveProcessorID]);
+    $this->assertEquals([$liveProcessorID], array_keys($processors), 'Live processor should still be returned even though it is on a different domain');
+
+    // The api won't permit disabling only live mode due to lack of integrity so use direct SQL
+    CRM_Core_DAO::executeQuery('UPDATE civicrm_payment_processor SET is_active = 0 WHERE is_test = 0');
+    Civi\Payment\System::singleton()->flushProcessors();
+    $processors = CRM_Financial_BAO_PaymentProcessor::getPaymentProcessors(['BackOffice', 'LiveMode'], [$liveProcessorID]);
+    $this->assertEquals([], array_keys($processors), 'Live processor should not be returned as it is inactive');
+
+    CRM_Core_DAO::executeQuery('UPDATE civicrm_payment_processor SET is_active = 0 WHERE is_test = 0');
+    $processors = CRM_Financial_BAO_PaymentProcessor::getPaymentProcessors(['BackOffice', 'TestMode'], [$testProcessorID]);
+    $this->assertEquals([$testProcessorID], array_keys($processors), 'The test processor should still be returned');
+
   }
 
   /**
@@ -80,7 +98,7 @@ class CRM_Financial_BAO_PaymentProcessorTest extends CiviUnitTestCase {
     $processors = CRM_Financial_BAO_PaymentProcessor::getPaymentProcessors(['NoEmailProvided']);
     $found = FALSE;
     foreach ($processors as $processor) {
-      if ($processor['class_name'] == 'Payment_Manual') {
+      if ($processor['class_name'] === 'Payment_Manual') {
         $found = TRUE;
         continue;
       }