You are here

protected function ContentEntityNormalizerTest::createMockFieldListItem in Drupal 9

Same name and namespace in other branches
  1. 8 core/modules/serialization/tests/src/Unit/Normalizer/ContentEntityNormalizerTest.php \Drupal\Tests\serialization\Unit\Normalizer\ContentEntityNormalizerTest::createMockFieldListItem()

Creates a mock field list item.

Parameters

bool $access:

bool $internal:

\Drupal\Core\Session\AccountInterface $user_context:

Return value

\Drupal\Core\Field\FieldItemListInterface|\PHPUnit\Framework\MockObject\MockObject

2 calls to ContentEntityNormalizerTest::createMockFieldListItem()
ContentEntityNormalizerTest::testNormalize in core/modules/serialization/tests/src/Unit/Normalizer/ContentEntityNormalizerTest.php
Tests the normalize() method.
ContentEntityNormalizerTest::testNormalizeWithAccountContext in core/modules/serialization/tests/src/Unit/Normalizer/ContentEntityNormalizerTest.php
Tests the normalize() method with account context passed.

File

core/modules/serialization/tests/src/Unit/Normalizer/ContentEntityNormalizerTest.php, line 153

Class

ContentEntityNormalizerTest
@coversDefaultClass \Drupal\serialization\Normalizer\ContentEntityNormalizer @group serialization

Namespace

Drupal\Tests\serialization\Unit\Normalizer

Code

protected function createMockFieldListItem($access, $internal, AccountInterface $user_context = NULL) {
  $data_definition = $this
    ->prophesize(DataDefinitionInterface::class);
  $mock = $this
    ->createMock('Drupal\\Core\\Field\\FieldItemListInterface');
  $mock
    ->expects($this
    ->once())
    ->method('getDataDefinition')
    ->will($this
    ->returnValue($data_definition
    ->reveal()));
  $data_definition
    ->isInternal()
    ->willReturn($internal)
    ->shouldBeCalled();
  if (!$internal) {
    $mock
      ->expects($this
      ->once())
      ->method('access')
      ->with('view', $user_context)
      ->will($this
      ->returnValue($access));
  }
  return $mock;
}