You are here

protected function DrupalWebTestCase::drupalCreateContentType in SimpleTest 6.2

Same name and namespace in other branches
  1. 7.2 drupal_web_test_case.php \DrupalWebTestCase::drupalCreateContentType()
  2. 7 drupal_web_test_case.php \DrupalWebTestCase::drupalCreateContentType()

Creates a custom content type based on default settings.

Parameters

$settings: An array of settings to change from the defaults. Example: 'type' => 'foo'.

Return value

Created content type.

File

./drupal_web_test_case.php, line 908

Class

DrupalWebTestCase
Test case for typical Drupal tests.

Code

protected function drupalCreateContentType($settings = array()) {

  // Find a non-existent random type name.
  do {
    $name = strtolower($this
      ->randomName(8));
  } 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;
  $saved_type = node_type_save($type);
  node_types_rebuild();
  menu_rebuild();
  $this
    ->assertEqual($saved_type, SAVED_NEW, t('Created content type %type.', array(
    '%type' => $type->type,
  )));

  // Reset permissions so that permissions for this content type are available.
  $this
    ->checkPermissions(array(), TRUE);
  return $type;
}