View source
<?php
class SaveDraftTestCase extends DrupalWebTestCase {
protected $admin;
public static function getInfo() {
return array(
'name' => 'Save draft',
'description' => 'Make sure the node form still works with Save Draft enabled.',
'group' => 'Save draft',
);
}
public function setUp() {
parent::setUp(array(
'save_draft',
));
$this->admin = $this
->drupalCreateUser(array(
'create story content',
'edit any story content',
'administer nodes',
));
$this
->drupalLogin($this->admin);
$this->title_key = "title";
$this->body_key = "body";
}
public function getNodeArray() {
$edit = array();
$edit[$this->title_key] = $this
->randomName(8);
$edit[$this->body_key] = $this
->randomName(8);
return $edit;
}
public function testNodeSave() {
$edit = $this
->getNodeArray();
$this
->drupalPost('node/add/story', $edit, t('Publish'));
$node = $this
->drupalGetNodeByTitle($edit[$this->title_key]);
$this
->assertEqual($node->status, 1, t('Node saved correctly.'));
$this
->drupalPost("node/{$node->nid}/edit", array(), t('Save as unpublish'));
$node = node_load($node->nid, NULL, TRUE);
$this
->assertEqual($node->status, 0, t('Node unpublished correctly.'));
$edit = $this
->getNodeArray();
$this
->drupalPost('node/add/story', $edit, t('Save as Draft'));
$node = $this
->drupalGetNodeByTitle($edit[$this->title_key]);
$this
->assertEqual($node->status, 0, t('Node saved correctly as draft.'));
$this
->drupalPost("node/{$node->nid}/edit", array(), t('Save Changes'));
$node = node_load($node->nid, NULL, TRUE);
$this
->assertEqual($node->status, 1, t('Node published correctly.'));
}
}