function TaxonomyFieldFilterTest::setUp

Same name and namespace in other branches
  1. 8.9.x core/modules/taxonomy/tests/src/Functional/Views/TaxonomyFieldFilterTest.php \Drupal\Tests\taxonomy\Functional\Views\TaxonomyFieldFilterTest::setUp()
  2. 10 core/modules/taxonomy/tests/src/Functional/Views/TaxonomyFieldFilterTest.php \Drupal\Tests\taxonomy\Functional\Views\TaxonomyFieldFilterTest::setUp()
  3. 11.x 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 63

Class

TaxonomyFieldFilterTest
Tests taxonomy field filters with translations.

Namespace

Drupal\Tests\taxonomy\Functional\Views

Code

public function setUp($import_test_views = TRUE, $modules = []) : void {
    parent::setUp($import_test_views, $modules);
    // 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',
    ]);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.