<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=us-ascii">
<meta name=Generator content="Microsoft Word 12 (filtered medium)">
<style>
<!--
/* Font Definitions */
@font-face
        {font-family:"Cambria Math";
        panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0in;
        margin-bottom:.0001pt;
        font-size:11.0pt;
        font-family:"Calibri","sans-serif";}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:blue;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {mso-style-priority:99;
        color:purple;
        text-decoration:underline;}
span.EmailStyle17
        {mso-style-type:personal-compose;
        font-family:"Calibri","sans-serif";
        color:windowtext;}
.MsoChpDefault
        {mso-style-type:export-only;}
@page Section1
        {size:8.5in 11.0in;
        margin:1.0in 1.0in 1.0in 1.0in;}
div.Section1
        {page:Section1;}
-->
</style>
<!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
</head>
<body lang=EN-US link=blue vlink=purple>
<div class=Section1>
<p class=MsoNormal>All,<o:p></o:p></p>
<p class=MsoNormal><o:p> </o:p></p>
<p class=MsoNormal>Is there a way to figure out the table prefix that Simpletest
generates at runtime? I am trying to run a test that does a bunch of inserts,
then I need to figure out how many rows were created in the table. However, I
can’t query the table because simpletest changes the name of it every
time. Also, I tried {table_name} instead of table_name in the query but it
didn’t work (line numbers inserted below to help with reading the error
message later):<o:p></o:p></p>
<p class=MsoNormal><o:p> </o:p></p>
<p class=MsoNormal style='text-autospace:none'><span style='font-size:10.0pt;
font-family:"Courier New";color:black'>21</span><span style='font-size:10.0pt;
font-family:"Courier New";color:blue'> public function </span><span
style='font-size:10.0pt;font-family:"Courier New";color:black'>test_sync () {</span><span
style='font-size:10.0pt;font-family:"Courier New"'><o:p></o:p></span></p>
<p class=MsoNormal style='text-autospace:none'><span style='font-size:10.0pt;
font-family:"Courier New";color:black'>22 </span><span style='font-size:
10.0pt;font-family:"Courier New";color:blue'>require_once</span><span
style='font-size:10.0pt;font-family:"Courier New";color:black'>(drupal_get_path(</span><span
style='font-size:10.0pt;font-family:"Courier New";color:#008200'>'module'</span><span
style='font-size:10.0pt;font-family:"Courier New";color:black'>,</span><span
style='font-size:10.0pt;font-family:"Courier New";color:#008200'>'compoundmanagement'</span><span
style='font-size:10.0pt;font-family:"Courier New";color:black'>).</span><span
style='font-size:10.0pt;font-family:"Courier New";color:#008200'>'/compoundmanagement.inc'</span><span
style='font-size:10.0pt;font-family:"Courier New";color:black'>);</span><span
style='font-size:10.0pt;font-family:"Courier New"'><o:p></o:p></span></p>
<p class=MsoNormal style='text-autospace:none'><span style='font-size:10.0pt;
font-family:"Courier New";color:black'>23 </span><span style='font-size:
10.0pt;font-family:"Courier New";color:#660000'>$result </span><span
style='font-size:10.0pt;font-family:"Courier New";color:black'>= db_query(</span><span
style='font-size:10.0pt;font-family:"Courier New";color:#008200'>'select
count(objdid) as count from {cpd_compounds}'</span><span style='font-size:10.0pt;
font-family:"Courier New";color:black'>);</span><span style='font-size:10.0pt;
font-family:"Courier New"'><o:p></o:p></span></p>
<p class=MsoNormal style='text-autospace:none'><span style='font-size:10.0pt;
font-family:"Courier New";color:black'>24 </span><span style='font-size:
10.0pt;font-family:"Courier New";color:#660000'>$row </span><span
style='font-size:10.0pt;font-family:"Courier New";color:black'>= </span><span
style='font-size:10.0pt;font-family:"Courier New";color:#660000'>$result</span><span
style='font-size:10.0pt;font-family:"Courier New";color:black'>->db_fetch_object(</span><span
style='font-size:10.0pt;font-family:"Courier New";color:#660000'>$result</span><span
style='font-size:10.0pt;font-family:"Courier New";color:black'>);</span><span
style='font-size:10.0pt;font-family:"Courier New"'><o:p></o:p></span></p>
<p class=MsoNormal style='text-autospace:none'><span style='font-size:10.0pt;
font-family:"Courier New";color:black'>25 </span><span style='font-size:
10.0pt;font-family:"Courier New";color:#660000'>$this</span><span
style='font-size:10.0pt;font-family:"Courier New";color:black'>->pass(</span><span
style='font-size:10.0pt;font-family:"Courier New";color:#008200'>'There are '</span><span
style='font-size:10.0pt;font-family:"Courier New";color:black'>.</span><span
style='font-size:10.0pt;font-family:"Courier New";color:#660000'>$row</span><span
style='font-size:10.0pt;font-family:"Courier New";color:black'>->count.</span><span
style='font-size:10.0pt;font-family:"Courier New";color:#008200'>' compounds in
cpd_compounds'</span><span style='font-size:10.0pt;font-family:"Courier New";
color:black'>);</span><span style='font-size:10.0pt;font-family:"Courier New"'><o:p></o:p></span></p>
<p class=MsoNormal style='text-autospace:none'><span style='font-size:10.0pt;
font-family:"Courier New";color:black'>26 </span><span style='font-size:
10.0pt;font-family:"Courier New";color:#660000'>$this</span><span
style='font-size:10.0pt;font-family:"Courier New";color:black'>->drupalGet(</span><span
style='font-size:10.0pt;font-family:"Courier New";color:#008200'>'sync_cpds'</span><span
style='font-size:10.0pt;font-family:"Courier New";color:black'>,</span><span
style='font-size:10.0pt;font-family:"Courier New";color:blue'>array</span><span
style='font-size:10.0pt;font-family:"Courier New";color:black'>(</span><span
style='font-size:10.0pt;font-family:"Courier New";color:#008200'>'absolute' </span><span
style='font-size:10.0pt;font-family:"Courier New";color:black'>=> </span><span
style='font-size:10.0pt;font-family:"Courier New";color:blue'>TRUE</span><span
style='font-size:10.0pt;font-family:"Courier New";color:black'>));</span><span
style='font-size:10.0pt;font-family:"Courier New"'><o:p></o:p></span></p>
<p class=MsoNormal style='text-autospace:none'><span style='font-size:10.0pt;
font-family:"Courier New";color:black'>27 </span><span style='font-size:
10.0pt;font-family:"Courier New";color:#660000'>$result </span><span
style='font-size:10.0pt;font-family:"Courier New";color:black'>= db_query(</span><span
style='font-size:10.0pt;font-family:"Courier New";color:#008200'>'select
count(objdid) as count from {cpd_compounds}'</span><span style='font-size:10.0pt;
font-family:"Courier New";color:black'>);</span><span style='font-size:10.0pt;
font-family:"Courier New"'><o:p></o:p></span></p>
<p class=MsoNormal style='text-autospace:none'><span style='font-size:10.0pt;
font-family:"Courier New";color:black'>28 </span><span style='font-size:
10.0pt;font-family:"Courier New";color:#660000'>$row </span><span
style='font-size:10.0pt;font-family:"Courier New";color:black'>= </span><span
style='font-size:10.0pt;font-family:"Courier New";color:#660000'>$result</span><span
style='font-size:10.0pt;font-family:"Courier New";color:black'>->db_fetch_object(</span><span
style='font-size:10.0pt;font-family:"Courier New";color:#660000'>$result</span><span
style='font-size:10.0pt;font-family:"Courier New";color:black'>);</span><span
style='font-size:10.0pt;font-family:"Courier New"'><o:p></o:p></span></p>
<p class=MsoNormal style='text-autospace:none'><span style='font-size:10.0pt;
font-family:"Courier New";color:black'>29 </span><span style='font-size:
10.0pt;font-family:"Courier New";color:#660000'>$this</span><span
style='font-size:10.0pt;font-family:"Courier New";color:black'>->pass(</span><span
style='font-size:10.0pt;font-family:"Courier New";color:#008200'>'There are now
'</span><span style='font-size:10.0pt;font-family:"Courier New";color:black'>.</span><span
style='font-size:10.0pt;font-family:"Courier New";color:#660000'>$row</span><span
style='font-size:10.0pt;font-family:"Courier New";color:black'>->count.</span><span
style='font-size:10.0pt;font-family:"Courier New";color:#008200'>' compounds in
cpd_compounds'</span><span style='font-size:10.0pt;font-family:"Courier New";
color:black'>);</span><span style='font-size:10.0pt;font-family:"Courier New"'><o:p></o:p></span></p>
<p class=MsoNormal style='text-autospace:none'><span style='font-size:10.0pt;
font-family:"Courier New";color:black'>30 </span><span style='font-size:
10.0pt;font-family:"Courier New";color:#660000'>$this</span><span
style='font-size:10.0pt;font-family:"Courier New";color:black'>->assertEqual(</span><span
style='font-size:10.0pt;font-family:"Courier New";color:#660000'>$row</span><span
style='font-size:10.0pt;font-family:"Courier New";color:black'>->count,</span><span
style='font-size:10.0pt;font-family:"Courier New";color:red'>1313</span><span
style='font-size:10.0pt;font-family:"Courier New";color:black'>,</span><span
style='font-size:10.0pt;font-family:"Courier New";color:#008200'>"CPD_COMPOUNDS
should have 1313 rows."</span><span style='font-size:10.0pt;font-family:
"Courier New";color:black'>);</span><span style='font-size:10.0pt;font-family:
"Courier New"'><o:p></o:p></span></p>
<p class=MsoNormal style='text-autospace:none'><span style='font-size:10.0pt;
font-family:"Courier New";color:black'>31 }<o:p></o:p></span></p>
<p class=MsoNormal style='text-autospace:none'><span style='color:black'><o:p> </o:p></span></p>
<p class=MsoNormal style='text-autospace:none'><span style='color:black'>The
test above threw this error:<o:p></o:p></span></p>
<p class=MsoNormal style='text-autospace:none'><span style='font-size:10.0pt;
font-family:"Courier New";color:black'><o:p> </o:p></span></p>
<p class=MsoNormal style='text-autospace:none'>An error occurred. <br>
/batch?id=18&op=do<br>
<br /><br>
<b>Fatal error</b>: Call to a member function db_fetch_object() on
a non-object in <b>C:\wamp\www\drupal\sites\all\modules\compoundmanagement\compoundmanagement.test</b>
on line <b>24</b><br /><span style='font-size:10.0pt;
font-family:"Courier New";color:black'><o:p></o:p></span></p>
<p class=MsoNormal style='text-autospace:none'><span style='font-size:10.0pt;
font-family:"Courier New"'><o:p> </o:p></span></p>
<p class=MsoNormal style='text-autospace:none'>Any ideas what to do here? I have
been developing in Drupal for a while now but am just now discovering the unit
testing available in SimpleTest.<o:p></o:p></p>
<p class=MsoNormal style='text-autospace:none'><o:p> </o:p></p>
<p class=MsoNormal style='text-autospace:none'>Best,<br>
Dave<o:p></o:p></p>
</div>
</body>
</html>