From 8925a12978ca7ec02fe870a9031db6c7ab4cfa1f Mon Sep 17 00:00:00 2001
From: quietone <quietone@2572884.no-reply.drupal.org>
Date: Wed, 18 Dec 2024 14:23:36 +1300
Subject: [PATCH] Issue #3484247 by mstrelan, smustgrave: Add NodeElement
 return typehints to protected test helper methods

---
 .../tests/src/FunctionalJavascript/MoveBlockFormTest.php | 3 ++-
 .../src/FunctionalJavascript/MediaLibraryTestBase.php    | 9 +++++----
 .../update/tests/src/Functional/UpdateTestBase.php       | 3 ++-
 .../TableDrag/TableDragTest.php                          | 4 ++--
 4 files changed, 11 insertions(+), 8 deletions(-)

diff --git a/core/modules/layout_builder/tests/src/FunctionalJavascript/MoveBlockFormTest.php b/core/modules/layout_builder/tests/src/FunctionalJavascript/MoveBlockFormTest.php
index 2c0923d7a88e..ba11617ffae7 100644
--- a/core/modules/layout_builder/tests/src/FunctionalJavascript/MoveBlockFormTest.php
+++ b/core/modules/layout_builder/tests/src/FunctionalJavascript/MoveBlockFormTest.php
@@ -4,6 +4,7 @@
 
 namespace Drupal\Tests\layout_builder\FunctionalJavascript;
 
+use Behat\Mink\Element\NodeElement;
 use Drupal\FunctionalJavascriptTests\WebDriverTestBase;
 use Drupal\layout_builder\Entity\LayoutBuilderEntityViewDisplay;
 use Drupal\Tests\contextual\FunctionalJavascript\ContextualLinkClickTrait;
