You are here

public function FeedTypeAccessControlHandlerTest::testCheckAccess in Feeds 8.3

@covers ::checkAccess

File

tests/src/Unit/FeedTypeAccessControlHandlerTest.php, line 44

Class

FeedTypeAccessControlHandlerTest
@coversDefaultClass \Drupal\feeds\FeedTypeAccessControlHandler @group feeds

Namespace

Drupal\Tests\feeds\Unit

Code

public function testCheckAccess() {
  $method = $this
    ->getMethod(FeedTypeAccessControlHandler::class, 'checkAccess');
  $result = $method
    ->invokeArgs($this->controller, [
    $this->entity
      ->reveal(),
    'view',
    $this->account
      ->reveal(),
  ]);
  $this
    ->assertTrue($result
    ->isAllowed());
  $result = $method
    ->invokeArgs($this->controller, [
    $this->entity
      ->reveal(),
    'delete',
    $this->account
      ->reveal(),
  ]);
  $this
    ->assertTrue($result
    ->isAllowed());
  $this->entity
    ->getCacheContexts()
    ->willReturn([]);
  $this->entity
    ->getCacheTags()
    ->willReturn([]);
  $this->entity
    ->getCacheMaxAge()
    ->willReturn(0);
  $this->entity
    ->isLocked()
    ->willReturn(TRUE);
  $this->entity
    ->isNew()
    ->willReturn(FALSE);
  $result = $method
    ->invokeArgs($this->controller, [
    $this->entity
      ->reveal(),
    'delete',
    $this->account
      ->reveal(),
  ]);
  $this
    ->assertFalse($result
    ->isAllowed());
  $this->account
    ->hasPermission('administer feeds')
    ->willReturn(FALSE);
  $result = $method
    ->invokeArgs($this->controller, [
    $this->entity
      ->reveal(),
    'delete',
    $this->account
      ->reveal(),
  ]);
  $this
    ->assertFalse($result
    ->isAllowed());
  $result = $method
    ->invokeArgs($this->controller, [
    $this->entity
      ->reveal(),
    'view',
    $this->account
      ->reveal(),
  ]);
  $this
    ->assertFalse($result
    ->isAllowed());
  $this->entity
    ->isNew()
    ->willReturn(TRUE);
  $result = $method
    ->invokeArgs($this->controller, [
    $this->entity
      ->reveal(),
    'delete',
    $this->account
      ->reveal(),
  ]);
  $this
    ->assertFalse($result
    ->isAllowed());
}