function AccessResultTest::testAllowedIfHasPermissions

Same name in other branches
  1. 9 core/tests/Drupal/Tests/Core/Access/AccessResultTest.php \Drupal\Tests\Core\Access\AccessResultTest::testAllowedIfHasPermissions()
  2. 10 core/tests/Drupal/Tests/Core/Access/AccessResultTest.php \Drupal\Tests\Core\Access\AccessResultTest::testAllowedIfHasPermissions()
  3. 11.x core/tests/Drupal/Tests/Core/Access/AccessResultTest.php \Drupal\Tests\Core\Access\AccessResultTest::testAllowedIfHasPermissions()

Tests allowedIfHasPermissions().

@covers ::allowedIfHasPermissions

@dataProvider providerTestAllowedIfHasPermissions

Parameters

string[] $permissions: The permissions to check for.

string $conjunction: The conjunction to use when checking for permission. 'AND' or 'OR'.

\Drupal\Core\Access\AccessResult $expected_access: The expected access check result.

File

core/tests/Drupal/Tests/Core/Access/AccessResultTest.php, line 923

Class

AccessResultTest
@coversDefaultClass \Drupal\Core\Access\AccessResult @group Access

Namespace

Drupal\Tests\Core\Access

Code

public function testAllowedIfHasPermissions($permissions, $conjunction, AccessResult $expected_access) {
    $account = $this->createMock('\\Drupal\\Core\\Session\\AccountInterface');
    $account->expects($this->any())
        ->method('hasPermission')
        ->willReturnMap([
        [
            'allowed',
            TRUE,
        ],
        [
            'denied',
            FALSE,
        ],
    ]);
    if ($permissions) {
        $expected_access->cachePerPermissions();
    }
    $access_result = AccessResult::allowedIfHasPermissions($account, $permissions, $conjunction);
    $this->assertEquals($expected_access, $access_result);
}

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