function 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[[api-linebreak]] @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;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.