You are here

protected function NodeLanguageTest::setUp in Zircon Profile 8.0

Same name and namespace in other branches
  1. 8 core/modules/node/src/Tests/Views/NodeLanguageTest.php \Drupal\node\Tests\Views\NodeLanguageTest::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 NodeTestBase::setUp

File

core/modules/node/src/Tests/Views/NodeLanguageTest.php, line 46
Contains \Drupal\node\Tests\Views\NodeLanguageTest.

Class

NodeLanguageTest
Tests node language fields, filters, and sorting.

Namespace

Drupal\node\Tests\Views

Code

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

  // Create Page content type.
  if ($this->profile != 'standard') {
    $this
      ->drupalCreateContentType(array(
      'type' => 'page',
      'name' => 'Basic page',
    ));
    ViewTestData::createTestViews(get_class($this), array(
      'node_test_views',
    ));
  }

  // Add two new languages.
  ConfigurableLanguage::createFromLangcode('fr')
    ->save();
  ConfigurableLanguage::createFromLangcode('es')
    ->save();

  // Make the body field translatable. The title is already translatable by
  // definition.
  $field_storage = FieldStorageConfig::loadByName('node', 'body');
  $field_storage
    ->setTranslatable(TRUE);
  $field_storage
    ->save();

  // Set up node titles. They should not include the words "French",
  // "English", or "Spanish", as there is a language field in the view
  // that prints out those words.
  $this->nodeTitles = array(
    LanguageInterface::LANGCODE_NOT_SPECIFIED => array(
      'First node und',
    ),
    'es' => array(
      'Primero nodo es',
      'Segundo nodo es',
      'Tercera nodo es',
    ),
    'en' => array(
      'First node en',
      'Second node en',
    ),
    'fr' => array(
      'Premier nœud fr',
    ),
  );

  // Create nodes with translations.
  foreach ($this->nodeTitles['es'] as $index => $title) {
    $node = $this
      ->drupalCreateNode(array(
      'title' => $title,
      'langcode' => 'es',
      'type' => 'page',
      'promote' => 1,
    ));
    foreach (array(
      'en',
      'fr',
    ) as $langcode) {
      if (isset($this->nodeTitles[$langcode][$index])) {
        $translation = $node
          ->addTranslation($langcode, array(
          'title' => $this->nodeTitles[$langcode][$index],
        ));
        $translation->body->value = $this
          ->randomMachineName(32);
      }
    }
    $node
      ->save();
  }

  // Create non-translatable nodes.
  foreach ($this->nodeTitles[LanguageInterface::LANGCODE_NOT_SPECIFIED] as $index => $title) {
    $node = $this
      ->drupalCreateNode(array(
      'title' => $title,
      'langcode' => LanguageInterface::LANGCODE_NOT_SPECIFIED,
      'type' => 'page',
      'promote' => 1,
    ));
    $node->body->value = $this
      ->randomMachineName(32);
    $node
      ->save();
  }
  $this->container
    ->get('router.builder')
    ->rebuild();
  $user = $this
    ->drupalCreateUser(array(
    'access content overview',
    'access content',
  ));
  $this
    ->drupalLogin($user);
}