Ralf,

This are no thoughts, this is how the transfer adapter itself is tested.
Your change adds problems when the given $files is not available or if you want to simulate upload errors.

Also the isValid method will still throw an error because receive just calls isValid. Best would be to catch the Attacker error and return a true instead of this error, but let all other errors pass.

Greetings
Thomas Weidner, I18N Team Leader, Zend Framework
http://www.thomasweidner.com

----- Original Message ----- From: "Ralf Eggert" <[EMAIL PROTECTED]>
To: <[email protected]>
Sent: Thursday, August 21, 2008 2:37 PM
Subject: Re: [fw-general] How to simulate a file upload to test form


Hi Thomas,

thanks for your thoughts. I solved this issue now by using my own file
transfer adapter for unit testing. It looks like this:

 class My_File_Transfer_Adapter_Test extends
       Zend_File_Transfer_Adapter_Http
 {
   public function __construct()
   {
     $this->_files = $this->_prepareFiles($_FILES);
   }

   public function receive($files = null)
   {
     return true;
   }

   public function isReceived($files = null)
   {
     return true;
   }
 }

In the testcase I manipulate the $_FILES array and set the transfer
adapter for the field:

 $form->getElement('employer_logo')->setTransferAdapter(
        new My_File_Transfer_Adapter_Test());

Works ok for me though I know it is not the best solution. Now I hope I
can use this as well for my controller tests... :-)

Thanks and best regards,

Ralf

Reply via email to