public function SaveDraftTestCase::testNodeSave in Save Draft 7
Same name and namespace in other branches
- 6.2 save_draft.test \SaveDraftTestCase::testNodeSave()
Make sure nodes save with the right publication status.
File
- ./
save_draft.test, line 78 - Link base test file - contains common functions for testing links.
Class
- SaveDraftTestCase
- @file Link base test file - contains common functions for testing links.
Code
public function testNodeSave() {
// Log in as a user who should see the save draft button.
$this
->drupalLogin($this->save_draft_user);
// Testing with drafts enabled.
variable_set('save_draft_enabled_article', SAVE_DRAFT_ENABLED);
// Make sure the publish and save as draft buttons are present when adding a
// node.
$this
->drupalGet('node/add/article');
$this
->assertRaw('<input type="submit" id="edit-submit" name="op" value="' . $this->button_publish . '" class="form-submit" />', t('Publish button visible on node create.'));
$this
->assertRaw('<input type="submit" id="edit-draft" name="op" value="' . $this->button_save_draft . '" class="form-submit" />', t('Save as draft button visible on node create.'));
// Publish a node, and make sure it's published.
$edit = $this
->getNodeArray();
$this
->drupalPost('node/add/article', $edit, $this->button_publish);
$node = $this
->drupalGetNodeByTitle($edit[$this->title_key]);
$this
->assertEqual($node->status, NODE_PUBLISHED, t('Node saved correctly.'));
// Make sure the save and unpublish buttons are present when on a published
// node.
$this
->drupalGet('node/' . $node->nid . '/edit');
$this
->assertRaw('<input type="submit" id="edit-submit" name="op" value="' . $this->button_save . '" class="form-submit" />', t('Save button visible on published node edit.'));
$this
->assertRaw('<input type="submit" id="edit-draft" name="op" value="' . $this->button_unpublish . '" class="form-submit" />', t('Unpublish button visible on published node edit.'));
// Unpublish it, and make sure it's unpublished.
$this
->drupalPost('node/' . $node->nid . '/edit', array(), $this->button_unpublish);
$node = node_load($node->nid, NULL, TRUE);
$this
->assertEqual($node->status, NODE_NOT_PUBLISHED, t('Node unpublished correctly.'));
// Save a new node as a draft, and make sure it's unpublished.
$edit = $this
->getNodeArray();
$this
->drupalPost('node/add/article', $edit, $this->button_save_draft);
$node = $this
->drupalGetNodeByTitle($edit[$this->title_key]);
$this
->assertEqual($node->status, NODE_NOT_PUBLISHED, t('Node saved correctly as draft.'));
// Make sure the publish and save draft buttons are present when on an
// unpublished draft.
$this
->drupalGet('node/' . $node->nid . '/edit');
$this
->assertRaw('<input type="submit" id="edit-submit" name="op" value="' . $this->button_publish . '" class="form-submit" />', t('Publish button visible on draft node edit.'));
$this
->assertRaw('<input type="submit" id="edit-draft" name="op" value="' . $this->button_save_draft . '" class="form-submit" />', t('Save draft button visible on draft node edit.'));
// Publish the node, and make sure it's published.
$this
->drupalPost('node/' . $node->nid . '/edit', array(), $this->button_publish);
$node = node_load($node->nid, NULL, TRUE);
$this
->assertEqual($node->status, NODE_PUBLISHED, t('Node published correctly.'));
// Testing with drafts disabled.
variable_set('save_draft_enabled_article', SAVE_DRAFT_DISABLED);
// Make sure the save draft button is not present when adding a node and
// drafts are disabled.
$this
->drupalGet('node/add/article');
$this
->assertRaw('<input type="submit" id="edit-submit" name="op" value="' . $this->button_save . '" class="form-submit" />', t('Save button visible on node create.'));
$this
->assertNoRaw('<input type="submit" id="edit-draft" name="op" value="' . $this->button_save_draft . '" class="form-submit" />', t('Save draft button not visible on node create.'));
// Publish a node and edit it again.
$edit = $this
->getNodeArray();
$this
->drupalPost('node/add/article', $edit, $this->button_save);
$node = $this
->drupalGetNodeByTitle($edit[$this->title_key]);
// Make sure the unpublish button is present when on a published node and
// drafts are disabled.
$this
->drupalGet('node/' . $node->nid . '/edit');
$this
->assertRaw('<input type="submit" id="edit-submit" name="op" value="' . $this->button_save . '" class="form-submit" />', t('Save button visible on published node edit.'));
$this
->assertNoRaw('<input type="submit" id="edit-draft" name="op" value="' . $this->button_unpublish . '" class="form-submit" />', t('Save draft disabled successfully on published node edit.'));
}