Commit ad2ec220 authored by alexpott's avatar alexpott

Issue #2068891 by saranraj.G: Fixed API node_last_changed() number of bound...

Issue #2068891 by saranraj.G: Fixed API node_last_changed() number of bound variables does not match number of tokens.
parent 1028ebdf
<?php
/**
* @file
* Contains \Drupal\node\Tests\NodeLastChangedTest.
*/
namespace Drupal\node\Tests;
use Drupal\simpletest\DrupalUnitTestBase;
/**
* Tests the node_last_changed() function.
*/
class NodeLastChangedTest extends DrupalUnitTestBase {
/**
* Modules to enable.
*
* @var array
*/
public static $modules = array('node', 'field');
public static function getInfo() {
return array(
'name' => 'Node Last Changed',
'description' => 'Tests the node_last_changed() function.',
'group' => 'Node',
);
}
public function setUp() {
parent::setUp();
$this->installSchema('node', 'node');
$this->installSchema('node', 'node_field_data');
$this->installSchema('node', 'node_field_revision');
}
/**
* Runs basic tests for node_last_changed function.
*/
function testNodeLastChanged() {
$node = entity_create('node', array('type' => 'article', 'title' => $this->randomName()));
$node->save();
// Test node last changed timestamp.
$changed_timestamp = node_last_changed($node->id());
$this->assertEqual($changed_timestamp, $node->getChangedTime(), 'Expected last changed timestamp returned.');
$changed_timestamp = node_last_changed($node->id(), $node->language()->id);
$this->assertEqual($changed_timestamp, $node->getChangedTime(), 'Expected last changed timestamp returned.');
}
}
......@@ -1105,8 +1105,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;
}
......
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