You are here

protected function ContentEntityNormalizerTest::createMockEntityReferenceFieldItemList in Acquia Content Hub 8

Creates a mock field entity reference field item list.

Parameters

string $name: Name of the mock field.

bool $access: Defines whether anyone has access to this field or not.

bool $user_context: The user context used to view the field.

Return value

\Drupal\Core\Field\FieldItemListInterface|\PHPUnit_Framework_MockObject_MockObject The mocked field items.

2 calls to ContentEntityNormalizerTest::createMockEntityReferenceFieldItemList()
ContentEntityNormalizerTest::testNormalizeReferenceField in tests/src/Unit/Normalizer/ContentEntityNormalizerTest.php
Tests the normalize() method.
ContentEntityNormalizerTest::testNormalizeTypeReferenceField in tests/src/Unit/Normalizer/ContentEntityNormalizerTest.php
Tests the normalize() method.

File

tests/src/Unit/Normalizer/ContentEntityNormalizerTest.php, line 1011

Class

ContentEntityNormalizerTest
PHPUnit test for the ContentEntityNormalizer class.

Namespace

Drupal\Tests\acquia_contenthub\Unit\Normalizer

Code

protected function createMockEntityReferenceFieldItemList($name, $access = TRUE, $user_context = NULL) {
  $mock = $this
    ->createMock('Drupal\\Core\\Field\\EntityReferenceFieldItemListInterface');
  $mock
    ->method('access')
    ->with('view', $user_context)
    ->will($this
    ->returnValue($access));
  $field_def = $this
    ->createMock('\\Drupal\\Core\\Field\\FieldDefinitionInterface');
  $field_def
    ->method('getName')
    ->willReturn($name);
  $field_def
    ->method('getType')
    ->willReturn('entity_reference');
  $mock
    ->method('getValue')
    ->willReturn('bla');
  $referenced_entities = [];
  $entity1 = $this
    ->createMock('\\Drupal\\Core\\Entity\\EntityInterface');
  $entity1
    ->method('id')
    ->willReturn('test-id-reference-1');
  $entity1
    ->method('uuid')
    ->willReturn('test-uuid-reference-1');
  $referenced_entities[] = $entity1;
  $entity2 = $this
    ->createMock('\\Drupal\\Core\\Entity\\EntityInterface');
  $entity2
    ->method('id')
    ->willReturn('test-id-reference-2');
  $entity2
    ->method('uuid')
    ->willReturn('test-uuid-reference-2');
  $referenced_entities[] = $entity2;
  $mock
    ->method('getFieldDefinition')
    ->willReturn($field_def);
  $mock
    ->method('referencedEntities')
    ->willReturn($referenced_entities);
  return $mock;
}