class TaxonomyFieldAllTermsTest
Same name and namespace in other branches
- 11.x core/modules/taxonomy/tests/src/Functional/Views/TaxonomyFieldAllTermsTest.php \Drupal\Tests\taxonomy\Functional\Views\TaxonomyFieldAllTermsTest
Tests the "All terms" taxonomy term field handler.
@group taxonomy
Hierarchy
- class \Drupal\Tests\BrowserTestBase uses \Drupal\Core\Test\FunctionalTestSetupTrait, \Drupal\Tests\UiHelperTrait, \Drupal\Core\Test\TestSetupTrait, \Drupal\Tests\block\Traits\BlockCreationTrait, \Drupal\FunctionalTests\AssertLegacyTrait, \Drupal\Tests\RandomGeneratorTrait, \Drupal\Tests\node\Traits\NodeCreationTrait, \Drupal\Tests\node\Traits\ContentTypeCreationTrait, \Drupal\Tests\ConfigTestTrait, \Drupal\Tests\TestRequirementsTrait, \Drupal\Tests\user\Traits\UserCreationTrait, \Drupal\Tests\XdebugRequestTrait, \Drupal\Tests\Traits\PhpUnitWarnings, \Drupal\Tests\PhpUnitCompatibilityTrait, \Symfony\Bridge\PhpUnit\ExpectDeprecationTrait, \Drupal\Tests\ExtensionListTestTrait implements \PHPUnit\Framework\TestCase
- class \Drupal\Tests\views\Functional\ViewTestBase uses \Drupal\views\Tests\ViewResultAssertionTrait implements \Drupal\Tests\BrowserTestBase
- class \Drupal\Tests\taxonomy\Functional\Views\TaxonomyTestBase uses \Drupal\Tests\field\Traits\EntityReferenceTestTrait implements \Drupal\Tests\views\Functional\ViewTestBase
- class \Drupal\Tests\taxonomy\Functional\Views\TaxonomyFieldAllTermsTest implements \Drupal\Tests\taxonomy\Functional\Views\TaxonomyTestBase
- class \Drupal\Tests\taxonomy\Functional\Views\TaxonomyTestBase uses \Drupal\Tests\field\Traits\EntityReferenceTestTrait implements \Drupal\Tests\views\Functional\ViewTestBase
- class \Drupal\Tests\views\Functional\ViewTestBase uses \Drupal\views\Tests\ViewResultAssertionTrait implements \Drupal\Tests\BrowserTestBase
Expanded class hierarchy of TaxonomyFieldAllTermsTest
File
-
core/
modules/ taxonomy/ tests/ src/ Functional/ Views/ TaxonomyFieldAllTermsTest.php, line 13
Namespace
Drupal\Tests\taxonomy\Functional\ViewsView source
class TaxonomyFieldAllTermsTest extends TaxonomyTestBase {
/**
* Views used by this test.
*
* @var array
*/
public static $testViews = [
'taxonomy_all_terms_test',
];
/**
* {@inheritdoc}
*/
protected $defaultTheme = 'stark';
/**
* Tests the "all terms" field handler.
*/
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');
// Test term1 links.
$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());
// Test term2 links.
$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());
}
/**
* Tests token replacement in the "all terms" field handler.
*/
public function testViewsHandlerAllTermsWithTokens() {
$view = Views::getView('taxonomy_all_terms_test');
$this->drupalGet('taxonomy_all_terms_token_test');
// Term itself: {{ term_node_tid }}
$this->assertSession()
->pageTextContains('Term: ' . $this->term1
->getName());
// The taxonomy term ID for the term: {{ term_node_tid__tid }}
$this->assertSession()
->pageTextContains('The taxonomy term ID for the term: ' . $this->term1
->id());
// The taxonomy term name for the term: {{ term_node_tid__name }}
$this->assertSession()
->pageTextContains('The taxonomy term name for the term: ' . $this->term1
->getName());
// The machine name for the vocabulary the term belongs to: {{ term_node_tid__vocabulary_vid }}
$this->assertSession()
->pageTextContains('The machine name for the vocabulary the term belongs to: ' . $this->term1
->bundle());
// The name for the vocabulary the term belongs to: {{ term_node_tid__vocabulary }}
$vocabulary = Vocabulary::load($this->term1
->bundle());
$this->assertSession()
->pageTextContains('The name for the vocabulary the term belongs to: ' . $vocabulary->label());
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.