function StateValuesCleanTest::testFormStateValuesClean
Same name in other branches
- 8.9.x core/modules/system/tests/src/Functional/Form/StateValuesCleanTest.php \Drupal\Tests\system\Functional\Form\StateValuesCleanTest::testFormStateValuesClean()
- 10 core/modules/system/tests/src/Functional/Form/StateValuesCleanTest.php \Drupal\Tests\system\Functional\Form\StateValuesCleanTest::testFormStateValuesClean()
- 11.x core/modules/system/tests/src/Functional/Form/StateValuesCleanTest.php \Drupal\Tests\system\Functional\Form\StateValuesCleanTest::testFormStateValuesClean()
Tests \Drupal\Core\Form\FormState::cleanValues().
File
-
core/
modules/ system/ tests/ src/ Functional/ Form/ StateValuesCleanTest.php, line 33
Class
- StateValuesCleanTest
- Tests the proper removal of submitted form values.
Namespace
Drupal\Tests\system\Functional\FormCode
public function testFormStateValuesClean() {
$this->drupalGet('form_test/form-state-values-clean');
$this->submitForm([], 'Submit');
$values = Json::decode($this->getSession()
->getPage()
->getContent());
// Setup the expected result.
$result = [
'beer' => 1000,
'baz' => [
'beer' => 2000,
],
];
// Verify that all internal Form API elements were removed.
$this->assertFalse(isset($values['form_id']), new FormattableMarkup('%element was removed.', [
'%element' => 'form_id',
]));
$this->assertFalse(isset($values['form_token']), new FormattableMarkup('%element was removed.', [
'%element' => 'form_token',
]));
$this->assertFalse(isset($values['form_build_id']), new FormattableMarkup('%element was removed.', [
'%element' => 'form_build_id',
]));
$this->assertFalse(isset($values['op']), new FormattableMarkup('%element was removed.', [
'%element' => 'op',
]));
// Verify that all buttons were removed.
$this->assertFalse(isset($values['foo']), new FormattableMarkup('%element was removed.', [
'%element' => 'foo',
]));
$this->assertFalse(isset($values['bar']), new FormattableMarkup('%element was removed.', [
'%element' => 'bar',
]));
$this->assertFalse(isset($values['baz']['foo']), new FormattableMarkup('%element was removed.', [
'%element' => 'foo',
]));
$this->assertFalse(isset($values['baz']['baz']), new FormattableMarkup('%element was removed.', [
'%element' => 'baz',
]));
// Verify values manually added for cleaning were removed.
$this->assertFalse(isset($values['wine']), new FormattableMarkup('%element was removed.', [
'%element' => 'wine',
]));
// Verify that nested form value still exists.
$this->assertTrue(isset($values['baz']['beer']), 'Nested form value still exists.');
// Verify that actual form values equal resulting form values.
$this->assertEquals($result, $values, 'Expected form values equal actual form values.');
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.