瀏覽代碼

Fixes #65 - use "_isPathWriteable" in "setDestination" method

Frank Brückner 12 年之前
父節點
當前提交
395b0873c7
共有 2 個文件被更改,包括 44 次插入5 次删除
  1. 12 5
      library/Zend/File/Transfer/Adapter/Abstract.php
  2. 32 0
      tests/Zend/File/Transfer/Adapter/AbstractTest.php

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

@@ -936,8 +936,8 @@ abstract class Zend_File_Transfer_Adapter_Abstract
     /**
      * Retrieves the filename of transferred files.
      *
-     * @param  string  $fileelement (Optional) Element to return the filename for
-     * @param  boolean $path        (Optional) Should the path also be returned ?
+     * @param  string|null   $file
+     * @param  boolean $path (Optional) Should the path also be returned ?
      * @return string|array
      */
     public function getFileName($file = null, $path = true)
@@ -1032,12 +1032,16 @@ abstract class Zend_File_Transfer_Adapter_Abstract
         $destination = rtrim($destination, "/\\");
         if (!is_dir($destination)) {
             require_once 'Zend/File/Transfer/Exception.php';
-            throw new Zend_File_Transfer_Exception('The given destination is not a directory or does not exist');
+            throw new Zend_File_Transfer_Exception(
+                'The given destination is not a directory or does not exist'
+            );
         }
 
-        if (!is_writable($destination)) {
+        if (!$this->_isPathWriteable($destination)) {
             require_once 'Zend/File/Transfer/Exception.php';
-            throw new Zend_File_Transfer_Exception('The given destination is not writeable');
+            throw new Zend_File_Transfer_Exception(
+                'The given destination is not writable'
+            );
         }
 
         if ($files === null) {
@@ -1063,6 +1067,7 @@ abstract class Zend_File_Transfer_Adapter_Abstract
      *
      * @param  null|string|array $files
      * @return null|string|array
+     * @throws Zend_File_Transfer_Exception
      */
     public function getDestination($files = null)
     {
@@ -1102,6 +1107,7 @@ abstract class Zend_File_Transfer_Adapter_Abstract
      *
      * @param  Zend_Translate|null $translator
      * @return Zend_File_Transfer_Abstract
+     * @throws Zend_File_Transfer_Exception
      */
     public function setTranslator($translator = null)
     {
@@ -1423,6 +1429,7 @@ abstract class Zend_File_Transfer_Adapter_Abstract
      * Tries to detect if we can read and write to the given path
      *
      * @param string $path
+     * @return bool
      */
     protected function _isPathWriteable($path)
     {

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

@@ -46,6 +46,11 @@ require_once 'Zend/Validate/File/Extension.php';
 class Zend_File_Transfer_Adapter_AbstractTest extends PHPUnit_Framework_TestCase
 {
     /**
+     * @var Zend_File_Transfer_Adapter_AbstractTest_MockAdapter
+     */
+    protected $adapter;
+
+    /**
      * Runs the test methods of this class.
      *
      * @return void
@@ -856,6 +861,33 @@ class Zend_File_Transfer_Adapter_AbstractTest extends PHPUnit_Framework_TestCase
                 'detectInfos' => false))
             , $this->adapter->getOptions('foo'));
     }
+
+    /**
+     * @group GH-65
+     */
+    public function testSetDestinationWithNonExistingPathShouldThrowException()
+    {
+        // Create temporary directory
+        $directory = dirname(__FILE__) . '/_files/destination';
+        if (!is_dir($directory)) {
+            @mkdir($directory);
+        }
+        chmod($directory, 0655);
+
+        // Test
+        try {
+            $this->adapter->setDestination($directory);
+            $this->fail('Destination is writable');
+        } catch (Zend_File_Transfer_Exception $e) {
+            $this->assertEquals(
+                'The given destination is not writable',
+                $e->getMessage()
+            );
+        }
+
+        // Remove temporary directory
+        @rmdir($directory);
+    }
 }
 
 class Zend_File_Transfer_Adapter_AbstractTest_MockAdapter extends Zend_File_Transfer_Adapter_Abstract