You are here

public function UniqueFieldCoreTestCase::testUniqueAllAuthor in Unique field 7

Test the unique requirement on the node author in the all scope.

File

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

  // 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';
  $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 Author has been added.', 'Content type added.');

  // Create another content type with the author set to be unique
  $edit = array();
  $edit['name'] = 'Unique Author 2';
  $edit['type'] = 'uf_author2';
  $edit['unique_field_fields[name]'] = 'name';
  $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 Author 2 has been added.', 'Content type added.');

  // Attempt to create 2 nodes with the same author in different content types
  $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-author2', $edit, t('Save'));
  $this
    ->assertText('The Author field requires a unique value, and the specified value is already used', 'Unique Author 2 (uf_author2) node with duplicate content could not be created');

  // Check for false negative: Attempt to create a node with a unique title
  $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-author2', $edit, t('Save'));
  $this
    ->assertText($edit['body[und][0][value]'], 'Unique Author 2 (uf_author2) node has been created');
}