summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoricewind1991 <robin@icewind.nl>2013-10-14 14:29:36 -0700
committericewind1991 <robin@icewind.nl>2013-10-14 14:29:36 -0700
commit2bb452726997b8b4f4ea9b92587fd7d880d35c29 (patch)
tree8f55e240642413bd83f89997fc5e34cc44dc46c0
parent4ae1d08241db80f24f2459340dd3be6d42406f1f (diff)
parent6df5c7ebd533f0c499197c83e04c4edc786db192 (diff)
downloadnextcloud-server-2bb452726997b8b4f4ea9b92587fd7d880d35c29.tar.gz
nextcloud-server-2bb452726997b8b4f4ea9b92587fd7d880d35c29.zip
Merge pull request #5340 from owncloud/fixing-5251-master
streamCopy() should return proper structure.
-rw-r--r--lib/private/helper.php4
-rw-r--r--tests/lib/helper.php34
2 files changed, 36 insertions, 2 deletions
diff --git a/lib/private/helper.php b/lib/private/helper.php
index a34640d8e36..1236e748256 100644
--- a/lib/private/helper.php
+++ b/lib/private/helper.php
@@ -509,11 +509,11 @@ class OC_Helper {
*
* @param resource $source
* @param resource $target
- * @return int the number of bytes copied
+ * @return array the number of bytes copied and result
*/
public static function streamCopy($source, $target) {
if (!$source or !$target) {
- return false;
+ return array(0, false);
}
$result = true;
$count = 0;
diff --git a/tests/lib/helper.php b/tests/lib/helper.php
index b4d896e5196..babafab52c0 100644
--- a/tests/lib/helper.php
+++ b/tests/lib/helper.php
@@ -208,4 +208,38 @@ class Test_Helper extends PHPUnit_Framework_TestCase {
->will($this->returnValue(true)); // filename(1) (2) (3).ext exists
$this->assertEquals('dir/filename(1) (2) (4).ext', OC_Helper::buildNotExistingFileNameForView('dir', 'filename(1) (2) (3).ext', $viewMock));
}
+
+ /**
+ * @dataProvider streamCopyDataProvider
+ */
+ public function testStreamCopy($expectedCount, $expectedResult, $source, $target) {
+
+ if (is_string($source)) {
+ $source = fopen($source, 'r');
+ }
+ if (is_string($target)) {
+ $target = fopen($target, 'w');
+ }
+
+ list($count, $result) = \OC_Helper::streamCopy($source, $target);
+
+ if (is_resource($source)) {
+ fclose($source);
+ }
+ if (is_resource($target)) {
+ fclose($target);
+ }
+
+ $this->assertSame($expectedCount, $count);
+ $this->assertSame($expectedResult, $result);
+ }
+
+
+ function streamCopyDataProvider() {
+ return array(
+ array(0, false, false, false),
+ array(0, false, \OC::$SERVERROOT . '/tests/data/lorem.txt', false),
+ array(446, true, \OC::$SERVERROOT . '/tests/data/lorem.txt', \OC::$SERVERROOT . '/tests/data/lorem-copy.txt'),
+ );
+ }
}