You are here

public function PanelsStorageTest::testAccess in Panels 8.4

Same name and namespace in other branches
  1. 8.3 tests/src/Unit/PanelsStorageTest.php \Drupal\Tests\panels\Unit\PanelsStorageTest::testAccess()

@covers ::access

File

tests/src/Unit/PanelsStorageTest.php, line 156

Class

PanelsStorageTest
Tests the PageManagerPanelsStorage service.

Namespace

Drupal\Tests\panels\Unit

Code

public function testAccess() {
  $this->storage
    ->load('id_exists')
    ->willReturn($this->pageVariant
    ->reveal());
  $this->storage
    ->load('doesnt_exist')
    ->willReturn(NULL);
  $account = $this
    ->prophesize(AccountInterface::class);
  $this->pageVariant
    ->access('read', $account
    ->reveal(), TRUE)
    ->willReturn(AccessResult::allowed());
  $panels_storage = new PageManagerPanelsStorage([], '', [], $this->entityTypeManager
    ->reveal());

  // Test the access condition.
  $this
    ->assertEquals(AccessResult::allowed(), $panels_storage
    ->access('id_exists', 'read', $account
    ->reveal()));

  // Should be forbidden if it doesn't exist.
  $this
    ->assertEquals(AccessResult::forbidden(), $panels_storage
    ->access('doesnt_exist', 'read', $account
    ->reveal()));

  // Test that 'change layout' becomes 'update'.
  $this->pageVariant
    ->access('update', $account
    ->reveal(), TRUE)
    ->willReturn(AccessResult::allowed());
  $this
    ->assertEquals(AccessResult::allowed(), $panels_storage
    ->access('id_exists', 'change layout', $account
    ->reveal()));
}