You are here

public function UniqueFieldCoreTestCase::testUniqueAllTitle in Unique field 7

Test the unique requirement on the title field in the all scope.

File

tests/core.test, line 71
Functional tests for the Unique Field module with Drupal core field types.

Class

UniqueFieldCoreTestCase
@file Functional tests for the Unique Field module with Drupal core field types.

Code

public function testUniqueAllTitle() {

  // Create a content type with the title set to be unique
  $edit = array();
  $edit['name'] = 'Unique Title';
  $edit['type'] = 'uf_title';
  $edit['unique_field_fields[title]'] = 'title';
  $edit['unique_field_scope'] = UNIQUE_FIELD_SCOPE_ALL;
  $this
    ->drupalPost('admin/structure/types/add', $edit, t('Save content type'));
  $this
    ->assertText('The content type Unique Title has been added.', 'Content type added.');

  // Create another content type with the title set to be unique
  $edit = array();
  $edit['name'] = 'Unique Title 2';
  $edit['type'] = 'uf_title2';
  $edit['unique_field_fields[title]'] = 'title';
  $edit['unique_field_scope'] = UNIQUE_FIELD_SCOPE_ALL;
  $this
    ->drupalPost('admin/structure/types/add', $edit, t('Save content type'));
  $this
    ->assertText('The content type Unique Title 2 has been added.', 'Content type added.');

  // Attempt to create 2 nodes with the same title in different content types
  $title = $this
    ->randomName(24);
  $edit = array();
  $edit['title'] = $title;
  $edit['body[und][0][value]'] = $this
    ->randomName(48);
  $this
    ->drupalPost('node/add/uf-title', $edit, t('Save'));
  $this
    ->assertText($edit['body[und][0][value]'], 'Unique Title (uf_title) node has been created');
  $edit['body[und][0][value]'] = $this
    ->randomName(48);
  $this
    ->drupalPost('node/add/uf-title2', $edit, t('Save'));
  $this
    ->assertText('The Title field requires a unique value, and the specified value is already used', 'Unique Title (uf_title) node with duplicate content could not be created');

  // Check for false negative: Attempt to create a node with a unique title
  $edit = array();
  $edit['title'] = $this
    ->randomName(24);
  $edit['body[und][0][value]'] = $this
    ->randomName(48);
  $this
    ->drupalPost('node/add/uf-title2', $edit, t('Save'));
  $this
    ->assertText($edit['body[und][0][value]'], 'Unique Title 2 (uf_title2) node has been created');
}