You are here

function TMGMTEntityTestCaseUtility::createNode in Translation Management Tool 7

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

object Newly created node object.

13 calls to TMGMTEntityTestCaseUtility::createNode()
TMGMTEntitySourceLanguageNoneTestCase::testLanguageNeutral in sources/entity/tmgmt_entity.source.none.test
Test if language neutral entities are not allowed for translation.
TMGMTEntitySourceListTestCase::setUp in sources/entity/ui/tmgmt_entity_ui.list.test
Overrides DrupalWebTestCase::setUp()
TMGMTEntitySourceListTestCase::testNodeEntityListings in sources/entity/ui/tmgmt_entity_ui.list.test
TMGMTEntitySourcePathAutoTestCase::testAliasCreation in sources/entity/tmgmt_entity.pathauto.test
Tests that pathauto aliases are correctly created.
TMGMTEntitySourceTestCase::testEntitySourceNode in sources/entity/tmgmt_entity.source.test
Tests nodes field translation.

... See full list

1 method overrides TMGMTEntityTestCaseUtility::createNode()
TMGMTFieldCollectionSourceTestCase::createNode in sources/field/tmgmt_field_collection.test
Creates a node of a given bundle.

File

tests/tmgmt.base.entity.test, line 174

Class

TMGMTEntityTestCaseUtility
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.

Code

function createNode($bundle, $sourcelang = 'en') {
  $node = array(
    'type' => $bundle,
    'language' => $sourcelang,
    // Ensure that the body field is defined for the node language.
    'body' => array(
      $sourcelang => array(
        0 => array(),
      ),
    ),
  );
  foreach ($this->field_names['node'][$bundle] as $field_name) {
    $field_info = field_info_field($field_name);
    $cardinality = $field_info['cardinality'] == FIELD_CARDINALITY_UNLIMITED ? 1 : $field_info['cardinality'];
    $field_langcode = field_is_translatable('node', $field_info) ? $sourcelang : LANGUAGE_NONE;

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