You are here

public function UniqueFieldCoreTestCase::testUniqueCtypeAuthor in Unique field 7

Test the unique requirement on the node author in the content type scope.

File

tests/core.test, line 112
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 testUniqueCtypeAuthor() {

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

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

  // Check for false negative: Attempt to create a node with a unique author
  $new_account = $this
    ->drupalCreateUser(array(
    'administer nodes',
    'bypass node access',
  ));
  $this
    ->drupalLogin($new_account);
  $edit = array();
  $edit['title'] = $this
    ->randomName(24);
  $edit['body[und][0][value]'] = $this
    ->randomName(48);
  $this
    ->drupalPost('node/add/uf-author', $edit, t('Save'));
  $this
    ->assertText($edit['body[und][0][value]'], 'Unique Author (uf_author) node has been created');
}