You are here

function FieldPropertyTestCase::testIsProperty in Field property 7

File

./field_property.test, line 30
Test integration for the field_property module.

Class

FieldPropertyTestCase
@file Test integration for the field_property module.

Code

function testIsProperty() {

  // Set the tags field on articles to be a property (non-revisionable data).
  $edit['instance[is_property]'] = TRUE;
  $this
    ->drupalPost('admin/structure/types/manage/article/fields/field_tags', $edit, 'Save settings');

  // Create a test node.
  $first = $node = $this
    ->drupalCreateNode(array(
    'type' => 'article',
  ));

  // Check that the help text appears on the node edit page.
  $this
    ->drupalGet("node/{$node->nid}/edit");
  $this
    ->assertText("This field is synchonized across all revisions.");

  // Edit the node, creating a second revision and changing data.
  $edit = array();
  $edit['body[und][0][value]'] = 'Second revision';
  $edit['field_tags[und]'] = 'term1, term2';
  $edit['revision'] = TRUE;
  $this
    ->drupalPost(NULL, $edit, 'Save');

  // Reload node objects.
  $first = node_load($first->nid, $first->vid, TRUE);
  $second = node_load($node->nid, NULL, TRUE);

  // The tags field in both revisions should be equal. Everything else diffferent.
  $this
    ->assertNotEqual($first->vid, $second->vid);
  $this
    ->assertEqual($first->field_tags, $second->field_tags);
  $this
    ->assertNotEqual($first->body, $second->body);

  // Enable revisionable data for the tags field again.
  $edit = array();
  $edit['instance[is_property]'] = FALSE;
  $this
    ->drupalPost('admin/structure/types/manage/article/fields/field_tags', $edit, 'Save settings');

  // Check that the property help text is no longer visible on the node edit page.
  $this
    ->drupalGet("node/{$node->nid}/edit");
  $this
    ->assertNoText("This field is synchonized across all revisions.");

  // Make a third revision with changed data.
  $edit = array();
  $edit['body[und][0][value]'] = 'Third revision';
  $edit['field_tags[und]'] = 'term1, term2, term3';
  $edit['revision'] = TRUE;
  $this
    ->drupalPost(NULL, $edit, 'Save');

  // Reload node objects.
  $first = node_load($first->nid, $first->vid, TRUE);
  $second = node_load($second->nid, $second->vid, TRUE);
  $third = node_load($node->nid, NULL, TRUE);
  $this
    ->assertNotEqual($second->vid, $third->vid);
  $this
    ->assertNotEqual($second->field_tags, $third->field_tags);
  $this
    ->assertNotEqual($second->body, $third->body);
  $this
    ->assertEqual($first->field_tags, $second->field_tags);
  $this
    ->assertNotEqual($first->body, $second->body);

  // Ensure a field on a non-revisionable entity cannot be changed into a property.
  $this
    ->drupalGet('admin/structure/types/manage/article/comment/fields/comment_body');
  $this
    ->assertNoFieldByName('instance[is_property]');
}