Tests that the right buttons are displayed for saving nodes.
function testNodeFormButtons() {
// Login as administrative user.
$this
->drupalLogin($this->admin_user);
// Verify the buttons on a node add form.
$this
->drupalGet('node/add/article');
$this
->assertButtons(array(
t('Save and publish'),
t('Save as unpublished'),
));
// Save the node and assert it's published after clicking
// 'Save and publish'.
$edit = array(
'title' => $this
->randomString(),
);
$this
->drupalPost('node/add/article', $edit, t('Save and publish'));
// Get the node.
$node_1 = node_load(1);
$this
->assertEqual(1, $node_1->status, 'Node is published');
// Verify the buttons on a node edit form.
$this
->drupalGet('node/' . $node_1->nid . '/edit');
$this
->assertButtons(array(
t('Save and keep published'),
t('Save and unpublish'),
));
// Save the node and verify it's still published after clicking
// 'Save and keep published'.
$this
->drupalPost(NULL, $edit, t('Save and keep published'));
$node = node_load(1, TRUE);
$this
->assertEqual(1, $node_1->status, 'Node is published');
// Save the node and verify it's unpublished after clicking
// 'Save and unpublish'.
$this
->drupalPost('node/' . $node_1->nid . '/edit', $edit, t('Save and unpublish'));
$node_1 = node_load(1, TRUE);
$this
->assertEqual(0, $node_1->status, 'Node is unpublished');
// Verify the buttons on an unpublished node edit screen.
$this
->drupalGet('node/' . $node_1->nid . '/edit');
$this
->assertButtons(array(
t('Save and keep unpublished'),
t('Save and publish'),
));
// Create a node as a normal user.
$this
->drupalLogout();
$this
->drupalLogin($this->web_user);
// Verify the buttons for a normal user.
$this
->drupalGet('node/add/article');
$this
->assertButtons(array(
t('Save'),
), FALSE);
// Create the node.
$edit = array(
'title' => $this
->randomString(),
);
$this
->drupalPost('node/add/article', $edit, t('Save'));
$node_2 = node_load(2);
$this
->assertEqual(1, $node_2->status, 'Node is published');
// Login as an administrator and unpublish the node that just
// was created by the normal user.
$this
->drupalLogout();
$this
->drupalLogin($this->admin_user);
$this
->drupalPost('node/' . $node_2->nid . '/edit', array(), t('Save and unpublish'));
$node_2 = node_load(2, TRUE);
$this
->assertEqual(0, $node_2->status, 'Node is unpublished');
// Login again as the normal user, save the node and verify
// it's still unpublished.
$this
->drupalLogout();
$this
->drupalLogin($this->web_user);
$this
->drupalPost('node/' . $node_2->nid . '/edit', array(), t('Save'));
$node_2 = node_load(2, TRUE);
$this
->assertEqual(0, $node_2->status, 'Node is still unpublished');
$this
->drupalLogout();
// Set article content type default to unpublished. This will change the
// the initial order of buttons and/or status of the node when creating
// a node.
variable_set('node_options_article', array(
'promote',
));
$this
->refreshVariables();
// Verify the buttons on a node add form for an administrator.
$this
->drupalLogin($this->admin_user);
$this
->drupalGet('node/add/article');
$this
->assertButtons(array(
t('Save as unpublished'),
t('Save and publish'),
));
// Verify the node is unpublished by default for a normal user.
$this
->drupalLogout();
$this
->drupalLogin($this->web_user);
$edit = array(
'title' => $this
->randomString(),
);
$this
->drupalPost('node/add/article', $edit, t('Save'));
$node_3 = node_load(3);
$this
->assertEqual(0, $node_3->status, 'Node is unpublished');
}