Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/server.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorThomas Müller <thomas.mueller@tmit.eu>2014-07-08 11:44:46 +0400
committerVincent Petry <pvince81@owncloud.com>2014-07-08 19:28:16 +0400
commita8ec0a7ccc55df2b72009b49a30fa0da9d99a31d (patch)
tree4d324dc4ccf6ec1350c3ab28b68afafd27d93722 /tests
parent3c3ebd5cf99e2d97d4f3de7c9a2434c71f194a2d (diff)
Upload abortion is now detected within the OC_Connector_Sabre_File::put()
OC_Connector_Sabre_AbortedUploadDetectionPlugin is pointless Adding unit test testUploadAbort() Backport of ea269f0 from master
Diffstat (limited to 'tests')
-rw-r--r--tests/lib/connector/sabre/aborteduploaddetectionplugin.php101
-rw-r--r--tests/lib/connector/sabre/file.php52
2 files changed, 47 insertions, 106 deletions
diff --git a/tests/lib/connector/sabre/aborteduploaddetectionplugin.php b/tests/lib/connector/sabre/aborteduploaddetectionplugin.php
deleted file mode 100644
index 201f1263867..00000000000
--- a/tests/lib/connector/sabre/aborteduploaddetectionplugin.php
+++ /dev/null
@@ -1,101 +0,0 @@
-<?php
-/**
- * Copyright (c) 2013 Thomas Müller <thomas.mueller@tmit.eu>
- * This file is licensed under the Affero General Public License version 3 or
- * later.
- * See the COPYING-README file.
- */
-
-class Test_OC_Connector_Sabre_AbortedUploadDetectionPlugin extends PHPUnit_Framework_TestCase {
-
- /**
- * @var Sabre_DAV_Server
- */
- private $server;
-
- /**
- * @var OC_Connector_Sabre_AbortedUploadDetectionPlugin
- */
- private $plugin;
-
- public function setUp() {
- $this->server = new Sabre_DAV_Server();
- $this->plugin = new OC_Connector_Sabre_AbortedUploadDetectionPlugin();
- $this->plugin->initialize($this->server);
- }
-
- /**
- * @dataProvider lengthProvider
- */
- public function testLength($expected, $headers)
- {
- $this->server->httpRequest = new Sabre_HTTP_Request($headers);
- $length = $this->plugin->getLength();
- $this->assertEquals($expected, $length);
- }
-
- /**
- * @dataProvider verifyContentLengthProvider
- */
- public function testVerifyContentLength($method, $fileSize, $headers)
- {
- $this->plugin->fileView = $this->buildFileViewMock($fileSize);
-
- $headers['REQUEST_METHOD'] = $method;
- $this->server->httpRequest = new Sabre_HTTP_Request($headers);
- $this->plugin->verifyContentLength('foo.txt');
- $this->assertTrue(true);
- }
-
- /**
- * @dataProvider verifyContentLengthFailedProvider
- * @expectedException Sabre_DAV_Exception_BadRequest
- */
- public function testVerifyContentLengthFailed($method, $fileSize, $headers)
- {
- $this->plugin->fileView = $this->buildFileViewMock($fileSize);
-
- // we expect unlink to be called
- $this->plugin->fileView->expects($this->once())->method('unlink');
-
- $headers['REQUEST_METHOD'] = $method;
- $this->server->httpRequest = new Sabre_HTTP_Request($headers);
- $this->plugin->verifyContentLength('foo.txt');
- }
-
- public function verifyContentLengthProvider() {
- return array(
- array('PUT', 1024, array()),
- array('PUT', 1024, array('HTTP_X_EXPECTED_ENTITY_LENGTH' => '1024')),
- array('PUT', 512, array('HTTP_CONTENT_LENGTH' => '512')),
- array('LOCK', 1024, array()),
- array('LOCK', 1024, array('HTTP_X_EXPECTED_ENTITY_LENGTH' => '1024')),
- array('LOCK', 512, array('HTTP_CONTENT_LENGTH' => '512')),
- );
- }
-
- public function verifyContentLengthFailedProvider() {
- return array(
- array('PUT', 1025, array('HTTP_X_EXPECTED_ENTITY_LENGTH' => '1024')),
- array('PUT', 525, array('HTTP_CONTENT_LENGTH' => '512')),
- );
- }
-
- public function lengthProvider() {
- return array(
- array(null, array()),
- array(1024, array('HTTP_X_EXPECTED_ENTITY_LENGTH' => '1024')),
- array(512, array('HTTP_CONTENT_LENGTH' => '512')),
- array(2048, array('HTTP_X_EXPECTED_ENTITY_LENGTH' => '2048', 'HTTP_CONTENT_LENGTH' => '1024')),
- );
- }
-
- private function buildFileViewMock($fileSize) {
- // mock filesystem
- $view = $this->getMock('\OC\Files\View', array('filesize', 'unlink'), array(), '', FALSE);
- $view->expects($this->any())->method('filesize')->withAnyParameters()->will($this->returnValue($fileSize));
-
- return $view;
- }
-
-}
diff --git a/tests/lib/connector/sabre/file.php b/tests/lib/connector/sabre/file.php
index e1fed0384c6..1928b50aea4 100644
--- a/tests/lib/connector/sabre/file.php
+++ b/tests/lib/connector/sabre/file.php
@@ -18,7 +18,7 @@ class Test_OC_Connector_Sabre_File extends PHPUnit_Framework_TestCase {
$file->fileView->expects($this->any())->method('file_put_contents')->withAnyParameters()->will($this->returnValue(false));
// action
- $etag = $file->put('test data');
+ $file->put('test data');
}
/**
@@ -27,12 +27,26 @@ class Test_OC_Connector_Sabre_File extends PHPUnit_Framework_TestCase {
public function testSimplePutFailsOnRename() {
// setup
$file = new OC_Connector_Sabre_File('/test.txt');
- $file->fileView = $this->getMock('\OC\Files\View', array('file_put_contents', 'rename'), array(), '', FALSE);
- $file->fileView->expects($this->any())->method('file_put_contents')->withAnyParameters()->will($this->returnValue(true));
- $file->fileView->expects($this->any())->method('rename')->withAnyParameters()->will($this->returnValue(false));
+ $file->fileView = $this->getMock('\OC\Files\View',
+ array('file_put_contents', 'rename', 'filesize'),
+ array(), '', FALSE);
+ $file->fileView->expects($this->any())
+ ->method('file_put_contents')
+ ->withAnyParameters()
+ ->will($this->returnValue(true));
+ $file->fileView->expects($this->any())
+ ->method('rename')
+ ->withAnyParameters()
+ ->will($this->returnValue(false));
+ $file->fileView->expects($this->any())
+ ->method('filesize')
+ ->withAnyParameters()
+ ->will($this->returnValue(123456));
+
+ $_SERVER['CONTENT_LENGTH'] = 123456;
// action
- $etag = $file->put('test data');
+ $file->put('test data');
}
/**
@@ -42,4 +56,32 @@ class Test_OC_Connector_Sabre_File extends PHPUnit_Framework_TestCase {
$file = new OC_Connector_Sabre_File('Shared');
$file->delete();
}
+
+ /**
+ * @expectedException Sabre_DAV_Exception_BadRequest
+ */
+ public function testUploadAbort() {
+ // setup
+ $file = new OC_Connector_Sabre_File('/test.txt');
+ $file->fileView = $this->getMock('\OC\Files\View',
+ array('file_put_contents', 'rename', 'filesize'),
+ array(), '', FALSE);
+ $file->fileView->expects($this->any())
+ ->method('file_put_contents')
+ ->withAnyParameters()
+ ->will($this->returnValue(true));
+ $file->fileView->expects($this->any())
+ ->method('rename')
+ ->withAnyParameters()
+ ->will($this->returnValue(false));
+ $file->fileView->expects($this->any())
+ ->method('filesize')
+ ->withAnyParameters()
+ ->will($this->returnValue(123456));
+
+ $_SERVER['CONTENT_LENGTH'] = 12345;
+
+ // action
+ $file->put('test data');
+ }
}