Commit 43cdf314 authored by webchick's avatar webchick

#492186 follow-up by nvanhove and Dave Reid: Fixed Authoring information is...

#492186 follow-up by nvanhove and Dave Reid: Fixed Authoring information is never updated. (with tests)
parent e5f48f0f
......@@ -931,9 +931,8 @@ function node_submit($node) {
global $user;
// A user might assign the node author by entering a user name in the node
// form, which we then need to translate to a user ID, unless we've already
// been provided a user ID by other means.
if (!empty($node->name) && !isset($node->uid)) {
// form, which we then need to translate to a user ID.
if (isset($node->name)) {
if ($account = user_load_by_name($node->name)) {
$node->uid = $account->uid;
}
......@@ -941,6 +940,7 @@ function node_submit($node) {
$node->uid = 0;
}
}
$node->created = !empty($node->date) ? strtotime($node->date) : REQUEST_TIME;
$node->validated = TRUE;
......
......@@ -230,12 +230,9 @@ function node_form($form, &$form_state, $node) {
'#title' => t('Authored on'),
'#maxlength' => 25,
'#description' => t('Format: %time. The date format is YYYY-MM-DD and %timezone is the timezone offset from UTC. Leave blank to use the time of form submission.', array('%time' => !empty($node->date) ? $node->date : format_date($node->created, 'custom', 'Y-m-d H:i:s O'), '%timezone' => !empty($node->date) ? $node->date : format_date($node->created, 'custom', 'O'))),
'#default_value' => !empty($node->date) ? $node->date : '',
);
if (isset($node->date)) {
$form['author']['date']['#default_value'] = $node->date;
}
// Node options for administrators
$form['options'] = array(
'#type' => 'fieldset',
......@@ -265,14 +262,6 @@ function node_form($form, &$form_state, $node) {
'#default_value' => $node->sticky,
);
// These values are used when the user has no administrator access.
foreach (array('uid', 'created') as $key) {
$form[$key] = array(
'#type' => 'value',
'#value' => $node->$key,
);
}
// Add the buttons.
$form['actions'] = array(
'#type' => 'container',
......
......@@ -212,6 +212,9 @@ class NodeRevisionsTestCase extends DrupalWebTestCase {
}
class PageEditTestCase extends DrupalWebTestCase {
protected $web_user;
protected $admin_user;
public static function getInfo() {
return array(
'name' => 'Node edit',
......@@ -223,14 +226,16 @@ class PageEditTestCase extends DrupalWebTestCase {
function setUp() {
parent::setUp();
$web_user = $this->drupalCreateUser(array('edit own page content', 'create page content'));
$this->drupalLogin($web_user);
$this->web_user = $this->drupalCreateUser(array('edit own page content', 'create page content'));
$this->admin_user = $this->drupalCreateUser(array('bypass node access', 'administer nodes'));
}
/**
* Check node edit functionality.
*/
function testPageEdit() {
$this->drupalLogin($this->web_user);
$langcode = LANGUAGE_NONE;
$title_key = "title";
$body_key = "body[$langcode][0][value]";
......@@ -291,6 +296,51 @@ class PageEditTestCase extends DrupalWebTestCase {
$second_node_version = node_load($node->nid, $revised_node->vid);
$this->assertNotIdentical($first_node_version->revision_uid, $second_node_version->revision_uid, 'Each revision has a distinct user.');
}
/**
* Check changing node authored by fields.
*/
function testPageAuthoredBy() {
$this->drupalLogin($this->admin_user);
// Create node to edit.
$langcode = LANGUAGE_NONE;
$body_key = "body[$langcode][0][value]";
$edit = array();
$edit['title'] = $this->randomName(8);;
$edit[$body_key] = $this->randomName(16);
$this->drupalPost('node/add/page', $edit, t('Save'));
// Check that the node was authored by the currently logged in user.
$node = $this->drupalGetNodeByTitle($edit['title']);
$this->assertIdentical($node->uid, $this->admin_user->uid, 'Node authored by admin user.');
// Try to change the 'authored by' field to an invalid user name.
$edit = array(
'name' => 'invalid-name',
);
$this->drupalPost('node/' . $node->nid . '/edit', $edit, t('Save'));
$this->assertText('The username invalid-name does not exist.');
// Change the authored by field to an empty string, which should assign
// authorship to the anonymous user (uid 0).
$edit['name'] = '';
$this->drupalPost('node/' . $node->nid . '/edit', $edit, t('Save'));
$node = node_load($node->nid, NULL, TRUE);
$this->assertIdentical($node->uid, '0', 'Node authored by anonymous user.');
// Change the authored by field to another user's name (that is not
// logged in).
$edit['name'] = $this->web_user->name;
$this->drupalPost('node/' . $node->nid . '/edit', $edit, t('Save'));
$node = node_load($node->nid, NULL, TRUE);
$this->assertIdentical($node->uid, $this->web_user->uid, 'Node authored by normal user.');
// Check that normal users cannot change the authored by information.
$this->drupalLogin($this->web_user);
$this->drupalGet('node/' . $node->nid . '/edit');
$this->assertNoFieldByName('name');
}
}
class PagePreviewTestCase extends DrupalWebTestCase {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment