You are here

public function NestedErViewmodeEntitiesDetectorTest::testRunWithNonTranslatableNestedERViewModeFields in Lingotek Translation 3.7.x

Same name and namespace in other branches
  1. 4.0.x tests/src/Unit/Plugin/RelatedEntitiesDetector/NestedErViewmodeEntitiesDetectorTest.php \Drupal\Tests\lingotek\Unit\Plugin\RelatedEntitiesDetector\NestedErViewmodeEntitiesDetectorTest::testRunWithNonTranslatableNestedERViewModeFields()
  2. 3.4.x tests/src/Unit/Plugin/RelatedEntitiesDetector/NestedErViewmodeEntitiesDetectorTest.php \Drupal\Tests\lingotek\Unit\Plugin\RelatedEntitiesDetector\NestedErViewmodeEntitiesDetectorTest::testRunWithNonTranslatableNestedERViewModeFields()
  3. 3.5.x tests/src/Unit/Plugin/RelatedEntitiesDetector/NestedErViewmodeEntitiesDetectorTest.php \Drupal\Tests\lingotek\Unit\Plugin\RelatedEntitiesDetector\NestedErViewmodeEntitiesDetectorTest::testRunWithNonTranslatableNestedERViewModeFields()
  4. 3.6.x tests/src/Unit/Plugin/RelatedEntitiesDetector/NestedErViewmodeEntitiesDetectorTest.php \Drupal\Tests\lingotek\Unit\Plugin\RelatedEntitiesDetector\NestedErViewmodeEntitiesDetectorTest::testRunWithNonTranslatableNestedERViewModeFields()
  5. 3.8.x tests/src/Unit/Plugin/RelatedEntitiesDetector/NestedErViewmodeEntitiesDetectorTest.php \Drupal\Tests\lingotek\Unit\Plugin\RelatedEntitiesDetector\NestedErViewmodeEntitiesDetectorTest::testRunWithNonTranslatableNestedERViewModeFields()

@covers ::extract

File

tests/src/Unit/Plugin/RelatedEntitiesDetector/NestedErViewmodeEntitiesDetectorTest.php, line 263

Class

NestedErViewmodeEntitiesDetectorTest
Unit test for the nested entity references views mode detector plugin

Namespace

Drupal\Tests\lingotek\Unit\Plugin\RelatedEntitiesDetector

Code

public function testRunWithNonTranslatableNestedERViewModeFields() {
  $this->lingotekConfiguration
    ->expects($this
    ->never())
    ->method('isFieldLingotekEnabled')
    ->with('entity_id', 'bundle', 'er_viewmode_field')
    ->willReturn(TRUE);
  $this->lingotekConfiguration
    ->expects($this
    ->never())
    ->method('isEnabled')
    ->with('another_entity', 'another_bundle')
    ->willReturn(TRUE);
  $titleFieldDefinition = $this
    ->createMock(BaseFieldDefinition::class);
  $titleFieldDefinition
    ->expects($this
    ->any())
    ->method('getType')
    ->willReturn('text');
  $titleFieldDefinition
    ->expects($this
    ->any())
    ->method('getName')
    ->willReturn('Title');
  $target_entity_type = $this
    ->createMock(ContentEntityType::class);
  $embedded_er_viewmode = $this
    ->createmock(ContentEntityInterface::class);
  $embedded_er_viewmode
    ->expects($this
    ->any())
    ->method('referencedEntities')
    ->willReturn([
    $embedded_er_viewmode,
  ]);
  $embedded_er_viewmode
    ->expects($this
    ->any())
    ->method('bundle')
    ->willReturn('another_bundle');
  $embedded_er_viewmode
    ->expects($this
    ->any())
    ->method('id')
    ->willreturn(2);
  $embedded_er_viewmode
    ->expects($this
    ->any())
    ->method('isTranslatable')
    ->willReturn(FALSE);
  $embedded_er_viewmode
    ->expects($this
    ->any())
    ->method('getEntityTypeId')
    ->willReturn('another_entity');
  $embedded_er_viewmode
    ->expects($this
    ->any())
    ->method('getUntranslated')
    ->willReturnSelf();
  $nestedEntityReferenceFieldStorageDefinition = $this
    ->createMock(FieldStorageDefinition::class);
  $nestedEntityReferenceFieldStorageDefinition
    ->expects($this
    ->any())
    ->method('getSetting')
    ->with('target_type')
    ->willReturn('another_entity');
  $nestedEntityReferenceFieldDefinition = $this
    ->createMock(BaseFieldDefinition::class);
  $nestedEntityReferenceFieldDefinition
    ->expects($this
    ->any())
    ->method('getType')
    ->willReturn('er_viewmode');
  $nestedEntityReferenceFieldDefinition
    ->expects($this
    ->any())
    ->method('getName')
    ->willReturn('Nested Reference');
  $nestedEntityReferenceFieldDefinition
    ->expects($this
    ->any())
    ->method('getFieldStorageDefinition')
    ->willReturn($nestedEntityReferenceFieldStorageDefinition);
  $this->entityTypeManager
    ->expects($this
    ->any())
    ->method('getDefinition')
    ->with('another_entity')
    ->willReturn($target_entity_type);
  $this->entityFieldManager
    ->expects($this
    ->any())
    ->method('getFieldDefinitions')
    ->willReturn([
    'title' => $titleFieldDefinition,
    'er_viewmode_field' => $nestedEntityReferenceFieldDefinition,
  ]);
  $itemList = $this
    ->createMock(EntityInterface::class);
  $itemList
    ->expects($this
    ->once())
    ->method('referencedEntities')
    ->willReturn([
    $embedded_er_viewmode,
  ]);
  $entity = $this
    ->createMock(ContentEntityInterface::class);
  $entity
    ->expects($this
    ->any())
    ->method('getEntityTypeId')
    ->willReturn($this->entityType
    ->id());
  $entity
    ->expects($this
    ->any())
    ->method('bundle')
    ->willReturn('bundle');
  $entity
    ->expects($this
    ->any())
    ->method('id')
    ->willReturn(1);
  $entity
    ->expects($this
    ->any())
    ->method('getUntranslated')
    ->willReturnSelf();
  $entity
    ->expects($this
    ->any())
    ->method('get')
    ->with('er_viewmode_field')
    ->willReturn($itemList);
  $entities = [];
  $related = [];
  $visited = [];
  $this->detector
    ->extract($entity, $entities, $related, 2, $visited);

  // Assert the entity is included, but not the non-translatable entity reference elements.
  $this
    ->assertCount(1, $entities);
  $this
    ->assertEquals($entities['entity_id'][1], $entity);

  // Assert the entity references are not included in the list.
  $this
    ->assertCount(0, $related);
}