diff --git a/core/modules/node/lib/Drupal/node/Tests/NodeLastChangedTest.php b/core/modules/node/lib/Drupal/node/Tests/NodeLastChangedTest.php new file mode 100644 index 0000000..40ca1a7 --- /dev/null +++ b/core/modules/node/lib/Drupal/node/Tests/NodeLastChangedTest.php @@ -0,0 +1,62 @@ + 'Node Last Changed', + 'description' => 'Test node_last_changed($nid) function', + 'group' => 'Node', + ); + } + + function setUp() { + parent::setUp(); + + // 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); + $this->web_user = $web_user; + } + + /** + * Runs basic tests for node_last_changed function. + */ + function testNodeLastChanged() { + // Use the default timestamps. + $edit = array( + 'uid' => $this->web_user->uid, + 'type' => 'article', + 'title' => $this->randomName(8), + ); + + entity_create('node', $edit)->save(); + $node = $this->drupalGetNodeByTitle($edit['title']); + + // Update the timestamps. + $node->created = 979534800; + $node->changed = 280299600; + $node->save(); + + //Test node last changed timestamp + $changed_timestamp = node_last_changed($node->nid); + $this->assertEqual($changed_timestamp, $node->changed, 'Function node_last_changed() returned expected timestamp.'); + } +} diff --git a/core/modules/node/node.module b/core/modules/node/node.module index 44f60e7..c45f17a 100644 --- a/core/modules/node/node.module +++ b/core/modules/node/node.module @@ -1263,8 +1263,12 @@ function node_page_title(EntityInterface $node) { * A unix timestamp indicating the last time the node was changed. */ function node_last_changed($nid, $langcode = NULL) { - $language_clause = isset($langcode) ? 'langcode = :langcode' : 'default_langcode = 1'; - $result = db_query('SELECT changed FROM {node_field_data} WHERE nid = :nid AND ' . $language_clause, array(':nid' => $nid, ':langcode' => $langcode))->fetch(); + if (isset($langcode)) { + $result = db_query('SELECT changed FROM {node_field_data} WHERE nid = :nid AND langcode = :langcode', array(':nid' => $nid, ':langcode' => $langcode))->fetch(); + } + else { + $result = db_query('SELECT changed FROM {node_field_data} WHERE nid = :nid AND default_langcode = :default_langcode', array(':nid' => $nid, ':default_langcode' => 1))->fetch(); + } return is_object($result) ? $result->changed : FALSE; }