class TermDisplayConfigurableTest
Same name and namespace in other branches
- 11.x core/modules/taxonomy/tests/src/Functional/Views/TermDisplayConfigurableTest.php \Drupal\Tests\taxonomy\Functional\Views\TermDisplayConfigurableTest
Tests making taxonomy term base fields' displays configurable.
@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\TermDisplayConfigurableTest 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 TermDisplayConfigurableTest
File
-
core/
modules/ taxonomy/ tests/ src/ Functional/ Views/ TermDisplayConfigurableTest.php, line 10
Namespace
Drupal\Tests\taxonomy\Functional\ViewsView source
class TermDisplayConfigurableTest extends TaxonomyTestBase {
/**
* {@inheritdoc}
*/
protected $defaultTheme = 'stark';
/**
* Views used by this test.
*
* @var array
*/
public static $testViews = [
'test_term_show_entity',
];
/**
* Sets base fields to configurable display and check settings are respected.
*/
public function testDisplayConfigurable() {
$user = $this->drupalCreateUser([
'administer nodes',
]);
$this->drupalLogin($user);
$assert = $this->assertSession();
// Check the taxonomy_term with default non-configurable display.
$this->drupalGet('test_term_show_entity');
// Name should be linked to entity and description should be displayed.
$assert->pageTextContains($this->term1
->getName());
$assert->linkByHrefExists($this->term1
->toUrl()
->toString());
$assert->pageTextContains($this->term1
->getDescription());
$assert->pageTextContains($this->term2
->getName());
$assert->linkByHrefExists($this->term2
->toUrl()
->toString());
$assert->pageTextContains($this->term2
->getDescription());
// The field labels should not be present.
$assert->pageTextNotContains('Name');
$assert->pageTextNotContains('Description');
// Enable helper module to make base fields' displays configurable.
\Drupal::service('module_installer')->install([
'taxonomy_term_display_configurable_test',
]);
// Configure display.
$display = \Drupal::service('entity_display.repository')->getViewDisplay('taxonomy_term', $this->vocabulary
->id(), 'default');
$display->setComponent('name', [
'type' => 'text_default',
'label' => 'above',
])
->save();
// Recheck the taxonomy_term with configurable display.
$this->drupalGet('test_term_show_entity');
// The description should be the first field in each row, with no label.
// Name field should be the second field in view row. Value should be
// displayed after the label. It should not be linked to the term.
$assert->pageTextContains('Name');
$assert->pageTextNotContains('Description');
$assert->pageTextContains($this->term1
->getName());
$assert->linkByHrefNotExists($this->term1
->toUrl()
->toString());
$assert->pageTextContains($this->term1
->getDescription());
$assert->elementTextContains('xpath', '//*[@class="views-row"][1]/div/div[1]//p', $this->term1
->getDescription());
$assert->elementTextContains('xpath', '//*[@class="views-row"][1]/div/div[2]/div[1]', 'Name');
$assert->elementTextContains('xpath', '//*[@class="views-row"][1]/div/div[2]/div[2]', $this->term1
->getName());
$assert->pageTextContains($this->term2
->getName());
$assert->linkByHrefNotExists($this->term2
->toUrl()
->toString());
$assert->pageTextContains($this->term2
->getDescription());
$assert->elementTextContains('xpath', '//*[@class="views-row"][2]/div/div[1]//p', $this->term2
->getDescription());
$assert->elementTextContains('xpath', '//*[@class="views-row"][2]/div/div[2]/div[1]', 'Name');
$assert->elementTextContains('xpath', '//*[@class="views-row"][2]/div/div[2]/div[2]', $this->term2
->getName());
// Remove 'name' field from display.
$display->removeComponent('name')
->save();
// Recheck the taxonomy_term with 'name' field removed from display.
// There should just be an unlabelled description. Nothing should be
// linked to the terms.
$this->drupalGet('test_term_show_entity');
$assert->pageTextNotContains('Name');
$assert->pageTextNotContains('Description');
$assert->pageTextNotContains($this->term1
->getName());
$assert->linkByHrefNotExists($this->term1
->toUrl()
->toString());
$assert->pageTextContains($this->term1
->getDescription());
$assert->pageTextNotContains($this->term2
->getName());
$assert->linkByHrefNotExists($this->term2
->toUrl()
->toString());
$assert->pageTextContains($this->term2
->getDescription());
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.