You are here

function DrupalTestCase::drupalCreateContentType in SimpleTest 6

Creates a custom content type based on default settings.

Parameters

settings An array of settings to change from the defaults, in the form of 'type' => 'foo':

File

./drupal_test_case.php, line 78

Class

DrupalTestCase
Test case for typical Drupal tests. Extends WebTestCase for comfortable browser usage but also implements all UnitTestCase methods, I wish WebTestCase would do this.

Code

function drupalCreateContentType($settings = []) {

  // find a non-existent random type name.
  do {
    $name = strtolower($this
      ->randomName(3, 'type_'));
  } while (node_get_types('type', $name));

  // Populate defaults array
  $defaults = array(
    'type' => $name,
    'name' => $name,
    'description' => '',
    'help' => '',
    'min_word_count' => 0,
    'title_label' => 'Title',
    'body_label' => 'Body',
    'has_title' => 1,
    'has_body' => 1,
  );

  // imposed values for a custom type
  $forced = array(
    'orig_type' => '',
    'old_type' => '',
    'module' => 'node',
    'custom' => 1,
    'modified' => 1,
    'locked' => 0,
  );
  $type = $forced + $settings + $defaults;
  $type = (object) $type;
  node_type_save($type);
  node_types_rebuild();
  $this->_cleanupContentTypes[] = $type->type;
  return $type;
}