function MenuAccessControlHandlerTest::testAccess

Same name in other branches
  1. 9 core/modules/system/tests/src/Kernel/MenuAccessControlHandlerTest.php \Drupal\Tests\system\Kernel\MenuAccessControlHandlerTest::testAccess()
  2. 8.9.x core/modules/system/tests/src/Kernel/MenuAccessControlHandlerTest.php \Drupal\Tests\system\Kernel\MenuAccessControlHandlerTest::testAccess()
  3. 11.x core/modules/system/tests/src/Kernel/MenuAccessControlHandlerTest.php \Drupal\Tests\system\Kernel\MenuAccessControlHandlerTest::testAccess()

@covers ::checkAccess @covers ::checkCreateAccess @dataProvider testAccessProvider

File

core/modules/system/tests/src/Kernel/MenuAccessControlHandlerTest.php, line 53

Class

MenuAccessControlHandlerTest
@coversDefaultClass \Drupal\system\MenuAccessControlHandler @group system

Namespace

Drupal\Tests\system\Kernel

Code

public function testAccess($permissions, $which_entity, $view_label_access_result, $view_access_result, $update_access_result, $delete_access_result, $create_access_result) : void {
    $user = $this->drupalCreateUser($permissions);
    $entity_values = $which_entity === 'unlocked' ? [
        'locked' => FALSE,
    ] : [
        'locked' => TRUE,
    ];
    $entity_values['id'] = $entity_values['label'] = 'llama';
    $entity = Menu::create($entity_values);
    $entity->save();
    static::assertEquals($view_label_access_result, $this->accessControlHandler
        ->access($entity, 'view label', $user, TRUE));
    static::assertEquals($view_access_result, $this->accessControlHandler
        ->access($entity, 'view', $user, TRUE));
    static::assertEquals($update_access_result, $this->accessControlHandler
        ->access($entity, 'update', $user, TRUE));
    static::assertEquals($delete_access_result, $this->accessControlHandler
        ->access($entity, 'delete', $user, TRUE));
    static::assertEquals($create_access_result, $this->accessControlHandler
        ->createAccess(NULL, $user, [], TRUE));
}

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