1 backdrop_web_test_case.php protected BackdropWebTestCase::backdropCreateContentType($settings = array())

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

core/modules/simpletest/backdrop_web_test_case.php, line 1168

Class

BackdropWebTestCase
Test case for typical Backdrop tests.

Code

protected function backdropCreateContentType($settings = array()) {
  // Find a non-existent random type name.
  do {
    $name = strtolower($this->randomName(8));
  } while (node_type_get_type($name));

  // Populate defaults array.
  $defaults = array(
    'type' => $name,
    'name' => $name,
    'base' => 'node_content',
    'description' => '',
    'help' => '',
    'title_label' => 'Title',
    'has_title' => 1,
    'is_new' => TRUE,
  );
  // 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);
  menu_rebuild();
  node_add_body_field($type);

  $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;
}