You are here

function TMGMTEntityTestCaseUtility::createNodeType in Translation Management Tool 7

Creates node type with several text fields with different cardinality.

Internally it calls TMGMTEntityTestCaseUtility::attachFields() to create and attach fields to newly created bundle. You can than use $this->field_names['node']['YOUR_BUNDLE_NAME'] to access them.

Parameters

string $machine_name: Machine name of the node type.

string $human_name: Human readable name of the node type.

int $language_content_type: Either 0 (disabled), 1 (language enabled but no translations), TRANSLATION_ENABLED or ENTITY_TRANSLATION_ENABLED. pparam bool $attach_fields (optional) If fields with the same translatability should automatically be attached to the node type.

10 calls to TMGMTEntityTestCaseUtility::createNodeType()
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()
TMGMTEntitySourcePathAutoTestCase::setUp in sources/entity/tmgmt_entity.pathauto.test
Overrides DrupalWebTestCase::setUp()
TMGMTEntitySourceTestCase::testEntitySourceNode in sources/entity/tmgmt_entity.source.test
Tests nodes field translation.
TMGMTEntitySourceTestCase::testRequestDataForSpecificLanguage in sources/entity/tmgmt_entity.source.test
Test if the source is able to pull content in requested language.

... See full list

File

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

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 createNodeType($machine_name, $human_name, $language_content_type = 0, $attach_fields = TRUE) {

  // Create new bundle.
  $type = array(
    'type' => $machine_name,
    'name' => $human_name,
    'base' => 'node_content',
    'description' => '',
    'custom' => 1,
    'modified' => 1,
    'locked' => 0,
  );
  $type = node_type_set_defaults($type);
  node_type_save($type);
  node_add_body_field($type);
  node_types_rebuild();

  // Set content type to be translatable as specified by
  // $language_content_type.
  $edit = array();
  $edit['language_content_type'] = $language_content_type;
  $this
    ->drupalPost('admin/structure/types/manage/' . $machine_name, $edit, t('Save content type'));
  $translatable = FALSE;
  if (defined('ENTITY_TRANSLATION_ENABLED') && $language_content_type == ENTITY_TRANSLATION_ENABLED) {
    $translatable = TRUE;
  }

  // Push in also the body field.
  $this->field_names['node'][$machine_name][] = 'body';
  if ($attach_fields) {
    $this
      ->attachFields('node', $machine_name, $translatable);
  }

  // Change body field to be translatable.
  $body = field_info_field('body');
  $body['translatable'] = $translatable;
  field_update_field($body);
}