ArgumentValidatorTermTest.php in Drupal 9
File
core/modules/taxonomy/tests/src/Kernel/Views/ArgumentValidatorTermTest.php
View source
<?php
namespace Drupal\Tests\taxonomy\Kernel\Views;
use Drupal\views\Views;
class ArgumentValidatorTermTest extends TaxonomyTestBase {
protected $terms = [];
protected $names = [];
protected $ids = [];
public static $testViews = [
'test_argument_validator_term',
];
protected function setUp($import_test_views = TRUE) : void {
parent::setUp($import_test_views);
for ($i = 0; $i < 3; $i++) {
$this->terms[] = $term = $this
->createTerm();
$this->names[] = $term
->label();
$this->ids[] = $term
->id();
}
}
public function testArgumentValidatorTerm() {
$view = Views::getView('test_argument_validator_term');
$view
->initHandlers();
$view->argument['tid']->options['validate_options']['multiple'] = 0;
foreach ($this->terms as $term) {
$this
->assertTrue($view->argument['tid']
->setArgument($term
->id()));
$this
->assertEquals($term
->label(), $view->argument['tid']
->getTitle());
$view->argument['tid']->validated_title = NULL;
$view->argument['tid']->argument_validated = NULL;
}
$this
->assertFalse($view->argument['tid']
->setArgument(rand(1000, 10000)));
$this
->assertEmpty($view->argument['tid']
->getTitle());
$view->argument['tid']->validated_title = NULL;
$view->argument['tid']->argument_validated = NULL;
$view->argument['tid']->options['validate_options']['multiple'] = 1;
$view->argument['tid']->options['break_phrase'] = TRUE;
$this
->assertTrue($view->argument['tid']
->setArgument($this->terms[0]
->id()));
$this
->assertEquals($this->terms[0]
->label(), $view->argument['tid']
->getTitle());
$view->argument['tid']->validated_title = NULL;
$view->argument['tid']->argument_validated = NULL;
$this
->assertTrue($view->argument['tid']
->setArgument(implode(',', $this->ids)));
$this
->assertEquals(implode(', ', $this->names), $view->argument['tid']
->getTitle());
$view->argument['tid']->validated_title = NULL;
$view->argument['tid']->argument_validated = NULL;
$this
->assertTrue($view->argument['tid']
->setArgument(implode('+', $this->ids)));
$this
->assertEquals(implode(' + ', $this->names), $view->argument['tid']
->getTitle());
$view->argument['tid']->validated_title = NULL;
$view->argument['tid']->argument_validated = NULL;
$this
->assertFalse($view->argument['tid']
->setArgument(rand(1000, 10000)));
$this
->assertEmpty($view->argument['tid']
->getTitle());
$view->argument['tid']->validated_title = NULL;
$view->argument['tid']->argument_validated = NULL;
$this
->assertFalse($view->argument['tid']
->setArgument(implode(',', [
rand(1000, 10000),
rand(1000, 10000),
])));
$this
->assertEmpty($view->argument['tid']
->getTitle());
$view->argument['tid']->validated_title = NULL;
$view->argument['tid']->argument_validated = NULL;
}
}