NodeRSSContentTest.php in Drupal 10
File
core/modules/node/tests/src/Functional/NodeRSSContentTest.php
View source
<?php
namespace Drupal\Tests\node\Functional;
use Drupal\filter\Entity\FilterFormat;
class NodeRSSContentTest extends NodeTestBase {
protected static $modules = [
'node_test',
'views',
];
protected $defaultTheme = 'stark';
protected function setUp() : void {
parent::setUp();
$user = $this
->drupalCreateUser([
'bypass node access',
'access content',
'create article content',
]);
$this
->drupalLogin($user);
}
public function testNodeRSSContent() {
$node = $this
->drupalCreateNode([
'type' => 'article',
'promote' => 1,
]);
$this
->drupalGet('rss.xml');
$rss_only_content = 'Extra data that should appear only in the RSS feed for node ' . $node
->id() . '.';
$this
->assertSession()
->responseContains($rss_only_content);
$non_rss_content = 'Extra data that should appear everywhere except the RSS feed for node ' . $node
->id() . '.';
$this
->assertSession()
->responseNotContains($non_rss_content);
$test_element = "<testElement>Value of testElement RSS element for node {$node->id()}.</testElement>";
$test_ns = 'xmlns:drupaltest="http://example.com/test-namespace"';
$this
->assertSession()
->responseContains($test_element);
$this
->assertSession()
->responseContains($test_ns);
$this
->drupalGet('node/' . $node
->id());
$this
->assertSession()
->responseNotContains($rss_only_content);
}
public function testUrlHandling() {
FilterFormat::create([
'format' => 'full_html',
'name' => 'Full HTML',
'filters' => [],
])
->save();
$defaults = [
'type' => 'article',
'promote' => 1,
];
$file_url_generator = \Drupal::service('file_url_generator');
$this
->drupalCreateNode($defaults + [
'body' => [
'value' => '<p><a href="' . $file_url_generator
->generateString('public://root-relative') . '">Root-relative URL</a></p>',
'format' => 'full_html',
],
]);
$protocol_relative_url = substr($file_url_generator
->generateAbsoluteString('public://protocol-relative'), strlen(\Drupal::request()
->getScheme() . ':'));
$this
->drupalCreateNode($defaults + [
'body' => [
'value' => '<p><a href="' . $protocol_relative_url . '">Protocol-relative URL</a></p>',
'format' => 'full_html',
],
]);
$absolute_url = $file_url_generator
->generateAbsoluteString('public://absolute');
$this
->drupalCreateNode($defaults + [
'body' => [
'value' => '<p><a href="' . $absolute_url . '">Absolute URL</a></p>',
'format' => 'full_html',
],
]);
$this
->drupalGet('rss.xml');
$this
->assertSession()
->responseContains($file_url_generator
->generateAbsoluteString('public://root-relative'));
$this
->assertSession()
->responseContains($protocol_relative_url);
$this
->assertSession()
->responseContains($absolute_url);
}
}