Przeglądaj źródła

[ZF-8321] Zend_Validate:

- fixed behaviour when ENV[MAGIC] is set

git-svn-id: http://framework.zend.com/svn/framework/standard/trunk@19033 44c647ce-9c0f-0410-b52a-842ac1e357ba
thomas 16 lat temu
rodzic
commit
a639f17a45

+ 11 - 6
library/Zend/Validate/File/MimeType.php

@@ -139,15 +139,20 @@ class Zend_Validate_File_MimeType extends Zend_Validate_Abstract
      */
     public function getMagicFile()
     {
-        if (null === $this->_magicfile && empty($_ENV['MAGIC'])) {
-            foreach ($this->_magicFiles as $file) {
-                // supressing errors which are thrown due to openbase_dir restrictions
-                if (@file_exists($file)) {
-                    $this->setMagicFile($file);
-                    break;
+        if (null === $this->_magicfile) {
+            if (!empty($_ENV['MAGIC'])) {
+                $this->setMagicFile($_ENV['MAGIC']);
+            } else {
+                foreach ($this->_magicFiles as $file) {
+                    // supressing errors which are thrown due to openbase_dir restrictions
+                    if (@file_exists($file)) {
+                        $this->setMagicFile($file);
+                        break;
+                    }
                 }
             }
         }
+
         return $this->_magicfile;
     }
 

+ 5 - 2
tests/Zend/Validate/File/MimeTypeTest.php

@@ -167,8 +167,11 @@ class Zend_Validate_File_MimeTypeTest extends PHPUnit_Framework_TestCase
     public function testSetAndGetMagicFile()
     {
         $validator = new Zend_Validate_File_MimeType('image/gif');
-        $mimetype  = $validator->getMagicFile();
-        $this->assertTrue(empty($mimetype));
+        if (!empty($_ENV['MAGIC'])) {
+            $mimetype  = $validator->getMagicFile();
+            $this->assertEquals($_ENV['MAGIC'], $mimetype);
+        }
+
         try {
             $validator->setMagicFile('/unknown/magic/file');
         } catch (Zend_Validate_Exception $e) {