diff --git a/core/modules/search/src/Tests/SearchAdvancedSearchFormTest.php b/core/modules/search/tests/src/Functional/SearchAdvancedSearchFormTest.php similarity index 85% rename from core/modules/search/src/Tests/SearchAdvancedSearchFormTest.php rename to core/modules/search/tests/src/Functional/SearchAdvancedSearchFormTest.php index ad00b5252f6ae2564fd6f0e05f0f0861f9397999..29c3817a72e557d765d04e79093436e2c1753274 100644 --- a/core/modules/search/src/Tests/SearchAdvancedSearchFormTest.php +++ b/core/modules/search/tests/src/Functional/SearchAdvancedSearchFormTest.php @@ -1,6 +1,6 @@ <?php -namespace Drupal\search\Tests; +namespace Drupal\Tests\search\Functional; /** * Indexes content and tests the advanced search form. @@ -53,14 +53,14 @@ public function testNodeType() { // Search for the title of the node with a POST query. $edit = ['or' => $this->node->label()]; - $this->drupalPostForm('search/node', $edit, t('Advanced search')); + $this->drupalPostForm('search/node', $edit, 'edit-submit--2'); $this->assertText($this->node->label(), 'Basic page node is found with POST query.'); // Search by node type. - $this->drupalPostForm('search/node', array_merge($edit, ['type[page]' => 'page']), t('Advanced search')); + $this->drupalPostForm('search/node', array_merge($edit, ['type[page]' => 'page']), 'edit-submit--2'); $this->assertText($this->node->label(), 'Basic page node is found with POST query and type:page.'); - $this->drupalPostForm('search/node', array_merge($edit, ['type[article]' => 'article']), t('Advanced search')); + $this->drupalPostForm('search/node', array_merge($edit, ['type[article]' => 'article']), 'edit-submit--2'); $this->assertText('search yielded no results', 'Article node is not found with POST query and type:article.'); } @@ -75,7 +75,7 @@ public function testFormRefill() { 'negative' => 'fish snake', 'type[page]' => 'page', ]; - $this->drupalPostForm('search/node', $edit, t('Advanced search')); + $this->drupalPostForm('search/node', $edit, 'edit-submit--2'); // Test that the encoded query appears in the page title. Only test the // part not including the quote, because assertText() cannot seem to find @@ -86,11 +86,11 @@ public function testFormRefill() { foreach ($edit as $key => $value) { if ($key != 'type[page]') { $elements = $this->xpath('//input[@name=:name]', [':name' => $key]); - $this->assertTrue(isset($elements[0]) && $elements[0]['value'] == $value, "Field $key is set to $value"); + $this->assertTrue(isset($elements[0]) && $elements[0]->getValue() == $value, "Field $key is set to $value"); } else { $elements = $this->xpath('//input[@name=:name]', [':name' => $key]); - $this->assertTrue(isset($elements[0]) && !empty($elements[0]['checked']), "Field $key is checked"); + $this->assertTrue(isset($elements[0]) && !empty($elements[0]->getAttribute('checked')), "Field $key is checked"); } } @@ -98,12 +98,12 @@ public function testFormRefill() { // search box, and verify that the advanced form is not filled out. // (It shouldn't be filled out unless you submit values in those fields.) $edit2 = ['keys' => 'cat dog OR gerbil -fish -snake']; - $this->drupalPostForm('search/node', $edit2, t('Advanced search')); + $this->drupalPostForm('search/node', $edit2, 'edit-submit--2'); $this->assertText('Search for cat dog OR gerbil -fish -snake'); foreach ($edit as $key => $value) { if ($key != 'type[page]') { $elements = $this->xpath('//input[@name=:name]', [':name' => $key]); - $this->assertFalse(isset($elements[0]) && $elements[0]['value'] == $value, "Field $key is not set to $value"); + $this->assertFalse(isset($elements[0]) && $elements[0]->getValue() == $value, "Field $key is not set to $value"); } } } diff --git a/core/modules/search/src/Tests/SearchBlockTest.php b/core/modules/search/tests/src/Functional/SearchBlockTest.php similarity index 97% rename from core/modules/search/src/Tests/SearchBlockTest.php rename to core/modules/search/tests/src/Functional/SearchBlockTest.php index 21afda7f05f5dd72ec3959db0aca2c8c8504014b..3c6b746017d6ceb401e3d634880497c57f13fc7b 100644 --- a/core/modules/search/src/Tests/SearchBlockTest.php +++ b/core/modules/search/tests/src/Functional/SearchBlockTest.php @@ -1,6 +1,6 @@ <?php -namespace Drupal\search\Tests; +namespace Drupal\Tests\search\Functional; /** * Tests if the search form block is available. @@ -31,7 +31,7 @@ public function testSearchFormBlock() { // Test availability of the search block in the admin "Place blocks" list. $this->drupalGet('admin/structure/block'); - $this->clickLinkPartialName('Place block'); + $this->getSession()->getPage()->findLink('Place block')->click(); $this->assertLinkByHref('/admin/structure/block/add/search_form_block/classy', 0, 'Did not find the search block in block candidate list.'); diff --git a/core/modules/search/src/Tests/SearchCommentTest.php b/core/modules/search/tests/src/Functional/SearchCommentTest.php similarity index 95% rename from core/modules/search/src/Tests/SearchCommentTest.php rename to core/modules/search/tests/src/Functional/SearchCommentTest.php index 704742925216140a80c8ac2e68c44ce63f19bd25..23167edb232826f6587d33ea3c866d92dcc99d7c 100644 --- a/core/modules/search/src/Tests/SearchCommentTest.php +++ b/core/modules/search/tests/src/Functional/SearchCommentTest.php @@ -1,10 +1,12 @@ <?php -namespace Drupal\search\Tests; +namespace Drupal\Tests\search\Functional; +use Behat\Mink\Exception\ResponseTextException; use Drupal\comment\Plugin\Field\FieldType\CommentItemInterface; use Drupal\comment\Tests\CommentTestTrait; use Drupal\field\Entity\FieldConfig; +use Drupal\Tests\Traits\Core\CronRunTrait; use Drupal\user\RoleInterface; use Drupal\filter\Entity\FilterFormat; @@ -16,6 +18,7 @@ class SearchCommentTest extends SearchTestBase { use CommentTestTrait; + use CronRunTrait; /** * Modules to enable. @@ -298,15 +301,18 @@ public function assertCommentAccess($assume_access, $message) { ]; $this->drupalPostForm('search/node', $edit, t('Search')); - if ($assume_access) { - $expected_node_result = $this->assertText($this->node->label()); - $expected_comment_result = $this->assertText($this->commentSubject); + try { + if ($assume_access) { + $this->assertSession()->pageTextContains($this->node->label()); + $this->assertSession()->pageTextContains($this->commentSubject); + } + else { + $this->assertSession()->pageTextContains(t('Your search yielded no results.')); + } } - else { - $expected_node_result = $this->assertText(t('Your search yielded no results.')); - $expected_comment_result = $this->assertText(t('Your search yielded no results.')); + catch (ResponseTextException $exception) { + $this->fail($message); } - $this->assertTrue($expected_node_result && $expected_comment_result, $message); } /** diff --git a/core/modules/search/src/Tests/SearchConfigSettingsFormTest.php b/core/modules/search/tests/src/Functional/SearchConfigSettingsFormTest.php similarity index 94% rename from core/modules/search/src/Tests/SearchConfigSettingsFormTest.php rename to core/modules/search/tests/src/Functional/SearchConfigSettingsFormTest.php index b081b857d0a4c0a56e25664d724030416a8e60ed..f404f8f1335c5a52c432335008829e26f2ce1177 100644 --- a/core/modules/search/src/Tests/SearchConfigSettingsFormTest.php +++ b/core/modules/search/tests/src/Functional/SearchConfigSettingsFormTest.php @@ -1,6 +1,6 @@ <?php -namespace Drupal\search\Tests; +namespace Drupal\Tests\search\Functional; use Drupal\Core\Url; use Drupal\search\Entity\SearchPage; @@ -217,9 +217,9 @@ public function testSearchModuleDisabling() { public function testDefaultSearchPageOrdering() { $this->drupalGet('search'); $elements = $this->xpath('//*[contains(@class, :class)]//a', [':class' => 'tabs primary']); - $this->assertIdentical((string) $elements[0]['href'], \Drupal::url('search.view_node_search')); - $this->assertIdentical((string) $elements[1]['href'], \Drupal::url('search.view_dummy_search_type')); - $this->assertIdentical((string) $elements[2]['href'], \Drupal::url('search.view_user_search')); + $this->assertIdentical($elements[0]->getAttribute('href'), \Drupal::url('search.view_node_search')); + $this->assertIdentical($elements[1]->getAttribute('href'), \Drupal::url('search.view_dummy_search_type')); + $this->assertIdentical($elements[2]->getAttribute('href'), \Drupal::url('search.view_user_search')); } /** @@ -272,8 +272,8 @@ public function testMultipleSearchPages() { // Ensure both search pages have their tabs displayed. $this->drupalGet('search'); $elements = $this->xpath('//*[contains(@class, :class)]//a', [':class' => 'tabs primary']); - $this->assertIdentical((string) $elements[0]['href'], Url::fromRoute('search.view_' . $first_id)->toString()); - $this->assertIdentical((string) $elements[1]['href'], Url::fromRoute('search.view_' . $second_id)->toString()); + $this->assertIdentical($elements[0]->getAttribute('href'), Url::fromRoute('search.view_' . $first_id)->toString()); + $this->assertIdentical($elements[1]->getAttribute('href'), Url::fromRoute('search.view_' . $second_id)->toString()); // Switch the weight of the search pages and check the order of the tabs. $edit = [ @@ -283,8 +283,8 @@ public function testMultipleSearchPages() { $this->drupalPostForm('admin/config/search/pages', $edit, t('Save configuration')); $this->drupalGet('search'); $elements = $this->xpath('//*[contains(@class, :class)]//a', [':class' => 'tabs primary']); - $this->assertIdentical((string) $elements[0]['href'], Url::fromRoute('search.view_' . $second_id)->toString()); - $this->assertIdentical((string) $elements[1]['href'], Url::fromRoute('search.view_' . $first_id)->toString()); + $this->assertIdentical($elements[0]->getAttribute('href'), Url::fromRoute('search.view_' . $second_id)->toString()); + $this->assertIdentical($elements[1]->getAttribute('href'), Url::fromRoute('search.view_' . $first_id)->toString()); // Check the initial state of the search pages. $this->drupalGet('admin/config/search/pages'); diff --git a/core/modules/search/src/Tests/SearchEmbedFormTest.php b/core/modules/search/tests/src/Functional/SearchEmbedFormTest.php similarity index 98% rename from core/modules/search/src/Tests/SearchEmbedFormTest.php rename to core/modules/search/tests/src/Functional/SearchEmbedFormTest.php index 5f3fbea32b3b3094f784d6b717c69ed13ccd8989..89f0d0d39fb776f440534cabb577f5a7a552faa0 100644 --- a/core/modules/search/src/Tests/SearchEmbedFormTest.php +++ b/core/modules/search/tests/src/Functional/SearchEmbedFormTest.php @@ -1,6 +1,6 @@ <?php -namespace Drupal\search\Tests; +namespace Drupal\Tests\search\Functional; /** * Verifies that a form embedded in search results works. diff --git a/core/modules/search/src/Tests/SearchLanguageTest.php b/core/modules/search/tests/src/Functional/SearchLanguageTest.php similarity index 95% rename from core/modules/search/src/Tests/SearchLanguageTest.php rename to core/modules/search/tests/src/Functional/SearchLanguageTest.php index ec150855d165ef5259c64542dd047edb32a81d40..d6e63074b0b5262b79023c51c1e3d83ee570cf4d 100644 --- a/core/modules/search/src/Tests/SearchLanguageTest.php +++ b/core/modules/search/tests/src/Functional/SearchLanguageTest.php @@ -1,6 +1,6 @@ <?php -namespace Drupal\search\Tests; +namespace Drupal\Tests\search\Functional; use Drupal\field\Entity\FieldStorageConfig; use Drupal\language\Entity\ConfigurableLanguage; @@ -99,12 +99,12 @@ public function testLanguages() { $this->assertText(t('French'), 'French is a possible choice.'); // Ensure selecting no language does not make the query different. - $this->drupalPostForm('search/node', [], t('Advanced search')); + $this->drupalPostForm('search/node', [], 'edit-submit--2'); $this->assertUrl(\Drupal::url('search.view_node_search', [], ['query' => ['keys' => ''], 'absolute' => TRUE]), [], 'Correct page redirection, no language filtering.'); // Pick French and ensure it is selected. $edit = ['language[fr]' => TRUE]; - $this->drupalPostForm('search/node', $edit, t('Advanced search')); + $this->drupalPostForm('search/node', $edit, 'edit-submit--2'); // Get the redirected URL. $url = $this->getUrl(); $parts = parse_url($url); @@ -113,7 +113,7 @@ public function testLanguages() { // Search for keyword node and language filter as Spanish. $edit = ['keys' => 'node', 'language[es]' => TRUE]; - $this->drupalPostForm('search/node', $edit, t('Advanced search')); + $this->drupalPostForm('search/node', $edit, 'edit-submit--2'); // Check for Spanish results. $this->assertLink('Second node this is the Spanish title', 0, 'Second node Spanish title found in search results'); $this->assertLink('Third node es', 0, 'Third node Spanish found in search results'); diff --git a/core/modules/search/src/Tests/SearchNodeUpdateAndDeletionTest.php b/core/modules/search/tests/src/Functional/SearchNodeUpdateAndDeletionTest.php similarity index 98% rename from core/modules/search/src/Tests/SearchNodeUpdateAndDeletionTest.php rename to core/modules/search/tests/src/Functional/SearchNodeUpdateAndDeletionTest.php index c19814e0263b63b962dace16895b857bae46b29f..0e9d35890c7daaff38a76b94cfaf1b9a8570f1ca 100644 --- a/core/modules/search/src/Tests/SearchNodeUpdateAndDeletionTest.php +++ b/core/modules/search/tests/src/Functional/SearchNodeUpdateAndDeletionTest.php @@ -1,6 +1,6 @@ <?php -namespace Drupal\search\Tests; +namespace Drupal\Tests\search\Functional; /** * Tests search index is updated properly when nodes are removed or updated. diff --git a/core/modules/search/src/Tests/SearchNumberMatchingTest.php b/core/modules/search/tests/src/Functional/SearchNumberMatchingTest.php similarity index 96% rename from core/modules/search/src/Tests/SearchNumberMatchingTest.php rename to core/modules/search/tests/src/Functional/SearchNumberMatchingTest.php index 7671c7b12469ce15375b76a8213a538b587b85f0..0de0c53e66ce4ff70768452bc9c07730d71aa662 100644 --- a/core/modules/search/src/Tests/SearchNumberMatchingTest.php +++ b/core/modules/search/tests/src/Functional/SearchNumberMatchingTest.php @@ -1,8 +1,9 @@ <?php -namespace Drupal\search\Tests; +namespace Drupal\Tests\search\Functional; use Drupal\Core\Language\LanguageInterface; +use Drupal\Tests\Traits\Core\CronRunTrait; /** * Tests that numbers can be searched with more complex matching. @@ -10,6 +11,9 @@ * @group search */ class SearchNumberMatchingTest extends SearchTestBase { + + use CronRunTrait; + /** * A user with permission to administer nodes. * diff --git a/core/modules/search/src/Tests/SearchNumbersTest.php b/core/modules/search/tests/src/Functional/SearchNumbersTest.php similarity index 96% rename from core/modules/search/src/Tests/SearchNumbersTest.php rename to core/modules/search/tests/src/Functional/SearchNumbersTest.php index dbb50396631daacaee872850c7b6de35a716c529..f1828102be2b660ae79831a15f81c84f2daa3342 100644 --- a/core/modules/search/src/Tests/SearchNumbersTest.php +++ b/core/modules/search/tests/src/Functional/SearchNumbersTest.php @@ -1,8 +1,9 @@ <?php -namespace Drupal\search\Tests; +namespace Drupal\Tests\search\Functional; use Drupal\Core\Language\LanguageInterface; +use Drupal\Tests\Traits\Core\CronRunTrait; /** * Tests that numbers can be searched. @@ -10,6 +11,9 @@ * @group search */ class SearchNumbersTest extends SearchTestBase { + + use CronRunTrait; + /** * A user with permission to administer nodes. * diff --git a/core/modules/search/src/Tests/SearchPageCacheTagsTest.php b/core/modules/search/tests/src/Functional/SearchPageCacheTagsTest.php similarity index 92% rename from core/modules/search/src/Tests/SearchPageCacheTagsTest.php rename to core/modules/search/tests/src/Functional/SearchPageCacheTagsTest.php index 0ea0e9460d3a8b5d5f023b8588f06fc878d8e521..799add68f8cbb322e7cfcb07a9d52ebe93c747d4 100644 --- a/core/modules/search/src/Tests/SearchPageCacheTagsTest.php +++ b/core/modules/search/tests/src/Functional/SearchPageCacheTagsTest.php @@ -1,8 +1,9 @@ <?php -namespace Drupal\search\Tests; +namespace Drupal\Tests\search\Functional; use Drupal\Core\Cache\Cache; +use Drupal\Tests\system\Functional\Cache\AssertPageCacheContextsAndTagsTrait; /** * Tests the search_page entity cache tags on the search results pages. @@ -11,6 +12,8 @@ */ class SearchPageCacheTagsTest extends SearchTestBase { + use AssertPageCacheContextsAndTagsTrait; + /** * {@inheritdoc} */ @@ -100,8 +103,8 @@ public function testSearchText() { $this->drupalGet('search/user'); $this->assertCacheTag('config:search.page.user_search'); $this->assertCacheTag('user_list'); - $this->assertNoCacheTag('search_index'); - $this->assertNoCacheTag('search_index:user_search'); + $this->assertSession()->responseHeaderNotContains('X-Drupal-Cache-Tags', 'search_index'); + $this->assertSession()->responseHeaderNotContains('X-Drupal-Cache-Tags', 'search_index:user_search'); // User search results. $edit['keys'] = $this->searchingUser->getUsername(); @@ -109,8 +112,8 @@ public function testSearchText() { $this->assertCacheTag('config:search.page.user_search'); $this->assertCacheTag('user_list'); $this->assertCacheTag('user:2'); - $this->assertNoCacheTag('search_index'); - $this->assertNoCacheTag('search_index:user_search'); + $this->assertSession()->responseHeaderNotContains('X-Drupal-Cache-Tags', 'search_index'); + $this->assertSession()->responseHeaderNotContains('X-Drupal-Cache-Tags', 'search_index:user_search'); } /** diff --git a/core/modules/search/src/Tests/SearchPageTextTest.php b/core/modules/search/tests/src/Functional/SearchPageTextTest.php similarity index 97% rename from core/modules/search/src/Tests/SearchPageTextTest.php rename to core/modules/search/tests/src/Functional/SearchPageTextTest.php index 95d097d207ee0e09b115a1559bd0dd288e2e4d5a..184742e3ffc0ffd4916a7df694505820790ad4b8 100644 --- a/core/modules/search/src/Tests/SearchPageTextTest.php +++ b/core/modules/search/tests/src/Functional/SearchPageTextTest.php @@ -1,6 +1,6 @@ <?php -namespace Drupal\search\Tests; +namespace Drupal\Tests\search\Functional; use Drupal\Component\Utility\Html; use Drupal\Component\Utility\Unicode; @@ -90,7 +90,7 @@ public function testSearchText() { $search_terms = 'Hear nothing > "see nothing" `feel' . " '1982."; $edit['keys'] = $search_terms; $this->drupalPostForm('search/node', $edit, t('Search')); - $actual_title = (string) current($this->xpath('//title')); + $actual_title = $this->xpath('//title')[0]->getText(); $this->assertEqual($actual_title, Html::decodeEntities(t($title_source, ['@keywords' => Unicode::truncate($search_terms, 60, TRUE, TRUE)])), 'Search page title is correct'); $edit['keys'] = $this->searchingUser->getUsername(); @@ -133,9 +133,9 @@ public function testSearchText() { // Make sure the "Please enter some keywords" message is NOT displayed if // you use "or" words or phrases in Advanced Search. - $this->drupalPostForm('search/node', ['or' => $this->randomMachineName() . ' ' . $this->randomMachineName()], t('Advanced search')); + $this->drupalPostForm('search/node', ['or' => $this->randomMachineName() . ' ' . $this->randomMachineName()], 'edit-submit--2'); $this->assertNoText(t('Please enter some keywords'), 'With advanced OR keywords entered, no keywords message is not displayed on node page'); - $this->drupalPostForm('search/node', ['phrase' => '"' . $this->randomMachineName() . '" "' . $this->randomMachineName() . '"'], t('Advanced search')); + $this->drupalPostForm('search/node', ['phrase' => '"' . $this->randomMachineName() . '" "' . $this->randomMachineName() . '"'], 'edit-submit--2'); $this->assertNoText(t('Please enter some keywords'), 'With advanced phrase entered, no keywords message is not displayed on node page'); // Verify that if you search for a too-short keyword, you get the right diff --git a/core/modules/search/src/Tests/SearchPreprocessLangcodeTest.php b/core/modules/search/tests/src/Functional/SearchPreprocessLangcodeTest.php similarity index 92% rename from core/modules/search/src/Tests/SearchPreprocessLangcodeTest.php rename to core/modules/search/tests/src/Functional/SearchPreprocessLangcodeTest.php index ab264a1a85b89610f9dee92835606dfcdb863d5b..54779d3b7236ec7867f9d1f6cf5bcbf9ff89c9ec 100644 --- a/core/modules/search/src/Tests/SearchPreprocessLangcodeTest.php +++ b/core/modules/search/tests/src/Functional/SearchPreprocessLangcodeTest.php @@ -1,6 +1,6 @@ <?php -namespace Drupal\search\Tests; +namespace Drupal\Tests\search\Functional; /** * Tests that the search preprocessing uses the correct language code. @@ -54,7 +54,7 @@ public function testPreprocessLangcode() { // function. If you search for text that is in the node, preprocess is // not invoked on the node during the search excerpt generation. $edit = ['or' => 'Additional text']; - $this->drupalPostForm('search/node', $edit, t('Advanced search')); + $this->drupalPostForm('search/node', $edit, 'edit-submit--2'); // Checks if the langcode message has been set by hook_search_preprocess(). $this->assertText('Langcode Preprocess Test: en'); @@ -81,7 +81,7 @@ public function testPreprocessStemming() { // Search for the title of the node with a POST query. $edit = ['or' => 'testing']; - $this->drupalPostForm('search/node', $edit, t('Advanced search')); + $this->drupalPostForm('search/node', $edit, 'edit-submit--2'); // Check if the node has been found. $this->assertText('Search results'); @@ -89,7 +89,7 @@ public function testPreprocessStemming() { // Search for the same node using a different query. $edit = ['or' => 'test']; - $this->drupalPostForm('search/node', $edit, t('Advanced search')); + $this->drupalPostForm('search/node', $edit, 'edit-submit--2'); // Check if the node has been found. $this->assertText('Search results'); diff --git a/core/modules/search/src/Tests/SearchQueryAlterTest.php b/core/modules/search/tests/src/Functional/SearchQueryAlterTest.php similarity index 97% rename from core/modules/search/src/Tests/SearchQueryAlterTest.php rename to core/modules/search/tests/src/Functional/SearchQueryAlterTest.php index 66269dd6c4e5c2c9b48b20589d81e0f95b2857c8..1fcf22e5f5a1124d8bd6cac2e862f33d7ec09880 100644 --- a/core/modules/search/src/Tests/SearchQueryAlterTest.php +++ b/core/modules/search/tests/src/Functional/SearchQueryAlterTest.php @@ -1,6 +1,6 @@ <?php -namespace Drupal\search\Tests; +namespace Drupal\Tests\search\Functional; /** * Tests that the node search query can be altered via the query alter hook. diff --git a/core/modules/search/src/Tests/SearchRankingTest.php b/core/modules/search/tests/src/Functional/SearchRankingTest.php similarity index 98% rename from core/modules/search/src/Tests/SearchRankingTest.php rename to core/modules/search/tests/src/Functional/SearchRankingTest.php index 55da9acbebca7ed48a8503e7f7457189fbb9c460..f7e17c4068f0eb3d332f7fe863f6ad085164688f 100644 --- a/core/modules/search/src/Tests/SearchRankingTest.php +++ b/core/modules/search/tests/src/Functional/SearchRankingTest.php @@ -1,12 +1,13 @@ <?php -namespace Drupal\search\Tests; +namespace Drupal\Tests\search\Functional; use Drupal\comment\Plugin\Field\FieldType\CommentItemInterface; use Drupal\comment\Tests\CommentTestTrait; use Drupal\Core\Url; use Drupal\filter\Entity\FilterFormat; use Drupal\search\Entity\SearchPage; +use Drupal\Tests\Traits\Core\CronRunTrait; /** * Indexes content and tests ranking factors. @@ -16,6 +17,7 @@ class SearchRankingTest extends SearchTestBase { use CommentTestTrait; + use CronRunTrait; /** * The node search page. diff --git a/core/modules/search/tests/src/Functional/SearchTestBase.php b/core/modules/search/tests/src/Functional/SearchTestBase.php index c0557d4164fcdd86279d7233dfc36b873ca550b7..570658de06ac379ec6ac29c4305dd9a21da088fc 100644 --- a/core/modules/search/tests/src/Functional/SearchTestBase.php +++ b/core/modules/search/tests/src/Functional/SearchTestBase.php @@ -3,7 +3,6 @@ namespace Drupal\Tests\search\Functional; use Drupal\Tests\BrowserTestBase; -use Drupal\Component\Render\FormattableMarkup; /** * Defines the common search test code. @@ -28,17 +27,7 @@ protected function setUp() { } /** - * Simulates submission of a form using GET instead of POST. - * - * Forms that use the GET method cannot be submitted with - * WebTestBase::drupalPostForm(), which explicitly uses POST to submit the - * form. So this method finds the form, verifies that it has input fields and - * a submit button matching the inputs to this method, and then calls - * WebTestBase::drupalGet() to simulate the form submission to the 'action' - * URL of the form (if set, or the current URL if not). - * - * See WebTestBase::drupalPostForm() for more detailed documentation of the - * function parameters. + * Submission of a form via press submit button. * * @param string $path * Location of the form to be submitted: either a Drupal path, absolute @@ -51,42 +40,27 @@ protected function setUp() { * this does not support AJAX. * @param string $form_html_id * (optional) HTML ID of the form, to disambiguate. + * + * @throws \Behat\Mink\Exception\ElementNotFoundException + * + * @todo: Replace after https://www.drupal.org/project/drupal/issues/2887411 */ protected function submitGetForm($path, $edit, $submit, $form_html_id = NULL) { if (isset($path)) { $this->drupalGet($path); } - if ($this->parse()) { - // Iterate over forms to find one that matches $edit and $submit. - $edit_save = $edit; - $xpath = '//form'; - if (!empty($form_html_id)) { - $xpath .= "[@id='" . $form_html_id . "']"; - } - $forms = $this->xpath($xpath); - foreach ($forms as $form) { - // Try to set the fields of this form as specified in $edit. - $edit = $edit_save; - $post = []; - $upload = []; - $submit_matches = $this->handleForm($post, $edit, $upload, $submit, $form); - if (!$edit && $submit_matches) { - // Everything matched, so "submit" the form. - $action = isset($form['action']) ? $this->getAbsoluteUrl((string) $form['action']) : NULL; - $this->drupalGet($action, ['query' => $post]); - return; - } - } - - // We have not found a form which contained all fields of $edit and - // the submit button. - foreach ($edit as $name => $value) { - $this->fail(new FormattableMarkup('Failed to set field @name to @value', ['@name' => $name, '@value' => $value])); - } - $this->assertTrue($submit_matches, format_string('Found the @submit button', ['@submit' => $submit])); - $this->fail(format_string('Found the requested form fields at @path', ['@path' => $path])); + $page = $this->getSession()->getPage(); + $wrapper = $page; + if ($form_html_id) { + $wrapper = $page->find('css', '#' . $form_html_id); + } + $button = $wrapper->findButton($submit); + $form = $this->assertSession()->elementExists('xpath', './ancestor::form', $button); + foreach ($edit as $selector => $value) { + $form->fillField($selector, $value); } + $button->press(); } }