function 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

drupal/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/RssTest.php, line 73
Definition of Drupal\taxonomy\Tests\RssTest.

Class

RssTest
Tests the rendering of term reference fields in RSS feeds.

Namespace

Drupal\taxonomy\Tests

Code

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 = array(
    "view_modes_custom[rss]" => '1',
  );
  $this
    ->drupalPost(NULL, $edit, t('Save'));

  // Change the format to 'RSS category'.
  $this
    ->drupalGet("admin/structure/types/manage/article/display/rss");
  $edit = array(
    "fields[taxonomy_" . $this->vocabulary->machine_name . "][type]" => 'taxonomy_term_reference_rss_category',
  );
  $this
    ->drupalPost(NULL, $edit, t('Save'));

  // Post an article.
  $edit = array();
  $langcode = LANGUAGE_NOT_SPECIFIED;
  $edit["title"] = $this
    ->randomName();
  $edit[$this->instance['field_name'] . '[' . $langcode . '][]'] = $term1->tid;
  $this
    ->drupalPost('node/add/article', $edit, t('Save'));

  // Check that the term is displayed when the RSS feed is viewed.
  $this
    ->drupalGet('rss.xml');
  $test_element = array(
    'key' => 'category',
    'value' => $term1->name,
    'attributes' => array(
      'domain' => url('taxonomy/term/' . $term1->tid, array(
        'absolute' => TRUE,
      )),
    ),
  );
  $this
    ->assertRaw(format_xml_elements(array(
    $test_element,
  )), 'Term is displayed when viewing the rss feed.');

  // Test that the feed page exists for the term.
  $this
    ->drupalGet("taxonomy/term/{$term1->tid}/feed");
  $this
    ->assertRaw('<rss version="2.0"', "Feed page is RSS.");
}