summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlex Pott2018-06-17 13:51:28 (GMT)
committerAlex Pott2018-06-17 13:51:28 (GMT)
commit396936c4560c3cb66e4cf3cd988ff0600b7a4f54 (patch)
tree8c3a83db983a7393f6d27b0942b3819240deb067
parentb263f5c4d0639cab997a417e5a2b81ebd0e9a998 (diff)
Issue #2887411 by vaplas, naveenvalecha, larowlan, dawehner, Lendude, borisson_: Add $form_html_id to drupalPostForm in BrowserTestBase and convert SearchAdvancedSearchFormTest from WTB to BTBHEAD8.6.x
-rw-r--r--core/modules/search/tests/src/Functional/SearchBlockTest.php16
-rw-r--r--core/modules/search/tests/src/Functional/SearchConfigSettingsFormTest.php2
-rw-r--r--core/modules/search/tests/src/Functional/SearchTestBase.php22
-rw-r--r--core/tests/Drupal/FunctionalTests/BrowserTestBaseTest.php11
-rw-r--r--core/tests/Drupal/Tests/BrowserTestBase.php13
5 files changed, 34 insertions, 30 deletions
diff --git a/core/modules/search/tests/src/Functional/SearchBlockTest.php b/core/modules/search/tests/src/Functional/SearchBlockTest.php
index 3c6b746..49427b2 100644
--- a/core/modules/search/tests/src/Functional/SearchBlockTest.php
+++ b/core/modules/search/tests/src/Functional/SearchBlockTest.php
@@ -47,14 +47,14 @@ class SearchBlockTest extends SearchTestBase {
// Test a normal search via the block form, from the front page.
$terms = ['keys' => 'test'];
- $this->submitGetForm('', $terms, t('Search'));
+ $this->drupalPostForm('', $terms, t('Search'));
$this->assertResponse(200);
$this->assertText('Your search yielded no results');
// Test a search from the block on a 404 page.
$this->drupalGet('foo');
$this->assertResponse(404);
- $this->submitGetForm(NULL, $terms, t('Search'));
+ $this->drupalPostForm(NULL, $terms, t('Search'));
$this->assertResponse(200);
$this->assertText('Your search yielded no results');
@@ -62,7 +62,7 @@ class SearchBlockTest extends SearchTestBase {
$visibility['request_path']['pages'] = 'search';
$block->setVisibilityConfig('request_path', $visibility['request_path']);
- $this->submitGetForm('', $terms, t('Search'));
+ $this->drupalPostForm('', $terms, t('Search'));
$this->assertResponse(200);
$this->assertText('Your search yielded no results');
@@ -78,7 +78,7 @@ class SearchBlockTest extends SearchTestBase {
// Test an empty search via the block form, from the front page.
$terms = ['keys' => ''];
- $this->submitGetForm('', $terms, t('Search'));
+ $this->drupalPostForm('', $terms, t('Search'));
$this->assertResponse(200);
$this->assertText('Please enter some keywords');
@@ -92,16 +92,16 @@ class SearchBlockTest extends SearchTestBase {
// Test that after entering a too-short keyword in the form, you can then
// search again with a longer keyword. First test using the block form.
- $this->submitGetForm('node', ['keys' => $this->randomMachineName(1)], t('Search'));
+ $this->drupalPostForm('node', ['keys' => $this->randomMachineName(1)], t('Search'));
$this->assertText('You must include at least one keyword to match in the content', 'Keyword message is displayed when searching for short word');
$this->assertNoText(t('Please enter some keywords'), 'With short word entered, no keywords message is not displayed');
- $this->submitGetForm(NULL, ['keys' => $this->randomMachineName()], t('Search'), 'search-block-form');
+ $this->drupalPostForm(NULL, ['keys' => $this->randomMachineName()], t('Search'), [], 'search-block-form');
$this->assertNoText('You must include at least one keyword to match in the content', 'Keyword message is not displayed when searching for long word after short word search');
// Same test again, using the search page form for the second search this
// time.
- $this->submitGetForm('node', ['keys' => $this->randomMachineName(1)], t('Search'));
- $this->drupalPostForm(NULL, ['keys' => $this->randomMachineName()], t('Search'), [], [], 'search-form');
+ $this->drupalPostForm('node', ['keys' => $this->randomMachineName(1)], t('Search'));
+ $this->drupalPostForm(NULL, ['keys' => $this->randomMachineName()], t('Search'), [], 'search-form');
$this->assertNoText('You must include at least one keyword to match in the content', 'Keyword message is not displayed when searching for long word after short word search');
}
diff --git a/core/modules/search/tests/src/Functional/SearchConfigSettingsFormTest.php b/core/modules/search/tests/src/Functional/SearchConfigSettingsFormTest.php
index f404f8f..2692a37 100644
--- a/core/modules/search/tests/src/Functional/SearchConfigSettingsFormTest.php
+++ b/core/modules/search/tests/src/Functional/SearchConfigSettingsFormTest.php
@@ -174,7 +174,7 @@ class SearchConfigSettingsFormTest extends SearchTestBase {
// Run a search from the search block on the node page. Verify you get
// to this plugin's search results page.
$terms = ['keys' => $info['keys']];
- $this->submitGetForm('node', $terms, t('Search'));
+ $this->drupalPostForm('node', $terms, t('Search'));
$current = $this->getURL();
$expected = \Drupal::url('search.view_' . $entity->id(), [], ['query' => ['keys' => $info['keys']], 'absolute' => TRUE]);
$this->assertEqual($current, $expected, 'Block redirected to right search page');
diff --git a/core/modules/search/tests/src/Functional/SearchTestBase.php b/core/modules/search/tests/src/Functional/SearchTestBase.php
index 570658d..e426a92 100644
--- a/core/modules/search/tests/src/Functional/SearchTestBase.php
+++ b/core/modules/search/tests/src/Functional/SearchTestBase.php
@@ -41,26 +41,14 @@ abstract class SearchTestBase extends BrowserTestBase {
* @param string $form_html_id
* (optional) HTML ID of the form, to disambiguate.
*
- * @throws \Behat\Mink\Exception\ElementNotFoundException
+ * @deprecated in Drupal 8.6.x, to be removed before Drupal 9.0.x. Use
+ * \Drupal\Tests\BrowserTestBase::drupalPostForm() instead.
*
- * @todo: Replace after https://www.drupal.org/project/drupal/issues/2887411
+ * @see https://www.drupal.org/node/2979950
*/
protected function submitGetForm($path, $edit, $submit, $form_html_id = NULL) {
- if (isset($path)) {
- $this->drupalGet($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();
+ @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);
+ $this->drupalPostForm($path, $edit, $submit, [], $form_html_id);
}
}
diff --git a/core/tests/Drupal/FunctionalTests/BrowserTestBaseTest.php b/core/tests/Drupal/FunctionalTests/BrowserTestBaseTest.php
index 2e8562b..92a0002 100644
--- a/core/tests/Drupal/FunctionalTests/BrowserTestBaseTest.php
+++ b/core/tests/Drupal/FunctionalTests/BrowserTestBaseTest.php
@@ -23,7 +23,7 @@ class BrowserTestBaseTest extends BrowserTestBase {
*
* @var array
*/
- public static $modules = ['test_page_test', 'form_test', 'system_test'];
+ public static $modules = ['test_page_test', 'form_test', 'system_test', 'node'];
/**
* Tests basic page test.
@@ -111,6 +111,15 @@ class BrowserTestBaseTest extends BrowserTestBase {
// Test drupalPostForm() with no-html response.
$values = Json::decode($this->drupalPostForm('form_test/form-state-values-clean', [], t('Submit')));
$this->assertTrue(1000, $values['beer']);
+
+ // Test drupalPostForm() with form by HTML id.
+ $this->drupalCreateContentType(['type' => 'page']);
+ $this->drupalLogin($this->drupalCreateUser(['create page content']));
+ $this->drupalGet('form-test/two-instances-of-same-form');
+ $this->getSession()->getPage()->fillField('edit-title-0-value', 'form1');
+ $this->getSession()->getPage()->fillField('edit-title-0-value--2', 'form2');
+ $this->drupalPostForm(NULL, [], 'Save', [], 'node-page-form--2');
+ $this->assertSession()->pageTextContains('Page form2 has been created.');
}
/**
diff --git a/core/tests/Drupal/Tests/BrowserTestBase.php b/core/tests/Drupal/Tests/BrowserTestBase.php
index 290be1a..4aaf6c5 100644
--- a/core/tests/Drupal/Tests/BrowserTestBase.php
+++ b/core/tests/Drupal/Tests/BrowserTestBase.php
@@ -924,7 +924,7 @@ abstract class BrowserTestBase extends TestCase {
/**
* Executes a form submission.
*
- * It will be done as usual POST request with Mink.
+ * It will be done as usual submit form with Mink.
*
* @param \Drupal\Core\Url|string $path
* Location of the post form. Either a Drupal path or an absolute path or
@@ -990,13 +990,20 @@ abstract class BrowserTestBase extends TestCase {
* POST data.
* @param array $options
* Options to be forwarded to the url generator.
+ * @param string|null $form_html_id
+ * (optional) HTML ID of the form to be submitted. On some pages
+ * there are many identical forms, so just using the value of the submit
+ * button is not enough. For example: 'trigger-node-presave-assign-form'.
+ * Note that this is not the Drupal $form_id, but rather the HTML ID of the
+ * form, which is typically the same thing but with hyphens replacing the
+ * underscores.
*
* @return string
* (deprecated) The response content after submit form. It is necessary for
* backwards compatibility and will be removed before Drupal 9.0. You should
* just use the webAssert object for your assertions.
*/
- protected function drupalPostForm($path, $edit, $submit, array $options = []) {
+ protected function drupalPostForm($path, $edit, $submit, array $options = [], $form_html_id = NULL) {
if (is_object($submit)) {
// Cast MarkupInterface objects to string.
$submit = (string) $submit;
@@ -1012,7 +1019,7 @@ abstract class BrowserTestBase extends TestCase {
$this->drupalGet($path, $options);
}
- $this->submitForm($edit, $submit);
+ $this->submitForm($edit, $submit, $form_html_id);
return $this->getSession()->getPage()->getContent();
}