Issue #3275843 by danflanagan8, smustgrave: Search Tests should not rely on Classy

(cherry picked from commit f40b8e85f7)
(cherry picked from commit 98df5e4e9e)
merge-requests/2585/head
Lauri Eskola 2022-08-03 16:08:28 +03:00
parent 0f3708a104
commit 16d5d4287f
No known key found for this signature in database
GPG Key ID: 382FC0F5B0DF53F8
4 changed files with 33 additions and 32 deletions

View File

@ -20,7 +20,7 @@ class SearchBlockTest extends BrowserTestBase {
/**
* {@inheritdoc}
*/
protected $defaultTheme = 'classy';
protected $defaultTheme = 'stark';
/**
* The administrative user.
@ -53,7 +53,7 @@ class SearchBlockTest extends BrowserTestBase {
// Test availability of the search block in the admin "Place blocks" list.
$this->drupalGet('admin/structure/block');
$this->getSession()->getPage()->findLink('Place block')->click();
$this->assertSession()->linkByHrefExists('/admin/structure/block/add/search_form_block/classy', 0,
$this->assertSession()->linkByHrefExists('/admin/structure/block/add/search_form_block/stark', 0,
'Did not find the search block in block candidate list.');
$block = $this->drupalPlaceBlock('search_form_block');
@ -104,7 +104,7 @@ class SearchBlockTest extends BrowserTestBase {
$this->drupalGet('');
$this->submitForm($terms, 'Search');
$this->assertSession()->statusCodeEquals(200);
$this->assertSession()->pageTextContains('Please enter some keywords');
$this->assertSession()->statusMessageContains('Please enter some keywords', 'error');
// Confirm that the user is redirected to the search page, when form is
// submitted empty.
@ -118,17 +118,17 @@ class SearchBlockTest extends BrowserTestBase {
// search again with a longer keyword. First test using the block form.
$this->drupalGet('node');
$this->submitForm(['keys' => $this->randomMachineName(1)], 'Search');
$this->assertSession()->pageTextContains('You must include at least one keyword to match in the content');
$this->assertSession()->pageTextNotContains('Please enter some keywords');
$this->assertSession()->statusMessageContains('You must include at least one keyword to match in the content', 'warning');
$this->assertSession()->statusMessageNotContains('Please enter some keywords');
$this->submitForm(['keys' => $this->randomMachineName()], 'Search', 'search-block-form');
$this->assertSession()->pageTextNotContains('You must include at least one keyword to match in the content');
$this->assertSession()->statusMessageNotContains('You must include at least one keyword to match in the content');
// Same test again, using the search page form for the second search this
// time.
$this->drupalGet('node');
$this->submitForm(['keys' => $this->randomMachineName(1)], 'Search');
$this->submitForm(['keys' => $this->randomMachineName()], 'Search', 'search-form');
$this->assertSession()->pageTextNotContains('You must include at least one keyword to match in the content');
$this->assertSession()->statusMessageNotContains('You must include at least one keyword to match in the content');
// Edit the block configuration so that it searches users instead of nodes,
// and test.

View File

@ -29,7 +29,7 @@ class SearchConfigSettingsFormTest extends BrowserTestBase {
/**
* {@inheritdoc}
*/
protected $defaultTheme = 'classy';
protected $defaultTheme = 'stark';
/**
* User who can search and administer search.
@ -77,7 +77,7 @@ class SearchConfigSettingsFormTest extends BrowserTestBase {
// Enable the search block.
$this->drupalPlaceBlock('search_form_block');
$this->drupalPlaceBlock('local_tasks_block');
$this->drupalPlaceBlock('local_tasks_block', ['id' => 'local_tasks']);
$this->drupalPlaceBlock('page_title_block');
}
@ -96,14 +96,14 @@ class SearchConfigSettingsFormTest extends BrowserTestBase {
$this->assertSession()->pageTextContains('Are you sure you want to re-index the site');
$this->drupalGet('admin/config/search/pages/reindex');
$this->submitForm([], 'Re-index site');
$this->assertSession()->pageTextContains('All search indexes will be rebuilt');
$this->assertSession()->statusMessageContains('All search indexes will be rebuilt', 'status');
$this->drupalGet('admin/config/search/pages');
$this->assertSession()->pageTextContains('There is 1 item left to index.');
// Test that the form saves with the default values.
$this->drupalGet('admin/config/search/pages');
$this->submitForm([], 'Save configuration');
$this->assertSession()->pageTextContains('The configuration options have been saved.');
$this->assertSession()->statusMessageContains('The configuration options have been saved.', 'status');
// Test that the form does not save with an invalid word length.
$edit = [
@ -111,7 +111,8 @@ class SearchConfigSettingsFormTest extends BrowserTestBase {
];
$this->drupalGet('admin/config/search/pages');
$this->submitForm($edit, 'Save configuration');
$this->assertSession()->pageTextNotContains('The configuration options have been saved.');
$this->assertSession()->statusMessageNotContains('The configuration options have been saved.');
$this->assertSession()->statusMessageContains('Minimum word length to index must be a number.', 'error');
// Test logging setting. It should be off by default.
$text = $this->randomMachineName(5);
@ -149,7 +150,7 @@ class SearchConfigSettingsFormTest extends BrowserTestBase {
$this->submitForm($edit, 'Save search page');
// Ensure that the modifications took effect.
$this->assertSession()->pageTextContains("The Dummy search type search page has been updated.");
$this->assertSession()->statusMessageContains("The Dummy search type search page has been updated.", 'status');
$this->drupalGet('admin/config/search/pages/manage/dummy_search_type');
$this->assertTrue($this->assertSession()->optionExists('edit-extra-type-settings-boost', 'ii')->isSelected());
}
@ -197,7 +198,7 @@ class SearchConfigSettingsFormTest extends BrowserTestBase {
foreach ($plugins as $other) {
if ($other != $entity_id) {
$path = 'search/' . $entities[$other]->getPath();
$this->assertSession()->elementNotExists('xpath', '//ul[@class="tabs primary"]/li/a[@data-drupal-link-system-path="' . $path . '"]');
$this->assertSession()->elementNotExists('xpath', '//div[@id="block-local-tasks"]//li/a[@data-drupal-link-system-path="' . $path . '"]');
}
}
@ -238,7 +239,7 @@ class SearchConfigSettingsFormTest extends BrowserTestBase {
foreach ($plugins as $entity_id) {
$path = 'search/' . $entities[$entity_id]->getPath();
$label = $entities[$entity_id]->label();
$this->assertSession()->elementTextContains('xpath', '//ul[@class="tabs primary"]/li/a[@data-drupal-link-system-path="' . $path . '"]', $label);
$this->assertSession()->elementTextContains('xpath', '//div[@id="block-local-tasks"]//li/a[@data-drupal-link-system-path="' . $path . '"]', $label);
}
}
}
@ -248,7 +249,7 @@ class SearchConfigSettingsFormTest extends BrowserTestBase {
*/
public function testDefaultSearchPageOrdering() {
$this->drupalGet('search');
$elements = $this->xpath('//*[contains(@class, :class)]//a', [':class' => 'tabs primary']);
$elements = $this->xpath('//div[@id="block-local-tasks"]//a');
$this->assertSame(Url::fromRoute('search.view_node_search')->toString(), $elements[0]->getAttribute('href'));
$this->assertSame(Url::fromRoute('search.view_dummy_search_type')->toString(), $elements[1]->getAttribute('href'));
$this->assertSame(Url::fromRoute('search.view_user_search')->toString(), $elements[2]->getAttribute('href'));
@ -280,7 +281,7 @@ class SearchConfigSettingsFormTest extends BrowserTestBase {
$first['path'] = strtolower($this->randomMachineName(8));
$this->submitForm($first, 'Save');
$this->assertDefaultSearch($first_id, 'The default page matches the only search page.');
$this->assertSession()->pageTextContains("The {$first['label']} search page has been added.");
$this->assertSession()->statusMessageContains("The {$first['label']} search page has been added.", 'status');
// Attempt to add a search page with an existing path.
$edit = [];
@ -291,7 +292,7 @@ class SearchConfigSettingsFormTest extends BrowserTestBase {
$edit['id'] = strtolower($this->randomMachineName(8));
$edit['path'] = $first['path'];
$this->submitForm($edit, 'Save');
$this->assertSession()->pageTextContains('The search page path must be unique.');
$this->assertSession()->statusMessageContains('The search page path must be unique.', 'error');
// Add a second search page.
$second = [];
@ -303,7 +304,7 @@ class SearchConfigSettingsFormTest extends BrowserTestBase {
// Ensure both search pages have their tabs displayed.
$this->drupalGet('search');
$elements = $this->xpath('//*[contains(@class, :class)]//a', [':class' => 'tabs primary']);
$elements = $this->xpath('//div[@id="block-local-tasks"]//a');
$this->assertSame(Url::fromRoute('search.view_' . $first_id)->toString(), $elements[0]->getAttribute('href'));
$this->assertSame(Url::fromRoute('search.view_' . $second_id)->toString(), $elements[1]->getAttribute('href'));
@ -315,7 +316,7 @@ class SearchConfigSettingsFormTest extends BrowserTestBase {
$this->drupalGet('admin/config/search/pages');
$this->submitForm($edit, 'Save configuration');
$this->drupalGet('search');
$elements = $this->xpath('//*[contains(@class, :class)]//a', [':class' => 'tabs primary']);
$elements = $this->xpath('//div[@id="block-local-tasks"]//a');
$this->assertSame(Url::fromRoute('search.view_' . $second_id)->toString(), $elements[0]->getAttribute('href'));
$this->assertSame(Url::fromRoute('search.view_' . $first_id)->toString(), $elements[1]->getAttribute('href'));
@ -326,7 +327,7 @@ class SearchConfigSettingsFormTest extends BrowserTestBase {
// Change the default search page.
$this->clickLink('Set as default');
$this->assertSession()->pageTextContains("The default search page is now {$second['label']}. Be sure to check the ordering of your search pages.");
$this->assertSession()->statusMessageContains("The default search page is now {$second['label']}. Be sure to check the ordering of your search pages.", 'status');
$this->verifySearchPageOperations($first_id, TRUE, TRUE, TRUE, FALSE);
$this->verifySearchPageOperations($second_id, TRUE, FALSE, FALSE, FALSE);
@ -347,7 +348,7 @@ class SearchConfigSettingsFormTest extends BrowserTestBase {
$this->clickLink('Delete');
$this->assertSession()->pageTextContains("Are you sure you want to delete the search page {$first['label']}?");
$this->submitForm([], 'Delete');
$this->assertSession()->pageTextContains("The search page {$first['label']} has been deleted.");
$this->assertSession()->statusMessageContains("The search page {$first['label']} has been deleted.", 'status');
$this->verifySearchPageOperations($first_id, FALSE, FALSE, FALSE, FALSE);
}

View File

@ -73,13 +73,13 @@ class SearchNodePunctuationTest extends BrowserTestBase {
$this->drupalGet('search/node');
$this->submitForm($edit, 'Search');
$this->assertSession()->responseNotContains('<strong>&</strong>amp;');
$this->assertSession()->pageTextContains('You must include at least one keyword');
$this->assertSession()->statusMessageContains('You must include at least one keyword', 'warning');
$edit = ['keys' => '&amp;'];
$this->drupalGet('search/node');
$this->submitForm($edit, 'Search');
$this->assertSession()->responseNotContains('<strong>&</strong>amp;');
$this->assertSession()->pageTextContains('You must include at least one keyword');
$this->assertSession()->statusMessageContains('You must include at least one keyword', 'warning');
}
}

View File

@ -135,16 +135,16 @@ class SearchPageTextTest extends BrowserTestBase {
$edit['keys'] = implode(' ', $keys);
$this->drupalGet('search/node');
$this->submitForm($edit, 'Search');
$this->assertSession()->pageTextContains("Your search used too many AND/OR expressions. Only the first {$limit} terms were included in this search.");
$this->assertSession()->statusMessageContains("Your search used too many AND/OR expressions. Only the first {$limit} terms were included in this search.", 'warning');
// Test that a search on Node or User with no keywords entered generates
// the "Please enter some keywords" message.
$this->drupalGet('search/node');
$this->submitForm([], 'Search');
$this->assertSession()->pageTextContains('Please enter some keywords');
$this->assertSession()->statusMessageContains('Please enter some keywords', 'error');
$this->drupalGet('search/user');
$this->submitForm([], 'Search');
$this->assertSession()->pageTextContains('Please enter some keywords');
$this->assertSession()->statusMessageContains('Please enter some keywords', 'error');
// Make sure the "Please enter some keywords" message is NOT displayed if
// you use "or" words or phrases in Advanced Search.
@ -152,22 +152,22 @@ class SearchPageTextTest extends BrowserTestBase {
$this->submitForm([
'or' => $this->randomMachineName() . ' ' . $this->randomMachineName(),
], 'edit-submit--2');
$this->assertSession()->pageTextNotContains('Please enter some keywords');
$this->assertSession()->statusMessageNotContains('Please enter some keywords');
$this->drupalGet('search/node');
$this->submitForm([
'phrase' => '"' . $this->randomMachineName() . '" "' . $this->randomMachineName() . '"',
], 'edit-submit--2');
$this->assertSession()->pageTextNotContains('Please enter some keywords');
$this->assertSession()->statusMessageNotContains('Please enter some keywords');
// Verify that if you search for a too-short keyword, you get the right
// message, and that if after that you search for a longer keyword, you
// do not still see the message.
$this->drupalGet('search/node');
$this->submitForm(['keys' => $this->randomMachineName(1)], 'Search');
$this->assertSession()->pageTextContains('You must include at least one keyword');
$this->assertSession()->pageTextNotContains('Please enter some keywords');
$this->assertSession()->statusMessageContains('You must include at least one keyword', 'warning');
$this->assertSession()->statusMessageNotContains('Please enter some keywords');
$this->submitForm(['keys' => $this->randomMachineName()], 'Search');
$this->assertSession()->pageTextNotContains('You must include at least one keyword');
$this->assertSession()->statusMessageNotContains('You must include at least one keyword');
// Test that if you search for a URL with .. in it, you still end up at
// the search page. See issue https://www.drupal.org/node/890058.