You are here

protected function TmgmtEntityTestTrait::createTranslatableNode in Translation Management Tool 8

Creates a node of a given bundle.

It uses $this->field_names to populate content of attached fields.

Parameters

string $bundle: Node type name.

string $sourcelang: Source lang of the node to be created.

Return value

\Drupal\node\NodeInterface Newly created node object.

14 calls to TmgmtEntityTestTrait::createTranslatableNode()
ContentTmgmtEntitySourceListTest::setUp in sources/content/tests/src/Functional/ContentTmgmtEntitySourceListTest.php
Overrides DrupalWebTestCase::setUp()
ContentTmgmtEntitySourceListTest::testNodeEntityListings in sources/content/tests/src/Functional/ContentTmgmtEntitySourceListTest.php
ContentTmgmtEntitySourceUiTest::testCart in sources/content/tests/src/Functional/ContentTmgmtEntitySourceUiTest.php
Test the entity source specific cart functionality.
ContentTmgmtEntitySourceUiTest::testCommentTranslateTab in sources/content/tests/src/Functional/ContentTmgmtEntitySourceUiTest.php
Test translating comments.
ContentTmgmtEntitySourceUiTest::testConsiderFieldSequences in sources/content/tests/src/Functional/ContentTmgmtEntitySourceUiTest.php
Test consider field sequences.

... See full list

File

tests/src/Functional/TmgmtEntityTestTrait.php, line 161

Class

TmgmtEntityTestTrait
Utility test case class with helper methods to create entities and their fields with populated translatable content. Extend this class if you create tests in which you need Drupal entities and/or fields.

Namespace

Drupal\Tests\tmgmt\Functional

Code

protected function createTranslatableNode($bundle, $sourcelang = 'en') {
  $node = array(
    'type' => $bundle,
    'langcode' => $sourcelang,
  );
  foreach ($this->field_names['node'][$bundle] as $field_name) {

    // @todo: Why are some missing?
    if ($field_storage_config = FieldStorageConfig::loadByName('node', $field_name)) {
      $cardinality = $field_storage_config
        ->getCardinality() == FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED ? 1 : $field_storage_config
        ->getCardinality();

      // Create two deltas for each field.
      for ($delta = 0; $delta <= $cardinality; $delta++) {
        $node[$field_name][$delta]['value'] = $this
          ->randomMachineName(20);
        $node[$field_name][$delta]['format'] = 'plain_text';
        if ($field_storage_config
          ->getType() == 'text_with_summary') {
          $node[$field_name][$delta]['summary'] = $this
            ->randomMachineName(10);
        }
      }
    }
  }
  return $this
    ->drupalCreateNode($node);
}