I implemented a function to load nodes which it is loaded from a unitary test..
function labdoo_rest_get_laptop($id) {
$node = node_load($id);
return $node;
}
And i get an error like this:
Test PDOStatement->execute() failed: <em class="placeholder">PDOException</em>: SQLSTATE[42S02]: Base table or view not found: 1146 TabTest PDOStatement->execute() failed: <em class="placeholder">PDOException</em>: SQLSTATE[42S02]: Base table or view not found: 1146 Table [error]
'lbd.simpletest291431node_type' doesn't exist: SELECT nt.*
FROM
{node_type} nt
WHERE (disabled = :db_condition_placeholder_0)
ORDER BY nt.type ASC; Array
(
[:db_condition_placeholder_0] => 0
)
in <em class="placeholder">_node_types_build()</em> (line <em class="placeholder">738</em> of <em
class="placeholder">/var/www/lbd/modules/node/node.module</em>).
le [error]
'lbd.simpletest291431node_type' doesn't exist: SELECT nt.*
FROM
{node_type} nt
WHERE (disabled = :db_condition_placeholder_0)
ORDER BY nt.type ASC; Array
(
[:db_condition_placeholder_0] => 0
)
in <em class="placeholder">_node_types_build()</em> (line <em class="placeholder">738</em> of <em
class="placeholder">/var/www/lbd/modules/node/node.module</em>).
The error is difficult to read... anyway i can understand it is trying to load the node from the database 'lbd.simpletest', but it is not correct!!, I don't know why it is trying to do this.... I tried the 'db_set_active' operation, but i receive the same error, also i could get the node information with sql_query but i prefer this method, it seems better.
My file (with name labdoo_rest.test) to test the SQL function is:
<?php
//TODO Add comments
class LabdooRestUnitaryTest extends DrupalUnitTestCase {
public static function getInfo() {
return array(
'name' => 'Labdoo REST test functionality',
'description' => "Test SQL operations: Review functions with SQL queries. ",
'group' => 'Labdoo'
);
}
function testHelloWorld () {
print "test message\n";
$this->assertTrue(TRUE,"My first test works");
}
function testGetLaptop () {
$id=2;
$result = labdoo_rest_get_laptop($id);
print "$result"."\n";
$this->assertTrue(TRUE,"Test get laptop");
}
}
Thanks for your help...
UPDATE:
- $id = 2; <- it is the node's nid, and the node exists
- I proved var_dump($node) but I didn't receive results because my error message is an exception (PDOException).
UPDATE2:
- I tested
drush php-eval "print print_r(node_load(2), 1)"
and it returns the correct information. - I am using druh with
drush test-clean && drush test-run ...
to run the function. I suppose the problem is related to thedrush test-run
call.
UPDATE3: - My code in the Github project: https://github.com/Labdoo/Labdoo-2.0/tree/features/web-services-api/modules/custom/labdoo_rest