public function ProgrammaticTest::testProgrammaticAccessBypass in Zircon Profile 8
Same name and namespace in other branches
- 8.0 core/modules/system/src/Tests/Form/ProgrammaticTest.php \Drupal\system\Tests\Form\ProgrammaticTest::testProgrammaticAccessBypass()
Test the programmed_bypass_access_check flag.
File
- core/
modules/ system/ src/ Tests/ Form/ ProgrammaticTest.php, line 100 - Contains \Drupal\system\Tests\Form\ProgrammaticTest.
Class
- ProgrammaticTest
- Tests the programmatic form submission behavior.
Namespace
Drupal\system\Tests\FormCode
public function testProgrammaticAccessBypass() {
$form_state = (new FormState())
->setValues([
'textfield' => 'dummy value',
'field_restricted' => 'dummy value',
]);
// Programmatically submit the form with a value for the restricted field.
// Since programmed_bypass_access_check is set to TRUE by default, the
// field is accessible and can be set.
\Drupal::formBuilder()
->submitForm('\\Drupal\\form_test\\Form\\FormTestProgrammaticForm', $form_state);
$values = $form_state
->get('programmatic_form_submit');
$this
->assertEqual($values['field_restricted'], 'dummy value', 'The value for the restricted field is stored correctly.');
// Programmatically submit the form with a value for the restricted field
// with programmed_bypass_access_check set to FALSE. Since access
// restrictions apply, the restricted field is inaccessible, and the value
// should not be stored.
$form_state
->setProgrammedBypassAccessCheck(FALSE);
\Drupal::formBuilder()
->submitForm('\\Drupal\\form_test\\Form\\FormTestProgrammaticForm', $form_state);
$values = $form_state
->get('programmatic_form_submit');
$this
->assertNotEqual($values['field_restricted'], 'dummy value', 'The value for the restricted field is not stored.');
}