comparison core/modules/taxonomy/tests/src/Functional/RssTest.php @ 17:129ea1e6d783

Update, including to Drupal core 8.6.10
author Chris Cannam
date Thu, 28 Feb 2019 13:21:36 +0000
parents
children af1871eacc83
comparison
equal deleted inserted replaced
16:c2387f117808 17:129ea1e6d783
1 <?php
2
3 namespace Drupal\Tests\taxonomy\Functional;
4
5 use Drupal\Core\Field\FieldStorageDefinitionInterface;
6 use Drupal\views\Views;
7
8 /**
9 * Ensure that data added as terms appears in RSS feeds if "RSS Category" format
10 * is selected.
11 *
12 * @group taxonomy
13 */
14 class RssTest extends TaxonomyTestBase {
15
16 /**
17 * Modules to enable.
18 *
19 * @var array
20 */
21 public static $modules = ['node', 'field_ui', 'views'];
22
23 /**
24 * Vocabulary for testing.
25 *
26 * @var \Drupal\taxonomy\VocabularyInterface
27 */
28 protected $vocabulary;
29
30 /**
31 * Name of the taxonomy term reference field.
32 *
33 * @var string
34 */
35 protected $fieldName;
36
37 protected function setUp() {
38 parent::setUp();
39
40 $this->drupalLogin($this->drupalCreateUser(['administer taxonomy', 'bypass node access', 'administer content types', 'administer node display']));
41 $this->vocabulary = $this->createVocabulary();
42 $this->fieldName = 'taxonomy_' . $this->vocabulary->id();
43
44 $handler_settings = [
45 'target_bundles' => [
46 $this->vocabulary->id() => $this->vocabulary->id(),
47 ],
48 'auto_create' => TRUE,
49 ];
50 $this->createEntityReferenceField('node', 'article', $this->fieldName, NULL, 'taxonomy_term', 'default', $handler_settings, FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED);
51
52 entity_get_form_display('node', 'article', 'default')
53 ->setComponent($this->fieldName, [
54 'type' => 'options_select',
55 ])
56 ->save();
57 entity_get_display('node', 'article', 'default')
58 ->setComponent($this->fieldName, [
59 'type' => 'entity_reference_label',
60 ])
61 ->save();
62 }
63
64 /**
65 * Tests that terms added to nodes are displayed in core RSS feed.
66 *
67 * Create a node and assert that taxonomy terms appear in rss.xml.
68 */
69 public function testTaxonomyRss() {
70 // Create two taxonomy terms.
71 $term1 = $this->createTerm($this->vocabulary);
72
73 // RSS display must be added manually.
74 $this->drupalGet("admin/structure/types/manage/article/display");
75 $edit = [
76 "display_modes_custom[rss]" => '1',
77 ];
78 $this->drupalPostForm(NULL, $edit, t('Save'));
79
80 // Change the format to 'RSS category'.
81 $this->drupalGet("admin/structure/types/manage/article/display/rss");
82 $edit = [
83 "fields[taxonomy_" . $this->vocabulary->id() . "][type]" => 'entity_reference_rss_category',
84 "fields[taxonomy_" . $this->vocabulary->id() . "][region]" => 'content',
85 ];
86 $this->drupalPostForm(NULL, $edit, t('Save'));
87
88 // Post an article.
89 $edit = [];
90 $edit['title[0][value]'] = $this->randomMachineName();
91 $edit[$this->fieldName . '[]'] = $term1->id();
92 $this->drupalPostForm('node/add/article', $edit, t('Save'));
93
94 // Check that the term is displayed when the RSS feed is viewed.
95 $this->drupalGet('rss.xml');
96 $test_element = sprintf(
97 '<category %s>%s</category>',
98 'domain="' . $term1->url('canonical', ['absolute' => TRUE]) . '"',
99 $term1->getName()
100 );
101 $this->assertRaw($test_element, 'Term is displayed when viewing the rss feed.');
102
103 // Test that the feed icon exists for the term.
104 $this->drupalGet("taxonomy/term/{$term1->id()}");
105 $this->assertLinkByHref("taxonomy/term/{$term1->id()}/feed");
106
107 // Test that the feed page exists for the term.
108 $this->drupalGet("taxonomy/term/{$term1->id()}/feed");
109 $assert = $this->assertSession();
110 $assert->responseHeaderContains('Content-Type', 'application/rss+xml');
111 // Ensure the RSS version is 2.0.
112 $rss_array = $this->getSession()->getDriver()->find('rss');
113 $this->assertEquals('2.0', reset($rss_array)->getAttribute('version'));
114
115 // Check that the "Exception value" is disabled by default.
116 $this->drupalGet('taxonomy/term/all/feed');
117 $this->assertResponse(404);
118 // Set the exception value to 'all'.
119 $view = Views::getView('taxonomy_term');
120 $arguments = $view->getDisplay()->getOption('arguments');
121 $arguments['tid']['exception']['value'] = 'all';
122 $view->getDisplay()->overrideOption('arguments', $arguments);
123 $view->storage->save();
124 // Check the article is shown in the feed.
125 $node = $this->drupalGetNodeByTitle($edit['title[0][value]']);
126 $raw_xml = '<title>' . $node->label() . '</title>';
127 $this->drupalGet('taxonomy/term/all/feed');
128 $this->assertRaw($raw_xml, "Raw text '$raw_xml' is found.");
129 // Unpublish the article and check that it is not shown in the feed.
130 $node->setUnpublished()->save();
131 $this->drupalGet('taxonomy/term/all/feed');
132 $this->assertNoRaw($raw_xml);
133 }
134
135 }