From e1f5526a12e2a99a663acb0de44c4ea9daa9747b Mon Sep 17 00:00:00 2001 From: Seamus Lee Date: Thu, 1 Jul 2021 07:54:05 +1000 Subject: [PATCH] [NFC] Add in unit test to lock in the fix for the is_deleted in where clause issue Move Unit test into its own class and use normal apiv4 wrapper rather than internal class as per Coleman --- .../api/v4/Action/ContactIsDeletedTest.php | 81 +++++++++++++++++++ 1 file changed, 81 insertions(+) create mode 100644 tests/phpunit/api/v4/Action/ContactIsDeletedTest.php diff --git a/tests/phpunit/api/v4/Action/ContactIsDeletedTest.php b/tests/phpunit/api/v4/Action/ContactIsDeletedTest.php new file mode 100644 index 0000000000..7892f43c42 --- /dev/null +++ b/tests/phpunit/api/v4/Action/ContactIsDeletedTest.php @@ -0,0 +1,81 @@ +cleanup(['tablesToTruncate' => $relatedTables]); + $displayNameFormat = '{contact.first_name}{ }{contact.last_name}'; + \Civi::settings()->set('display_name_format', $displayNameFormat); + + return parent::setUpHeadless(); + } + + /** + * This locks in a fix to ensure that if a user doesn't have permission to view the is_deleted field that doesn't hard fail if that field happens to be in an APIv4 call. + */ + public function testIsDeletedPermission(): void { + $contact = $this->createLoggedInUser(); + \CRM_Core_Config::singleton()->userPermissionClass->permissions = ['access CiviCRM', 'view all contacts']; + $originalQuery = civicrm_api4('Contact', 'get', [ + 'checkPermissions' => TRUE, + 'select' => ['id', 'display_name', 'is_deleted'], + 'where' => [['first_name', '=', 'phoney']], + ]); + + try { + $isDeletedQuery = civicrm_api4('Contact', 'get', [ + 'checkPermissions' => TRUE, + 'select' => ['id', 'display_name'], + 'where' => [['first_name', '=', 'phoney'], ['is_deleted', '=', 0]], + ]); + $this->assertEquals(count($originalQuery), count($isDeletedQuery)); + } + catch (\API_Exception $e) { + $this->fail('An Exception Should not have been raised'); + } + try { + $isDeletedJoinTest = civicrm_api4('Email', 'get', [ + 'checkPermissions' => TRUE, + 'where' => [['contact_id.first_name', '=', 'phoney'], ['contact_id.is_deleted', '=', 0]], + ]); + } + catch (\API_Exception $e) { + $this->fail('An Exception Should not have been raised'); + } + } + +} -- 2.25.1