DraftyTestCase.test in Drafty 7
File
tests/DraftyTestCase.test
View source
<?php
class DraftyTestCase extends DraftyWebTestCase {
public static function getInfo() {
return array(
'name' => 'Drafty',
'description' => 'Test revision manipulation.',
'group' => 'Drafty',
);
}
function testDraftRevisions() {
$node = new stdClass();
$node->title = 'Title A';
$node->type = 'article';
$node->status = 1;
$this
->setRevision($node);
node_save($node);
$published_vid = $node->vid;
$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;
$this
->assertNotEqual($published_vid, $draft_vid);
$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);
}
function testDraftyRevisionCleanup() {
$node = new stdClass();
$node->title = 'Title A';
$node->type = 'article';
$node->status = 1;
$this
->setRevision($node);
node_save($node);
$first_published_vid = $node->vid;
$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;
$this
->cronRun();
$nodes = node_load_multiple(array(
$node->nid,
), array(
'vid' => $first_published_vid,
));
$this
->assertTrue(!empty($nodes), 'Old published revision is still present.');
variable_set('drafty_delete_old_revisions', TRUE);
$node->title = 'Title C';
$this
->setRevision($node);
$node->is_draft_revision = TRUE;
node_save($node);
$this
->cronRun();
$nodes = node_load_multiple(array(
$node->nid,
), array(
'vid' => $second_published_vid,
));
$this
->assertTrue(empty($nodes), 'Old published revision has been deleted.');
}
}