public function FormBuilderTest::providerTestChildAccessInheritance in Drupal 8
Same name and namespace in other branches
- 9 core/tests/Drupal/Tests/Core/Form/FormBuilderTest.php \Drupal\Tests\Core\Form\FormBuilderTest::providerTestChildAccessInheritance()
Data provider for testChildAccessInheritance.
Return value
array
File
- core/
tests/ Drupal/ Tests/ Core/ Form/ FormBuilderTest.php, line 642 - Contains \Drupal\Tests\Core\Form\FormBuilderTest.
Class
- FormBuilderTest
- @coversDefaultClass \Drupal\Core\Form\FormBuilder @group Form
Namespace
Drupal\Tests\Core\FormCode
public function providerTestChildAccessInheritance() {
$data = [];
$element = [
'child0' => [
'#type' => 'checkbox',
],
'child1' => [
'#type' => 'checkbox',
],
'child2' => [
'#type' => 'fieldset',
'child2.0' => [
'#type' => 'checkbox',
],
'child2.1' => [
'#type' => 'checkbox',
],
'child2.2' => [
'#type' => 'checkbox',
],
],
];
// Sets access FALSE on the root level, this should be inherited completely.
$clone = $element;
$clone['#access'] = FALSE;
$expected_access = [];
$expected_access[] = [
[],
FALSE,
];
$expected_access[] = [
[
'child0',
],
FALSE,
];
$expected_access[] = [
[
'child1',
],
FALSE,
];
$expected_access[] = [
[
'child2',
],
FALSE,
];
$expected_access[] = [
[
'child2',
'child2.0',
],
FALSE,
];
$expected_access[] = [
[
'child2',
'child2.1',
],
FALSE,
];
$expected_access[] = [
[
'child2',
'child2.2',
],
FALSE,
];
$data['access-false-root'] = [
$clone,
$expected_access,
];
$clone = $element;
$access_result = AccessResult::forbidden();
$clone['#access'] = $access_result;
$expected_access = [];
$expected_access[] = [
[],
$access_result,
];
$expected_access[] = [
[
'child0',
],
$access_result,
];
$expected_access[] = [
[
'child1',
],
$access_result,
];
$expected_access[] = [
[
'child2',
],
$access_result,
];
$expected_access[] = [
[
'child2',
'child2.0',
],
$access_result,
];
$expected_access[] = [
[
'child2',
'child2.1',
],
$access_result,
];
$expected_access[] = [
[
'child2',
'child2.2',
],
$access_result,
];
$data['access-forbidden-root'] = [
$clone,
$expected_access,
];
// Allow access on the most outer level but set FALSE otherwise.
$clone = $element;
$clone['#access'] = TRUE;
$clone['child0']['#access'] = FALSE;
$expected_access = [];
$expected_access[] = [
[],
TRUE,
];
$expected_access[] = [
[
'child0',
],
FALSE,
];
$expected_access[] = [
[
'child1',
],
NULL,
];
$expected_access[] = [
[
'child2',
],
NULL,
];
$expected_access[] = [
[
'child2',
'child2.0',
],
NULL,
];
$expected_access[] = [
[
'child2',
'child2.1',
],
NULL,
];
$expected_access[] = [
[
'child2',
'child2.2',
],
NULL,
];
$data['access-true-root'] = [
$clone,
$expected_access,
];
// Allow access on the most outer level but forbid otherwise.
$clone = $element;
$access_result_allowed = AccessResult::allowed();
$clone['#access'] = $access_result_allowed;
$access_result_forbidden = AccessResult::forbidden();
$clone['child0']['#access'] = $access_result_forbidden;
$expected_access = [];
$expected_access[] = [
[],
$access_result_allowed,
];
$expected_access[] = [
[
'child0',
],
$access_result_forbidden,
];
$expected_access[] = [
[
'child1',
],
NULL,
];
$expected_access[] = [
[
'child2',
],
NULL,
];
$expected_access[] = [
[
'child2',
'child2.0',
],
NULL,
];
$expected_access[] = [
[
'child2',
'child2.1',
],
NULL,
];
$expected_access[] = [
[
'child2',
'child2.2',
],
NULL,
];
$data['access-allowed-root'] = [
$clone,
$expected_access,
];
// Allow access on the most outer level, deny access on a parent, and allow
// on a child. The denying should be inherited.
$clone = $element;
$clone['#access'] = TRUE;
$clone['child2']['#access'] = FALSE;
$clone['child2.0']['#access'] = TRUE;
$clone['child2.1']['#access'] = TRUE;
$clone['child2.2']['#access'] = TRUE;
$expected_access = [];
$expected_access[] = [
[],
TRUE,
];
$expected_access[] = [
[
'child0',
],
NULL,
];
$expected_access[] = [
[
'child1',
],
NULL,
];
$expected_access[] = [
[
'child2',
],
FALSE,
];
$expected_access[] = [
[
'child2',
'child2.0',
],
FALSE,
];
$expected_access[] = [
[
'child2',
'child2.1',
],
FALSE,
];
$expected_access[] = [
[
'child2',
'child2.2',
],
FALSE,
];
$data['access-mixed-parents'] = [
$clone,
$expected_access,
];
$clone = $element;
$clone['#access'] = $access_result_allowed;
$clone['child2']['#access'] = $access_result_forbidden;
$clone['child2.0']['#access'] = $access_result_allowed;
$clone['child2.1']['#access'] = $access_result_allowed;
$clone['child2.2']['#access'] = $access_result_allowed;
$expected_access = [];
$expected_access[] = [
[],
$access_result_allowed,
];
$expected_access[] = [
[
'child0',
],
NULL,
];
$expected_access[] = [
[
'child1',
],
NULL,
];
$expected_access[] = [
[
'child2',
],
$access_result_forbidden,
];
$expected_access[] = [
[
'child2',
'child2.0',
],
$access_result_forbidden,
];
$expected_access[] = [
[
'child2',
'child2.1',
],
$access_result_forbidden,
];
$expected_access[] = [
[
'child2',
'child2.2',
],
$access_result_forbidden,
];
$data['access-mixed-parents-object'] = [
$clone,
$expected_access,
];
return $data;
}