You are here

public function NodeOptionPremiumHelperTest::testHasFullAccessAsOwner in Node Option Premium 8

Tests that the owner of an entity always has access.

@covers ::hasFullAccess

File

tests/src/Unit/NodeOptionPremiumHelperTest.php, line 181

Class

NodeOptionPremiumHelperTest
@coversDefaultClass \Drupal\nopremium\NodeOptionPremiumHelper

Namespace

Drupal\Tests\nopremium\Unit

Code

public function testHasFullAccessAsOwner() {
  $node = $this
    ->createPremiumNode();

  // The account has none of the permissions.
  $this->account
    ->hasPermission(Argument::type('string'))
    ->wilLReturn(FALSE);

  // The account is authenticated.
  $this->account
    ->isAuthenticated()
    ->willReturn(TRUE);

  // The entity's owner ID and the account ID are the same.
  $node
    ->getOwnerId()
    ->willReturn(4);
  $this->account
    ->id()
    ->willReturn(4);

  // The account has no update access for this entity.
  $node
    ->access('update', $this->account
    ->reveal())
    ->willReturn(FALSE);

  // Configure the entity to be premium.
  $node = $node
    ->reveal();
  $node->premium = new \stdClass();
  $node->premium->value = TRUE;
  $this
    ->assertTrue($this->helper
    ->hasFullAccess($node, $this->account
    ->reveal()));
}