From: eileen Date: Sun, 18 Oct 2020 23:14:53 +0000 (+1300) Subject: Add test for recurring links and clean up method of retrieving recurring X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=4790df8a54c9b62d53415c0359b1e7e92f438571;p=civicrm-core.git Add test for recurring links and clean up method of retrieving recurring --- diff --git a/CRM/Contribute/BAO/ContributionRecur.php b/CRM/Contribute/BAO/ContributionRecur.php index c44cd2f3bc..a8f20086aa 100644 --- a/CRM/Contribute/BAO/ContributionRecur.php +++ b/CRM/Contribute/BAO/ContributionRecur.php @@ -163,6 +163,7 @@ class CRM_Contribute_BAO_ContributionRecur extends CRM_Contribute_DAO_Contributi * (since it still makes sense to update / cancel */ public static function getPaymentProcessorObject($id) { + CRM_Core_Error::deprecatedFunctionWarning('Use Civi\Payment\System'); $processor = self::getPaymentProcessor($id); return is_array($processor) ? $processor['object'] : NULL; } diff --git a/CRM/Contribute/Page/Tab.php b/CRM/Contribute/Page/Tab.php index fac5a250bc..0c0ebb3244 100644 --- a/CRM/Contribute/Page/Tab.php +++ b/CRM/Contribute/Page/Tab.php @@ -69,7 +69,7 @@ class CRM_Contribute_Page_Tab extends CRM_Core_Page { ]; if ($recurID) { - $paymentProcessorObj = CRM_Contribute_BAO_ContributionRecur::getPaymentProcessorObject($recurID); + $paymentProcessorObj = Civi\Payment\System::singleton()->getById(CRM_Contribute_BAO_ContributionRecur::getPaymentProcessorID($recurID)); if ($paymentProcessorObj) { if ($paymentProcessorObj->supports('cancelRecurring')) { unset($links[CRM_Core_Action::DISABLE]['extra'], $links[CRM_Core_Action::DISABLE]['ref']); diff --git a/Civi/Payment/System.php b/Civi/Payment/System.php index fbbfc7d146..358ce7f023 100644 --- a/Civi/Payment/System.php +++ b/Civi/Payment/System.php @@ -104,16 +104,19 @@ class System { * * @param int $id * - * @return \CRM_Core_Payment|NULL + * @return \CRM_Core_Payment * - * @throws \CiviCRM_API3_Exception + * @throws \CiviCRM_API3_Exception|\CRM_Core_Exception */ public function getById($id) { - if ($id == 0) { + if (isset($this->cache[$id])) { + return $this->cache[$id]; + } + if ((int) $id === 0) { return new \CRM_Core_Payment_Manual(); } $processor = civicrm_api3('payment_processor', 'getsingle', ['id' => $id, 'is_test' => NULL]); - return self::getByProcessor($processor); + return $this->getByProcessor($processor); } /** diff --git a/tests/phpunit/CRM/Contribute/Page/TabTest.php b/tests/phpunit/CRM/Contribute/Page/TabTest.php new file mode 100644 index 0000000000..d2bb725a00 --- /dev/null +++ b/tests/phpunit/CRM/Contribute/Page/TabTest.php @@ -0,0 +1,59 @@ +individualCreate(); + $recurID = ContributionRecur::create()->setValues([ + 'contact_id' => $contactID, + 'amount' => 10, + 'frequency_interval' => 'week', + 'start_date' => 'now', + 'is_active' => TRUE, + 'contribution_status_id:name' => 'Pending', + ]) + ->addChain( + 'contribution', + Contribution::create()->setValues([ + 'contribution_id' => '$id', + 'financial_type_id:name' => 'Donation', + 'total_amount' => 60, + 'receive_date' => 'now', + 'contact_id' => $contactID, + ]) + )->execute()->first()['id']; + $page = new CRM_Contribute_Page_Tab(); + $page->_contactId = $contactID; + $page->_action = CRM_Core_Action::VIEW; + $page->browse(); + + $templateVariable = CRM_Core_Smarty::singleton()->get_template_vars(); + $this->assertEquals('Mr. Anthony Anderson II', $templateVariable['displayName']); + $this->assertEquals("ViewEditCancel", + $templateVariable['activeRecurRows'][1]['action'] + ); + } + +}