You are here

protected function BambooTwigTestBase::setUpArticles in Bamboo Twig 8.5

Same name and namespace in other branches
  1. 8.4 tests/src/Functional/BambooTwigTestBase.php \Drupal\Tests\bamboo_twig\Functional\BambooTwigTestBase::setUpArticles()

Setup default articles node for testing.

Summary: | Nid | Title | EN | DE | FR | |-----|----------|--------------|----|--------------| | 1 | News N°1 | X (original) | | | | 2 | News N°2 | X (original) | | X | | 3 | News N°3 | X (original) | X | X | | 4 | News N°4 | | | X (original) | | 5 | News N°5 | X | | X (original) |

4 calls to BambooTwigTestBase::setUpArticles()
BambooTwigI18nTest::setUp in tests/src/Functional/BambooTwigI18nTest.php
BambooTwigLoaderTest::setUp in tests/src/Functional/BambooTwigLoaderTest.php
BambooTwigRenderTest::setUp in tests/src/Functional/BambooTwigRenderTest.php
BambooTwigTokenTest::setUp in tests/src/Functional/BambooTwigTokenTest.php

File

tests/src/Functional/BambooTwigTestBase.php, line 81

Class

BambooTwigTestBase
Has some additional helper methods to make test code more readable.

Namespace

Drupal\Tests\bamboo_twig\Functional

Code

protected function setUpArticles() {

  // Create an article content type that we will use for testing.
  $this
    ->drupalCreateContentType([
    'type' => 'article',
    'name' => 'Article',
  ]);

  // Create a reference field for tag(s) on article.
  $this
    ->createEntityReferenceField('node', 'article', 'field_tags', NULL, 'taxonomy_term', 'default', [
    'target_bundles' => [
      'tags' => 'tags',
    ],
  ], FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED);

  /** @var \Drupal\Core\Entity\EntityDisplayRepositoryInterface $entity_display_repository */
  $entity_display_repository = $this->container
    ->get('entity_display.repository');

  // Show on default display and teaser.
  $entity_display_repository
    ->getViewDisplay('node', 'article', 'default')
    ->setComponent('field_tags', [
    'type' => 'entity_reference_label',
  ])
    ->save();

  // Add default nodes.
  $this->articles = [];
  $article = $this->entityTypeManager
    ->getStorage('node')
    ->create([
    'type' => 'article',
    'title' => 'News N°1',
    'field_tags' => $this->tags[3],
  ]);
  $article
    ->save();
  $this->articles[] = $article;
  $article = $this->entityTypeManager
    ->getStorage('node')
    ->create([
    'type' => 'article',
    'title' => 'News N°2',
    'field_tags' => $this->tags[1],
  ]);
  $article
    ->save();
  $article_translation = $article
    ->addTranslation('fr', $article
    ->toArray());
  $article_translation->title = 'Article N°2';
  $article_translation
    ->save();
  $this->articles[] = $article;
  $article = $this->entityTypeManager
    ->getStorage('node')
    ->create([
    'type' => 'article',
    'title' => 'News N°3',
    'field_tags' => $this->tags[2],
  ]);
  $article
    ->save();
  $article_translation = $article
    ->addTranslation('fr', $article
    ->toArray());
  $article_translation->title = 'Article N°3';
  $article_translation
    ->save();
  $article_translation = $article
    ->addTranslation('de', $article
    ->toArray());
  $article_translation->title = 'Artikel N°3';
  $article_translation
    ->save();
  $this->articles[] = $article;
  $article = $this->entityTypeManager
    ->getStorage('node')
    ->create([
    'type' => 'article',
    'title' => 'Article N°4',
    'langcode' => 'fr',
    'field_tags' => $this->tags[0],
  ]);
  $article
    ->save();
  $this->articles[] = $article;
  $article = $this->entityTypeManager
    ->getStorage('node')
    ->create([
    'type' => 'article',
    'title' => 'Article N°5',
    'langcode' => 'fr',
    'field_tags' => $this->tags[4],
  ]);
  $article
    ->save();
  $article_translation = $article
    ->addTranslation('en', $article
    ->toArray());
  $article_translation->title = 'News N°5';
  $article_translation
    ->save();
  $this->articles[] = $article;
}