mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-19 11:06:15 +00:00
Merge commit '74a0bd98c28991664fc0a3b0e8b34dc4f9dbf009' into 2.2
This commit is contained in:
commit
c5b19b658a
2 changed files with 24 additions and 5 deletions
|
@ -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'));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue