[development] Extending simpletest.module: testing queries

Tim Altman web at timaltman.com
Sun Nov 27 11:20:26 UTC 2005


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.

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_').  There is potential for damage to the  
database tables if your code doesn't use the table prefixing characters  
("{" and "}") correctly, but that should be minimal since table prefixes  
are needed anyway.

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'.  Each test would need to first  
create needed tables (perhaps via 'simpletest_prime_table', which would  
create a table via the definition in database.* or copy the current table  
structure and data from the DB) and add in some test data, if needed.   
When the test completes, simpletest.module would drop the table it  
created, leaving the database as prestine as before the test had run.

Comments?

-- 
Tim Altman


More information about the development mailing list