TaxonomyFieldAllTermsTest.php in Drupal 10
File
core/modules/taxonomy/tests/src/Functional/Views/TaxonomyFieldAllTermsTest.php
View source
<?php
namespace Drupal\Tests\taxonomy\Functional\Views;
use Drupal\views\Views;
use Drupal\taxonomy\Entity\Vocabulary;
class TaxonomyFieldAllTermsTest extends TaxonomyTestBase {
public static $testViews = [
'taxonomy_all_terms_test',
];
protected $defaultTheme = 'stark';
public function testViewsHandlerAllTermsField() {
$this->term1
->setName('<em>Markup</em>')
->save();
$view = Views::getView('taxonomy_all_terms_test');
$this
->executeView($view);
$this
->drupalGet('taxonomy_all_terms_test');
$xpath = '//a[@href="' . $this->term1
->toUrl()
->toString() . '"]';
$this
->assertSession()
->elementsCount('xpath', $xpath, 2);
$links = $this
->xpath($xpath);
$this
->assertEquals($this->term1
->label(), $links[0]
->getText());
$this
->assertEquals($this->term1
->label(), $links[1]
->getText());
$this
->assertSession()
->assertEscaped($this->term1
->label());
$xpath = '//a[@href="' . $this->term2
->toUrl()
->toString() . '"]';
$this
->assertSession()
->elementsCount('xpath', $xpath, 2);
$links = $this
->xpath($xpath);
$this
->assertEquals($this->term2
->label(), $links[0]
->getText());
$this
->assertEquals($this->term2
->label(), $links[1]
->getText());
}
public function testViewsHandlerAllTermsWithTokens() {
$view = Views::getView('taxonomy_all_terms_test');
$this
->drupalGet('taxonomy_all_terms_token_test');
$this
->assertSession()
->pageTextContains('Term: ' . $this->term1
->getName());
$this
->assertSession()
->pageTextContains('The taxonomy term ID for the term: ' . $this->term1
->id());
$this
->assertSession()
->pageTextContains('The taxonomy term name for the term: ' . $this->term1
->getName());
$this
->assertSession()
->pageTextContains('The machine name for the vocabulary the term belongs to: ' . $this->term1
->bundle());
$vocabulary = Vocabulary::load($this->term1
->bundle());
$this
->assertSession()
->pageTextContains('The name for the vocabulary the term belongs to: ' . $vocabulary
->label());
}
}