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 ad00b5252f6a..29c3817a72e5 100644 --- a/core/modules/search/src/Tests/SearchAdvancedSearchFormTest.php +++ b/core/modules/search/tests/src/Functional/SearchAdvancedSearchFormTest.php @@ -1,6 +1,6 @@ $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 @@ class SearchAdvancedSearchFormTest extends SearchTestBase { '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 @@ class SearchAdvancedSearchFormTest extends SearchTestBase { 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 @@ class SearchAdvancedSearchFormTest extends SearchTestBase { // 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 21afda7f05f5..3c6b746017d6 100644 --- a/core/modules/search/src/Tests/SearchBlockTest.php +++ b/core/modules/search/tests/src/Functional/SearchBlockTest.php @@ -1,6 +1,6 @@ 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 704742925216..23167edb2328 100644 --- a/core/modules/search/src/Tests/SearchCommentTest.php +++ b/core/modules/search/tests/src/Functional/SearchCommentTest.php @@ -1,10 +1,12 @@ 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 b081b857d0a4..f404f8f1335c 100644 --- a/core/modules/search/src/Tests/SearchConfigSettingsFormTest.php +++ b/core/modules/search/tests/src/Functional/SearchConfigSettingsFormTest.php @@ -1,6 +1,6 @@ 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 @@ class SearchConfigSettingsFormTest extends SearchTestBase { // 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 @@ class SearchConfigSettingsFormTest extends SearchTestBase { $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 5f3fbea32b3b..89f0d0d39fb7 100644 --- a/core/modules/search/src/Tests/SearchEmbedFormTest.php +++ b/core/modules/search/tests/src/Functional/SearchEmbedFormTest.php @@ -1,6 +1,6 @@ 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 @@ class SearchLanguageTest extends SearchTestBase { // 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 c19814e0263b..0e9d35890c7d 100644 --- a/core/modules/search/src/Tests/SearchNodeUpdateAndDeletionTest.php +++ b/core/modules/search/tests/src/Functional/SearchNodeUpdateAndDeletionTest.php @@ -1,6 +1,6 @@ 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 @@ class SearchPageCacheTagsTest extends SearchTestBase { $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 95d097d207ee..184742e3ffc0 100644 --- a/core/modules/search/src/Tests/SearchPageTextTest.php +++ b/core/modules/search/tests/src/Functional/SearchPageTextTest.php @@ -1,6 +1,6 @@ "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 @@ class SearchPageTextTest extends SearchTestBase { // 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 ab264a1a85b8..54779d3b7236 100644 --- a/core/modules/search/src/Tests/SearchPreprocessLangcodeTest.php +++ b/core/modules/search/tests/src/Functional/SearchPreprocessLangcodeTest.php @@ -1,6 +1,6 @@ '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 @@ class SearchPreprocessLangcodeTest extends SearchTestBase { // 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 @@ class SearchPreprocessLangcodeTest extends SearchTestBase { // 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 66269dd6c4e5..1fcf22e5f5a1 100644 --- a/core/modules/search/src/Tests/SearchQueryAlterTest.php +++ b/core/modules/search/tests/src/Functional/SearchQueryAlterTest.php @@ -1,6 +1,6 @@ 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(); } }