ArgumentValidatorTermTest.php in Zircon Profile 8
File
core/modules/taxonomy/src/Tests/Views/ArgumentValidatorTermTest.php
View source
<?php
namespace Drupal\taxonomy\Tests\Views;
use Drupal\views\Views;
class ArgumentValidatorTermTest extends TaxonomyTestBase {
protected $terms = [];
protected $names = [];
protected $ids = [];
public static $modules = [
'taxonomy',
'taxonomy_test_views',
'views_test_config',
];
public static $testViews = [
'test_argument_validator_term',
];
protected function setUp() {
parent::setUp();
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']->validator->options['type'] = 'tid';
foreach ($this->terms as $term) {
$this
->assertTrue($view->argument['tid']
->setArgument($term
->id()));
$this
->assertEqual($view->argument['tid']
->getTitle(), $term
->label());
$view->argument['tid']->validated_title = NULL;
$view->argument['tid']->argument_validated = NULL;
}
$this
->assertFalse($view->argument['tid']
->setArgument(rand(1000, 10000)));
$this
->assertEqual('', $view->argument['tid']
->getTitle());
$view->argument['tid']->validated_title = NULL;
$view->argument['tid']->argument_validated = NULL;
$view->argument['tid']->validator->options['type'] = 'tids';
$view->argument['tid']->options['break_phrase'] = TRUE;
$this
->assertTrue($view->argument['tid']
->setArgument($this->terms[0]
->id()));
$this
->assertEqual($view->argument['tid']
->getTitle(), $this->terms[0]
->label());
$view->argument['tid']->validated_title = NULL;
$view->argument['tid']->argument_validated = NULL;
$this
->assertTrue($view->argument['tid']
->setArgument(implode(',', $this->ids)));
$this
->assertEqual($view->argument['tid']
->getTitle(), implode(', ', $this->names));
$view->argument['tid']->validated_title = NULL;
$view->argument['tid']->argument_validated = NULL;
$this
->assertTrue($view->argument['tid']
->setArgument(implode('+', $this->ids)));
$this
->assertEqual($view->argument['tid']
->getTitle(), implode(' + ', $this->names));
$view->argument['tid']->validated_title = NULL;
$view->argument['tid']->argument_validated = NULL;
$this
->assertFalse($view->argument['tid']
->setArgument(rand(1000, 10000)));
$this
->assertEqual('', $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
->assertEqual('', $view->argument['tid']
->getTitle());
$view->argument['tid']->validated_title = NULL;
$view->argument['tid']->argument_validated = NULL;
}
}