You are here

protected function RowEntityRenderersTest::setUp in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/views/src/Tests/Entity/RowEntityRenderersTest.php \Drupal\views\Tests\Entity\RowEntityRenderersTest::setUp()

Parameters

bool $import_test_views: Should the views specififed on the test class be imported. If you need to setup some additional stuff, like fields, you need to call false and then call createTestViews for your own.

Overrides ViewKernelTestBase::setUp

File

core/modules/views/src/Tests/Entity/RowEntityRenderersTest.php, line 54
Contains \Drupal\views\Tests\Entity\RowEntityRenderersTest.

Class

RowEntityRenderersTest
Tests the entity row renderers.

Namespace

Drupal\views\Tests\Entity

Code

protected function setUp() {
  parent::setUp();
  $this
    ->installEntitySchema('node');
  $this
    ->installEntitySchema('user');
  $this
    ->installSchema('node', array(
    'node_access',
  ));
  $this
    ->installConfig(array(
    'node',
    'language',
  ));

  // The entity.node.canonical route must exist when nodes are rendered.
  $this->container
    ->get('router.builder')
    ->rebuild();
  $this->langcodes = array(
    \Drupal::languageManager()
      ->getDefaultLanguage()
      ->getId(),
  );
  for ($i = 0; $i < 2; $i++) {
    $langcode = 'l' . $i;
    $this->langcodes[] = $langcode;
    ConfigurableLanguage::createFromLangcode($langcode)
      ->save();
  }

  // Make sure we do not try to render non-existing user data.
  $node_type = NodeType::create(array(
    'type' => 'test',
  ));
  $node_type
    ->setDisplaySubmitted(FALSE);
  $node_type
    ->save();
  $this->values = array();
  $controller = \Drupal::entityManager()
    ->getStorage('node');
  $langcode_index = 0;
  for ($i = 0; $i < count($this->langcodes); $i++) {

    // Create a node with a different default language each time.
    $default_langcode = $this->langcodes[$langcode_index++];
    $node = $controller
      ->create(array(
      'type' => 'test',
      'uid' => 0,
      'langcode' => $default_langcode,
    ));

    // Ensure the default language is processed first.
    $langcodes = array_merge(array(
      $default_langcode,
    ), array_diff($this->langcodes, array(
      $default_langcode,
    )));
    foreach ($langcodes as $langcode) {

      // Ensure we have a predictable result order.
      $this->values[$i][$langcode] = $i . '-' . $langcode . '-' . $this
        ->randomMachineName();
      if ($langcode != $default_langcode) {
        $node
          ->addTranslation($langcode, array(
          'title' => $this->values[$i][$langcode],
        ));
      }
      else {
        $node
          ->setTitle($this->values[$i][$langcode]);
      }
      $node
        ->save();
    }
  }
}