public function TestImporter::testGetTarget in Feeds Paragraphs 8
@covers ::getTarget
File
- tests/
src/ Unit/ TestImporter.php, line 190
Class
- TestImporter
- @group Feeds Paragraphs @coversDefaultClass \Drupal\feeds_para_mapper\Importer
Namespace
Drupal\Tests\feeds_para_mapper\UnitCode
public function testGetTarget() {
$this->entityHelper->values = array();
$method = $this
->getMethod(Importer::class, 'getTarget');
$any = Argument::any();
$str = Argument::type('string');
$paragraph = $this
->prophesize(Paragraph::class);
$paragraph
->hasField($any)
->willReturn(true);
$values = array(
array(
'entity' => $paragraph
->reveal(),
),
);
$this->node
->hasField($str)
->willReturn(true);
$fieldItem = $this
->prophesize(EntityReferenceRevisionsFieldItemList::class);
$fieldItem
->getValue()
->willReturn($values);
$this->node
->get($str)
->willReturn($fieldItem
->reveal());
$paragraph
->get($str)
->willReturn($fieldItem
->reveal());
$args = array(
$this->node
->reveal(),
$this->field,
);
// Call getTarget:
$result = $method
->invokeArgs($this->importer, $args);
self::assertNotEmpty($result, "Result not empty");
foreach ($result as $item) {
self::assertInstanceOf(Paragraph::class, $item, "The result item is paragraph");
}
// Test with non-nested field:
$info = $this->field
->get('target_info');
$info->path = array(
array(
'bundle' => 'bundle_one',
'host_field' => 'paragraph_field',
'host_entity' => 'node',
'order' => 0,
),
);
$this->field
->set('target_info', $info);
$args = array(
$paragraph
->reveal(),
$this->field,
);
// Call getTarget:
$result = $method
->invokeArgs($this->importer, $args);
self::assertNotEmpty($result, "Result not empty");
foreach ($result as $item) {
self::assertInstanceOf(Paragraph::class, $item, "The result item is paragraph");
}
}