public function testBindAndUtilityMethods()
 {
     $this->fileData->bind($this->getTestData());
     $this->assertFalse($this->fileData->hasError(), 'no errors in the file');
     $this->assertEquals(10, $this->fileData->getFileSize(), 'file size is 10 bytes');
     $this->assertEquals('text/html', $this->fileData->getMimeType(), 'mime type is text/html');
     $this->assertEquals('/tmp/phpFile0123', $this->fileData->getTempFileName(), 'tmp file name is correct');
     $this->assertEquals('c:\\my documents\\file.html', $this->fileData->getOriginalFileName(), 'original name is correct');
 }
 public function validate($value, phValidatable $errors)
 {
     if ($this->_required && $value === null) {
         $errors->addError($this->getError(self::REQUIRED));
         return;
     }
     if ($value === null) {
         return;
         // go no further, no file passed
     }
     $data = new phFileFormDataItem('parse');
     try {
         $data->bind($value);
     } catch (phFileDataException $e) {
         $errors->addError($this->getError(self::FILE_ERROR, array('%error%' => 'invalid file data')));
         return;
         // no point in going further, bad data
     }
     if ($this->_required && !file_exists($data->getTempFileName())) {
         $errors->addError($this->getError(self::REQUIRED));
         return;
     }
     if ($data->hasError()) {
         $errors->addError($this->getError(self::FILE_ERROR, array('%error%' => $data->getFileErrorString())));
         return;
         // no point in going further, bad data
     }
     if (sizeof($this->_mimeTypes) > 0 && !in_array($data->getMimeType(), $this->_mimeTypes)) {
         $validTypes = '';
         foreach ($this->_mimeTypes as $m) {
             $validTypes .= $m . ', ';
         }
         $errors->addError($this->getError(self::INVALID_MIME_TYPE, array('%types%' => substr($validTypes, 0, -2))));
         return;
     }
 }