You are here

public function FormBuilderTest::testChildAccessInheritance in Drupal 9

Same name and namespace in other branches
  1. 8 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 613
Contains \Drupal\Tests\Core\Form\FormBuilderTest.

Class

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

Namespace

Drupal\Tests\Core\Form

Code

public function testChildAccessInheritance($element, $access_checks) {
  $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);
}