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