diff --git a/framework/validators/CFileValidator.php b/framework/validators/CFileValidator.php index acbe6dfb7..6fc73a6ca 100644 --- a/framework/validators/CFileValidator.php +++ b/framework/validators/CFileValidator.php @@ -183,7 +183,7 @@ class CFileValidator extends CValidator */ protected function validateFile($object, $attribute, $file) { - $error=(null!==$file ? null : $file->getError()); + $error=(null===$file ? null : $file->getError()); if($error==UPLOAD_ERR_INI_SIZE || $error==UPLOAD_ERR_FORM_SIZE || $this->maxSize!==null && $file->getSize()>$this->maxSize) { $message=$this->tooLarge!==null?$this->tooLarge : Yii::t('yii','The file "{file}" is too large. Its size cannot exceed {limit} bytes.'); diff --git a/tests/framework/validators/CFileValidatorTest.php b/tests/framework/validators/CFileValidatorTest.php index 518761899..af650d423 100644 --- a/tests/framework/validators/CFileValidatorTest.php +++ b/tests/framework/validators/CFileValidatorTest.php @@ -39,10 +39,16 @@ class CFileValidatorTest extends CTestCase public function testValidate() { $model = new ValidatorTestModel(__CLASS__); - $uploadedFile = new CUploadedFile('test.txt', __FILE__, 'text/plain', 40, UPLOAD_ERR_OK); $model->uploaded_file = $uploadedFile; - $this->assertTrue($model->validate(), 'Valid file validation failed!'); } + + public function testValidateNoFile() + { + $model = new ValidatorTestModel(__CLASS__); + $uploadedFile = new CUploadedFile('test.txt', __FILE__, 'text/plain', 40, UPLOAD_ERR_NO_FILE); + $model->uploaded_file = $uploadedFile; + $this->assertFalse($model->validate(), 'File with error passed validation!'); + } }