diff options
author | Angie Byron <webchick@24967.no-reply.drupal.org> | 2010-04-20 09:30:21 +0000 |
---|---|---|
committer | Angie Byron <webchick@24967.no-reply.drupal.org> | 2010-04-20 09:30:21 +0000 |
commit | 8e94b5d6d400d33c0f840a7ae97ff8a715272a79 (patch) | |
tree | 5b3f3878eb1164873c55a889469435bf250f705f /modules/node/node.test | |
parent | 993117df998b0f59d459adde04555e33fac567f6 (diff) | |
download | brdo-8e94b5d6d400d33c0f840a7ae97ff8a715272a79.tar.gz brdo-8e94b5d6d400d33c0f840a7ae97ff8a715272a79.tar.bz2 |
#322759 by coltrane, jpmckinney: Fixed Allow hook_node_presave() to alter other node fields.
Diffstat (limited to 'modules/node/node.test')
-rw-r--r-- | modules/node/node.test | 61 |
1 files changed, 59 insertions, 2 deletions
diff --git a/modules/node/node.test b/modules/node/node.test index ac8c9fc8a..053a5968c 100644 --- a/modules/node/node.test +++ b/modules/node/node.test @@ -925,7 +925,7 @@ class NodeSaveTestCase extends DrupalWebTestCase { } function setUp() { - parent::setUp(); + parent::setUp('node_test'); // Create a user that is allowed to post; we'll use this to test the submission. $web_user = $this->drupalCreateUser(array('create article content')); $this->drupalLogin($web_user); @@ -952,7 +952,7 @@ class NodeSaveTestCase extends DrupalWebTestCase { 'nid' => $test_nid, 'is_new' => TRUE, ); - $node = node_submit((object)$node); + $node = node_submit((object) $node); // Verify that node_submit did not overwrite the user ID. $this->assertEqual($node->uid, $this->web_user->uid, t('Function node_submit() preserves user ID')); @@ -965,6 +965,63 @@ class NodeSaveTestCase extends DrupalWebTestCase { $node_by_title = $this->drupalGetNodeByTitle($title); $this->assertTrue($node_by_title, t('Node load by node title.')); } + + /** + * Check that the "created" and "changed" timestamps are set correctly when + * saving a new node or updating an existing node. + */ + function testTimestamps() { + // Use the default timestamps. + $edit = array( + 'uid' => $this->web_user->uid, + 'type' => 'article', + 'title' => $this->randomName(8), + ); + + node_save((object) $edit); + $node = $this->drupalGetNodeByTitle($edit['title']); + $this->assertEqual($node->created, REQUEST_TIME, t('Creating a node sets default "created" timestamp.')); + $this->assertEqual($node->changed, REQUEST_TIME, t('Creating a node sets default "changed" timestamp.')); + + // Store the timestamps. + $created = $node->created; + $changed = $node->changed; + + node_save($node); + $node = $this->drupalGetNodeByTitle($edit['title']); + $this->assertEqual($node->created, $created, t('Updating a node preserves "created" timestamp.')); + + // Programmatically set the timestamps using hook_node_presave. + $node->title = 'testing_node_presave'; + + node_save($node); + $node = $this->drupalGetNodeByTitle('testing_node_presave'); + $this->assertEqual($node->created, 280299600, t('Saving a node uses "created" timestamp set in presave hook.')); + $this->assertEqual($node->changed, 979534800, t('Saving a node uses "changed" timestamp set in presave hook.')); + + // Programmatically set the timestamps on the node. + $edit = array( + 'uid' => $this->web_user->uid, + 'type' => 'article', + 'title' => $this->randomName(8), + 'created' => 280299600, // Sun, 19 Nov 1978 05:00:00 GMT + 'changed' => 979534800, // Drupal 1.0 release. + ); + + node_save((object) $edit); + $node = $this->drupalGetNodeByTitle($edit['title']); + $this->assertEqual($node->created, 280299600, t('Creating a node uses user-set "created" timestamp.')); + $this->assertNotEqual($node->changed, 979534800, t('Creating a node doesn\'t use user-set "changed" timestamp.')); + + // Update the timestamps. + $node->created = 979534800; + $node->changed = 280299600; + + node_save($node); + $node = $this->drupalGetNodeByTitle($edit['title']); + $this->assertEqual($node->created, 979534800, t('Updating a node uses user-set "created" timestamp.')); + $this->assertNotEqual($node->changed, 280299600, t('Updating a node doesn\'t use user-set "changed" timestamp.')); + } } /** |