diff --git a/tests/Sabre/DAV/ServerEventsTest.php b/tests/Sabre/DAV/ServerEventsTest.php index e9490d4f97..733b78a1fd 100644 --- a/tests/Sabre/DAV/ServerEventsTest.php +++ b/tests/Sabre/DAV/ServerEventsTest.php @@ -52,6 +52,30 @@ public function testAfterCreateCollection() $this->assertEquals($newPath, $this->tempPath); } + public function testAfterCopy() + { + $tmpPath1 = ''; + $tmpPath2 = ''; + $this->server->on('afterCopy', function ($source, $destination) use (&$tmpPath1, &$tmpPath2) { + $tmpPath1 = $source; + $tmpPath2 = $destination; + }); + + $oldPath = '/oldCopy.txt'; + $newPath = '/newCopy.txt'; + + $this->server->createFile($oldPath, 'body'); + $request = new HTTP\Request('COPY', $oldPath, [ + 'Destination' => $newPath, + ]); + $this->server->httpRequest = $request; + + $this->server->exec(); + $this->assertEquals(201, $this->server->httpResponse->getStatus()); + $this->assertEquals(trim($oldPath, '/'), $tmpPath1); + $this->assertEquals(trim($newPath, '/'), $tmpPath2); + } + public function afterHandler($path) { $this->tempPath = $path; @@ -91,6 +115,32 @@ public function testBeforeBindCancel() $this->assertEquals(500, $this->server->httpResponse->getStatus()); } + public function testBeforeCopyCancel() + { + $tmpPath1 = ''; + $tmpPath2 = ''; + $this->server->on('beforeCopy', function ($source, $destination) use (&$tmpPath1, &$tmpPath2) { + $tmpPath1 = $source; + $tmpPath2 = $destination; + + return false; + }); + + $oldPath = '/oldCopy.txt'; + $newPath = '/newCopy.txt'; + + $this->server->createFile($oldPath, 'body'); + $request = new HTTP\Request('COPY', $oldPath, [ + 'Destination' => $newPath, + ]); + $this->server->httpRequest = $request; + + $this->server->exec(); + $this->assertEquals(500, $this->server->httpResponse->getStatus()); + $this->assertEquals(trim($oldPath, '/'), $tmpPath1); + $this->assertEquals(trim($newPath, '/'), $tmpPath2); + } + public function beforeBindCancelHandler($path) { return false;