You are here

public function FieldLinkDetectorTest::testRunWithoutLinkFields in Lingotek Translation 3.7.x

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

@covers ::extract

File

tests/src/Unit/Plugin/RelatedEntitiesDetector/FieldLinkDetectorTest.php, line 113

Class

FieldLinkDetectorTest
Unit test for the html links entity detector plugin.

Namespace

Drupal\Tests\lingotek\Unit\Plugin\RelatedEntitiesDetector

Code

public function testRunWithoutLinkFields() {
  $titleFieldDefinition = $this
    ->createMock(BaseFieldDefinition::class);
  $titleFieldDefinition
    ->expects($this
    ->once())
    ->method('getType')
    ->willReturn('text');
  $titleFieldDefinition
    ->expects($this
    ->any())
    ->method('getName')
    ->willReturn('Title');
  $this->entityFieldManager
    ->expects($this
    ->any())
    ->method('getFieldDefinitions')
    ->willReturn([
    $titleFieldDefinition,
  ]);
  $entity = $this
    ->createMock(ContentEntityInterface::class);
  $entity
    ->expects($this
    ->any())
    ->method('getEntityTypeId')
    ->willReturn($this->entityType
    ->getBundleEntityType());
  $entity
    ->expects($this
    ->any())
    ->method('id')
    ->willReturn(1);
  $entity
    ->expects($this
    ->any())
    ->method('uuid')
    ->willReturn('this-is-my-uuid');
  $entity
    ->expects($this
    ->any())
    ->method('bundle')
    ->willReturn($this->entityType
    ->id());
  $entity
    ->expects($this
    ->once())
    ->method('getUntranslated')
    ->willReturnSelf();
  $entities = [];
  $related = [];
  $visited = [];
  $this
    ->assertEmpty($entities);
  $this->detector
    ->extract($entity, $entities, $related, 1, $visited);
  $this
    ->assertCount(1, $entities);
  $this
    ->assertCount(1, $entities['entity_id']);
  $this
    ->assertEquals($entities['entity_id'][1], $entity);
}