On Sun, Apr 18, 2010 at 9:17 AM, dmitrybelyakov <shiftplatf...@gmail.com>wrote:

>
> Hi,
>
> I have a quick question on the best approach to testing Zend_Form classes
> that have Zend_Form_Element_File in them.
>
> I have constructed a small test that shows what i am trying to do. In this
> test the file element is optional so we not goig to provide a value for
> that.
>
> The test is checking if we can process a valid submission:
>
>
>    public function testCanProcessValidSubmission()
>    {
>        $form = new Zend_Form();
>        $form->setAttrib('enctype', 'multipart/form-data');
>
>        //Add text field
>        $username = new Zend_Form_Element_Text('username');
>        $username->setRequired(true);
>        $form->addElement($username, 'username');
>
>        //Add file field
>        $file = new Zend_Form_Element_File('image');
>        $file->setLabel('Upload an image:');
>        $file->setDestination('/tmp');
>        $form->addElement($file, 'image');
>
>        //Prepare form data
>        $formData = array();
>        $formData['username'] = 'Test user name';
>
>
>        //Validate
>        $result = $form->isValid($formData);
>
>        //Assert validation passed
>        $this->assertTrue($result);
>    }
>
>
> The form is working fine from the browser, i just whant to programmatically
> test it for accepting valid data submission but that always fails.
>
> I guess that has something to do with the global $_FILES array - just no
> idea how should we alter that for testing.
>


Have you dumped $form->getMessages() to see what's failing?

-- 
Support real health care reform:
http://phimg.org/

--
David Mintz
http://davidmintz.org/

Reply via email to