public function ConflictTestCase::testConflictCase in Conflict 7
Test case when user should get conflicts.
Emulates conflicts for title and body fields.
File
- ./
conflict.test, line 276 - Tests for conflict.module.
Class
Code
public function testConflictCase() {
$orig_title = $this
->randomName();
$orig_body = $this
->randomString();
$conflict_title = $this
->randomName();
$conflict_body = $this
->randomString();
// Create the node to work with.
$node = $this
->drupalCreateNode(array(
'title' => $this
->randomName(),
'body' => array(
LANGUAGE_NONE => array(
array(
'value' => $this
->randomString(),
'summary' => '',
),
),
),
));
// Load the edit page up.
$this
->drupalGet("node/{$node->nid}/edit");
// Before submitting the form, make changes to the node from somewhere else.
$conflict = clone $node;
$conflict->title = $orig_title;
$conflict->body['und'][0]['value'] = $orig_body;
node_save($conflict);
// Fudge the timestamps in the database.
db_query('UPDATE {node} SET changed = changed + 100 WHERE nid = :nid', array(
':nid' => $conflict->nid,
));
db_query('UPDATE {node_revision} SET timestamp = timestamp + 100 WHERE nid = :nid', array(
':nid' => $conflict->nid,
));
// Attempt to make changes.
$edit['title'] = $conflict_title;
$edit['body[und][0][value]'] = $conflict_body;
$this
->drupalPost(NULL, $edit, t('Save'));
$this
->assertText(t('The Title field was changed by another user while you were editing it. Save again to overwrite it.'));
$this
->assertText(t('The Body field was changed by another user while you were editing it. Save again to overwrite it.'));
$this
->assertFieldByXPath('//*[@id="edit-title" and contains(@class, "error")]', $conflict_title, 'Title field was highlighted with error and contains conflicted data.');
$this
->assertFieldByXPath('//*[@id="edit-body-und-0-value" and contains(@class, "error")]', $conflict_body, 'Body field was highlighted with error and contains conflicted data.');
}