3 namespace Drupal\Tests\taxonomy\Functional\Views;
5 use Drupal\views\Views;
6 use Drupal\taxonomy\Entity\Vocabulary;
9 * Tests the "All terms" taxonomy term field handler.
13 class TaxonomyFieldAllTermsTest extends TaxonomyTestBase {
16 * Views used by this test.
20 public static $testViews = ['taxonomy_all_terms_test'];
23 * Tests the "all terms" field handler.
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');
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());
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());
44 * Tests token replacement in the "all terms" field handler.
46 public function testViewsHandlerAllTermsWithTokens() {
47 $view = Views::getView('taxonomy_all_terms_test');
48 $this->drupalGet('taxonomy_all_terms_token_test');
50 // Term itself: {{ term_node_tid }}
51 $this->assertText('Term: ' . $this->term1->getName());
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());
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());
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->bundle());
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());