SitePoint Sponsor |
|
User Tag List
Results 1 to 7 of 7
Thread: SimpleTest File Uploads
-
Nov 8, 2006, 08:34 #1
- Join Date
- Mar 2005
- Posts
- 251
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
SimpleTest File Uploads
Hey guys.
I noticed in the docs that SimpleTest now supports file uploads, has anyone got or seen an example of how this is done?
Thanks
-
Nov 8, 2006, 09:01 #2
- Join Date
- Apr 2003
- Location
- London
- Posts
- 2,423
- Mentioned
- 2 Post(s)
- Tagged
- 0 Thread(s)
Hi...
You just go...
PHP Code:$this->setField('upload_here', 'path/to/file');
yours, MarcusMarcus Baker
Testing: SimpleTest, Cgreen, Fakemail
Other: Phemto dependency injector
Books: PHP in Action, 97 things
-
Nov 8, 2006, 10:11 #3
- Join Date
- Mar 2005
- Posts
- 251
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Cheers Marcus, it did indeed just work....
I wasn't expecting it to be so simple ;-)
-
Nov 8, 2006, 12:09 #4
- Join Date
- Mar 2005
- Posts
- 251
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
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?
-
Nov 9, 2006, 02:22 #5
- Join Date
- Sep 2003
- Location
- Wixom, Michigan
- Posts
- 591
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
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?Garcia
-
Nov 9, 2006, 04:54 #6
- Join Date
- Mar 2005
- Posts
- 251
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
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.
-
Apr 14, 2009, 01:24 #7
- Join Date
- Dec 2007
- Posts
- 348
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
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..
Bookmarks