From 93118e02f5d343bd490c6c28038fca017f843193 Mon Sep 17 00:00:00 2001 From: GoZ Date: Sat, 25 Mar 2017 11:39:36 +0100 Subject: [PATCH] Issue #2863842: Convert web tests to browser tests for search module --- .../src/Functional}/SearchAdvancedSearchFormTest.php | 18 +++++++++--------- .../src/Functional}/SearchCommentTest.php | 12 ++++++------ .../src/Functional}/SearchEmbedFormTest.php | 2 +- .../src/Functional}/SearchLanguageTest.php | 8 ++++---- .../Functional}/SearchNodeUpdateAndDeletionTest.php | 2 +- .../src/Functional}/SearchNumberMatchingTest.php | 6 +++++- .../src/Functional}/SearchNumbersTest.php | 6 +++++- .../src/Functional}/SearchPageCacheTagsTest.php | 5 ++++- .../src/Functional}/SearchPageTextTest.php | 8 ++++---- .../src/Functional}/SearchPreprocessLangcodeTest.php | 8 ++++---- .../src/Functional}/SearchQueryAlterTest.php | 2 +- .../src/Functional}/SearchRankingTest.php | 4 +++- .../tests/Drupal/FunctionalTests/AssertLegacyTrait.php | 14 ++++++++++++++ 13 files changed, 61 insertions(+), 34 deletions(-) rename core/modules/search/{src/Tests => tests/src/Functional}/SearchAdvancedSearchFormTest.php (85%) rename core/modules/search/{src/Tests => tests/src/Functional}/SearchCommentTest.php (96%) rename core/modules/search/{src/Tests => tests/src/Functional}/SearchEmbedFormTest.php (98%) rename core/modules/search/{src/Tests => tests/src/Functional}/SearchLanguageTest.php (95%) rename core/modules/search/{src/Tests => tests/src/Functional}/SearchNodeUpdateAndDeletionTest.php (98%) rename core/modules/search/{src/Tests => tests/src/Functional}/SearchNumberMatchingTest.php (96%) rename core/modules/search/{src/Tests => tests/src/Functional}/SearchNumbersTest.php (96%) rename core/modules/search/{src/Tests => tests/src/Functional}/SearchPageCacheTagsTest.php (97%) rename core/modules/search/{src/Tests => tests/src/Functional}/SearchPageTextTest.php (97%) rename core/modules/search/{src/Tests => tests/src/Functional}/SearchPreprocessLangcodeTest.php (92%) rename core/modules/search/{src/Tests => tests/src/Functional}/SearchQueryAlterTest.php (97%) rename core/modules/search/{src/Tests => tests/src/Functional}/SearchRankingTest.php (98%) 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 ad00b52..29c3817 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 @@ 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/SearchCommentTest.php b/core/modules/search/tests/src/Functional/SearchCommentTest.php similarity index 96% rename from core/modules/search/src/Tests/SearchCommentTest.php rename to core/modules/search/tests/src/Functional/SearchCommentTest.php index 7047429..a3f4e83 100644 --- a/core/modules/search/src/Tests/SearchCommentTest.php +++ b/core/modules/search/tests/src/Functional/SearchCommentTest.php @@ -1,10 +1,11 @@ drupalPostForm('search/node', $edit, t('Search')); if ($assume_access) { - $expected_node_result = $this->assertText($this->node->label()); - $expected_comment_result = $this->assertText($this->commentSubject); + $this->assertSession()->pageTextContains($this->node->label()); + $this->assertSession()->pageTextContains($this->commentSubject); } else { - $expected_node_result = $this->assertText(t('Your search yielded no results.')); - $expected_comment_result = $this->assertText(t('Your search yielded no results.')); + $this->assertSession()->pageTextContains(t('Your search yielded no results.')); } - $this->assertTrue($expected_node_result && $expected_comment_result, $message); } /** 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 5f3fbea..89f0d0d 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 @@ 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 9b86052..a2cdd8c 100644 --- a/core/modules/search/src/Tests/SearchNodeUpdateAndDeletionTest.php +++ b/core/modules/search/tests/src/Functional/SearchNodeUpdateAndDeletionTest.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 @@ 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 ab264a1..54779d3 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 @@ 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 66269dd..1fcf22e 100644 --- a/core/modules/search/src/Tests/SearchQueryAlterTest.php +++ b/core/modules/search/tests/src/Functional/SearchQueryAlterTest.php @@ -1,6 +1,6 @@ assertSession()->responseHeaderNotContains() instead. + */ + protected function assertNoCacheTag($cache_tag) { + @trigger_error('assertNoCacheTag() is deprecated and will be removed before Drupal 9.0.0. Please use $this->assertSession()->responseHeaderNotContains() instead.', E_USER_DEPRECATED); + $this->assertSession()->responseHeaderNotContains('X-Drupal-Cache-Tags', $cache_tag); + } + + /** * Checks that current response header equals value. * * @param string $name -- 2.8.1