You are here

public function TestRevisionHandler::testCleanUp in Feeds Paragraphs 8

@covers ::cleanUp

File

tests/src/Unit/TestRevisionHandler.php, line 152

Class

TestRevisionHandler
@group Feeds Paragraphs @coversDefaultClass \Drupal\feeds_para_mapper\RevisionHandler

Namespace

Drupal\Tests\feeds_para_mapper\Unit

Code

public function testCleanUp() {
  $paragraphs = $this->entityHelper->paragraphs;
  $paragraph = $paragraphs[2];

  // Mock RevisionHandler:
  $revHandler = $this
    ->getMockBuilder(RevisionHandler::class)
    ->disableOriginalConstructor()
    ->setMethods(array(
    'removeUnused',
  ))
    ->getMock();
  $arr = $this
    ->isType('array');
  $revHandler
    ->expects($this
    ->atLeastOnce())
    ->method('removeUnused')
    ->with($arr, $arr, $this
    ->isInstanceOf(FieldConfigInterface::class));

  // Mock Importer:
  $importer = $this
    ->getMockBuilder(Importer::class)
    ->disableOriginalConstructor()
    ->getMock();
  $importer
    ->expects($this
    ->atLeastOnce())
    ->method('loadTarget')
    ->with($this
    ->isInstanceOf(EntityInterface::class), $this
    ->isInstanceOf(FieldConfigInterface::class))
    ->willReturn(array(
    $paragraph
      ->reveal(),
    $paragraph
      ->reveal(),
  ));
  $this
    ->updateProperty(RevisionHandler::class, $revHandler, 'importer', $importer);
  $this
    ->updateProperty(RevisionHandler::class, $revHandler, 'entity', $this->node
    ->reveal());
  $field = end($this->fieldHelper->fields)
    ->reveal();
  $info = $this
    ->getTargetInfo();
  $info->paragraphs = array(
    $paragraph
      ->reveal(),
  );
  $field
    ->set('target_info', $info);

  // And call the method:
  $method = $this
    ->getMethod($revHandler, 'cleanUp');
  $method
    ->invoke($revHandler, array(
    $field,
  ));
}