From 2c50777fcb9d495c7739f4f3ab5d7d68a38da0ba Mon Sep 17 00:00:00 2001 From: Tim Otten Date: Tue, 22 Feb 2022 20:21:00 -0800 Subject: [PATCH] (REF) E2E_Extern_*RestTest - Extract `isOldQSupported()` This patch changes the way a certain carve-out works, but it doesn't change the outcome. Background: There are two E2E tests: * `LegacyRestTest` extends `BaseRestTest` and targets `extern/rest.php`. It tests `rest.php?entity=ENTITY&action=ACTION` as well as `rest.php?q=civicrm/ENTITY/ACTION`. * `AuthxRestTest` extends `BaseRestTest` and targets `civicrm/ajax/rest`. It only tests `civicrm/ajax/rest?entity=ENTITY&action=ACTION`. The `q` parameter cannot be used realiably with CMS routing (`q=civicrm/ajax/rest&q=civicrm/ENTITY/ACTION`). So we skip testing that combination. The patch merely changes how the skip works. --- tests/phpunit/E2E/Extern/AuthxRestTest.php | 9 ++------- tests/phpunit/E2E/Extern/BaseRestTest.php | 22 +++++++++++++++++++++ tests/phpunit/E2E/Extern/LegacyRestTest.php | 4 ++++ 3 files changed, 28 insertions(+), 7 deletions(-) diff --git a/tests/phpunit/E2E/Extern/AuthxRestTest.php b/tests/phpunit/E2E/Extern/AuthxRestTest.php index 159f4f36f0..bfa8f748de 100644 --- a/tests/phpunit/E2E/Extern/AuthxRestTest.php +++ b/tests/phpunit/E2E/Extern/AuthxRestTest.php @@ -33,13 +33,8 @@ class E2E_Extern_AuthxRestTest extends E2E_Extern_BaseRestTest { return CRM_Utils_System::url('civicrm/ajax/rest', NULL, TRUE, NULL, FALSE, TRUE); } - public function apiTestCases() { - $r = parent::apiTestCases(); - $r = array_filter($r, function($case) { - // The 'civicrm/ajax/rest' end-point does not support '?q' inputs. - return !isset($case[0]['q']); - }); - return $r; + protected function isOldQSupported(): bool { + return FALSE; } } diff --git a/tests/phpunit/E2E/Extern/BaseRestTest.php b/tests/phpunit/E2E/Extern/BaseRestTest.php index 931dbfebc6..199dd1069f 100644 --- a/tests/phpunit/E2E/Extern/BaseRestTest.php +++ b/tests/phpunit/E2E/Extern/BaseRestTest.php @@ -27,6 +27,21 @@ abstract class E2E_Extern_BaseRestTest extends CiviEndToEndTestCase { protected $old_api_keys; protected $adminContactId; + /** + * Enable testing of `civicrm/{$entity}/{$action}` from APIv3 REST? + * + * The APIv3 REST end-point supported two notations: + * + * - `rest.php?entity=ENTITY&action=ACTION` + * - `rest.php?q=civicrm/ENTITY/ACTON`. + * + * The former better documentation, tooling, and compatibility. The latter is conflicted + * is some cases. + * + * @return bool + */ + abstract protected function isOldQSupported(): bool; + /** * @param $apiResult * @param $cmpvar @@ -202,6 +217,13 @@ abstract class E2E_Extern_BaseRestTest extends CiviEndToEndTestCase { 0, ); + if (!$this->isOldQSupported()) { + $cases = array_filter($cases, function($case) { + // The 'civicrm/ajax/rest' end-point does not support '?q' inputs. + return !isset($case[0]['q']); + }); + } + return $cases; } diff --git a/tests/phpunit/E2E/Extern/LegacyRestTest.php b/tests/phpunit/E2E/Extern/LegacyRestTest.php index e6c72a092a..26966d426a 100644 --- a/tests/phpunit/E2E/Extern/LegacyRestTest.php +++ b/tests/phpunit/E2E/Extern/LegacyRestTest.php @@ -28,4 +28,8 @@ class E2E_Extern_LegacyRestTest extends E2E_Extern_BaseRestTest { ->getUrl('civicrm', 'extern/rest.php'); } + protected function isOldQSupported(): bool { + return TRUE; + } + } -- 2.25.1