You are here

public function FieldDataProducerAccessTest::testFieldDataProducerAccessCheck in Open Social 10.1.x

Same name and namespace in other branches
  1. 10.3.x modules/custom/social_graphql/tests/src/Kernel/FieldDataProducerAccessTest.php \Drupal\Tests\social_graphql\Kernel\FieldDataProducerAccessTest::testFieldDataProducerAccessCheck()
  2. 10.0.x modules/custom/social_graphql/tests/src/Kernel/FieldDataProducerAccessTest.php \Drupal\Tests\social_graphql\Kernel\FieldDataProducerAccessTest::testFieldDataProducerAccessCheck()
  3. 10.2.x modules/custom/social_graphql/tests/src/Kernel/FieldDataProducerAccessTest.php \Drupal\Tests\social_graphql\Kernel\FieldDataProducerAccessTest::testFieldDataProducerAccessCheck()

Verify that access check is performed for supporting fields.

@covers ::resolve

File

modules/custom/social_graphql/tests/src/Kernel/FieldDataProducerAccessTest.php, line 19

Class

FieldDataProducerAccessTest
@coversDefaultClass \Drupal\social_graphql\Plugin\GraphQL\DataProducer\Field\Field @group social_graphql

Namespace

Drupal\Tests\social_graphql\Kernel

Code

public function testFieldDataProducerAccessCheck() {

  /** @var \Drupal\social_graphql\Plugin\GraphQL\DataProducer\Field\Field $data_producer */
  $data_producer = $this->container
    ->get('plugin.manager.graphql.data_producer')
    ->createInstance('field');
  $allowed_item_list = $this
    ->createMock(FieldItemListInterface::class);
  $allowed_item_list
    ->method('access')
    ->willReturn(TRUE);
  $allowed_entity = $this
    ->createMock(FieldableEntityInterface::class);
  $allowed_entity
    ->method('hasField')
    ->willReturn(TRUE);
  $allowed_entity
    ->method('get')
    ->willReturn($allowed_item_list);
  self::assertEquals($allowed_item_list, $data_producer
    ->resolve($allowed_entity, 'allowed_field'));
  $disallowed_item_list = $this
    ->createMock(FieldItemListInterface::class);
  $disallowed_item_list
    ->method('access')
    ->willReturn(FALSE);
  $disallowed_entity = $this
    ->createMock(FieldableEntityInterface::class);
  $disallowed_entity
    ->method('hasField')
    ->willReturn(TRUE);
  $disallowed_entity
    ->method('get')
    ->willReturn($disallowed_item_list);
  self::assertEquals(NULL, $data_producer
    ->resolve($disallowed_entity, 'disallowed_field'));
}