ArgumentValidatorTest.php in Views taxonomy term name into ID 8
File
tests/src/Functional/ArgumentValidatorTest.php
View source
<?php
namespace Drupal\Tests\views_taxonomy_term_name_into_id\Functional;
use Drupal\Core\Field\FieldStorageDefinitionInterface;
use Drupal\Tests\field\Traits\EntityReferenceTestTrait;
use Drupal\Tests\taxonomy\Traits\TaxonomyTestTrait;
if (!trait_exists('\\Drupal\\Tests\\taxonomy\\Traits\\TaxonomyTestTrait')) {
class_alias('\\Drupal\\Tests\\taxonomy\\Functional\\TaxonomyTestTrait', '\\Drupal\\Tests\\taxonomy\\Traits\\TaxonomyTestTrait');
}
use Drupal\Tests\views\Functional\ViewTestBase;
use Drupal\views\Tests\ViewTestData;
class ArgumentValidatorTest extends ViewTestBase {
use EntityReferenceTestTrait;
use TaxonomyTestTrait;
public static $modules = [
'views_taxonomy_term_name_into_id_test',
];
protected $defaultTheme = 'stark';
public static $testViews = [
'test_argument_taxonomy_name_into_id',
];
protected $terms;
protected $node;
protected function setUp($import_test_views = TRUE) {
parent::setUp($import_test_views);
ViewTestData::createTestViews(get_class($this), [
'views_taxonomy_term_name_into_id_test',
]);
$vocabulary = $this
->createVocabulary();
$this
->drupalCreateContentType([
'type' => 'article',
]);
$field_name = 'field_' . $vocabulary
->id();
$handler_settings = [
'target_bundles' => [
$vocabulary
->id() => $vocabulary
->id(),
],
'auto_create' => TRUE,
];
$this
->createEntityReferenceField('node', 'article', $field_name, 'Tags', 'taxonomy_term', 'default', $handler_settings, FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED);
$this->terms[1] = $this
->createTerm($vocabulary, [
'name' => 'First',
]);
$this->terms[2] = $this
->createTerm($vocabulary, [
'name' => 'Second',
]);
$settings = [
'type' => 'article',
'title' => 'Article 1',
];
$settings[$field_name][0]['target_id'] = $this->terms[1]
->id();
$this->node = $this
->drupalCreateNode($settings);
}
public function testViewsWithTaxonomyTermNameArgument() {
$this
->drupalGet('test_argument_taxonomy_name_into_id/' . $this->terms[1]
->getName());
$this
->assertLink($this->node
->label());
$this
->drupalGet('test_argument_taxonomy_name_into_id/' . $this->terms[2]
->getName());
$this
->assertResponse(200);
$this
->assertNoLink($this->node
->label());
$this
->drupalGet('test_argument_taxonomy_name_into_id/xyz');
$this
->assertResponse(404);
}
}