You are here

function BlockContentFieldFilterTest::setUp in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/block_content/src/Tests/Views/BlockContentFieldFilterTest.php \Drupal\block_content\Tests\Views\BlockContentFieldFilterTest::setUp()

Sets up a Drupal site for running functional and integration tests.

Installs Drupal with the installation profile specified in \Drupal\simpletest\WebTestBase::$profile into the prefixed database.

Afterwards, installs any additional modules specified in the static \Drupal\simpletest\WebTestBase::$modules property of each class in the class hierarchy.

After installation all caches are flushed and several configuration values are reset to the values of the parent site executing the test, since the default values may be incompatible with the environment in which tests are being executed.

Overrides BlockContentTestBase::setUp

File

core/modules/block_content/src/Tests/Views/BlockContentFieldFilterTest.php, line 43
Contains \Drupal\block_content\Tests\Views\BlockContentFieldFilterTest.

Class

BlockContentFieldFilterTest
Tests block_content field filters with translations.

Namespace

Drupal\block_content\Tests\Views

Code

function setUp() {
  parent::setUp();

  // 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 = array(
    'en' => 'Food in Paris',
    'es' => 'Comida en Paris',
    'fr' => 'Nouriture 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 (array(
    'es',
    'fr',
  ) as $langcode) {
    $translation = $block_content
      ->addTranslation($langcode, [
      'info' => $this->blockContentInfos[$langcode],
    ]);
    $translation->body->value = $this->blockContentInfos[$langcode];
  }
  $block_content
    ->save();
}