diff --git a/lib/Cake/Test/Case/Utility/ValidationTest.php b/lib/Cake/Test/Case/Utility/ValidationTest.php index c3583800e..21b1a18ef 100644 --- a/lib/Cake/Test/Case/Utility/ValidationTest.php +++ b/lib/Cake/Test/Case/Utility/ValidationTest.php @@ -2174,12 +2174,27 @@ class ValidationTest extends CakeTestCase { * @return void */ public function testMimeType() { - $file = CORE_PATH . 'Cake' . DS . 'Test' . DS . 'test_app' . DS . 'webroot' . DS . 'img' . DS . 'cake.power.gif'; - $this->assertTrue(Validation::mimeType($file, array('image/gif'))); - $this->assertTrue(Validation::mimeType(array('tmp_name' => $file), array('image/gif'))); + $image = CORE_PATH . 'Cake' . DS . 'Test' . DS . 'test_app' . DS . 'webroot' . DS . 'img' . DS . 'cake.power.gif'; + $File = new File($image, false); + $this->skipIf(!$File->mime(), 'Cannot determine mimeType'); + $this->assertTrue(Validation::mimeType($image, array('image/gif'))); + $this->assertTrue(Validation::mimeType(array('tmp_name' => $image), array('image/gif'))); - $this->assertFalse(Validation::mimeType($file, array('image/png'))); - $this->assertFalse(Validation::mimeType(array('tmp_name' => $file), array('image/png'))); + $this->assertFalse(Validation::mimeType($image, array('image/png'))); + $this->assertFalse(Validation::mimeType(array('tmp_name' => $image), array('image/png'))); + } + +/** + * testMimeTypeFalse method + * + * @expectedException CakeException + * @return void + */ + public function testMimeTypeFalse() { + $image = CORE_PATH . 'Cake' . DS . 'Test' . DS . 'test_app' . DS . 'webroot' . DS . 'img' . DS . 'cake.power.gif'; + $File = new File($image, false); + $this->skipIf($File->mime(), 'mimeType can be determined, no Exception will be thrown'); + Validation::mimeType($image, array('image/gif')); } /** diff --git a/lib/Cake/Utility/Validation.php b/lib/Cake/Utility/Validation.php index 5ff9d9ea2..d08c227ae 100644 --- a/lib/Cake/Utility/Validation.php +++ b/lib/Cake/Utility/Validation.php @@ -865,6 +865,7 @@ class Validation { * @param string|array $check * @param array $mimeTypes to check for * @return boolean Success + * @throws CakeException when mime type can not be determined. */ public static function mimeType($check, $mimeTypes = array()) { if (is_array($check) && isset($check['tmp_name'])) { @@ -874,6 +875,9 @@ class Validation { $File = new File($check); $mime = $File->mime(); + if ($mime === false) { + throw new CakeException(__d('cake_dev', 'Can not determine the mimetype.')); + } return in_array($mime, $mimeTypes); }