1 node_type_example.test | public NodeTypeExampleTest::testInstallationApi() |
API-level content type test.
This test will verify that, when the module is installed, it:
- Adds a new content type, node_type_example.
- Attaches a body field.
- Attaches three other fields.
- Creates a view mode, node_type_example_list.
File
- modules/
examples/ node_type_example/ tests/ node_type_example.test, line 33 - Simpletest case for the Node Type Example module.
Class
- NodeTypeExampleTest
- Functionality tests for The Node Type Example module.
Code
public function testInstallationApi() {
// At this point, the module should be installed. First check for the
// content type.
$node_type = node_type_get_type('node_type_example');
$this->assertTrue($node_type, 'The content type has been created.', 'API');
// Verify the body field has been added too.
$body = field_info_instance('node', 'body', 'node_type_example');
$this->assertTrue($body, 'The content type has a body field.', 'API');
// Now check for our attached fields.
$attached_fields = _node_type_example_installed_instances();
foreach ($attached_fields as $field_name => $field_info) {
$field = field_info_instance('node', $field_name, 'node_type_example');
$this->assertTrue($field,
"The $field_name field has been added to the content type.", 'API');
}
// entity_get_info() invokes hook_entity_info_alter(), so it's a good place
// to verify that our code works.
$entities = entity_get_info('node');
$this->assertTrue(isset($entities['view modes']['node_type_example_list']),
'The view mode has been added.', 'API');
}