You are here

public function NodeFieldTestCase::testCreateDeleteFields in Node Field 7.2

Test method. Run by Simpletest.

Create node and some node fields for it and then delete node.

File

tests/node_field.test, line 46
Test creation and deletion of node field.

Class

NodeFieldTestCase
Test node fields.

Code

public function testCreateDeleteFields() {

  // Enable node fields for Article.
  $node_field_settings = [
    'node_field_node_types[article]' => TRUE,
  ];
  $this
    ->drupalPost('admin/config/content/node-field', $node_field_settings, t('Save configuration'));

  // Create an article.
  $node_settings = [
    'type' => 'article',
    'title' => $this
      ->randomName(10),
    'body' => [
      LANGUAGE_NONE => [
        [
          $this
            ->randomName(64),
        ],
      ],
    ],
  ];
  $node = $this
    ->drupalCreateNode($node_settings);

  // Create one field of each type.
  $node_field_types = node_field_types_info();
  foreach ($node_field_types as $node_field_type) {
    $field = [
      'node_fields[new][type]' => $node_field_type['type'],
      'node_fields[new][title]' => $this
        ->randomName(8),
    ];
    $this
      ->drupalPost('node/' . $node->nid . '/node-field', $field, t('Save'));
  }

  // Delete created article.
  $delete = [];
  $this
    ->drupalPost('node/' . $node->nid . '/delete', $delete, t('Delete'));
}