You are here

public function TermNameFieldTest::testTermNameField in Drupal 9

Same name and namespace in other branches
  1. 8 core/modules/taxonomy/tests/src/Functional/Views/TermNameFieldTest.php \Drupal\Tests\taxonomy\Functional\Views\TermNameFieldTest::testTermNameField()

Tests term name field plugin functionality.

File

core/modules/taxonomy/tests/src/Functional/Views/TermNameFieldTest.php, line 29

Class

TermNameFieldTest
Tests the term_name field handler.

Namespace

Drupal\Tests\taxonomy\Functional\Views

Code

public function testTermNameField() {
  $this->term1->name->value = $this
    ->randomMachineName() . ' ' . $this
    ->randomMachineName();
  $this->term1
    ->save();
  $user = $this
    ->drupalCreateUser([
    'access content',
  ]);
  $this
    ->drupalLogin($user);
  $view = Views::getView('test_taxonomy_term_name');
  $view
    ->initDisplay();
  $this
    ->executeView($view);
  $this
    ->assertEquals($this->term1
    ->getName(), $view
    ->getStyle()
    ->getField(0, 'name'));
  $this
    ->assertEquals($this->term2
    ->getName(), $view
    ->getStyle()
    ->getField(1, 'name'));
  $view = Views::getView('test_taxonomy_term_name');
  $display =& $view->storage
    ->getDisplay('default');
  $display['display_options']['fields']['name']['convert_spaces'] = TRUE;
  $view->storage
    ->invalidateCaches();
  $this
    ->executeView($view);
  $this
    ->assertEquals(str_replace(' ', '-', $this->term1
    ->getName()), $view
    ->getStyle()
    ->getField(0, 'name'));
  $this
    ->assertEquals($this->term2
    ->getName(), $view
    ->getStyle()
    ->getField(1, 'name'));
}