TermDisplayConfigurableTest.php in Drupal 9
File
core/modules/taxonomy/tests/src/Functional/Views/TermDisplayConfigurableTest.php
View source
<?php
namespace Drupal\Tests\taxonomy\Functional\Views;
class TermDisplayConfigurableTest extends TaxonomyTestBase {
protected $defaultTheme = 'classy';
public static $testViews = [
'test_term_show_entity',
];
public function testDisplayConfigurable() {
$user = $this
->drupalCreateUser([
'administer nodes',
]);
$this
->drupalLogin($user);
$assert = $this
->assertSession();
$this
->drupalGet('test_term_show_entity');
$assert
->elementTextContains('css', 'h2 > a > .field--name-name', $this->term1
->getName());
$assert
->elementNotExists('css', '.field--name-name .field__item');
$assert
->elementNotExists('css', '.field--name-name .field__label');
\Drupal::service('module_installer')
->install([
'taxonomy_term_display_configurable_test',
]);
$display = \Drupal::service('entity_display.repository')
->getViewDisplay('taxonomy_term', $this->vocabulary
->id(), 'default');
$display
->setComponent('name', [
'type' => 'text_default',
'label' => 'above',
])
->save();
$this
->drupalGet('test_term_show_entity');
$assert
->elementTextContains('css', 'div.field--name-name > div.field__item', $this->term1
->getName());
$assert
->elementExists('css', 'div.field--name-name > div.field__label');
$display
->removeComponent('name')
->save();
$this
->drupalGet('test_term_show_entity');
$assert
->responseNotContains($this->term1
->getName());
$assert
->elementNotExists('css', 'div.field--name-name');
}
}