| 7 node.test | NodeSaveTestCase::testTimestamps() |
| 8 node.test | NodeSaveTestCase::testTimestamps() |
Check that the "created" and "changed" timestamps are set correctly when saving a new node or updating an existing node.
File
- modules/
node/ node.test, line 1189 - Tests for node.module.
Code
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'], TRUE);
$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', TRUE);
$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'], TRUE);
$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.'));
}
Login or register to post comments