You are here

function DraftyTestCase::testDraftRevisions in Drafty 7

Create a node and check creation of draft and published revisions.

File

tests/DraftyTestCase.test, line 23

Class

DraftyTestCase
Test drafty revision support with a single entity.

Code

function testDraftRevisions() {
  $node = new stdClass();
  $node->title = 'Title A';
  $node->type = 'article';
  $node->status = 1;
  $this
    ->setRevision($node);
  node_save($node);

  // Save the vid for later comparison.
  $published_vid = $node->vid;

  // Save a new draft.
  $node = node_load($node->nid);
  $this
    ->assertEqual($node->title, 'Title A');
  $node->title = 'Title B';
  $this
    ->setRevision($node);
  $node->is_draft_revision = TRUE;
  node_save($node);
  $draft_vid = $node->vid;

  // Confirm that the published and draft version IDs differ.
  $this
    ->assertNotEqual($published_vid, $draft_vid);

  // Confirm that loading the node gets the published revision.
  $node = node_load($node->nid);
  $this
    ->assertEqual($node->title, 'Title A');
  drafty()
    ->publishRevision('node', $node->nid, $draft_vid);
  $node = node_load($node->nid);
  $this
    ->assertEqual($node->title, 'Title B');
  $this
    ->assertNotEqual($node->vid, $draft_vid);
}