function BlockContentFieldFilterTest::setUp

Same name in other branches
  1. 9 core/modules/block_content/tests/src/Functional/Views/BlockContentFieldFilterTest.php \Drupal\Tests\block_content\Functional\Views\BlockContentFieldFilterTest::setUp()
  2. 10 core/modules/block_content/tests/src/Functional/Views/BlockContentFieldFilterTest.php \Drupal\Tests\block_content\Functional\Views\BlockContentFieldFilterTest::setUp()
  3. 11.x core/modules/block_content/tests/src/Functional/Views/BlockContentFieldFilterTest.php \Drupal\Tests\block_content\Functional\Views\BlockContentFieldFilterTest::setUp()

Overrides BlockContentTestBase::setUp

File

core/modules/block_content/tests/src/Functional/Views/BlockContentFieldFilterTest.php, line 42

Class

BlockContentFieldFilterTest
Tests block_content field filters with translations.

Namespace

Drupal\Tests\block_content\Functional\Views

Code

public function setUp($import_test_views = TRUE) {
    parent::setUp($import_test_views);
    // Add two new languages.
    ConfigurableLanguage::createFromLangcode('fr')->save();
    ConfigurableLanguage::createFromLangcode('es')->save();
    // Make the body field translatable. The info is already translatable by
    // definition.
    $field_storage = FieldStorageConfig::loadByName('block_content', 'body');
    $field_storage->setTranslatable(TRUE);
    $field_storage->save();
    // Set up block_content infos.
    $this->blockContentInfos = [
        'en' => 'Food in Paris',
        'es' => 'Comida en Paris',
        'fr' => 'Nourriture en Paris',
    ];
    // Create block_content with translations.
    $block_content = $this->createBlockContent([
        'info' => $this->blockContentInfos['en'],
        'langcode' => 'en',
        'type' => 'basic',
        'body' => [
            [
                'value' => $this->blockContentInfos['en'],
            ],
        ],
    ]);
    foreach ([
        'es',
        'fr',
    ] as $langcode) {
        $translation = $block_content->addTranslation($langcode, [
            'info' => $this->blockContentInfos[$langcode],
        ]);
        $translation->body->value = $this->blockContentInfos[$langcode];
    }
    $block_content->save();
}

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