aboutsummaryrefslogtreecommitdiffstats
path: root/apps/dav/tests/unit/Connector/Sabre/FilesPluginTest.php
diff options
context:
space:
mode:
authorVincent Petry <pvince81@owncloud.com>2016-06-09 11:29:20 +0200
committerVincent Petry <pvince81@owncloud.com>2016-06-09 15:51:41 +0200
commit1399e87d57e1b91a5d6888021bef310d35f10b4f (patch)
tree132d296ad09cb857067f0bc62000d33d99a36224 /apps/dav/tests/unit/Connector/Sabre/FilesPluginTest.php
parent4c26abe228bedb0ebb0ffa5a6f5f399e16871880 (diff)
downloadnextcloud-server-1399e87d57e1b91a5d6888021bef310d35f10b4f.tar.gz
nextcloud-server-1399e87d57e1b91a5d6888021bef310d35f10b4f.zip
DAV now returns file name with Content-Disposition header
Fixes issue where Chrome would append ".txt" to XML files when downloaded in the web UI
Diffstat (limited to 'apps/dav/tests/unit/Connector/Sabre/FilesPluginTest.php')
-rw-r--r--apps/dav/tests/unit/Connector/Sabre/FilesPluginTest.php66
1 files changed, 65 insertions, 1 deletions
diff --git a/apps/dav/tests/unit/Connector/Sabre/FilesPluginTest.php b/apps/dav/tests/unit/Connector/Sabre/FilesPluginTest.php
index 80f284e470e..2b3f3e15d1a 100644
--- a/apps/dav/tests/unit/Connector/Sabre/FilesPluginTest.php
+++ b/apps/dav/tests/unit/Connector/Sabre/FilesPluginTest.php
@@ -73,6 +73,11 @@ class FilesPluginTest extends TestCase {
*/
private $config;
+ /**
+ * @var \OCP\IRequest | \PHPUnit_Framework_MockObject_MockObject
+ */
+ private $request;
+
public function setUp() {
parent::setUp();
$this->server = $this->getMockBuilder('\Sabre\DAV\Server')
@@ -88,11 +93,13 @@ class FilesPluginTest extends TestCase {
$this->config->expects($this->any())->method('getSystemValue')
->with($this->equalTo('data-fingerprint'), $this->equalTo(''))
->willReturn('my_fingerprint');
+ $this->request = $this->getMock('\OCP\IRequest');
$this->plugin = new FilesPlugin(
$this->tree,
$this->view,
- $this->config
+ $this->config,
+ $this->request
);
$this->plugin->initialize($this->server);
}
@@ -268,6 +275,7 @@ class FilesPluginTest extends TestCase {
$this->tree,
$this->view,
$this->config,
+ $this->getMock('\OCP\IRequest'),
true);
$this->plugin->initialize($this->server);
@@ -484,4 +492,60 @@ class FilesPluginTest extends TestCase {
$this->plugin->checkMove('FolderA/test.txt', 'test.txt');
}
+
+ public function downloadHeadersProvider() {
+ return [
+ [
+ false,
+ 'attachment; filename*=UTF-8\'\'somefile.xml; filename="somefile.xml"'
+ ],
+ [
+ true,
+ 'attachment; filename="somefile.xml"'
+ ],
+ ];
+ }
+
+ /**
+ * @dataProvider downloadHeadersProvider
+ */
+ public function testDownloadHeaders($isClumsyAgent, $contentDispositionHeader) {
+ $request = $this->getMockBuilder('Sabre\HTTP\RequestInterface')
+ ->disableOriginalConstructor()
+ ->getMock();
+ $response = $this->getMockBuilder('Sabre\HTTP\ResponseInterface')
+ ->disableOriginalConstructor()
+ ->getMock();
+
+ $request
+ ->expects($this->once())
+ ->method('getPath')
+ ->will($this->returnValue('test/somefile.xml'));
+
+ $node = $this->getMockBuilder('\OCA\DAV\Connector\Sabre\File')
+ ->disableOriginalConstructor()
+ ->getMock();
+ $node
+ ->expects($this->once())
+ ->method('getName')
+ ->will($this->returnValue('somefile.xml'));
+
+ $this->tree
+ ->expects($this->once())
+ ->method('getNodeForPath')
+ ->with('test/somefile.xml')
+ ->will($this->returnValue($node));
+
+ $this->request
+ ->expects($this->once())
+ ->method('isUserAgent')
+ ->will($this->returnValue($isClumsyAgent));
+
+ $response
+ ->expects($this->once())
+ ->method('addHeader')
+ ->with('Content-Disposition', $contentDispositionHeader);
+
+ $this->plugin->httpGet($request, $response);
+ }
}