You are here

public function PageAccessTest::testAccessDelete in Page Manager 8

Same name and namespace in other branches
  1. 8.4 tests/src/Unit/PageAccessTest.php \Drupal\Tests\page_manager\Unit\PageAccessTest::testAccessDelete()

@covers ::checkAccess

@dataProvider providerTestAccessDelete

File

tests/src/Unit/PageAccessTest.php, line 117
Contains \Drupal\Tests\page_manager\Unit\PageAccessTest.

Class

PageAccessTest
Tests access for Page entities.

Namespace

Drupal\Tests\page_manager\Unit

Code

public function testAccessDelete($is_new, $expected) {
  $this->entityType
    ->getAdminPermission()
    ->willReturn('test permission');
  $page = $this
    ->prophesize(PageInterface::class);
  $page
    ->isNew()
    ->willReturn($is_new);
  $page
    ->language()
    ->willReturn($this
    ->prophesize(LanguageInterface::class)
    ->reveal());
  $page
    ->uuid()
    ->shouldBeCalled();
  $page
    ->getEntityTypeId()
    ->shouldBeCalled();

  // Ensure that the cache tag is added for the temporary conditions.
  if ($is_new) {
    $page
      ->getCacheTags()
      ->willReturn([
      'page:1',
    ]);
    $page
      ->getCacheContexts()
      ->willReturn([]);
    $page
      ->getCacheMaxAge()
      ->willReturn(0);
  }
  else {
    $this->cacheContextsManager
      ->assertValidTokens([
      'user.permissions',
    ])
      ->willReturn(TRUE);
  }
  $account = $this
    ->prophesize(AccountInterface::class);
  $account
    ->hasPermission('test permission')
    ->willReturn(TRUE);
  $account
    ->id()
    ->shouldBeCalled();
  $this
    ->assertSame($expected, $this->pageAccess
    ->access($page
    ->reveal(), 'delete', $account
    ->reveal()));
}