From 02b969e7a312bd90fc8c299aa652b6e7bbeafda9 Mon Sep 17 00:00:00 2001 From: Eileen McNaughton Date: Tue, 14 Feb 2023 15:35:19 +1300 Subject: [PATCH] Make activity_type_id available to links, test --- CRM/Activity/Selector/Search.php | 4 ++ .../CRM/Activity/Selector/SearchTest.php | 37 ++++++++++++++++++- 2 files changed, 40 insertions(+), 1 deletion(-) diff --git a/CRM/Activity/Selector/Search.php b/CRM/Activity/Selector/Search.php index 04a68f94be..3e73fc2855 100644 --- a/CRM/Activity/Selector/Search.php +++ b/CRM/Activity/Selector/Search.php @@ -303,6 +303,10 @@ class CRM_Activity_Selector_Search extends CRM_Core_Selector_Base implements CRM 'id' => $result->activity_id, 'cid' => $contactId, 'cxt' => $this->_context, + // Parameter for hook locked in by CRM_Activity_Selector_SearchTest + // Any additional parameters added should follow apiv4 style + // and be added to the test. + 'activity_type_id' => $row['activity_type_id'], ], ts('more'), FALSE, diff --git a/tests/phpunit/CRM/Activity/Selector/SearchTest.php b/tests/phpunit/CRM/Activity/Selector/SearchTest.php index bb0c848d8d..4190594003 100644 --- a/tests/phpunit/CRM/Activity/Selector/SearchTest.php +++ b/tests/phpunit/CRM/Activity/Selector/SearchTest.php @@ -78,9 +78,44 @@ class CRM_Activity_Selector_SearchTest extends CiviUnitTestCase { * * @return array */ - protected function getSearchRows(array $queryParams, ?CRM_Utils_Sort $sort): array { + protected function getSearchRows(array $queryParams = [], ?CRM_Utils_Sort $sort = NULL): array { $searchSelector = new CRM_Activity_Selector_Search($queryParams, CRM_Core_Action::VIEW); return $searchSelector->getRows(4, 0, 50, $sort); } + /** + * Test activity_type_id reaches the hook. + */ + public function testActivityLinkHook(): void { + $this->activityCreate([]); + CRM_Utils_Hook::singleton() + ->setHook('civicrm_links', [__CLASS__, 'linkHook']); + $row = $this->getSearchRows()[0]; + $this->assertEquals('', $row['action'], 'Value should be unset by hook'); + } + + /** + * Implement link hook to check activity_type_id is set. + * + * @param string $op + * The type of operation being performed. + * @param string $objectName + * The name of the object. + * @param int $objectId + * The unique identifier for the object. + * @param array $links + * (optional) the links array (introduced in v3.2). + * @param int|null $mask + * (optional) the bitmask to show/hide links. + * @param array $values + * (optional) the values to fill the links. + * + * @noinspection PhpUnusedParameterInspection + */ + public static function linkHook(string $op, string $objectName, int &$objectId, array &$links, int &$mask = NULL, array $values = []): void { + if ($values['activity_type_id']) { + $links = []; + } + } + } -- 2.25.1