Mercurial > hg > isophonics-drupal-site
comparison core/modules/search/tests/src/Functional/SearchTestBase.php @ 17:129ea1e6d783
Update, including to Drupal core 8.6.10
| author | Chris Cannam |
|---|---|
| date | Thu, 28 Feb 2019 13:21:36 +0000 |
| parents | 4c8ae668cc8c |
| children |
comparison
equal
deleted
inserted
replaced
| 16:c2387f117808 | 17:129ea1e6d783 |
|---|---|
| 1 <?php | 1 <?php |
| 2 | 2 |
| 3 namespace Drupal\Tests\search\Functional; | 3 namespace Drupal\Tests\search\Functional; |
| 4 | 4 |
| 5 @trigger_error(__NAMESPACE__ . '\SearchTestBase is deprecated in Drupal 8.6.x and will be removed before Drupal 9.0.0. Instead, use \Drupal\Tests\BrowserTestBase. See https://www.drupal.org/node/2979950.', E_USER_DEPRECATED); | |
| 6 | |
| 5 use Drupal\Tests\BrowserTestBase; | 7 use Drupal\Tests\BrowserTestBase; |
| 6 use Drupal\Component\Utility\SafeMarkup; | |
| 7 | 8 |
| 8 /** | 9 /** |
| 9 * Defines the common search test code. | 10 * Defines the common search test code. |
| 11 * | |
| 12 * @deprecated in Drupal 8.6.0 and will be removed in Drupal 9.0.0. Use | |
| 13 * \Drupal\Tests\BrowserTestBase instead. | |
| 14 * | |
| 15 * @see https://www.drupal.org/node/2979950 | |
| 10 */ | 16 */ |
| 11 abstract class SearchTestBase extends BrowserTestBase { | 17 abstract class SearchTestBase extends BrowserTestBase { |
| 12 | 18 |
| 13 /** | 19 /** |
| 14 * Modules to enable. | 20 * Modules to enable. |
| 26 $this->drupalCreateContentType(['type' => 'article', 'name' => 'Article']); | 32 $this->drupalCreateContentType(['type' => 'article', 'name' => 'Article']); |
| 27 } | 33 } |
| 28 } | 34 } |
| 29 | 35 |
| 30 /** | 36 /** |
| 31 * Simulates submission of a form using GET instead of POST. | 37 * Submission of a form via press submit button. |
| 32 * | |
| 33 * Forms that use the GET method cannot be submitted with | |
| 34 * WebTestBase::drupalPostForm(), which explicitly uses POST to submit the | |
| 35 * form. So this method finds the form, verifies that it has input fields and | |
| 36 * a submit button matching the inputs to this method, and then calls | |
| 37 * WebTestBase::drupalGet() to simulate the form submission to the 'action' | |
| 38 * URL of the form (if set, or the current URL if not). | |
| 39 * | |
| 40 * See WebTestBase::drupalPostForm() for more detailed documentation of the | |
| 41 * function parameters. | |
| 42 * | 38 * |
| 43 * @param string $path | 39 * @param string $path |
| 44 * Location of the form to be submitted: either a Drupal path, absolute | 40 * Location of the form to be submitted: either a Drupal path, absolute |
| 45 * path, or NULL to use the current page. | 41 * path, or NULL to use the current page. |
| 46 * @param array $edit | 42 * @param array $edit |
| 49 * @param string $submit | 45 * @param string $submit |
| 50 * Value of the submit button to submit clicking. Unlike drupalPostForm(), | 46 * Value of the submit button to submit clicking. Unlike drupalPostForm(), |
| 51 * this does not support AJAX. | 47 * this does not support AJAX. |
| 52 * @param string $form_html_id | 48 * @param string $form_html_id |
| 53 * (optional) HTML ID of the form, to disambiguate. | 49 * (optional) HTML ID of the form, to disambiguate. |
| 50 * | |
| 51 * @deprecated in Drupal 8.6.x, to be removed before Drupal 9.0.x. Use | |
| 52 * \Drupal\Tests\BrowserTestBase::drupalPostForm() instead. | |
| 53 * | |
| 54 * @see https://www.drupal.org/node/2979950 | |
| 54 */ | 55 */ |
| 55 protected function submitGetForm($path, $edit, $submit, $form_html_id = NULL) { | 56 protected function submitGetForm($path, $edit, $submit, $form_html_id = NULL) { |
| 56 if (isset($path)) { | 57 @trigger_error(__CLASS__ . '::' . __FUNCTION__ . '() is deprecated in Drupal 8.6.x, for removal before the Drupal 9.0.0 release. Use \Drupal\Tests\BrowserTestBase::drupalPostForm() instead. See https://www.drupal.org/node/2979950.', E_USER_DEPRECATED); |
| 57 $this->drupalGet($path); | 58 $this->drupalPostForm($path, $edit, $submit, [], $form_html_id); |
| 58 } | |
| 59 | |
| 60 if ($this->parse()) { | |
| 61 // Iterate over forms to find one that matches $edit and $submit. | |
| 62 $edit_save = $edit; | |
| 63 $xpath = '//form'; | |
| 64 if (!empty($form_html_id)) { | |
| 65 $xpath .= "[@id='" . $form_html_id . "']"; | |
| 66 } | |
| 67 $forms = $this->xpath($xpath); | |
| 68 foreach ($forms as $form) { | |
| 69 // Try to set the fields of this form as specified in $edit. | |
| 70 $edit = $edit_save; | |
| 71 $post = []; | |
| 72 $upload = []; | |
| 73 $submit_matches = $this->handleForm($post, $edit, $upload, $submit, $form); | |
| 74 if (!$edit && $submit_matches) { | |
| 75 // Everything matched, so "submit" the form. | |
| 76 $action = isset($form['action']) ? $this->getAbsoluteUrl((string) $form['action']) : NULL; | |
| 77 $this->drupalGet($action, ['query' => $post]); | |
| 78 return; | |
| 79 } | |
| 80 } | |
| 81 | |
| 82 // We have not found a form which contained all fields of $edit and | |
| 83 // the submit button. | |
| 84 foreach ($edit as $name => $value) { | |
| 85 $this->fail(SafeMarkup::format('Failed to set field @name to @value', ['@name' => $name, '@value' => $value])); | |
| 86 } | |
| 87 $this->assertTrue($submit_matches, format_string('Found the @submit button', ['@submit' => $submit])); | |
| 88 $this->fail(format_string('Found the requested form fields at @path', ['@path' => $path])); | |
| 89 } | |
| 90 } | 59 } |
| 91 | 60 |
| 92 } | 61 } |
