FeedsItemTargetIdFormatterTest.php in Feeds 8.3
File
tests/src/Functional/Plugin/Field/FieldFormatter/FeedsItemTargetIdFormatterTest.php
View source
<?php
namespace Drupal\Tests\feeds\Functional\Plugin\Field\FieldFormatter;
class FeedsItemTargetIdFormatterTest extends FeedsItemFormatterTestBase {
protected function setUp() {
parent::setUp();
$this->container
->get('entity_display.repository')
->getViewDisplay('node', 'article', 'default')
->setComponent('feeds_item', [
'type' => 'feeds_item_target_id',
'weight' => 1,
])
->save();
}
public function testFeedsItemTargetIdFormatter($input, $expected) {
$feed = $this
->createCsvFeed();
$article = $this
->createNodeWithFeedsItem($feed);
$article->feeds_item->target_id = $input;
$display = $this->container
->get('entity_display.repository')
->getViewDisplay($article
->getEntityTypeId(), $article
->bundle(), 'default');
$content = $display
->build($article);
$rendered_content = $this->container
->get('renderer')
->renderRoot($content);
if ($expected) {
$this
->assertStringContainsString($expected, (string) $rendered_content);
}
else {
$this
->assertFeedsItemFieldNotDisplayed($rendered_content, $input);
}
}
public function providerTargetIds() {
return [
'empty target id' => [
'',
NULL,
],
'existing target id' => [
'1',
'<div>1</div>',
],
'non existing target id' => [
'123',
NULL,
],
'weird html string target id' => [
'<em>Skeletor!!!!</em>',
NULL,
],
];
}
}