From 67557afe78676d009d6d7280b6dcf6bbbdc9a2d9 Mon Sep 17 00:00:00 2001 From: eileen Date: Tue, 14 Jul 2020 18:42:05 +1200 Subject: [PATCH] Unit test for https://github.com/civicrm/civicrm-core/pull/16860 --- .../Financial/BAO/PaymentProcessorTest.php | 20 ++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/tests/phpunit/CRM/Financial/BAO/PaymentProcessorTest.php b/tests/phpunit/CRM/Financial/BAO/PaymentProcessorTest.php index 6c84e1e1e0..f9b02b641c 100644 --- a/tests/phpunit/CRM/Financial/BAO/PaymentProcessorTest.php +++ b/tests/phpunit/CRM/Financial/BAO/PaymentProcessorTest.php @@ -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; } -- 2.25.1