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.

Dmitry.
-- 
View this message in context: 
http://n4.nabble.com/Testing-isValid-on-zend-form-with-a-file-element-tp2014862p2014862.html
Sent from the Zend Framework mailing list archive at Nabble.com.

Reply via email to