function DateFormatAccessControlHandlerTest::testAccess

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

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

File

core/modules/system/tests/src/Kernel/DateFormatAccessControlHandlerTest.php, line 55

Class

DateFormatAccessControlHandlerTest
@coversDefaultClass \Drupal\system\DateFormatAccessControlHandler @group system

Namespace

Drupal\Tests\system\Kernel

Code

public function testAccess($which_user, $which_entity, $view_label_access_result, $view_access_result, $update_access_result, $delete_access_result, $create_access_result) {
    // We must always create user 1, so that a "normal" user has an ID >1.
    $root_user = $this->drupalCreateUser();
    if ($which_user === 'user1') {
        $user = $root_user;
    }
    else {
        $permissions = $which_user === 'admin' ? [
            'administer site configuration',
        ] : [];
        $user = $this->drupalCreateUser($permissions);
    }
    $entity_values = $which_entity === 'unlocked' ? [
        'locked' => FALSE,
    ] : [
        'locked' => TRUE,
    ];
    $entity_values['id'] = $this->randomMachineName();
    $entity = DateFormat::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.