You are here

public function NestedLayoutBuilderEntitiesDetectorTest::testRunWithLingotekDisabledNestedLayoutBuilderEntities in Lingotek Translation 3.6.x

Same name and namespace in other branches
  1. 4.0.x tests/src/Unit/Plugin/RelatedEntitiesDetector/NestedLayoutBuilderEntitiesDetectorTest.php \Drupal\Tests\lingotek\Unit\Plugin\RelatedEntitiesDetector\NestedLayoutBuilderEntitiesDetectorTest::testRunWithLingotekDisabledNestedLayoutBuilderEntities()
  2. 3.5.x tests/src/Unit/Plugin/RelatedEntitiesDetector/NestedLayoutBuilderEntitiesDetectorTest.php \Drupal\Tests\lingotek\Unit\Plugin\RelatedEntitiesDetector\NestedLayoutBuilderEntitiesDetectorTest::testRunWithLingotekDisabledNestedLayoutBuilderEntities()
  3. 3.7.x tests/src/Unit/Plugin/RelatedEntitiesDetector/NestedLayoutBuilderEntitiesDetectorTest.php \Drupal\Tests\lingotek\Unit\Plugin\RelatedEntitiesDetector\NestedLayoutBuilderEntitiesDetectorTest::testRunWithLingotekDisabledNestedLayoutBuilderEntities()
  4. 3.8.x tests/src/Unit/Plugin/RelatedEntitiesDetector/NestedLayoutBuilderEntitiesDetectorTest.php \Drupal\Tests\lingotek\Unit\Plugin\RelatedEntitiesDetector\NestedLayoutBuilderEntitiesDetectorTest::testRunWithLingotekDisabledNestedLayoutBuilderEntities()

@covers ::extract @dataProvider dataProviderTranslationModules

File

tests/src/Unit/Plugin/RelatedEntitiesDetector/NestedLayoutBuilderEntitiesDetectorTest.php, line 489

Class

NestedLayoutBuilderEntitiesDetectorTest
Unit test for the nested layout builder entities detector plugin

Namespace

Drupal\Tests\lingotek\Unit\Plugin\RelatedEntitiesDetector

Code

public function testRunWithLingotekDisabledNestedLayoutBuilderEntities($module_data, $field_name, $field_type) {
  $this->lingotekConfiguration
    ->expects($this
    ->once())
    ->method('isEnabled')
    ->with('block_content', 'basic')
    ->willReturn(TRUE);
  $this->lingotekConfiguration
    ->expects($this
    ->once())
    ->method('isFieldLingotekEnabled')
    ->with('entity_id', 'bundle', $field_name)
    ->willReturn(FALSE);
  $this->moduleHandler
    ->expects($this
    ->any())
    ->method('moduleExists')
    ->withConsecutive([
    'layout_builder_at',
  ], [
    'layout_builder_st',
  ])
    ->willReturnOnConsecutiveCalls($module_data['layout_builder_at'], $module_data['layout_builder_st']);
  $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);
  $target_entity_type
    ->expects($this
    ->any())
    ->method('getKey')
    ->with('revision')
    ->willReturn('revision_id');
  $embedded_block = $this
    ->createMock(ContentEntityInterface::class);
  $embedded_block
    ->expects($this
    ->any())
    ->method('isTranslatable')
    ->willReturn(TRUE);
  $embedded_block
    ->expects($this
    ->any())
    ->method('bundle')
    ->willReturn('basic');
  $embedded_block
    ->expects($this
    ->any())
    ->method('id')
    ->willReturn(2);
  $embedded_block
    ->expects($this
    ->any())
    ->method('getEntityTypeId')
    ->willReturn('block_content');
  $embedded_block
    ->expects($this
    ->any())
    ->method('getUntranslated')
    ->willReturnSelf();
  $nestedLayoutFieldDefinition = $this
    ->createMock(BaseFieldDefinition::class);
  $nestedLayoutFieldDefinition
    ->expects($this
    ->any())
    ->method('getType')
    ->willReturn($field_type);
  $nestedLayoutFieldDefinition
    ->expects($this
    ->any())
    ->method('getName')
    ->willReturn('Nested Block');
  $query = $this
    ->createMock(QueryInterface::class);
  $query
    ->expects($this
    ->any())
    ->method('condition')
    ->willReturnSelf();
  $query
    ->expects($this
    ->any())
    ->method('execute')
    ->willReturn([
    1,
  ]);
  $entityStorage = $this
    ->createMock(EntityStorageInterface::class);
  $entityStorage
    ->expects($this
    ->any())
    ->method('load')
    ->with(1)
    ->willReturn($embedded_block);
  $entityStorage
    ->expects($this
    ->any())
    ->method('getQuery')
    ->willReturn($query);
  $entityStorage
    ->expects($this
    ->any())
    ->method('getEntityType')
    ->willReturn($target_entity_type);
  $this->entityTypeManager
    ->expects($this
    ->any())
    ->method('getDefinition')
    ->with('block_content')
    ->willReturn($target_entity_type);
  $this->entityTypeManager
    ->expects($this
    ->any())
    ->method('getStorage')
    ->with('block_content')
    ->willReturn($entityStorage);
  $this->entityFieldManager
    ->expects($this
    ->any())
    ->method('getFieldDefinitions')
    ->withConsecutive([
    'entity_id',
  ], [
    'block_content',
  ])
    ->willReturn([
    'title' => $titleFieldDefinition,
    $field_name => $nestedLayoutFieldDefinition,
  ], []);
  $componentArray = [
    'configuration' => [
      'block_revision_id' => 1,
    ],
  ];
  $component = $this
    ->createMock(SectionComponent::class);
  $component
    ->expects($this
    ->any())
    ->method('getPluginId')
    ->willReturn('inline_block');
  $component
    ->expects($this
    ->any())
    ->method('toArray')
    ->willReturn($componentArray);
  $componentItemList = [
    $component,
  ];
  $sectionObject = $this
    ->createMock(Section::class);
  $sectionObject
    ->expects($this
    ->any())
    ->method('getComponents')
    ->willReturn($componentItemList);
  $sectionItemList = [
    [
      'section' => $sectionObject,
    ],
  ];
  $layoutField = $this
    ->createMock(LayoutSectionItemList::class);
  $layoutField
    ->expects($this
    ->any())
    ->method('getValue')
    ->willReturn($sectionItemList);
  $entity = $this
    ->createMock(ContentEntityInterface::class);
  $entity
    ->expects($this
    ->any())
    ->method('getEntityTypeId')
    ->willReturn($this->entityType
    ->id());
  $entity
    ->expects($this
    ->any())
    ->method('id')
    ->willReturn(1);
  $entity
    ->expects($this
    ->any())
    ->method('bundle')
    ->willReturn('bundle');
  $entity
    ->expects($this
    ->any())
    ->method('getUntranslated')
    ->willReturnSelf();
  $entity
    ->expects($this
    ->any())
    ->method('get')
    ->with(OverridesSectionStorage::FIELD_NAME)
    ->willReturn($layoutField);
  $entities = [];
  $related = [];
  $visited = [];
  $this->detector
    ->extract($entity, $entities, $related, 2, $visited);

  // Assert the entity is included, but not the non-translatable layout blocks.
  $this
    ->assertCount(2, $entities);
  $this
    ->assertEquals($entities['entity_id'][1], $entity);
  $this
    ->assertEquals($entities['block_content'][2], $embedded_block);

  // Assert the layout blocks are not included as related.
  $this
    ->assertCount(0, $related);
}