protected function FeedsParaMapperNestedImportTestCase::testNestedImport in Feeds Paragraphs 7
Test importing nodes with nested paragraphs fields.
- Tests importing a node.
- Checks that the host Paragraphs field exists on the created node.
- Check that the paragraphs bundle field value matches the source.
File
- tests/
importing.test, line 113 - Contains ImportingTestCase.
Class
- FeedsParaMapperNestedImportTestCase
- Tests importing to a content type with a nested Paragraphs field.
Code
protected function testNestedImport() {
parent::import();
parent::topHostParagraphsFieldExists();
parent::topHostParagraphsEntityExists();
$items = parent::getTopHostParagraphsEntities();
krsort($this->bundles);
$this->bundles = array_values($this->bundles);
foreach ($this->bundles as $bundle) {
foreach ($bundle['fields'] as $field) {
$machine_name = 'field_' . $field['name'];
$value = $this
->getValues($items[0], $machine_name);
$value = reset($value);
$message = "Field has value";
$this
->assertNotNull($value, $message, 'Nested Importing');
if ($field['type'] === 'paragraphs') {
$pi = new ParagraphsItemEntity();
$isParagraph = get_class($value) === get_class($pi);
$message = "Value is paragraph";
$this
->assertTrue($isParagraph, $message, 'Nested Importing');
}
elseif ($field['type'] === "text") {
$message = "Value is text";
$this
->assertTrue(is_string($value), $message, 'Nested Importing');
$source_value = "This is a dummy text";
$value_matches = $value === $source_value;
$message = "The value of the bundle field matches the source value";
$this
->assertTrue($value_matches, $message, 'Nested Importing');
}
else {
$source_value = array(
"My image alt",
"My image title",
"public:///image.png",
);
$found = 0;
foreach ($source_value as $item) {
if (in_array($item, $value)) {
$found++;
}
}
$message = "The value of the bundle field matches the source value";
$this
->assertEqual(count($source_value), $found, $message, "Nested Importing");
}
}
}
}