You are here

function DraftyTestCase::testDraftyRevisionCleanup in Drafty 7

Create a published node. Then create a draft and check if the previous published revision was cleaned by cron.

File

tests/DraftyTestCase.test, line 61

Class

DraftyTestCase
Test drafty revision support with a single entity.

Code

function testDraftyRevisionCleanup() {
  $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.
  $first_published_vid = $node->vid;

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

  // Run cron
  $this
    ->cronRun();

  // Check that the $first_published_vid is still present
  $nodes = node_load_multiple(array(
    $node->nid,
  ), array(
    'vid' => $first_published_vid,
  ));
  $this
    ->assertTrue(!empty($nodes), 'Old published revision is still present.');

  // Configure drafty to clean old published revisions
  variable_set('drafty_delete_old_revisions', TRUE);

  // Create new draft revision
  $node->title = 'Title C';
  $this
    ->setRevision($node);
  $node->is_draft_revision = TRUE;
  node_save($node);

  // Run cron
  $this
    ->cronRun();

  // Confirm the the second published revision has been deleted.
  $nodes = node_load_multiple(array(
    $node->nid,
  ), array(
    'vid' => $second_published_vid,
  ));
  $this
    ->assertTrue(empty($nodes), 'Old published revision has been deleted.');
}