View source
<?php
namespace Drupal\Tests\feeds\Functional\Plugin\Field\FieldFormatter;
use Drupal\feeds\FeedInterface;
use Drupal\Tests\feeds\Functional\FeedsBrowserTestBase;
abstract class FeedsItemFormatterTestBase extends FeedsBrowserTestBase {
public static $modules = [
'feeds',
'node',
'user',
'file',
'field',
];
protected function setUp() {
parent::setUp();
$this
->createFieldWithStorage('feeds_item', [
'type' => 'feeds_item',
'label' => 'Feeds item',
]);
}
protected function createCsvFeed() {
$feed_type = $this
->createFeedTypeForCsv([
'guid',
'title',
], [
'mappings' => array_merge($this
->getDefaultMappings(), [
[
'target' => 'feeds_item',
'map' => [
'guid' => 'guid',
'url' => 'url',
],
],
]),
]);
$feed = $this
->createFeed($feed_type
->id(), [
'source' => $this
->resourcesPath() . '/csv/content.csv',
]);
return $feed;
}
protected function assertFeedsItemFieldNotDisplayed($rendered_content, $input) {
$this
->assertStringNotContainsString('<div>Feeds item</div>', (string) $rendered_content);
$this
->assertStringNotContainsString('<div>' . $input . '</div>', (string) $rendered_content);
}
public function addFieldToFeed(FeedInterface $feed) {
$feed_type_id = $feed
->getType()
->id();
$this
->createFieldWithStorage('oneliner', [
'entity_type' => 'feeds_feed',
'bundle' => $feed_type_id,
'type' => 'text',
'label' => 'Witty one liner label',
]);
$this->container
->get('entity_display.repository')
->getViewDisplay('feeds_feed', $feed_type_id, 'default')
->setComponent('oneliner', [
'type' => 'text_default',
'settings' => [
'label' => 'Witty one liner',
],
])
->save();
$feed = $this
->reloadEntity($feed);
$feed->oneliner = [
'value' => 'He is not only from medieval Japan, but also from an alternate universe, so naturally he speaks English!',
'format' => 'plain_text',
];
$feed
->save();
return $feed;
}
}