FeedsItemImportedFormatterTest.php in Feeds 8.3
File
tests/src/Functional/Plugin/Field/FieldFormatter/FeedsItemImportedFormatterTest.php
View source
<?php
namespace Drupal\Tests\feeds\Functional\Plugin\Field\FieldFormatter;
class FeedsItemImportedFormatterTest extends FeedsItemFormatterTestBase {
protected function setUp() {
parent::setUp();
$this->container
->get('entity_display.repository')
->getViewDisplay('node', 'article', 'default')
->setComponent('feeds_item', [
'type' => 'feeds_item_imported',
'weight' => 1,
])
->save();
}
protected function switchToCustomDateFormat() {
$settings = [
'date_format' => 'custom',
'custom_date_format' => 'm-d-Y',
];
$this->container
->get('entity_display.repository')
->getViewDisplay('node', 'article', 'default')
->setComponent('feeds_item', [
'type' => 'feeds_item_imported',
'settings' => $settings,
'weight' => 1,
])
->save();
}
public function testFeedsItemImportedFormatter($input, $expected) {
$feed = $this
->createCsvFeed();
$article = $this
->createNodeWithFeedsItem($feed);
$article->feeds_item->imported = $input;
if ($input == '1543370515') {
$this
->switchToCustomDateFormat();
}
$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);
$this
->assertStringContainsString($expected, (string) $rendered_content);
}
public function providerImported() {
return [
'timestamp default date format' => [
'1543374515',
'<div>Wed, 11/28/2018 - 14:08</div>',
],
'timestamp custom date format' => [
'1543370515',
'<div>11-28-2018</div>',
],
];
}
}