Forráskód Böngészése

[ZF-6897] Zend_File_Transfer:

 - fixed getDestination on non-existing files


git-svn-id: http://framework.zend.com/svn/framework/standard/trunk@15884 44c647ce-9c0f-0410-b52a-842ac1e357ba
thomas 16 éve
szülő
commit
833cc9a859

+ 12 - 2
library/Zend/File/Transfer/Adapter/Abstract.php

@@ -1010,7 +1010,7 @@ abstract class Zend_File_Transfer_Adapter_Abstract
             }
         } else {
             $files = $this->_getFiles($files, true, true);
-            if (empty($this->_files) and is_string($orig)) {
+            if (empty($files) and is_string($orig)) {
                 $this->_files[$orig]['destination'] = $destination;
             }
 
@@ -1030,8 +1030,18 @@ abstract class Zend_File_Transfer_Adapter_Abstract
      */
     public function getDestination($files = null)
     {
-        $files        = $this->_getFiles($files, false);
+        $orig  = $files;
+        $files = $this->_getFiles($files, false, true);
         $destinations = array();
+        if (empty($files) and is_string($orig)) {
+            if (isset($this->_files[$orig]['destination'])) {
+                $destinations[$orig] = $this->_files[$orig]['destination'];
+            } else {
+                require_once 'Zend/File/Transfer/Exception.php';
+                throw new Zend_File_Transfer_Exception(sprintf('"%s" not found by file transfer adapter', $orig));
+            }
+        }
+
         foreach ($files as $key => $content) {
             if (isset($this->_files[$key]['destination'])) {
                 $destinations[$key] = $this->_files[$key]['destination'];

+ 13 - 0
tests/Zend/File/Transfer/Adapter/AbstractTest.php

@@ -727,6 +727,19 @@ class Zend_File_Transfer_Adapter_AbstractTest extends PHPUnit_Framework_TestCase
             $this->assertContains('does not exist', $e->getMessage());
         }
     }
+
+    public function testTransferDestinationAtNonExistingElement()
+    {
+        $directory = dirname(__FILE__);
+        $this->adapter->setDestination($directory, 'nonexisting');
+        $this->assertEquals($directory, $this->adapter->getDestination('nonexisting'));
+        try {
+            $this->assertTrue(is_string($this->adapter->getDestination('reallynonexisting')));
+            $this->fail();
+        } catch(Exception $e) {
+            $this->assertContains('not found', $e->getMessage());
+        }
+    }
 }
 
 class Zend_File_Transfer_Adapter_AbstractTest_MockAdapter extends Zend_File_Transfer_Adapter_Abstract