Upgraded drupal core with security updates
[yaffs-website] / web / core / modules / taxonomy / tests / src / Functional / Views / TaxonomyFieldAllTermsTest.php
1 <?php
2
3 namespace Drupal\Tests\taxonomy\Functional\Views;
4
5 use Drupal\views\Views;
6 use Drupal\taxonomy\Entity\Vocabulary;
7
8 /**
9  * Tests the "All terms" taxonomy term field handler.
10  *
11  * @group taxonomy
12  */
13 class TaxonomyFieldAllTermsTest extends TaxonomyTestBase {
14
15   /**
16    * Views used by this test.
17    *
18    * @var array
19    */
20   public static $testViews = ['taxonomy_all_terms_test'];
21
22   /**
23    * Tests the "all terms" field handler.
24    */
25   public function testViewsHandlerAllTermsField() {
26     $this->term1->setName('<em>Markup</em>')->save();
27     $view = Views::getView('taxonomy_all_terms_test');
28     $this->executeView($view);
29     $this->drupalGet('taxonomy_all_terms_test');
30
31     $actual = $this->xpath('//a[@href="' . $this->term1->url() . '"]');
32     $this->assertEqual(count($actual), 2, 'Correct number of taxonomy term1 links');
33     $this->assertEqual($actual[0]->getText(), $this->term1->label());
34     $this->assertEqual($actual[1]->getText(), $this->term1->label());
35     $this->assertEscaped($this->term1->label());
36
37     $actual = $this->xpath('//a[@href="' . $this->term2->url() . '"]');
38     $this->assertEqual(count($actual), 2, 'Correct number of taxonomy term2 links');
39     $this->assertEqual($actual[0]->getText(), $this->term2->label());
40     $this->assertEqual($actual[1]->getText(), $this->term2->label());
41   }
42
43   /**
44    * Tests token replacement in the "all terms" field handler.
45    */
46   public function testViewsHandlerAllTermsWithTokens() {
47     $view = Views::getView('taxonomy_all_terms_test');
48     $this->drupalGet('taxonomy_all_terms_token_test');
49
50     // Term itself: {{ term_node_tid }}
51     $this->assertText('Term: ' . $this->term1->getName());
52
53     // The taxonomy term ID for the term: {{ term_node_tid__tid }}
54     $this->assertText('The taxonomy term ID for the term: ' . $this->term1->id());
55
56     // The taxonomy term name for the term: {{ term_node_tid__name }}
57     $this->assertText('The taxonomy term name for the term: ' . $this->term1->getName());
58
59     // The machine name for the vocabulary the term belongs to: {{ term_node_tid__vocabulary_vid }}
60     $this->assertText('The machine name for the vocabulary the term belongs to: ' . $this->term1->getVocabularyId());
61
62     // The name for the vocabulary the term belongs to: {{ term_node_tid__vocabulary }}
63     $vocabulary = Vocabulary::load($this->term1->bundle());
64     $this->assertText('The name for the vocabulary the term belongs to: ' . $vocabulary->label());
65   }
66
67 }