3 namespace Drupal\search\Tests;
5 use Drupal\simpletest\WebTestBase;
6 use Drupal\Component\Render\FormattableMarkup;
9 * Defines the common search test code.
11 * @deprecated Scheduled for removal in Drupal 9.0.0.
12 * Use \Drupal\Tests\search\Functional\SearchTestBase instead.
14 abstract class SearchTestBase extends WebTestBase {
21 public static $modules = ['node', 'search', 'dblog'];
23 protected function setUp() {
26 // Create Basic page and Article node types.
27 if ($this->profile != 'standard') {
28 $this->drupalCreateContentType(['type' => 'page', 'name' => 'Basic page']);
29 $this->drupalCreateContentType(['type' => 'article', 'name' => 'Article']);
34 * Simulates submission of a form using GET instead of POST.
36 * Forms that use the GET method cannot be submitted with
37 * WebTestBase::drupalPostForm(), which explicitly uses POST to submit the
38 * form. So this method finds the form, verifies that it has input fields and
39 * a submit button matching the inputs to this method, and then calls
40 * WebTestBase::drupalGet() to simulate the form submission to the 'action'
41 * URL of the form (if set, or the current URL if not).
43 * See WebTestBase::drupalPostForm() for more detailed documentation of the
44 * function parameters.
47 * Location of the form to be submitted: either a Drupal path, absolute
48 * path, or NULL to use the current page.
50 * Form field data to submit. Unlike drupalPostForm(), this does not support
52 * @param string $submit
53 * Value of the submit button to submit clicking. Unlike drupalPostForm(),
54 * this does not support AJAX.
55 * @param string $form_html_id
56 * (optional) HTML ID of the form, to disambiguate.
58 protected function submitGetForm($path, $edit, $submit, $form_html_id = NULL) {
60 $this->drupalGet($path);
64 // Iterate over forms to find one that matches $edit and $submit.
67 if (!empty($form_html_id)) {
68 $xpath .= "[@id='" . $form_html_id . "']";
70 $forms = $this->xpath($xpath);
71 foreach ($forms as $form) {
72 // Try to set the fields of this form as specified in $edit.
76 $submit_matches = $this->handleForm($post, $edit, $upload, $submit, $form);
77 if (!$edit && $submit_matches) {
78 // Everything matched, so "submit" the form.
79 $action = isset($form['action']) ? $this->getAbsoluteUrl((string) $form['action']) : NULL;
80 $this->drupalGet($action, ['query' => $post]);
85 // We have not found a form which contained all fields of $edit and
87 foreach ($edit as $name => $value) {
88 $this->fail(new FormattableMarkup('Failed to set field @name to @value', ['@name' => $name, '@value' => $value]));
90 $this->assertTrue($submit_matches, format_string('Found the @submit button', ['@submit' => $submit]));
91 $this->fail(format_string('Found the requested form fields at @path', ['@path' => $path]));