From 2bef9e06732d98cee4dd0f0429dedb799091de2f Mon Sep 17 00:00:00 2001 From: Angie Byron Date: Wed, 13 Jan 2010 05:55:12 +0000 Subject: #261258 by pwolanin, Damien Tournoud, David_Rothstein: Fix node_save() insertion logic. (with tests) --- modules/node/node.test | 48 +++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 47 insertions(+), 1 deletion(-) (limited to 'modules/node/node.test') diff --git a/modules/node/node.test b/modules/node/node.test index c9f4fbd76..7ec078d35 100644 --- a/modules/node/node.test +++ b/modules/node/node.test @@ -88,7 +88,7 @@ class NodeRevisionsTestCase extends DrupalWebTestCase { public static function getInfo() { return array( 'name' => 'Node revisions', - 'description' => 'Create a node with revisions and test viewing, reverting, and deleting revisions.', + 'description' => 'Create a node with revisions and test viewing, saving, reverting, and deleting revisions.', 'group' => 'Node', ); } @@ -164,6 +164,52 @@ class NodeRevisionsTestCase extends DrupalWebTestCase { '@type' => 'Basic page', '%title' => $nodes[1]->title)), t('Revision deleted.')); $this->assertTrue(db_query('SELECT COUNT(vid) FROM {node_revision} WHERE nid = :nid and vid = :vid', array(':nid' => $node->nid, ':vid' => $nodes[1]->vid))->fetchField() == 0, t('Revision not found.')); } + + /** + * Checks that revisions are correctly saved without log messages. + */ + function testNodeRevisionWithoutLogMessage() { + // Create a node with an initial log message. + $log = $this->randomName(10); + $node = $this->drupalCreateNode(array('log' => $log)); + + // Save over the same revision but do not provide a log message, and check + // that the original log message is preserved. + $new_title = $this->randomName(10) . 'testNodeRevisionWithoutLogMessage1'; + $updated_node = (object) array( + 'nid' => $node->nid, + 'vid' => $node->vid, + 'uid' => $node->uid, + 'type' => $node->type, + 'title' => array(LANGUAGE_NONE => array(array('value' => $new_title))), + 'log' => '', + ); + node_save($updated_node); + $this->drupalGet('node/' . $node->nid); + $this->assertText($new_title, t('New node title appears on the page.')); + $node_revision = node_load($node->nid, NULL, TRUE); + $this->assertEqual($node_revision->log, $log, t('After an existing node revision is re-saved without a log message, the original log message is preserved.')); + + // Create another node with an initial log message. + $node = $this->drupalCreateNode(array('log' => $log)); + + // Save a new node revision without providing a log message, and check that + // this revision has an empty log message. + $new_title = $this->randomName(10) . 'testNodeRevisionWithoutLogMessage2'; + $updated_node = (object) array( + 'nid' => $node->nid, + 'vid' => $node->vid, + 'uid' => $node->uid, + 'type' => $node->type, + 'title' => array(LANGUAGE_NONE => array(array('value' => $new_title))), + 'revision' => 1, + ); + node_save($updated_node); + $this->drupalGet('node/' . $node->nid); + $this->assertText($new_title, t('New node title appears on the page.')); + $node_revision = node_load($node->nid, NULL, TRUE); + $this->assertTrue(empty($node_revision->log), t('After a new node revision is saved with an empty log message, the log message for the node is empty.')); + } } class PageEditTestCase extends DrupalWebTestCase { -- cgit v1.2.3