SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Addict
    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

  2. #2
    ********* Victim lastcraft's Avatar
    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'); 
    It should just work.

    yours, Marcus
    Marcus Baker
    Testing: SimpleTest, Cgreen, Fakemail
    Other: Phemto dependency injector
    Books: PHP in Action, 97 things

  3. #3
    SitePoint Addict
    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 ;-)

  4. #4
    SitePoint Addict
    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?

  5. #5
    SitePoint Evangelist ghurtado's Avatar
    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

  6. #6
    SitePoint Addict
    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.

  7. #7
    SitePoint Addict
    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •