Same name and namespace in other branches
  1. 8.9.x core/modules/taxonomy/tests/src/Kernel/Views/ArgumentTransformTermTest.php \Drupal\Tests\taxonomy\Kernel\Views\ArgumentTransformTermTest
  2. 9 core/modules/taxonomy/tests/src/Kernel/Views/ArgumentTransformTermTest.php \Drupal\Tests\taxonomy\Kernel\Views\ArgumentTransformTermTest

Tests taxonomy term argument transformation.

@group taxonomy

Hierarchy

Expanded class hierarchy of ArgumentTransformTermTest

See also

\Drupal\taxonomy\Plugin\views\argument_validator\TermName

File

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

Namespace

Drupal\Tests\taxonomy\Kernel\Views
View source
class ArgumentTransformTermTest extends TaxonomyTestBase {

  /**
   * {@inheritdoc}
   */
  public static $testViews = [
    'test_argument_transform_term',
  ];

  /**
   * Tests term argument transformation of hyphens and spaces.
   *
   * @dataProvider termArgumentTransformationProvider
   *
   * @param string $name
   *   The name of the taxonomy term to use for the test.
   */
  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);
  }

  /**
   * Provides data for testTermArgumentTransformation().
   *
   * @return array[]
   *   Test data.
   */
  public static function termArgumentTransformationProvider() {
    return [
      'space in the middle' => [
        'name' => Random::machineName() . ' ' . Random::machineName(),
      ],
      'space at the start' => [
        'name' => ' ' . Random::machineName(),
      ],
      'space at the end' => [
        'name' => Random::machineName() . ' ',
      ],
    ];
  }

}

Members

Namesort descending Modifiers Type Description Overrides
ArgumentTransformTermTest::$testViews public static property Views to be enabled. Overrides ViewsKernelTestBase::$testViews
ArgumentTransformTermTest::termArgumentTransformationProvider public static function Provides data for testTermArgumentTransformation().
ArgumentTransformTermTest::testTermArgumentTransformation public function Tests term argument transformation of hyphens and spaces.
ContentTypeCreationTrait::createContentType protected function Creates a custom content type based on default settings. Aliased as: drupalCreateContentType
EntityReferenceFieldCreationTrait::createEntityReferenceField protected function Creates a field of an entity reference field storage on the specified bundle.
NodeCreationTrait::createNode protected function Creates a node based on default settings. Aliased as: drupalCreateNode
NodeCreationTrait::getNodeByTitle public function Get a node from the database based on its title.
TaxonomyTestBase::$modules protected static property Modules to enable. Overrides ViewsKernelTestBase::$modules
TaxonomyTestBase::$nodes protected property Stores the nodes used for the different tests.
TaxonomyTestBase::$term1 protected property Stores the first term used in the different tests.
TaxonomyTestBase::$term2 protected property Stores the second term used in the different tests.
TaxonomyTestBase::$vocabulary protected property The vocabulary used for creating terms.
TaxonomyTestBase::createTerm protected function Creates and returns a taxonomy term.
TaxonomyTestBase::mockStandardInstall protected function Provides a workaround for the inability to use the standard profile.
TaxonomyTestBase::setUp protected function Overrides ViewsKernelTestBase::setUp
UserCreationTrait::checkPermissions protected function Checks whether a given list of permission names is valid.
UserCreationTrait::createAdminRole protected function Creates an administrative role.
UserCreationTrait::createRole protected function Creates a role with specified permissions.
UserCreationTrait::createUser protected function Create a user with a given set of permissions.
UserCreationTrait::grantPermissions protected function Grant permissions to a user role.
UserCreationTrait::setCurrentUser protected function Switch the current logged in user.
UserCreationTrait::setUpCurrentUser protected function Creates a random user account and sets it as current user.
ViewResultAssertionTrait::assertIdenticalResultset protected function Verifies that a result set returned by a View matches expected values.
ViewResultAssertionTrait::assertIdenticalResultsetHelper protected function Performs View result assertions.
ViewResultAssertionTrait::assertNotIdenticalResultset protected function Verifies that a result set returned by a View differs from certain values.
ViewsKernelTestBase::dataSet protected function Returns a very simple test dataset. 8
ViewsKernelTestBase::executeView protected function Executes a view.
ViewsKernelTestBase::orderResultSet protected function Orders a nested array containing a result set based on a given column.
ViewsKernelTestBase::schemaDefinition protected function Returns the schema definition. 6
ViewsKernelTestBase::setUpFixtures protected function Sets up the configuration and schema of views and views_test_data modules. 7
ViewsKernelTestBase::viewsData protected function Returns the views data definition. 22