You are here

protected function EntityDefaultLanguageTest::createNode in Drupal 8

Same name and namespace in other branches
  1. 9 core/modules/language/tests/src/Kernel/EntityDefaultLanguageTest.php \Drupal\Tests\language\Kernel\EntityDefaultLanguageTest::createNode()

Creates a new node of given type and language using Entity API.

Parameters

string $type: The node content type.

string $langcode: (optional) Language code to pass to entity create.

Return value

\Drupal\node\NodeInterface The node created.

1 call to EntityDefaultLanguageTest::createNode()
EntityDefaultLanguageTest::testEntityTranslationDefaultLanguageViaCode in core/modules/language/tests/src/Kernel/EntityDefaultLanguageTest.php
Tests that default language code is properly set for new nodes.

File

core/modules/language/tests/src/Kernel/EntityDefaultLanguageTest.php, line 136

Class

EntityDefaultLanguageTest
Tests default language code is properly generated for entities.

Namespace

Drupal\Tests\language\Kernel

Code

protected function createNode($type, $langcode = NULL) {
  $values = [
    'type' => $type,
    'title' => $this
      ->randomString(),
  ];
  if (!empty($langcode)) {
    $values['langcode'] = $langcode;
  }
  $node = $this->container
    ->get('entity_type.manager')
    ->getStorage('node')
    ->create($values);
  return $node;
}