I noticed in the docs that SimpleTest now supports file uploads, has anyone got or seen an example of how this is done?
Slightly switching topic here, but I wondered whether anyone has suggestions.
When running unit tests we have a separate test database that loads up fixtures at the start of all tests and then the tearDown methods rollback all the fixtures out of the test database.
When moving to functional testing using WebTestCase, such as for file uploads, the operations affect the real (or at least the development) database. To use file uploads as an example, a File model as well as saving the file will also save a corresponding row to the database.
I can think of a few 'hacky' ways to clean this out of the database but I was wondering if any of you guys have a better strategy for dealing with this?
My own hack involves actually sending DELETE queries in the constructor of the test class file. I was using tearDown() before I realized that it gets run after every method in the test, which is not quite what I want, since the mock data gets used in every unit test within the test case.
Is there a method that gets called at the end of all the tests in the test case?
Well I suppose you could put it in a destructor.
But this didn't solve the problem that tests access the test database and the browser accesses the development / production database.
Ideally I don't want tests touching either the development or production database.
Initially I thought of setting up a different domain that the SimpleTest browser accesses, and testing the domain to decide whether to load the test or development database.
After a bit of digging however I've got a much better method. WebTestCase allows you to add custom headers, so I'm adding a User-agent:simpletest and detecting this in the application. If it's detected it loads the test database, otherwise the development database is loaded as normal.
Thanks for your suggestions.
it's embarrassing, but before I came across this (three-year-old) thread I had the impression simpletest couldn't do file uploads!!
so, bump in case anyone else is as behind the times as me..