You are here

public function NodeExampleTestCase::testInstallationApi in Examples for Developers 7

API-level content type test.

This test will verify that when the module is installed, it:

  • Adds a new content type, node_example.
  • Attaches a body field.
  • Attaches three other fields.
  • Creates a view mode, example_node_list.

File

node_example/node_example.test, line 45
Simpletest case for node_example module.

Class

NodeExampleTestCase
Functionality tests for node example module.

Code

public function testInstallationApi() {

  // At this point, the module should be installed.
  // First check for our content type.
  $node_type = node_type_get_type('node_example');
  $this
    ->assertTrue($node_type, 'Node Example Type was created.', 'API');

  // How about the body field?
  $body = field_info_instance('node', 'body', 'node_example');
  $this
    ->assertTrue($body, 'Node Example Type has a body field.', 'API');

  // Now look for our attached fields.
  // We made a handy function that tells us...
  $attached_fields = _node_example_installed_instances();
  foreach ($attached_fields as $field_name => $field_info) {
    $field = field_info_instance('node', $field_name, 'node_example');
    $this
      ->assertTrue($field, 'Field: ' . $field_name . ' was attached to node_example.', 'API');
  }

  // And that view mode...
  // 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']['example_node_list']), 'Added example_node_list view mode.', 'API');
}