You are here

public function ArgumentTransformTermTest::testTermArgumentTransformation in Drupal 9

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

Tests term argument transformation of hyphens and spaces.

@dataProvider termArgumentTransformationProvider

Parameters

string $name: The name of the taxonomy term to use for the test.

File

core/modules/taxonomy/tests/src/Kernel/Views/ArgumentTransformTermTest.php, line 29

Class

ArgumentTransformTermTest
Tests taxonomy term argument transformation.

Namespace

Drupal\Tests\taxonomy\Kernel\Views

Code

public function testTermArgumentTransformation($name) {

  /** @var \Drupal\taxonomy\TermInterface $term */
  $term = $this
    ->createTerm([
    'name' => $name,
  ]);

  /** @var \Drupal\views\ViewExecutable $view */
  $view = Views::getView('test_argument_transform_term');
  $view
    ->initHandlers();

  /** @var string $hyphenated_term */
  $hyphenated_term = str_replace(' ', '-', $term
    ->label());
  $this
    ->assertTrue($view->argument['tid']
    ->setArgument($hyphenated_term));

  // Assert hyphens are converted back to spaces.
  $this
    ->assertEquals($term
    ->label(), $view->argument['tid']->argument);
}