[development] Extending simpletest.module: testing queries
Gildas COTOMALE
gildas.cotomale at gmail.com
Sun Nov 27 14:28:05 UTC 2005
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...
> 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?
>
you consume time, processor power, bandwith and space for nothing... imho
have a look on drupal db error handling too.
--
vi is a real WYSIWYG editor: you see text, you get text.
More information about the development
mailing list