From b33c55b86f4d2abf58e0fb3148a82150f8e2d3bc Mon Sep 17 00:00:00 2001 From: Eileen McNaughton Date: Tue, 24 Oct 2023 00:23:09 +1300 Subject: [PATCH] Fix Contribution MainTest to set payment processor properties better --- .../Contribute/Form/Contribution/MainTest.php | 25 +++++++++++++------ 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/tests/phpunit/CRM/Contribute/Form/Contribution/MainTest.php b/tests/phpunit/CRM/Contribute/Form/Contribution/MainTest.php index 0bb03f4988..90e80c071f 100644 --- a/tests/phpunit/CRM/Contribute/Form/Contribution/MainTest.php +++ b/tests/phpunit/CRM/Contribute/Form/Contribution/MainTest.php @@ -22,16 +22,11 @@ class CRM_Contribute_Form_Contribution_MainTest extends CiviUnitTestCase { /** * The id of the contribution page's payment processor. + * * @var int */ private $paymentProcessorId; - /** - * The price set of the contribution page. - * @var int - */ - private $priceSetId; - /** * Clean up DB. */ @@ -127,6 +122,7 @@ class CRM_Contribute_Form_Contribution_MainTest extends CiviUnitTestCase { 'payment_processor_type_id' => 'Dummy', 'is_test' => 0, ]); + $this->supportPreApproval(); $contributionPageParams = (array_merge($params, [ 'currency' => 'NZD', @@ -149,7 +145,6 @@ class CRM_Contribute_Form_Contribution_MainTest extends CiviUnitTestCase { /** @var \CRM_Contribute_Form_Contribution_Main $form */ $form = $this->getFormObject('CRM_Contribute_Form_Contribution_Main', $submittedValues); $form->preProcess(); - $form->_paymentProcessor['object']->setSupports(['PreApproval' => TRUE, 'BackOffice' => TRUE]); $form->buildQuickForm(); // Need these values to create more realistic submit params (in getSubmitParams). $this->paymentProcessorId = $paymentProcessor; @@ -237,4 +232,20 @@ class CRM_Contribute_Form_Contribution_MainTest extends CiviUnitTestCase { $this->assertEquals($expected, $isRecur); } + /** + * Set the dummy processor to support preApproval. + * + * @throws \CRM_Core_Exception + */ + protected function supportPreApproval(): void { + $processors = CRM_Financial_BAO_PaymentProcessor::getAllPaymentProcessors('live'); + $cacheKey = 'CRM_Financial_BAO_Payment_Processor_live__' . CRM_Core_Config::domainID(); + foreach ($processors as $processor) { + if ($processor['payment_processor_type'] === 'Dummy') { + $processor['object']->setSupports(['PreApproval' => TRUE]); + } + } + CRM_Utils_Cache::singleton()->set($cacheKey, $processors); + } + } -- 2.25.1