diff --git a/core/modules/search/lib/Drupal/search/Form/SearchBlockForm.php b/core/modules/search/lib/Drupal/search/Form/SearchBlockForm.php index bc38e5d..2da0f9e 100644 --- a/core/modules/search/lib/Drupal/search/Form/SearchBlockForm.php +++ b/core/modules/search/lib/Drupal/search/Form/SearchBlockForm.php @@ -66,6 +66,7 @@ public function buildForm(array $form, array &$form_state) { $route = 'search.view_' . $entity_id; $form['#action'] = \Drupal::url($route); + $form['#token'] = FALSE; $form['#method'] = 'get'; $form['keys'] = array( @@ -78,7 +79,12 @@ public function buildForm(array $form, array &$form_state) { ); $form['actions'] = array('#type' => 'actions'); - $form['actions']['submit'] = array('#type' => 'submit', '#value' => $this->t('Search')); + $form['actions']['submit'] = array( + '#type' => 'submit', + '#value' => $this->t('Search'), + // Prevent op from showing up in the query string. + '#name' => '', + ); return $form; } diff --git a/core/modules/search/lib/Drupal/search/Tests/SearchBlockTest.php b/core/modules/search/lib/Drupal/search/Tests/SearchBlockTest.php index 1b96bce..d4e45db 100644 --- a/core/modules/search/lib/Drupal/search/Tests/SearchBlockTest.php +++ b/core/modules/search/lib/Drupal/search/Tests/SearchBlockTest.php @@ -2,7 +2,7 @@ /** * @file - * Definition of Drupal\search\Tests\SearchBlockTest. + * Contains \Drupal\search\Tests\SearchBlockTest. */ namespace Drupal\search\Tests; @@ -71,11 +71,14 @@ protected function testSearchFormBlock() { $this->assertResponse(200); $this->assertText('Your search yielded no results'); - // Confirm that the user is redirected to the search page. + // Confirm that the form submits to the default search page. + /** @var $search_page_repository \Drupal\search\SearchPageRepositoryInterface */ + $search_page_repository = \Drupal::service('search.search_page_repository'); + $entity_id = $search_page_repository->getDefaultSearchPage(); $this->assertEqual( $this->getUrl(), - url('search/node', array('query' => array('keys' => $terms['keys'], 'op' => 'Search'), 'absolute' => TRUE)), - 'Redirected to correct url.' + \Drupal::url('search.view_' . $entity_id, array(), array('query' => array('keys' => $terms['keys']), 'absolute' => TRUE)), + 'Submitted to correct url.' ); // Test an empty search via the block form, from the front page. @@ -88,7 +91,7 @@ protected function testSearchFormBlock() { // submitted empty. $this->assertEqual( $this->getUrl(), - url('search/node', array('query' => array('keys' => '', 'op' => 'Search'), 'absolute' => TRUE)), + \Drupal::url('search.view_' . $entity_id, array(), array('query' => array('keys' => ''), 'absolute' => TRUE)), 'Redirected to correct url.' ); diff --git a/core/modules/search/lib/Drupal/search/Tests/SearchTestBase.php b/core/modules/search/lib/Drupal/search/Tests/SearchTestBase.php index 9651064..58193a0 100644 --- a/core/modules/search/lib/Drupal/search/Tests/SearchTestBase.php +++ b/core/modules/search/lib/Drupal/search/Tests/SearchTestBase.php @@ -8,6 +8,7 @@ namespace Drupal\search\Tests; use Drupal\simpletest\WebTestBase; +use Drupal\Component\Utility\String; /** * Defines the common search test code. @@ -45,7 +46,7 @@ function setUp() { * function parameters. * * @param string $path - * Location of the form to be posted to: either a Drupal path, absolute + * Location of the form to be submitted: either a Drupal path, absolute * path, or NULL to use the current page. * @param array $edit * Form field data to submit. Unlike drupalPostForm(), this does not support diff --git a/core/modules/simpletest/lib/Drupal/simpletest/WebTestBase.php b/core/modules/simpletest/lib/Drupal/simpletest/WebTestBase.php index 942ebab..e7ceb44 100644 --- a/core/modules/simpletest/lib/Drupal/simpletest/WebTestBase.php +++ b/core/modules/simpletest/lib/Drupal/simpletest/WebTestBase.php @@ -2152,6 +2152,8 @@ protected function handleForm(&$post, &$edit, &$upload, $submit, $form) { } } } + // An empty name means the value is not sent. + unset($post['']); return $submit_matches; }