NodeTypeTestCase::testNodeTypeEditing

7 node.test NodeTypeTestCase::testNodeTypeEditing()
8 node.test NodeTypeTestCase::testNodeTypeEditing()

Test editing a node type using the UI.

File

modules/node/node.test, line 1337
Tests for node.module.

Code

function testNodeTypeEditing() {
  $web_user = $this->drupalCreateUser(array('bypass node access', 'administer content types'));
  $this->drupalLogin($web_user);

  $instance = field_info_instance('node', 'body', 'page');
  $this->assertEqual($instance['label'], 'Body', t('Body field was found.'));

  // Verify that title and body fields are displayed.
  $this->drupalGet('node/add/page');
  $this->assertRaw('Title', t('Title field was found.'));
  $this->assertRaw('Body', t('Body field was found.'));

  // Rename the title field.
  $edit = array(
    'title_label' => 'Foo',
  );
  $this->drupalPost('admin/structure/types/manage/page', $edit, t('Save content type'));
  // Refresh the field information for the rest of the test.
  field_info_cache_clear();

  $this->drupalGet('node/add/page');
  $this->assertRaw('Foo', t('New title label was displayed.'));
  $this->assertNoRaw('Title', t('Old title label was not displayed.'));

  // Change the name, machine name and description.
  $edit = array(
    'name' => 'Bar', 
    'type' => 'bar', 
    'description' => 'Lorem ipsum.',
  );
  $this->drupalPost('admin/structure/types/manage/page', $edit, t('Save content type'));
  field_info_cache_clear();

  $this->drupalGet('node/add');
  $this->assertRaw('Bar', t('New name was displayed.'));
  $this->assertRaw('Lorem ipsum', t('New description was displayed.'));
  $this->clickLink('Bar');
  $this->assertEqual(url('node/add/bar', array('absolute' => TRUE)), $this->getUrl(), t('New machine name was used in URL.'));
  $this->assertRaw('Foo', t('Title field was found.'));
  $this->assertRaw('Body', t('Body field was found.'));

  // Remove the body field.
  $this->drupalPost('admin/structure/types/manage/bar/fields/body/delete', NULL, t('Delete'));
  // Resave the settings for this type.
  $this->drupalPost('admin/structure/types/manage/bar', array(), t('Save content type'));
  // Check that the body field doesn't exist.
  $this->drupalGet('node/add/bar');
  $this->assertNoRaw('Body', t('Body field was not found.'));
}
Login or register to post comments