function RecipeFormInputTest::testRecipeInputViaForm
Tests collecting recipe input via a form.
File
-
core/
modules/ system/ tests/ src/ Functional/ Form/ RecipeFormInputTest.php, line 28
Class
- RecipeFormInputTest
- @covers \Drupal\Core\Recipe\RecipeInputFormTrait @group system
Namespace
Drupal\Tests\system\Functional\FormCode
public function testRecipeInputViaForm() : void {
$this->drupalGet('/form-test/recipe-input');
$assert_session = $this->assertSession();
// There should only be one nested input element on the page: the one
// defined by the input_test recipe.
$assert_session->elementsCount('css', 'input[name*="["]', 1);
// The default value and description should be visible.
$assert_session->fieldValueEquals('input_test[owner]', 'Dries Buytaert');
$assert_session->pageTextContains('The name of the site owner.');
// All recipe inputs are required.
$this->submitForm([
'input_test[owner]' => '',
], 'Apply recipe');
$assert_session->statusMessageContains("Site owner's name field is required.", 'error');
// All inputs should be validated with their own constraints.
$this->submitForm([
'input_test[owner]' => 'Hacker Joe',
], 'Apply recipe');
$assert_session->statusMessageContains("I don't think you should be owning sites.", 'error');
// The correct element should be flagged as invalid.
$assert_session->elementAttributeExists('named', [
'field',
'input_test[owner]',
], 'aria-invalid');
// Submit the form with a valid value and apply the recipe, to prove that
// it was passed through correctly.
$this->submitForm([
'input_test[owner]' => 'Legitimate Human',
], 'Apply recipe');
$this->assertSame("Legitimate Human's Turf", $this->config('system.site')
->get('name'));
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.