protected function FeedsParaMapperSingleValueTestCase::checkFileFieldImport in Feeds Paragraphs 7
Test importing nodes with image field in a Paragraphs bundle.
The point of this test is to check if the module works, when the a field module sets multiple targets to a field, e.g: image:alt and image:title
- 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.
1 call to FeedsParaMapperSingleValueTestCase::checkFileFieldImport()
- FeedsParaMapperSingleValueTestCase::testImport in tests/
importing.test - Test importing nodes with paragraphs field value.
File
- tests/
importing.test, line 58 - Contains ImportingTestCase.
Class
- FeedsParaMapperSingleValueTestCase
- Tests importing a single value to a content type with a Paragraphs field.
Code
protected function checkFileFieldImport() {
$items = parent::getTopHostParagraphsEntities();
$last = count($this->bundles[0]['fields']) - 1;
$image_field = "field_" . $this->bundles[0]['fields'][$last]['name'];
$lang = $items[0]
->langcode();
$image_field_exists = isset($items[0]->{$image_field});
$message = format_string("The image field @field exists", array(
'@field' => $image_field,
));
$this
->assertTrue($image_field_exists, $message);
$expected_values = array(
'alt' => 'My image alt',
'title' => "My image title",
'uri' => 'public:///image.png',
);
foreach ($expected_values as $field => $expected_value) {
$value_exists = isset($items[0]->{$image_field}[$lang][0][$field]);
$message = format_string("The image sub-field @field has value", array(
"@field" => $field,
));
$this
->assertTrue($value_exists, $message, 'Importing');
$value_matches = $items[0]->{$image_field}[$lang][0][$field] === $expected_value;
$message = format_string("The value of the image sub-field @field matches the source value", array(
"@field" => $field,
));
$this
->assertTrue($value_matches, $message, 'Importing');
}
}