function MenuAccessControlHandlerTest::testAccessProvider

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

File

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

Class

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

Namespace

Drupal\Tests\system\Kernel

Code

public static function testAccessProvider() {
    // RefinableCacheableDependencyTrait::addCacheContexts() only needs the
    // container to perform an assertion, but we can't use the container here,
    // so disable assertions for the purposes of this test.
    $assertions = ini_set('zend.assertions', 0);
    $data = [
        'no permission + unlocked' => [
            [],
            'unlocked',
            AccessResult::allowed(),
            AccessResult::neutral()->addCacheContexts([
                'user.permissions',
            ])
                ->setReason("The 'administer menu' permission is required."),
            AccessResult::neutral()->addCacheContexts([
                'user.permissions',
            ])
                ->setReason("The 'administer menu' permission is required."),
            AccessResult::neutral()->addCacheContexts([
                'user.permissions',
            ])
                ->setReason("The 'administer menu' permission is required.")
                ->addCacheTags([
                'config:system.menu.llama',
            ]),
            AccessResult::neutral()->addCacheContexts([
                'user.permissions',
            ])
                ->setReason("The 'administer menu' permission is required."),
        ],
        'no permission + locked' => [
            [],
            'locked',
            AccessResult::allowed(),
            AccessResult::neutral()->addCacheContexts([
                'user.permissions',
            ])
                ->setReason("The 'administer menu' permission is required."),
            AccessResult::neutral()->addCacheContexts([
                'user.permissions',
            ])
                ->setReason("The 'administer menu' permission is required."),
            AccessResult::forbidden()->addCacheTags([
                'config:system.menu.llama',
            ])
                ->setReason("The Menu config entity is locked."),
            AccessResult::neutral()->addCacheContexts([
                'user.permissions',
            ])
                ->setReason("The 'administer menu' permission is required."),
        ],
        'admin + unlocked' => [
            [
                'administer menu',
            ],
            'unlocked',
            AccessResult::allowed(),
            AccessResult::allowed()->addCacheContexts([
                'user.permissions',
            ]),
            AccessResult::allowed()->addCacheContexts([
                'user.permissions',
            ]),
            AccessResult::allowed()->addCacheContexts([
                'user.permissions',
            ])
                ->addCacheTags([
                'config:system.menu.llama',
            ]),
            AccessResult::allowed()->addCacheContexts([
                'user.permissions',
            ]),
        ],
        'admin + locked' => [
            [
                'administer menu',
            ],
            'locked',
            AccessResult::allowed(),
            AccessResult::allowed()->addCacheContexts([
                'user.permissions',
            ]),
            AccessResult::allowed()->addCacheContexts([
                'user.permissions',
            ]),
            AccessResult::forbidden()->addCacheTags([
                'config:system.menu.llama',
            ])
                ->setReason("The Menu config entity is locked."),
            AccessResult::allowed()->addCacheContexts([
                'user.permissions',
            ]),
        ],
    ];
    if ($assertions !== FALSE) {
        ini_set('zend.assertions', $assertions);
    }
    return $data;
}

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