diff --git a/core/tests/Drupal/FunctionalTests/BrowserTestBaseTest.php b/core/tests/Drupal/FunctionalTests/BrowserTestBaseTest.php index 2701dcb..7c3b3a9 100644 --- a/core/tests/Drupal/FunctionalTests/BrowserTestBaseTest.php +++ b/core/tests/Drupal/FunctionalTests/BrowserTestBaseTest.php @@ -3,6 +3,7 @@ namespace Drupal\FunctionalTests; use Behat\Mink\Exception\ExpectationException; +use Drupal\Component\Serialization\Json; use Drupal\Component\Utility\Html; use Drupal\Core\Url; use Drupal\Tests\BrowserTestBase; @@ -98,13 +99,18 @@ public function testForm() { // Test drupalPostForm(). $edit = ['bananas' => 'red']; - $this->drupalPostForm('form-test/object-builder', $edit, 'Save'); + $result = $this->drupalPostForm('form-test/object-builder', $edit, 'Save'); + $this->assertSame($this->getSession()->getPage()->getContent(), $result); $value = $config_factory->get('form_test.object')->get('bananas'); $this->assertSame('red', $value); $this->drupalPostForm('form-test/object-builder', NULL, 'Save'); $value = $config_factory->get('form_test.object')->get('bananas'); $this->assertSame('', $value); + + // Test drupalPostForm() with no-html response. + $values = Json::decode($this->drupalPostForm('form_test/form-state-values-clean', [], t('Submit'))); + $this->assertTrue(1000, $values['beer']); } /** diff --git a/core/tests/Drupal/Tests/BrowserTestBase.php b/core/tests/Drupal/Tests/BrowserTestBase.php index bd50c23..9a754ad 100644 --- a/core/tests/Drupal/Tests/BrowserTestBase.php +++ b/core/tests/Drupal/Tests/BrowserTestBase.php @@ -920,6 +920,9 @@ protected function submitForm(array $edit, $submit, $form_html_id = NULL) { * POST data. * @param array $options * Options to be forwarded to the url generator. + * + * @return string + * The response content after submit form. */ protected function drupalPostForm($path, $edit, $submit, array $options = []) { if (is_object($submit)) { @@ -938,6 +941,11 @@ protected function drupalPostForm($path, $edit, $submit, array $options = []) { } $this->submitForm($edit, $submit); + + // Returns response content for BC purposes. Feel free to use the webAssert + // object for your assertions. + // @see \Drupal\simpletest\WebTestBase::drupalPostForm() + return $this->getSession()->getPage()->getContent(); } /**