public function RssTest::testTaxonomyRss in Drupal 10
Same name and namespace in other branches
- 8 core/modules/taxonomy/tests/src/Functional/RssTest.php \Drupal\Tests\taxonomy\Functional\RssTest::testTaxonomyRss()
- 9 core/modules/taxonomy/tests/src/Functional/RssTest.php \Drupal\Tests\taxonomy\Functional\RssTest::testTaxonomyRss()
Tests that terms added to nodes are displayed in core RSS feed.
Create a node and assert that taxonomy terms appear in rss.xml.
File
- core/
modules/ taxonomy/ tests/ src/ Functional/ RssTest.php, line 82
Class
- RssTest
- Ensure that data added as terms appears in RSS feeds if "RSS Category" format is selected.
Namespace
Drupal\Tests\taxonomy\FunctionalCode
public function testTaxonomyRss() {
// Create two taxonomy terms.
$term1 = $this
->createTerm($this->vocabulary);
// RSS display must be added manually.
$this
->drupalGet("admin/structure/types/manage/article/display");
$edit = [
"display_modes_custom[rss]" => '1',
];
$this
->submitForm($edit, 'Save');
// Change the format to 'RSS category'.
$this
->drupalGet("admin/structure/types/manage/article/display/rss");
$edit = [
"fields[taxonomy_" . $this->vocabulary
->id() . "][type]" => 'entity_reference_rss_category',
"fields[taxonomy_" . $this->vocabulary
->id() . "][region]" => 'content',
];
$this
->submitForm($edit, 'Save');
// Post an article.
$edit = [];
$edit['title[0][value]'] = $this
->randomMachineName();
$edit[$this->fieldName . '[]'] = $term1
->id();
$this
->drupalGet('node/add/article');
$this
->submitForm($edit, 'Save');
// Check that the term is displayed when the RSS feed is viewed.
$this
->drupalGet('rss.xml');
$test_element = sprintf('<category %s>%s</category>', 'domain="' . $term1
->toUrl('canonical', [
'absolute' => TRUE,
])
->toString() . '"', $term1
->getName());
$this
->assertSession()
->responseContains($test_element);
// Test that the feed icon exists for the term.
$this
->drupalGet("taxonomy/term/{$term1->id()}");
$this
->assertSession()
->linkByHrefExists("taxonomy/term/{$term1->id()}/feed");
// Test that the feed page exists for the term.
$this
->drupalGet("taxonomy/term/{$term1->id()}/feed");
$assert = $this
->assertSession();
$assert
->responseHeaderContains('Content-Type', 'application/rss+xml');
// Ensure the RSS version is 2.0.
$rss_array = $this
->getSession()
->getDriver()
->find('rss');
$this
->assertEquals('2.0', reset($rss_array)
->getAttribute('version'));
// Check that the "Exception value" is disabled by default.
$this
->drupalGet('taxonomy/term/all/feed');
$this
->assertSession()
->statusCodeEquals(404);
// Set the exception value to 'all'.
$view = Views::getView('taxonomy_term');
$arguments = $view
->getDisplay()
->getOption('arguments');
$arguments['tid']['exception']['value'] = 'all';
$view
->getDisplay()
->overrideOption('arguments', $arguments);
$view->storage
->save();
// Check the article is shown in the feed.
$node = $this
->drupalGetNodeByTitle($edit['title[0][value]']);
$raw_xml = '<title>' . $node
->label() . '</title>';
$this
->drupalGet('taxonomy/term/all/feed');
$this
->assertSession()
->responseContains($raw_xml);
// Unpublish the article and check that it is not shown in the feed.
$node
->setUnpublished()
->save();
$this
->drupalGet('taxonomy/term/all/feed');
$this
->assertSession()
->responseNotContains($raw_xml);
}