From a39ed900a6871f42bb670ac1dbad70b115c6ba1a Mon Sep 17 00:00:00 2001 From: quietone <quietone@2572884.no-reply.drupal.org> Date: Sat, 28 Dec 2024 21:26:16 +1300 Subject: [PATCH] Issue #3495574 by nikolay shapovalov, nicxvan: Move helpers in hold_test.module and delete it --- core/.phpstan-baseline.php | 12 ----- .../MediaLibraryTestBase.php | 5 +- .../tests/modules/hold_test/hold_test.install | 6 ++- .../tests/modules/hold_test/hold_test.module | 42 ----------------- .../modules/hold_test/src/HoldTestHelper.php | 46 +++++++++++++++++++ .../Ajax/ThrobberTest.php | 17 +++---- 6 files changed, 62 insertions(+), 66 deletions(-) delete mode 100644 core/modules/system/tests/modules/hold_test/hold_test.module create mode 100644 core/modules/system/tests/modules/hold_test/src/HoldTestHelper.php diff --git a/core/.phpstan-baseline.php b/core/.phpstan-baseline.php index 004f1747f5d7..cdc32086a3da 100644 --- a/core/.phpstan-baseline.php +++ b/core/.phpstan-baseline.php @@ -38133,18 +38133,6 @@ 'count' => 1, 'path' => __DIR__ . '/modules/system/tests/modules/form_test/src/FormTestServiceObject.php', ]; -$ignoreErrors[] = [ - 'message' => '#^Function hold_test_request\\(\\) has no return type specified\\.$#', - 'identifier' => 'missingType.return', - 'count' => 1, - 'path' => __DIR__ . '/modules/system/tests/modules/hold_test/hold_test.module', -]; -$ignoreErrors[] = [ - 'message' => '#^Function hold_test_response\\(\\) has no return type specified\\.$#', - 'identifier' => 'missingType.return', - 'count' => 1, - 'path' => __DIR__ . '/modules/system/tests/modules/hold_test/hold_test.module', -]; $ignoreErrors[] = [ 'message' => '#^Method Drupal\\\\hold_test\\\\EventSubscriber\\\\HoldTestSubscriber\\:\\:hold\\(\\) has no return type specified\\.$#', 'identifier' => 'missingType.return', diff --git a/core/modules/media_library/tests/src/FunctionalJavascript/MediaLibraryTestBase.php b/core/modules/media_library/tests/src/FunctionalJavascript/MediaLibraryTestBase.php index 806bdf73a5ca..a6ace76f5ced 100644 --- a/core/modules/media_library/tests/src/FunctionalJavascript/MediaLibraryTestBase.php +++ b/core/modules/media_library/tests/src/FunctionalJavascript/MediaLibraryTestBase.php @@ -6,6 +6,7 @@ use Behat\Mink\Element\NodeElement; use Drupal\FunctionalJavascriptTests\WebDriverTestBase; +use Drupal\hold_test\HoldTestHelper; use Drupal\media\Entity\Media; /** @@ -434,11 +435,11 @@ protected function switchToMediaLibraryGrid() { * Switches to the table display of the widget view. */ protected function switchToMediaLibraryTable() { - hold_test_response(TRUE); + HoldTestHelper::responseHold(TRUE); $this->getSession()->getPage()->clickLink('Table'); // Assert the display change is correctly announced for screen readers. $this->assertAnnounceContains('Loading table view.'); - hold_test_response(FALSE); + HoldTestHelper::responseHold(FALSE); $this->assertAnnounceContains('Changed to table view.'); $this->assertMediaLibraryTable(); } diff --git a/core/modules/system/tests/modules/hold_test/hold_test.install b/core/modules/system/tests/modules/hold_test/hold_test.install index 64ef37da2704..d4f4cc8309d6 100644 --- a/core/modules/system/tests/modules/hold_test/hold_test.install +++ b/core/modules/system/tests/modules/hold_test/hold_test.install @@ -7,10 +7,12 @@ declare(strict_types=1); +use Drupal\hold_test\HoldTestHelper; + /** * Implements hook_install(). */ function hold_test_install(): void { - hold_test_request(FALSE); - hold_test_response(FALSE); + HoldTestHelper::requestHold(FALSE); + HoldTestHelper::responseHold(FALSE); } diff --git a/core/modules/system/tests/modules/hold_test/hold_test.module b/core/modules/system/tests/modules/hold_test/hold_test.module deleted file mode 100644 index 37314070d68b..000000000000 --- a/core/modules/system/tests/modules/hold_test/hold_test.module +++ /dev/null @@ -1,42 +0,0 @@ -<?php - -/** - * @file - * Contains functions for testing hold request/response. - */ - -declare(strict_types=1); - -use Drupal\hold_test\EventSubscriber\HoldTestSubscriber; - -/** - * Request hold. - * - * @param bool $status - * TRUE - enable hold, FALSE - disable hold. - */ -function hold_test_request($status) { - $site_path = \Drupal::getContainer()->getParameter('site.path'); - file_put_contents($site_path . '/hold_test_request.txt', $status); - // If we're releasing the hold wait for a bit to allow the subscriber to read - // the file. - if (!$status) { - usleep(HoldTestSubscriber::WAIT * 2); - } -} - -/** - * Response hold. - * - * @param bool $status - * TRUE - enable hold, FALSE - disable hold. - */ -function hold_test_response($status) { - $site_path = \Drupal::getContainer()->getParameter('site.path'); - file_put_contents($site_path . '/hold_test_response.txt', $status); - // If we're releasing the hold wait for a bit to allow the subscriber to read - // the file. - if (!$status) { - usleep(HoldTestSubscriber::WAIT * 2); - } -} diff --git a/core/modules/system/tests/modules/hold_test/src/HoldTestHelper.php b/core/modules/system/tests/modules/hold_test/src/HoldTestHelper.php new file mode 100644 index 000000000000..e3518fb0345d --- /dev/null +++ b/core/modules/system/tests/modules/hold_test/src/HoldTestHelper.php @@ -0,0 +1,46 @@ +<?php + +declare(strict_types=1); + +namespace Drupal\hold_test; + +use Drupal\hold_test\EventSubscriber\HoldTestSubscriber; + +/** + * Contains methods for testing hold request/response. + */ +class HoldTestHelper { + + /** + * Request hold. + * + * @param bool $status + * TRUE - enable hold, FALSE - disable hold. + */ + public static function requestHold(bool $status): void { + $site_path = \Drupal::getContainer()->getParameter('site.path'); + file_put_contents($site_path . '/hold_test_request.txt', $status); + // If we're releasing the hold wait for a bit to allow the subscriber to + // read the file. + if (!$status) { + usleep(HoldTestSubscriber::WAIT * 2); + } + } + + /** + * Response hold. + * + * @param bool $status + * TRUE - enable hold, FALSE - disable hold. + */ + public static function responseHold(bool $status): void { + $site_path = \Drupal::getContainer()->getParameter('site.path'); + file_put_contents($site_path . '/hold_test_response.txt', $status); + // If we're releasing the hold wait for a bit to allow the subscriber to + // read the file. + if (!$status) { + usleep(HoldTestSubscriber::WAIT * 2); + } + } + +} diff --git a/core/tests/Drupal/FunctionalJavascriptTests/Ajax/ThrobberTest.php b/core/tests/Drupal/FunctionalJavascriptTests/Ajax/ThrobberTest.php index 0372ae1cd996..6b2a17d4c6eb 100644 --- a/core/tests/Drupal/FunctionalJavascriptTests/Ajax/ThrobberTest.php +++ b/core/tests/Drupal/FunctionalJavascriptTests/Ajax/ThrobberTest.php @@ -5,6 +5,7 @@ namespace Drupal\FunctionalJavascriptTests\Ajax; use Drupal\FunctionalJavascriptTests\WebDriverTestBase; +use Drupal\hold_test\HoldTestHelper; /** * Tests the throbber. @@ -64,28 +65,28 @@ public function testThemingThrobberElement(): void { // Test theming fullscreen throbber. $session->executeScript($custom_ajax_progress_indicator_fullscreen); - hold_test_response(TRUE); + HoldTestHelper::responseHold(TRUE); $page->clickLink('Content: Published (grouped)'); $this->assertNotNull($web_assert->waitForElement('css', '.custom-ajax-progress-fullscreen'), 'Custom ajaxProgressIndicatorFullscreen.'); - hold_test_response(FALSE); + HoldTestHelper::responseHold(FALSE); $web_assert->assertNoElementAfterWait('css', '.custom-ajax-progress-fullscreen'); // Test theming throbber message. $web_assert->waitForElementVisible('css', '[data-drupal-selector="edit-options-group-info-add-group"]'); $session->executeScript($custom_ajax_progress_message); - hold_test_response(TRUE); + HoldTestHelper::responseHold(TRUE); $page->pressButton('Add another item'); $this->assertNotNull($web_assert->waitForElement('css', '.ajax-progress-throbber .custom-ajax-progress-message'), 'Custom ajaxProgressMessage.'); - hold_test_response(FALSE); + HoldTestHelper::responseHold(FALSE); $web_assert->assertNoElementAfterWait('css', '.ajax-progress-throbber'); // Test theming throbber. $web_assert->waitForElementVisible('css', '[data-drupal-selector="edit-options-group-info-group-items-3-title"]'); $session->executeScript($custom_ajax_progress_throbber); - hold_test_response(TRUE); + HoldTestHelper::responseHold(TRUE); $page->pressButton('Add another item'); $this->assertNotNull($web_assert->waitForElement('css', '.custom-ajax-progress-throbber'), 'Custom ajaxProgressThrobber.'); - hold_test_response(FALSE); + HoldTestHelper::responseHold(FALSE); $web_assert->assertNoElementAfterWait('css', '.custom-ajax-progress-throbber'); // Test progress throbber position on a dropbutton in a table display. @@ -93,10 +94,10 @@ public function testThemingThrobberElement(): void { $this->clickLink('Place block'); $web_assert->assertWaitOnAjaxRequest(); $this->assertNotEmpty($web_assert->waitForElementVisible('css', '#drupal-modal')); - hold_test_response(TRUE); + HoldTestHelper::responseHold(TRUE); $this->clickLink('Place block'); $this->assertNotNull($web_assert->waitForElement('xpath', '//div[contains(@class, "dropbutton-wrapper")]/following-sibling::div[contains(@class, "ajax-progress-throbber")]')); - hold_test_response(FALSE); + HoldTestHelper::responseHold(FALSE); $web_assert->assertNoElementAfterWait('css', '.ajax-progress-throbber'); } -- GitLab