You are here

public function EntityAccessTest::testAuthorAccessAllowed in Open Social 10.2.x

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

Tests the EntityAccessHelper::nodeAccessCheck for Author Access Allowed.

File

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

Class

EntityAccessTest
Unit test of entity_access_by_field hook_node_access implementation.

Namespace

Drupal\entity_access_by_field\Tests

Code

public function testAuthorAccessAllowed() {
  $node = $this
    ->prophesize(NodeInterface::class);
  $this->fieldValue = 'nonexistant';
  $this->fieldType = 'entity_access_field';
  $this->nodeOwnerId = 5;
  $fieldDefinitionInterface = $this
    ->createMock('Drupal\\Core\\Field\\FieldConfigInterface');
  $fieldDefinitionInterface
    ->expects($this
    ->once())
    ->method('getType')
    ->willReturn($this->fieldType);
  $fieldDefinitionInterface
    ->expects($this
    ->any())
    ->method('id')
    ->willReturn($this->fieldId);
  $fieldItemListInterface = $this
    ->createMock('Drupal\\Core\\Field\\FieldItemListInterface');
  $fieldItemListInterface
    ->expects($this
    ->any())
    ->method('getValue')
    ->willReturn([
    0 => [
      'value' => $this->fieldValue,
    ],
  ]);
  $node
    ->get('entity_access_field')
    ->willReturn($fieldItemListInterface);
  $node
    ->getFieldDefinitions()
    ->willReturn([
    $this->fieldType => $fieldDefinitionInterface,
  ]);
  $node
    ->getCacheContexts()
    ->willReturn(NULL);
  $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(2, $access_result);
  $this
    ->assertNotEquals(0, $access_result);
  $this
    ->assertNotEquals(1, $access_result);
}