You are here

public function EntityAccessTest::testForbiddenAccess in Open Social 8.9

Same name and namespace in other branches
  1. 8 modules/custom/entity_access_by_field/tests/src/Unit/EntityAccessTest.php \Drupal\entity_access_by_field\Tests\EntityAccessTest::testForbiddenAccess()
  2. 8.2 modules/custom/entity_access_by_field/tests/src/Unit/EntityAccessTest.php \Drupal\entity_access_by_field\Tests\EntityAccessTest::testForbiddenAccess()
  3. 8.3 modules/custom/entity_access_by_field/tests/src/Unit/EntityAccessTest.php \Drupal\entity_access_by_field\Tests\EntityAccessTest::testForbiddenAccess()
  4. 8.4 modules/custom/entity_access_by_field/tests/src/Unit/EntityAccessTest.php \Drupal\entity_access_by_field\Tests\EntityAccessTest::testForbiddenAccess()
  5. 8.5 modules/custom/entity_access_by_field/tests/src/Unit/EntityAccessTest.php \Drupal\entity_access_by_field\Tests\EntityAccessTest::testForbiddenAccess()
  6. 8.6 modules/custom/entity_access_by_field/tests/src/Unit/EntityAccessTest.php \Drupal\entity_access_by_field\Tests\EntityAccessTest::testForbiddenAccess()
  7. 8.7 modules/custom/entity_access_by_field/tests/src/Unit/EntityAccessTest.php \Drupal\entity_access_by_field\Tests\EntityAccessTest::testForbiddenAccess()
  8. 8.8 modules/custom/entity_access_by_field/tests/src/Unit/EntityAccessTest.php \Drupal\entity_access_by_field\Tests\EntityAccessTest::testForbiddenAccess()
  9. 10.3.x modules/custom/entity_access_by_field/tests/src/Unit/EntityAccessTest.php \Drupal\entity_access_by_field\Tests\EntityAccessTest::testForbiddenAccess()
  10. 10.0.x modules/custom/entity_access_by_field/tests/src/Unit/EntityAccessTest.php \Drupal\entity_access_by_field\Tests\EntityAccessTest::testForbiddenAccess()
  11. 10.1.x modules/custom/entity_access_by_field/tests/src/Unit/EntityAccessTest.php \Drupal\entity_access_by_field\Tests\EntityAccessTest::testForbiddenAccess()
  12. 10.2.x modules/custom/entity_access_by_field/tests/src/Unit/EntityAccessTest.php \Drupal\entity_access_by_field\Tests\EntityAccessTest::testForbiddenAccess()

Tests the EntityAccessHelper::nodeAccessCheck for Forbidden Access.

File

modules/custom/entity_access_by_field/tests/src/Unit/EntityAccessTest.php, line 43

Class

EntityAccessTest
Unit test of entity_access_by_field hook_node_access implementation.

Namespace

Drupal\entity_access_by_field\Tests

Code

public function testForbiddenAccess() {
  $node = $this
    ->prophesize(NodeInterface::class);
  $this->fieldId = 'node.article.field_content_visibility';
  $this->fieldValue = 'public';
  $this->fieldType = 'entity_access_field';
  $this->accountId = 5;
  $this->nodeOwnerId = 3;
  $fieldDefinitionInterface = $this
    ->getMock('Drupal\\Core\\Field\\FieldConfigInterface');
  $fieldDefinitionInterface
    ->expects($this
    ->once())
    ->method('getType')
    ->willReturn($this->fieldType);
  $fieldDefinitionInterface
    ->expects($this
    ->any())
    ->method('id')
    ->willReturn('node.article.field_content_visibility');
  $fieldItemListInterface = $this
    ->getMock('Drupal\\Core\\Field\\FieldItemListInterface');
  $fieldItemListInterface
    ->expects($this
    ->any())
    ->method('getValue')
    ->willReturn([
    0 => [
      'value' => 'public',
    ],
  ]);
  $node
    ->get('entity_access_field')
    ->willReturn($fieldItemListInterface);
  $node
    ->getFieldDefinitions()
    ->willReturn([
    $this->fieldType => $fieldDefinitionInterface,
  ]);
  $node
    ->getOwnerId()
    ->willReturn($this->nodeOwnerId);
  $node = $node
    ->reveal();
  $op = 'view';
  $account = $this
    ->prophesize(AccountInterface::class);
  $account
    ->hasPermission('view ' . $this->fieldId . ':' . $this->fieldValue . ' content')
    ->willReturn(FALSE);
  $account
    ->id()
    ->willReturn($this->accountId);
  $account = $account
    ->reveal();
  $access_result = EntityAccessHelper::nodeAccessCheck($node, $op, $account);
  $this
    ->assertEquals(1, $access_result);
  $this
    ->assertNotEquals(0, $access_result);
  $this
    ->assertNotEquals(2, $access_result);
}