Chris@17: drupalLogin($this->drupalCreateUser(['administer taxonomy', 'bypass node access', 'administer content types', 'administer node display'])); Chris@17: $this->vocabulary = $this->createVocabulary(); Chris@17: $this->fieldName = 'taxonomy_' . $this->vocabulary->id(); Chris@17: Chris@17: $handler_settings = [ Chris@17: 'target_bundles' => [ Chris@17: $this->vocabulary->id() => $this->vocabulary->id(), Chris@17: ], Chris@17: 'auto_create' => TRUE, Chris@17: ]; Chris@17: $this->createEntityReferenceField('node', 'article', $this->fieldName, NULL, 'taxonomy_term', 'default', $handler_settings, FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED); Chris@17: Chris@17: entity_get_form_display('node', 'article', 'default') Chris@17: ->setComponent($this->fieldName, [ Chris@17: 'type' => 'options_select', Chris@17: ]) Chris@17: ->save(); Chris@17: entity_get_display('node', 'article', 'default') Chris@17: ->setComponent($this->fieldName, [ Chris@17: 'type' => 'entity_reference_label', Chris@17: ]) Chris@17: ->save(); Chris@17: } Chris@17: Chris@17: /** Chris@17: * Tests that terms added to nodes are displayed in core RSS feed. Chris@17: * Chris@17: * Create a node and assert that taxonomy terms appear in rss.xml. Chris@17: */ Chris@17: public function testTaxonomyRss() { Chris@17: // Create two taxonomy terms. Chris@17: $term1 = $this->createTerm($this->vocabulary); Chris@17: Chris@17: // RSS display must be added manually. Chris@17: $this->drupalGet("admin/structure/types/manage/article/display"); Chris@17: $edit = [ Chris@17: "display_modes_custom[rss]" => '1', Chris@17: ]; Chris@17: $this->drupalPostForm(NULL, $edit, t('Save')); Chris@17: Chris@17: // Change the format to 'RSS category'. Chris@17: $this->drupalGet("admin/structure/types/manage/article/display/rss"); Chris@17: $edit = [ Chris@17: "fields[taxonomy_" . $this->vocabulary->id() . "][type]" => 'entity_reference_rss_category', Chris@17: "fields[taxonomy_" . $this->vocabulary->id() . "][region]" => 'content', Chris@17: ]; Chris@17: $this->drupalPostForm(NULL, $edit, t('Save')); Chris@17: Chris@17: // Post an article. Chris@17: $edit = []; Chris@17: $edit['title[0][value]'] = $this->randomMachineName(); Chris@17: $edit[$this->fieldName . '[]'] = $term1->id(); Chris@17: $this->drupalPostForm('node/add/article', $edit, t('Save')); Chris@17: Chris@17: // Check that the term is displayed when the RSS feed is viewed. Chris@17: $this->drupalGet('rss.xml'); Chris@17: $test_element = sprintf( Chris@17: '%s', Chris@18: 'domain="' . $term1->toUrl('canonical', ['absolute' => TRUE])->toString() . '"', Chris@17: $term1->getName() Chris@17: ); Chris@17: $this->assertRaw($test_element, 'Term is displayed when viewing the rss feed.'); Chris@17: Chris@17: // Test that the feed icon exists for the term. Chris@17: $this->drupalGet("taxonomy/term/{$term1->id()}"); Chris@17: $this->assertLinkByHref("taxonomy/term/{$term1->id()}/feed"); Chris@17: Chris@17: // Test that the feed page exists for the term. Chris@17: $this->drupalGet("taxonomy/term/{$term1->id()}/feed"); Chris@17: $assert = $this->assertSession(); Chris@17: $assert->responseHeaderContains('Content-Type', 'application/rss+xml'); Chris@17: // Ensure the RSS version is 2.0. Chris@17: $rss_array = $this->getSession()->getDriver()->find('rss'); Chris@17: $this->assertEquals('2.0', reset($rss_array)->getAttribute('version')); Chris@17: Chris@17: // Check that the "Exception value" is disabled by default. Chris@17: $this->drupalGet('taxonomy/term/all/feed'); Chris@17: $this->assertResponse(404); Chris@17: // Set the exception value to 'all'. Chris@17: $view = Views::getView('taxonomy_term'); Chris@17: $arguments = $view->getDisplay()->getOption('arguments'); Chris@17: $arguments['tid']['exception']['value'] = 'all'; Chris@17: $view->getDisplay()->overrideOption('arguments', $arguments); Chris@17: $view->storage->save(); Chris@17: // Check the article is shown in the feed. Chris@17: $node = $this->drupalGetNodeByTitle($edit['title[0][value]']); Chris@17: $raw_xml = '' . $node->label() . ''; Chris@17: $this->drupalGet('taxonomy/term/all/feed'); Chris@17: $this->assertRaw($raw_xml, "Raw text '$raw_xml' is found."); Chris@17: // Unpublish the article and check that it is not shown in the feed. Chris@17: $node->setUnpublished()->save(); Chris@17: $this->drupalGet('taxonomy/term/all/feed'); Chris@17: $this->assertNoRaw($raw_xml); Chris@17: } Chris@17: Chris@17: }