You are here

public function ArgumentValidatorTermNameTest::testArgumentValidatorTermNameAccess in Drupal 10

Tests the access checking in term name argument validator plugin.

File

core/modules/taxonomy/tests/src/Kernel/Views/ArgumentValidatorTermNameTest.php, line 151

Class

ArgumentValidatorTermNameTest
Tests the plugin of the taxonomy: taxonomy_term_name argument validator.

Namespace

Drupal\Tests\taxonomy\Kernel\Views

Code

public function testArgumentValidatorTermNameAccess() {
  $this
    ->installConfig([
    'user',
  ]);
  $this
    ->setCurrentUser($this
    ->createUser([
    'access content',
  ]));
  $view = Views::getView('test_taxonomy_name_argument');
  $view
    ->initHandlers();

  // Enable access checking on validator.
  $view->argument['name']->options['validate_options']['access'] = TRUE;

  // Allow all bundles.
  $view->argument['name']->options['validate_options']['bundles'] = [];

  // A uniquely named unpublished term in an allowed bundle.
  $this->terms[0]
    ->setUnpublished()
    ->save();
  $this
    ->assertFalse($view->argument['name']
    ->setArgument($this->names[0]));
  $view->argument['name']->validated_title = NULL;
  $view->argument['name']->argument_validated = NULL;

  // A name used by two terms in a single vocabulary. One is unpublished.
  // We re-name the second term to match the first one.
  $this->terms[1]
    ->set('name', $this->names[0])
    ->save();
  $this->names[1] = $this->terms[1]
    ->label();
  $this
    ->assertTrue($view->argument['name']
    ->setArgument($this->names[0]));
  $this
    ->assertEquals($this->names[0], $view->argument['name']
    ->getTitle());
  $view->argument['name']->validated_title = NULL;
  $view->argument['name']->argument_validated = NULL;

  // A name shared by a term in each vocabulary. One is unpublished.
  $this->terms[3]
    ->setUnpublished()
    ->save();
  $this
    ->assertTrue($view->argument['name']
    ->setArgument($this->names[3]));
  $this
    ->assertEquals($this->names[3], $view->argument['name']
    ->getTitle());
}