View source
<?php
namespace Drupal\Tests\views_rss\Functional;
use Drupal\field\Entity\FieldConfig;
use Drupal\file\Entity\File;
use Drupal\Tests\BrowserTestBase;
class DisplayFeedTest extends BrowserTestBase {
protected $strictConfigSchema = FALSE;
public static $modules = [
'file',
'image',
'node',
'taxonomy',
'views',
'views_rss',
'views_rss_core',
'views_rss_test_config',
];
protected $defaultTheme = 'classy';
protected $testStartTime;
public function setUp() {
parent::setUp();
$this->testStartTime = \Drupal::time()
->getCurrentTime();
}
public function testFeedOutput() {
$this
->drupalCreateContentType([
'type' => 'page',
]);
FieldConfig::create([
'entity_type' => 'node',
'field_name' => 'field_image',
'bundle' => 'page',
])
->save();
\Drupal::service('file_system')
->copy($this->root . '/core/misc/druplicon.png', 'public://example.jpg');
$image = File::create([
'uri' => 'public://example.jpg',
]);
$image
->save();
$node_title = 'This "cool" & "neat" article\'s title';
$node = $this
->drupalCreateNode([
'title' => $node_title,
'body' => [
0 => [
'value' => 'A paragraph',
'format' => filter_default_format(),
],
],
'field_image' => $image,
]);
$node_link = $node
->toUrl()
->setAbsolute()
->toString();
$node2 = $this
->drupalCreateNode();
$node2
->setCreatedTime(strtotime('-1 day'))
->save();
$this
->drupalGet('views-rss.xml');
$this
->assertSession()
->responseHeaderEquals('Content-Type', 'application/rss+xml; charset=utf-8');
$this
->assertEquals($node_title, $this
->getSession()
->getDriver()
->getText('//item/title'));
$this
->assertEquals($node_link, $this
->getSession()
->getDriver()
->getText('//item/link'));
$this
->assertEquals($node_link, $this
->getSession()
->getDriver()
->getText('//item/comments'));
$this
->assertSession()
->responseContains('<p>A paragraph</p>');
$selector = sprintf('enclosure[@url="%s"][@length="%s"][@type="%s"]', file_create_url('public://example.jpg'), $image
->getSize(), $image
->getMimeType());
$this
->assertNotNull($this
->getSession()
->getDriver()
->find($selector));
$this
->drupalGet('views-rss.xml', [
'query' => [
'field_tags_target_id' => 1,
],
]);
$this
->assertContains('views-rss.xml?field_tags_target_id=1', $this
->getSession()
->getDriver()
->getText('//item/source/@url'));
$this
->assertEquals(gmdate('r', $node
->getCreatedTime()), $this
->getSession()
->getDriver()
->getText('//channel/pubDate'));
$this
->assertGreaterThanOrEqual($this->testStartTime, strtotime($this
->getSession()
->getDriver()
->getText('//channel/lastBuildDate')));
}
}