/** * @group ZF-11258 */ public function testZF11258() { $validator = new File\UploadFile(); $this->assertFalse($validator->isValid(__DIR__ . '/_files/nofile.mo')); $this->assertTrue(array_key_exists('fileUploadFileErrorFileNotFound', $validator->getMessages())); $this->assertContains("not found", current($validator->getMessages())); }
public function testEmptyFileShouldReturnFalseAndDisplayNotFoundMessage() { $validator = new File\UploadFile(); $this->assertFalse($validator->isValid('')); $this->assertArrayHasKey(File\UploadFile::FILE_NOT_FOUND, $validator->getMessages()); $filesArray = array('name' => '', 'size' => 0, 'tmp_name' => '', 'error' => UPLOAD_ERR_NO_FILE, 'type' => ''); $this->assertFalse($validator->isValid($filesArray)); $this->assertArrayHasKey(File\UploadFile::FILE_NOT_FOUND, $validator->getMessages()); }
/** * Overrides isValid() * * If the reason for failure is self::ATTACK, we can assume that * is_uploaded_file() has failed -- which is * * @param mixed $value * @return void */ public function isValid($value) { if (null === $this->request || !method_exists($this->request, 'isPut') || !$this->request->isPut() && !$this->request->isPatch()) { // In absence of a request object, an HTTP request, or a PATCH/PUT // operation, just use the parent logic. return parent::isValid($value); } $result = parent::isValid($value); if ($result !== false) { return $result; } if (!isset($this->abstractOptions['messages'][static::ATTACK])) { return $result; } if (count($this->abstractOptions['messages']) > 1) { return $result; } unset($this->abstractOptions['messages'][static::ATTACK]); return true; }