final protected function FeedsMapperTestCase::createContentType in Feeds 7
Same name and namespace in other branches
- 6 tests/feeds_mapper.test \FeedsMapperTestCase::createContentType()
- 7.2 tests/feeds_mapper.test \FeedsMapperTestCase::createContentType()
Create a new content-type, and add a field to it. Mostly copied from cck/tests/content.crud.test ContentUICrud::testAddFieldUI
Parameters
$typename: (Optional) the name of the content-type to create, defaults to a random name.
$fields: (Optional) an keyed array of $field_name => $field_type used to add additional fields to the new content type.
Return value
The name of the new typename.
5 calls to FeedsMapperTestCase::createContentType()
- FeedsMapperContentTestCase::test in tests/
feeds_mapper_content.test - Basic test loading a doulbe entry CSV file.
- FeedsMapperDateTestCase::test in tests/
feeds_mapper_date.test - Basic test loading a single entry CSV file.
- FeedsMapperEmfieldTestCase::test in tests/
feeds_mapper_emfield.test - Basic test loading a doulbe entry CSV file.
- FeedsMapperFileFieldTestCase::test in tests/
feeds_mapper_filefield.test - Basic test loading a single entry CSV file.
- FeedsMapperLinkTestCase::test in tests/
feeds_mapper_link.test - Basic test loading a single entry CSV file.
File
- tests/
feeds_mapper_test.inc, line 102 - Helper class with auxiliary functions for feeds mapper module tests.
Class
- FeedsMapperTestCase
- Base class for implementing Feeds Mapper test cases.
Code
protected final function createContentType($typename = NULL, $fields = array()) {
if ($typename == NULL) {
$typename = 'content_type_' . mt_rand();
}
// Create the content type.
$edit = array(
'type' => $typename,
'name' => $typename,
);
$this
->drupalPost('admin/content/types/add', $edit, 'Save content type');
$this
->assertText('The content type ' . $typename . ' has been added', 'Content type created');
$admin_type_url = 'admin/content/node-type/' . str_replace('_', '-', $typename);
// Create the fields
foreach ($fields as $field_name => $options) {
if (is_string($options)) {
$options = array(
'type' => $options,
);
}
$field_type = isset($options['type']) ? $options['type'] : 'text';
$field_widget = isset($options['widget']) ? $options['widget'] : $this
->selectFieldWidget($field_name, $field_type);
$this
->assertTrue($field_widget !== NULL, "Field type {$field_type} supported");
$label = $field_name . '_' . $field_type . '_label';
$edit = array(
'_add_new_field[label]' => $label,
'_add_new_field[field_name]' => $field_name,
'_add_new_field[type]' => $field_type,
'_add_new_field[widget_type]' => $field_widget,
);
$this
->drupalPost($admin_type_url . '/fields', $edit, 'Save');
// (Default) Configure the field.
$edit = isset($options['settings']) ? $options['settings'] : array();
$this
->drupalPost(NULL, $edit, 'Save field settings');
$this
->assertText('Added field ' . $label);
}
return $typename;
}