From 3d18ab5d9128e64b3900ee7b3781df5677ace4ef Mon Sep 17 00:00:00 2001 From: Eileen McNaughton Date: Thu, 31 Aug 2023 18:07:40 +1200 Subject: [PATCH] Fix Contribution_Tab links to have weight, improve test --- CRM/Contribute/Page/Tab.php | 6 +++++- tests/phpunit/CRM/Contribute/Page/TabTest.php | 12 +++++------- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/CRM/Contribute/Page/Tab.php b/CRM/Contribute/Page/Tab.php index 4755a44e41..641bb6ee4f 100644 --- a/CRM/Contribute/Page/Tab.php +++ b/CRM/Contribute/Page/Tab.php @@ -55,7 +55,7 @@ class CRM_Contribute_Page_Tab extends CRM_Core_Page { 'title' => ts('View Recurring Payment'), 'url' => 'civicrm/contact/view/contributionrecur', 'qs' => "reset=1&id=%%crid%%&cid=%%cid%%&context={$context}", - 'weight' => -20, + 'weight' => CRM_Core_Action::getWeight(CRM_Core_Action::VIEW), ], ]; @@ -77,6 +77,7 @@ class CRM_Contribute_Page_Tab extends CRM_Core_Page { 'title' => ts('Edit Recurring Payment'), 'url' => 'civicrm/contribute/updaterecur', 'qs' => "reset=1&action=update&crid=%%crid%%&cid=%%cid%%&context={$context}", + 'weight' => CRM_Core_Action::getWeight(CRM_Core_Action::UPDATE), ]; } @@ -85,6 +86,7 @@ class CRM_Contribute_Page_Tab extends CRM_Core_Page { 'title' => ts('Cancel'), 'url' => 'civicrm/contribute/unsubscribe', 'qs' => 'reset=1&crid=%%crid%%&cid=%%cid%%&context=' . $context, + 'weight' => CRM_Core_Action::getWeight(CRM_Core_Action::DISABLE), ]; if ($paymentProcessorObj->supports('UpdateSubscriptionBillingInfo')) { @@ -93,6 +95,7 @@ class CRM_Contribute_Page_Tab extends CRM_Core_Page { 'title' => ts('Change Billing Details'), 'url' => 'civicrm/contribute/updatebilling', 'qs' => "reset=1&crid=%%crid%%&cid=%%cid%%&context={$context}", + 'weight' => 110, ]; } if (!empty($templateContribution['id']) && $paymentProcessorObj->supportsEditRecurringContribution()) { @@ -103,6 +106,7 @@ class CRM_Contribute_Page_Tab extends CRM_Core_Page { 'title' => ts('View Template Contribution'), 'url' => 'civicrm/contact/view/contribution', 'qs' => "reset=1&id={$templateContribution['id']}&cid=%%cid%%&action=view&context={$context}&force_create_template=1", + 'weight' => 120, ]; } diff --git a/tests/phpunit/CRM/Contribute/Page/TabTest.php b/tests/phpunit/CRM/Contribute/Page/TabTest.php index d2a86a1bd4..cd3280ad4e 100644 --- a/tests/phpunit/CRM/Contribute/Page/TabTest.php +++ b/tests/phpunit/CRM/Contribute/Page/TabTest.php @@ -20,8 +20,6 @@ class CRM_Contribute_Page_TabTest extends CiviUnitTestCase { /** * Clean up after test. - * - * @throws \CRM_Core_Exception */ public function tearDown(): void { $this->quickCleanUpFinancialEntities(); @@ -38,7 +36,7 @@ class CRM_Contribute_Page_TabTest extends CiviUnitTestCase { $templateVariable = CRM_Core_Smarty::singleton()->get_template_vars(); $this->assertEquals('Mr. Anthony Anderson II', $templateVariable['displayName']); - $this->assertEquals("ViewEditCancel", + $this->assertEquals("ViewEditCancel", $this->getActionHtml() ); } @@ -76,10 +74,11 @@ class CRM_Contribute_Page_TabTest extends CiviUnitTestCase { * * @return array * @throws \CRM_Core_Exception - * @throws \Civi\API\Exception\UnauthorizedException */ - protected function setupTemplate($recurParams = []): array { + protected function setupTemplate(array $recurParams = []): array { $contactID = $recurParams['contact_id'] ?? $this->individualCreate(); + $_REQUEST['action'] = CRM_Core_Action::VIEW; + $_REQUEST['cid'] = $contactID; $recurID = ContributionRecur::create()->setValues(array_merge([ 'contact_id' => $contactID, 'amount' => 10, @@ -99,8 +98,7 @@ class CRM_Contribute_Page_TabTest extends CiviUnitTestCase { ]) )->execute()->first()['id']; $page = new CRM_Contribute_Page_Tab(); - $page->_contactId = $contactID; - $page->_action = CRM_Core_Action::VIEW; + $page->preProcess(); $page->browse(); return [$contactID, $recurID]; } -- 2.25.1