Skip to content

Commit

Permalink
Include unit tests to cover the code changes
Browse files Browse the repository at this point in the history
  • Loading branch information
jvillafanez committed Mar 31, 2022
1 parent b282db9 commit 347e775
Showing 1 changed file with 50 additions and 0 deletions.
50 changes: 50 additions & 0 deletions tests/Sabre/DAV/ServerEventsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 347e775

Please sign in to comment.