function FormBuilderTest::testChildAccessInheritance

Same name in other branches
  1. 9 core/tests/Drupal/Tests/Core/Form/FormBuilderTest.php \Drupal\Tests\Core\Form\FormBuilderTest::testChildAccessInheritance()
  2. 8.9.x core/tests/Drupal/Tests/Core/Form/FormBuilderTest.php \Drupal\Tests\Core\Form\FormBuilderTest::testChildAccessInheritance()
  3. 11.x core/tests/Drupal/Tests/Core/Form/FormBuilderTest.php \Drupal\Tests\Core\Form\FormBuilderTest::testChildAccessInheritance()

@covers ::buildForm

@dataProvider providerTestChildAccessInheritance

File

core/tests/Drupal/Tests/Core/Form/FormBuilderTest.php, line 652

Class

FormBuilderTest
@coversDefaultClass \Drupal\Core\Form\FormBuilder @group Form

Namespace

Drupal\Tests\Core\Form

Code

public function testChildAccessInheritance($element, $access_checks) : void {
    $form_arg = new TestFormWithPredefinedForm();
    $form_arg->setForm($element);
    $form_state = new FormState();
    $form = $this->formBuilder
        ->buildForm($form_arg, $form_state);
    $actual_access_structure = [];
    $expected_access_structure = [];
    // Ensure that the expected access checks are set.
    foreach ($access_checks as $access_check) {
        $parents = $access_check[0];
        $parents[] = '#access';
        $actual_access = NestedArray::getValue($form, $parents);
        $actual_access_structure[] = [
            $parents,
            $actual_access,
        ];
        $expected_access_structure[] = [
            $parents,
            $access_check[1],
        ];
    }
    $this->assertEquals($expected_access_structure, $actual_access_structure);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.