Hi,
I want to test a form with PHPUnIt which contains several fields and a
file element. Here is the very simplified test case (simplified means I
left out a couple of form elements):
public function testValidatingCorrectInput()
{
// create instance of form
$form = new EmployerEditForm();
// define input data
$inputData = array(
'employer_id' => '1',
'employer_type' => 'standard',
'employer_company' => 'Musterfirma',
'submit_employer_edit' => 'submit_employer_edit',
);
// define expected erros
$expectedErrors = array(
'employer_id' => array(
),
'employer_type' => array(
),
'employer_company' => array(
),
'employer_logo' => array(
),
'submit_employer_edit' => array(
),
);
// check if form is valid
$this->assertTrue($form->isValid($inputData));
}
This test fails and when I check the form errors with $form->getErrors()
I get the result that employer_logo has an error called
"fileUploadErrorFileNotFound". I tried to mess around with $_FILES
before the test is run to simulare an uploaded file but then I get the
error "fileUploadErrorAttack". I also set $inputData['employer_logo'] to
the path of a test image, but then I get an exception:
Zend_File_Transfer_Exception: "employer_logo" not found by
file transfer adapter
So what is the best way to test the isValid() method of a form which
contains a file element?
Thanks and best regards,
Ralf