function DateFormatAccessControlHandlerTest::testAccessProvider

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

File

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

Class

DateFormatAccessControlHandlerTest
@coversDefaultClass \Drupal\system\DateFormatAccessControlHandler @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' => [
            'permissionless',
            'unlocked',
            AccessResult::allowed(),
            AccessResult::neutral()->addCacheContexts([
                'user.permissions',
            ])
                ->setReason("The 'administer site configuration' permission is required."),
            AccessResult::neutral()->addCacheContexts([
                'user.permissions',
            ])
                ->setReason("The 'administer site configuration' permission is required.")
                ->addCacheTags([
                'rendered',
            ]),
            AccessResult::neutral()->addCacheContexts([
                'user.permissions',
            ])
                ->setReason("The 'administer site configuration' permission is required.")
                ->addCacheTags([
                'rendered',
            ]),
            AccessResult::neutral()->addCacheContexts([
                'user.permissions',
            ])
                ->setReason("The 'administer site configuration' permission is required."),
        ],
        'permissionless + locked' => [
            'permissionless',
            'locked',
            AccessResult::allowed(),
            AccessResult::neutral()->addCacheContexts([
                'user.permissions',
            ])
                ->setReason("The 'administer site configuration' permission is required."),
            AccessResult::forbidden()->addCacheTags([
                'rendered',
            ])
                ->setReason("The DateFormat config entity is locked."),
            AccessResult::forbidden()->addCacheTags([
                'rendered',
            ])
                ->setReason("The DateFormat config entity is locked."),
            AccessResult::neutral()->addCacheContexts([
                'user.permissions',
            ])
                ->setReason("The 'administer site configuration' permission is required."),
        ],
        'admin + unlocked' => [
            'admin',
            'unlocked',
            AccessResult::allowed(),
            AccessResult::allowed()->addCacheContexts([
                'user.permissions',
            ]),
            AccessResult::allowed()->addCacheContexts([
                'user.permissions',
            ])
                ->addCacheTags([
                'rendered',
            ]),
            AccessResult::allowed()->addCacheContexts([
                'user.permissions',
            ])
                ->addCacheTags([
                'rendered',
            ]),
            AccessResult::allowed()->addCacheContexts([
                'user.permissions',
            ]),
        ],
        'admin + locked' => [
            'admin',
            'locked',
            AccessResult::allowed(),
            AccessResult::allowed()->addCacheContexts([
                'user.permissions',
            ]),
            AccessResult::forbidden()->addCacheTags([
                'rendered',
            ])
                ->setReason("The DateFormat config entity is locked."),
            AccessResult::forbidden()->addCacheTags([
                'rendered',
            ])
                ->setReason("The DateFormat config entity is locked."),
            AccessResult::allowed()->addCacheContexts([
                'user.permissions',
            ]),
        ],
        'user1 + unlocked' => [
            'user1',
            'unlocked',
            AccessResult::allowed(),
            AccessResult::allowed()->addCacheContexts([
                'user.permissions',
            ]),
            AccessResult::allowed()->addCacheContexts([
                'user.permissions',
            ])
                ->addCacheTags([
                'rendered',
            ]),
            AccessResult::allowed()->addCacheContexts([
                'user.permissions',
            ])
                ->addCacheTags([
                'rendered',
            ]),
            AccessResult::allowed()->addCacheContexts([
                'user.permissions',
            ]),
        ],
        'user1 + locked' => [
            'user1',
            'locked',
            AccessResult::allowed(),
            AccessResult::allowed()->addCacheContexts([
                'user.permissions',
            ]),
            AccessResult::forbidden()->addCacheTags([
                'rendered',
            ])
                ->setReason("The DateFormat config entity is locked."),
            AccessResult::forbidden()->addCacheTags([
                'rendered',
            ])
                ->setReason("The DateFormat 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.