[development] Extending simpletest.module: testing queries

Tim Altman web at timaltman.com
Sun Nov 27 15:54:31 UTC 2005

On Sun, 27 Nov 2005 15:28:05 +0100, Gildas COTOMALE  
<gildas.cotomale at gmail.com> wrote:

> 2005/11/27, Tim Altman <web at timaltman.com>:
>> Greetings:
>> I looked at simpletest.module this morning and I think there's an
>> important test functionality missing: testing how functions handle
>> database queries.  For example, if I want to test various aspects of
>> upload_total_space_used() (it outputs the total disk space used by
>> uploaded files), I have to first make sure there is data in the table.   
>> If
>> there isn't, my test won't work.
> The easiest and fastest way to know if a table is not empty is to do
> do an "SELECT COUNT(*) FROM "_that_tabe...

True, but that doesn't necessarily mean the table has the data you need  
for testing.

>> Thus, I'd like to propose a way that simpletest.module can interact with
>> the database in a non-destructive way.  I think the easiest way to do so
>> is for simpletest.module to create the tables being tested itself with a
>> prefix (such as 'simpletest_').
>> Simpletest.module would implement a DB function called  
>> 'simpletest_query'
>> which works similar to 'db_query'.  Following the normal table prefix
>> defined in settings.php, simpletest_query would add 'simpletest_' to  
>> table
>> names.  Thus, if a table prefix 'prefix_' was defined, the 'files' table
>> would become 'prefix_simpletest_files'.

I realized that we'd also have to override db_query, so the 'simpletest_'  
prefix was added to queries sent by module functions rather than the test.


>> Comments?
> you consume time, processor power, bandwith and space for nothing... imho

We're talking about unit testing here, not everyday usage.  The point is  
to test Drupal.  Using the idea outlined above, we'd have a way of testing  
more functions automatically.  I certainly wouldn't call that "nothing".

> have a look on drupal db error handling too.

OK?  The idea outlined above would also allow us to test that.

Tim Altman

More information about the development mailing list