You are here

protected function ContentEntityNormalizerTest::createMockFieldListItem in Drupal 10

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()
  2. 9 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: The value that access() will return.

bool $internal: The value that isInternal() will return.

\Drupal\Core\Session\AccountInterface $user_context: The user context used for the access check.

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 157

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;
}