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. 11.x core/modules/system/tests/src/Kernel/MenuAccessControlHandlerTest.php \Drupal\Tests\system\Kernel\MenuAccessControlHandlerTest::testAccessProvider()

File

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

Class

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

Namespace

Drupal\Tests\system\Kernel

Code

public function testAccessProvider() {
    $c = new ContainerBuilder();
    $cache_contexts_manager = $this->prophesize(CacheContextsManager::class);
    $cache_contexts_manager->assertValidTokens()
        ->willReturn(TRUE);
    $cache_contexts_manager->reveal();
    $c->set('cache_contexts_manager', $cache_contexts_manager);
    \Drupal::setContainer($c);
    return [
        'permissionless + 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."),
        ],
        'permissionless + 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',
            ]),
        ],
    ];
}

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