function ContentEntityNormalizerTest::createMockFieldListItem

Same name in other branches
  1. 8.9.x core/modules/serialization/tests/src/Unit/Normalizer/ContentEntityNormalizerTest.php \Drupal\Tests\serialization\Unit\Normalizer\ContentEntityNormalizerTest::createMockFieldListItem()
  2. 10 core/modules/serialization/tests/src/Unit/Normalizer/ContentEntityNormalizerTest.php \Drupal\Tests\serialization\Unit\Normalizer\ContentEntityNormalizerTest::createMockFieldListItem()
  3. 11.x 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')
        ->willReturn($data_definition->reveal());
    $data_definition->isInternal()
        ->willReturn($internal)
        ->shouldBeCalled();
    if (!$internal) {
        $mock->expects($this->once())
            ->method('access')
            ->with('view', $user_context)
            ->willReturn($access);
    }
    return $mock;
}

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