public function TaxonomyFieldFilterTest::setUp in Drupal 9
Same name and namespace in other branches
- 8 core/modules/taxonomy/tests/src/Functional/Views/TaxonomyFieldFilterTest.php \Drupal\Tests\taxonomy\Functional\Views\TaxonomyFieldFilterTest::setUp()
- 10 core/modules/taxonomy/tests/src/Functional/Views/TaxonomyFieldFilterTest.php \Drupal\Tests\taxonomy\Functional\Views\TaxonomyFieldFilterTest::setUp()
Overrides ViewTestBase::setUp
File
- core/
modules/ taxonomy/ tests/ src/ Functional/ Views/ TaxonomyFieldFilterTest.php, line 60
Class
- TaxonomyFieldFilterTest
- Tests taxonomy field filters with translations.
Namespace
Drupal\Tests\taxonomy\Functional\ViewsCode
public function setUp($import_test_views = TRUE) : void {
parent::setUp($import_test_views);
// Add two new languages.
ConfigurableLanguage::createFromLangcode('fr')
->save();
ConfigurableLanguage::createFromLangcode('es')
->save();
// Set up term names.
$this->termNames = [
'en' => 'Food in Paris',
'es' => 'Comida en Paris',
'fr' => 'Nourriture en Paris',
];
// Create a vocabulary.
$this->vocabulary = Vocabulary::create([
'name' => 'Views testing tags',
'vid' => 'views_testing_tags',
]);
$this->vocabulary
->save();
// Add a translatable field to the vocabulary.
$field = FieldStorageConfig::create([
'field_name' => 'field_foo',
'entity_type' => 'taxonomy_term',
'type' => 'text',
]);
$field
->save();
FieldConfig::create([
'field_name' => 'field_foo',
'entity_type' => 'taxonomy_term',
'label' => 'Foo',
'bundle' => 'views_testing_tags',
])
->save();
// Create term with translations.
$taxonomy = $this
->createTermWithProperties([
'name' => $this->termNames['en'],
'langcode' => 'en',
'description' => $this->termNames['en'],
'field_foo' => $this->termNames['en'],
]);
foreach ([
'es',
'fr',
] as $langcode) {
$translation = $taxonomy
->addTranslation($langcode, [
'name' => $this->termNames[$langcode],
]);
$translation->description->value = $this->termNames[$langcode];
$translation->field_foo->value = $this->termNames[$langcode];
}
$taxonomy
->save();
Views::viewsData()
->clear();
ViewTestData::createTestViews(static::class, [
'taxonomy_test_views',
]);
}