state_flow.test in State Machine 7
File
modules/state_flow/tests/state_flow.test
View source
<?php
class StateFlowUnitTest extends DrupalWebTestCase {
public static function getInfo() {
return array(
'name' => 'StateFlow basic tests',
'description' => 'Perform basic unit tests on the StateFlow revision state machine.',
'group' => 'State Machine',
);
}
function setup() {
parent::setup('state_machine', 'state_flow');
}
function testStateFlowStateMachine() {
$node = $this
->drupalCreateNode();
$machine = state_flow_load_state_machine($node);
$this
->assertEqual($machine
->get_current_state(), 'draft', t('New nodes should default to the "draft" state.'));
$machine
->fire_event('publish');
$this
->assertEqual($machine
->get_current_state(), 'published', t('State should be "published" after firing the "publish" event.'));
$this
->drupalGet("node/{$node->nid}/edit");
$this
->assertFieldChecked('edit-revision', t('Revision checkbox should be checked after editing a "published" node.'));
$old_title = $node->title;
$edit = array();
$edit['title'] = $this
->randomName(8);
$this
->drupalPost("node/{$node->nid}/edit", $edit, t('Save'));
$this
->assertTitle($old_title, t('Node title should stay the original despite the update.'));
$this
->assertText(t('Program program @title has been updated.', array(
'@title' => $edit['title'],
)), t('The new node title should be saved.'));
$this
->assertEqual($machine
->get_current_state(), 'draft', t('Updated published nodes should default to the "draft" state for their latest revision.'));
$machine
->fire_event('publish');
$this
->assertEqual($machine
->get_current_state(), 'published', t('State should be "published" after firing the "publish" event.'));
$this
->assertTitle($edit['title'], t('Node title should be updated to second revision, now published.'));
}
}