@@ -236,7 +237,7 @@ protected function moveBlockWithKeyboard($direction, $block_label, array $update
    * @return \Behat\Mink\Element\NodeElement
    *   The row handle element.
    */
-  protected function findRowHandle($block_label) {
+  protected function findRowHandle($block_label): NodeElement {
     $assert_session = $this->assertSession();
     return $assert_session->elementExists('css', "[data-drupal-selector=\"edit-components\"] td:contains(\"$block_label\") a.tabledrag-handle");
   }
diff --git a/core/modules/media_library/tests/src/FunctionalJavascript/MediaLibraryTestBase.php b/core/modules/media_library/tests/src/FunctionalJavascript/MediaLibraryTestBase.php
index a97832a15e5b..806bdf73a5ca 100644
--- a/core/modules/media_library/tests/src/FunctionalJavascript/MediaLibraryTestBase.php
+++ b/core/modules/media_library/tests/src/FunctionalJavascript/MediaLibraryTestBase.php
@@ -4,6 +4,7 @@
 
 namespace Drupal\Tests\media_library\FunctionalJavascript;
 
+use Behat\Mink\Element\NodeElement;
 use Drupal\FunctionalJavascriptTests\WebDriverTestBase;
 use Drupal\media\Entity\Media;
 
@@ -154,7 +155,7 @@ protected function waitForElementTextContains($selector, $text, $timeout = 10000
    * @todo replace with whatever gets added in
    *   https://www.drupal.org/node/3061852
    */
-  protected function assertElementExistsAfterWait($selector, $locator, $timeout = 10000) {
+  protected function assertElementExistsAfterWait($selector, $locator, $timeout = 10000): NodeElement {
     $element = $this->assertSession()->waitForElement($selector, $locator, $timeout);
     $this->assertNotEmpty($element);
     return $element;
@@ -166,7 +167,7 @@ protected function assertElementExistsAfterWait($selector, $locator, $timeout =
    * @return \Behat\Mink\Element\NodeElement
    *   The menu of available media types.
    */
-  protected function getTypesMenu() {
+  protected function getTypesMenu(): NodeElement {
     return $this->assertSession()
       ->elementExists('css', '.js-media-library-menu');
   }
@@ -275,7 +276,7 @@ protected function pressSaveButton($expect_errors = FALSE) {
    * @return \Behat\Mink\Element\NodeElement
    *   The NodeElement found via $after_open_selector.
    */
-  protected function openMediaLibraryForField($field_name, $after_open_selector = '.js-media-library-menu') {
+  protected function openMediaLibraryForField($field_name, $after_open_selector = '.js-media-library-menu'): NodeElement {
     $this->assertElementExistsAfterWait('css', "#$field_name-media-library-wrapper.js-media-library-widget")
       ->pressButton('Add media');
     $this->waitForText('Add or select media');
@@ -302,7 +303,7 @@ protected function openMediaLibraryForField($field_name, $after_open_selector =
    * @return \Behat\Mink\Element\NodeElement
    *   The "additional selected media" area.
    */
-  protected function getSelectionArea($open = TRUE) {
+  protected function getSelectionArea($open = TRUE): NodeElement {
     $summary = $this->assertElementExistsAfterWait('css', 'summary:contains("Additional selected media")');
     if ($open) {
       $summary->click();
diff --git a/core/modules/update/tests/src/Functional/UpdateTestBase.php b/core/modules/update/tests/src/Functional/UpdateTestBase.php
index 67848f65001f..9dc5fe053d6d 100644
--- a/core/modules/update/tests/src/Functional/UpdateTestBase.php
+++ b/core/modules/update/tests/src/Functional/UpdateTestBase.php
@@ -4,6 +4,7 @@
 
 namespace Drupal\Tests\update\Functional;
 
+use Behat\Mink\Element\NodeElement;
 use Drupal\Core\Url;
 use Drupal\Tests\BrowserTestBase;
 
@@ -294,7 +295,7 @@ protected function assertUpdateTableElementNotContains($text) {
    * @return \Behat\Mink\Element\NodeElement
    *   The update element.
    */
-  protected function findUpdateElementByLabel($label, int $index = 0) {
+  protected function findUpdateElementByLabel($label, int $index = 0): NodeElement {
     $update_elements = $this->getSession()->getPage()
       ->findAll('css', $this->updateTableLocator . " .project-update__version:contains(\"$label\")");
     $this->assertGreaterThanOrEqual($index, count($update_elements));
diff --git a/core/tests/Drupal/FunctionalJavascriptTests/TableDrag/TableDragTest.php b/core/tests/Drupal/FunctionalJavascriptTests/TableDrag/TableDragTest.php
index 6d5148650423..dec8abda4038 100644
--- a/core/tests/Drupal/FunctionalJavascriptTests/TableDrag/TableDragTest.php
+++ b/core/tests/Drupal/FunctionalJavascriptTests/TableDrag/TableDragTest.php
@@ -556,7 +556,7 @@ protected function assertTableRow(NodeElement $row, string $id, int $weight, str
    * @return \Behat\Mink\Element\NodeElement
    *   The row element.
    */
-  protected function findRowById($id, $table_id = 'tabledrag-test-table') {
+  protected function findRowById($id, $table_id = 'tabledrag-test-table'): NodeElement {
     $xpath = "//table[@id='$table_id']/tbody/tr[.//input[@name='table[$id][id]']]";
     $row = $this->getSession()->getPage()->find('xpath', $xpath);
     $this->assertNotEmpty($row);
@@ -572,7 +572,7 @@ protected function findRowById($id, $table_id = 'tabledrag-test-table') {
    * @return \Behat\Mink\Element\NodeElement
    *   The toggle element.
    */
-  protected function findWeightsToggle($expected_text) {
+  protected function findWeightsToggle($expected_text): NodeElement {
     $toggle = $this->getSession()->getPage()->findButton($expected_text);
     $this->assertNotEmpty($toggle);
     return $toggle;
-- 
GitLab