From 953a02aad86b00fc85ccb243aedb6831a435a1c6 Mon Sep 17 00:00:00 2001
From: prashantdsala <p1989chauhan@gmail.com>
Date: Thu, 24 Apr 2025 16:07:16 +0530
Subject: [PATCH 1/4] Conditional default value for label

---
 core/modules/search/src/Form/SearchPageFormBase.php | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/core/modules/search/src/Form/SearchPageFormBase.php b/core/modules/search/src/Form/SearchPageFormBase.php
index a0df9cbee015..f2dca1183ff4 100644
--- a/core/modules/search/src/Form/SearchPageFormBase.php
+++ b/core/modules/search/src/Form/SearchPageFormBase.php
@@ -76,8 +76,9 @@ public function form(array $form, FormStateInterface $form_state) {
       '#type' => 'textfield',
       '#title' => $this->t('Label'),
       '#description' => $this->t('The label for this search page.'),
-      '#default_value' => $this->entity->label(),
+      '#default_value' => !$this->entity->isNew() ? $this->entity->label() : '',
       '#maxlength' => '255',
+      '#required' => TRUE,
     ];
 
     $form['id'] = [
-- 
GitLab


From 87e5a5fbf2f1b0851b606007f16bbc6e80b4e42f Mon Sep 17 00:00:00 2001
From: prashantdsala <p1989chauhan@gmail.com>
Date: Thu, 24 Apr 2025 20:04:44 +0530
Subject: [PATCH 2/4] Functional Javascript test to verify the bug

---
 .../SearchPageMachineNameTest.php             | 67 +++++++++++++++++++
 1 file changed, 67 insertions(+)
 create mode 100644 core/modules/search/tests/src/FunctionalJavascript/SearchPageMachineNameTest.php

diff --git a/core/modules/search/tests/src/FunctionalJavascript/SearchPageMachineNameTest.php b/core/modules/search/tests/src/FunctionalJavascript/SearchPageMachineNameTest.php
new file mode 100644
index 000000000000..1502ee20829e
--- /dev/null
+++ b/core/modules/search/tests/src/FunctionalJavascript/SearchPageMachineNameTest.php
@@ -0,0 +1,67 @@
+<?php
+
+declare(strict_types=1);
+
+namespace Drupal\Tests\search\FunctionalJavascript;
+
+use Drupal\FunctionalJavascriptTests\WebDriverTestBase;
+
+/**
+ * Tests the search page machine name field behavior.
+ *
+ * @group search
+ */
+class SearchPageMachineNameTest extends WebDriverTestBase {
+
+  /**
+   * {@inheritdoc}
+   */
+  protected static $modules = ['node', 'search'];
+
+  /**
+   * {@inheritdoc}
+   */
+  protected $defaultTheme = 'stark';
+
+  /**
+   * Tests that machine name field is not automatically updated with label.
+   *
+   * This test verifies a bug where the machine name field is not automatically
+   * updated when the label field changes. The machine name should be automatically
+   * generated from the label, but currently it is not.
+   *
+   * @see https://www.drupal.org/project/drupal/issues/XXXXX
+   */
+  public function testMachineNameNotUpdated() {
+    // Log in as admin.
+    $this->drupalLogin($this->drupalCreateUser([
+      'search content',
+      'administer search',
+      'use advanced search',
+      'access user profiles',
+    ]));
+
+    // Visit the search pages configuration page.
+    $this->drupalGet('admin/config/search/pages');
+
+    // Select "Content" from the search page type dropdown.
+    $this->getSession()->getPage()->selectFieldOption('search_type', 'node_search');
+
+    // Click "Add Search Page" button.
+    $this->getSession()->getPage()->pressButton('edit-add-search-submit');
+
+    // Fill in the label field.
+    $this->getSession()->getPage()->fillField('Label', 'Test page');
+
+    // Wait for any potential JavaScript updates to complete.
+    $this->getSession()->wait(1000);
+
+    // Get the machine name field value.
+    $machine_name = $this->getSession()->getPage()->findField('Machine-readable name')->getValue();
+
+    // Assert that the machine name is not automatically updated.
+    // This is currently a bug - the machine name should be 'test_page' but it's not.
+    $this->assertNotEquals('test_page', $machine_name, 'Machine name should be automatically updated to "test_page" when label is "Test page", but it is not. This is a bug.');
+  }
+
+}
-- 
GitLab


From 55fce6b4b24224bc161d592edb1440ce31adbf4a Mon Sep 17 00:00:00 2001
From: prashantdsala <p1989chauhan@gmail.com>
Date: Thu, 24 Apr 2025 20:26:31 +0530
Subject: [PATCH 3/4] phpstan issue fix

---
 .../src/FunctionalJavascript/SearchPageMachineNameTest.php    | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/core/modules/search/tests/src/FunctionalJavascript/SearchPageMachineNameTest.php b/core/modules/search/tests/src/FunctionalJavascript/SearchPageMachineNameTest.php
index 1502ee20829e..df18df7b0cfb 100644
--- a/core/modules/search/tests/src/FunctionalJavascript/SearchPageMachineNameTest.php
+++ b/core/modules/search/tests/src/FunctionalJavascript/SearchPageMachineNameTest.php
@@ -30,9 +30,9 @@ class SearchPageMachineNameTest extends WebDriverTestBase {
    * updated when the label field changes. The machine name should be automatically
    * generated from the label, but currently it is not.
    *
-   * @see https://www.drupal.org/project/drupal/issues/XXXXX
+   * @see https://www.drupal.org/project/drupal/issues/3520941#comment-16084573
    */
-  public function testMachineNameNotUpdated() {
+  public function testMachineNameNotUpdated(): void {
     // Log in as admin.
     $this->drupalLogin($this->drupalCreateUser([
       'search content',
-- 
GitLab


From 721515b97644b0b6ee94c418e3f9d4d7bd9b807f Mon Sep 17 00:00:00 2001
From: prashantdsala <p1989chauhan@gmail.com>
Date: Fri, 25 Apr 2025 10:50:29 +0530
Subject: [PATCH 4/4] Functional test issue fix

---
 .../SearchPageMachineNameTest.php                   | 13 ++++++-------
 1 file changed, 6 insertions(+), 7 deletions(-)

diff --git a/core/modules/search/tests/src/FunctionalJavascript/SearchPageMachineNameTest.php b/core/modules/search/tests/src/FunctionalJavascript/SearchPageMachineNameTest.php
index df18df7b0cfb..73571f3b7974 100644
--- a/core/modules/search/tests/src/FunctionalJavascript/SearchPageMachineNameTest.php
+++ b/core/modules/search/tests/src/FunctionalJavascript/SearchPageMachineNameTest.php
@@ -24,15 +24,15 @@ class SearchPageMachineNameTest extends WebDriverTestBase {
   protected $defaultTheme = 'stark';
 
   /**
-   * Tests that machine name field is not automatically updated with label.
+   * Tests that machine name field automatically updated with label.
    *
-   * This test verifies a bug where the machine name field is not automatically
+   * This test verifies that the machine name field is automatically
    * updated when the label field changes. The machine name should be automatically
-   * generated from the label, but currently it is not.
+   * generated from the label.
    *
    * @see https://www.drupal.org/project/drupal/issues/3520941#comment-16084573
    */
-  public function testMachineNameNotUpdated(): void {
+  public function testMachineNameUpdated(): void {
     // Log in as admin.
     $this->drupalLogin($this->drupalCreateUser([
       'search content',
@@ -59,9 +59,8 @@ public function testMachineNameNotUpdated(): void {
     // Get the machine name field value.
     $machine_name = $this->getSession()->getPage()->findField('Machine-readable name')->getValue();
 
-    // Assert that the machine name is not automatically updated.
-    // This is currently a bug - the machine name should be 'test_page' but it's not.
-    $this->assertNotEquals('test_page', $machine_name, 'Machine name should be automatically updated to "test_page" when label is "Test page", but it is not. This is a bug.');
+    // Assert that the machine name matches the expected value.
+    $this->assertEquals('test_page', $machine_name, 'Machine name should be automatically updated to match the label value.');
   }
 
 }
-- 
GitLab