diff --git a/apps/dav/lib/Connector/Sabre/File.php b/apps/dav/lib/Connector/Sabre/File.php index c2c6baaa4893..7b2c405c18f3 100644 --- a/apps/dav/lib/Connector/Sabre/File.php +++ b/apps/dav/lib/Connector/Sabre/File.php @@ -232,7 +232,7 @@ public function put($data) { if (isset($this->request->server['HTTP_X_OC_MTIME'])) { $mtime = $this->sanitizeMtime($this->request->server ['HTTP_X_OC_MTIME']); if ($this->fileView->touch($this->path, $mtime)) { - header('X-OC-MTime: accepted'); + $this->header('X-OC-MTime: accepted'); } } @@ -498,7 +498,7 @@ private function createFileChunked($data) { $this->request->server ['HTTP_X_OC_MTIME'] ); if ($targetStorage->touch($targetInternalPath, $mtime)) { - header('X-OC-MTime: accepted'); + $this->header('X-OC-MTime: accepted'); } } @@ -651,4 +651,8 @@ public function getChecksum($algo = null) { return ''; } + + protected function header($string) { + \header($string); + } } diff --git a/apps/dav/tests/unit/Connector/Sabre/FileTest.php b/apps/dav/tests/unit/Connector/Sabre/FileTest.php index 7e78ffd49905..b665cb3273d0 100644 --- a/apps/dav/tests/unit/Connector/Sabre/FileTest.php +++ b/apps/dav/tests/unit/Connector/Sabre/FileTest.php @@ -325,7 +325,11 @@ private function doPut($path, $viewRoot = null, \OC\AppFramework\Http\Request $r null ); - $file = new File($view, $info, null, $request); + /** @var File | \PHPUnit_Framework_MockObject_MockObject $file */ + $file = $this->getMockBuilder(File::class) + ->setConstructorArgs([$view, $info, null, $request]) + ->setMethods(['header']) + ->getMock(); // beforeMethod locks $view->lockFile($path, ILockingProvider::LOCK_SHARED); @@ -345,15 +349,6 @@ public function testPutSingleFile() { $this->assertNotEmpty($this->doPut('/foo.txt')); } - /** - * Determine if the underlying storage supports a negative mtime value - * - * @return boolean true if negative mtime is supported - */ - private function supportsNegativeMtime() { - return (getenv("PRIMARY_STORAGE_CONFIG") !== "swift"); - } - public function legalMtimeProvider() { return [ "string" => [ @@ -398,19 +393,17 @@ public function legalMtimeProvider() { ], "negative int" => [ 'HTTP_X_OC_MTIME' => -34, - 'expected result' => ($this->supportsNegativeMtime() ? -34 : 0) + 'expected result' => -34 ], "negative float" => [ 'HTTP_X_OC_MTIME' => -34.43, - 'expected result' => ($this->supportsNegativeMtime() ? -34 : 0) + 'expected result' => -34 ], ]; } /** * Test putting a file with string Mtime - * @runInSeparateProcess - * @preserveGlobalState disabled * @dataProvider legalMtimeProvider */ public function testPutSingleFileLegalMtime($requestMtime, $resultMtime) { @@ -426,8 +419,6 @@ public function testPutSingleFileLegalMtime($requestMtime, $resultMtime) { /** * Test putting a file with string Mtime using chunking - * @runInSeparateProcess - * @preserveGlobalState disabled * @dataProvider legalMtimeProvider */ public function testChunkedPutLegalMtime($requestMtime, $resultMtime) { diff --git a/lib/private/Files/Storage/Common.php b/lib/private/Files/Storage/Common.php index c0c6af2e49de..1c56606f9610 100644 --- a/lib/private/Files/Storage/Common.php +++ b/lib/private/Files/Storage/Common.php @@ -170,7 +170,7 @@ public function getPermissions($path) { public function filemtime($path) { $stat = $this->stat($path); - if (isset($stat['mtime']) && $stat['mtime'] > 0) { + if (isset($stat['mtime'])) { return $stat['mtime']; } else { return 0;