0

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]
&#039;lbd.simpletest291431node_type&#039; doesn&#039;t exist: SELECT nt.*
FROM 
{node_type} nt
WHERE  (disabled = :db_condition_placeholder_0) 
ORDER BY nt.type ASC; Array
(
    [:db_condition_placeholder_0] =&gt; 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]
    &#039;lbd.simpletest291431node_type&#039; doesn&#039;t exist: SELECT nt.*
    FROM 
    {node_type} nt
    WHERE  (disabled = :db_condition_placeholder_0) 
    ORDER BY nt.type ASC; Array
    (
        [:db_condition_placeholder_0] =&gt; 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 the drush 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

  • could you var_dump($node);exit(); and tell us whats being passed to node_load – saadlulu Jan 8 '14 at 14:48
  • Thanks @saadlulu for your response, I updated the question with your suggestions. – carlos.baez Jan 8 '14 at 15:48
  • Does the table "lbd.simpletest291431node_type" exists? Looks like there is something wrong in your database configuration... – Matt Jan 8 '14 at 16:52
  • There is a lbd.simpletest (lbd is the database which contains a table "simpletest").. but It wouldn't load this table, I want to get the nodes from the table "node". – carlos.baez Jan 9 '14 at 16:13
  • Please show the code of your testing file. Upload it to GitHub and put a link here. Without showing what you are doing it is difficult to spot what can be wrong. – dashohoxha Jan 9 '14 at 19:31
0

Maybe you should define on the test class what profile are you using. Somehow simpletest does not detect it automatically. Without knowing which profile to install, it will not know what is a laptop node, because this content type has not been created. You can try to define on the test class the attribute:

protected $profile = 'labdoo';

See as an example: https://github.com/dashohoxha/oauth2_client/tree/7.x-1.x/tests

In particular, the shell script can be interesting: https://github.com/dashohoxha/oauth2_client/blob/7.x-1.x/tests/run_tests.sh

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.