Skip to content

Commit

Permalink
Merge pull request #1341 from woutersamaey/patch-1
Browse files Browse the repository at this point in the history
New event "afterCreateCollection" like "afterCreateFile"
  • Loading branch information
phil-davis authored Nov 16, 2021
2 parents 20d39d0 + 759efe8 commit 71bbf40
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 3 deletions.
1 change: 1 addition & 0 deletions lib/DAV/Server.php
Original file line number Diff line number Diff line change
Expand Up @@ -1237,6 +1237,7 @@ public function createCollection($uri, MkCol $mkCol)

$this->tree->markDirty($parentUri);
$this->emit('afterBind', [$uri]);
$this->emit('afterCreateCollection', [$uri]);
}

/**
Expand Down
36 changes: 33 additions & 3 deletions tests/Sabre/DAV/ServerEventsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,47 @@ class ServerEventsTest extends AbstractServer

private $exception;

public function testAfterBind()
public function testAfterBindOfFile()
{
$this->server->on('afterBind', [$this, 'afterBindHandler']);
$this->server->on('afterBind', [$this, 'afterHandler']);
$newPath = 'afterBind';

$this->tempPath = '';
$this->server->createFile($newPath, 'body');
$this->assertEquals($newPath, $this->tempPath);
}

public function afterBindHandler($path)
public function testAfterBindOfCollection()
{
$this->server->on('afterBind', [$this, 'afterHandler']);
$newPath = 'afterBind';

$this->tempPath = '';
$this->server->createDirectory($newPath);
$this->assertEquals($newPath, $this->tempPath);
}

public function testAfterCreateFile()
{
$this->server->on('afterCreateFile', [$this, 'afterHandler']);
$newPath = 'afterCreateFile';

$this->tempPath = '';
$this->server->createFile($newPath, 'body');
$this->assertEquals($newPath, $this->tempPath);
}

public function testAfterCreateCollection()
{
$this->server->on('afterCreateCollection', [$this, 'afterHandler']);
$newPath = 'afterCreateCollection';

$this->tempPath = '';
$this->server->createDirectory($newPath);
$this->assertEquals($newPath, $this->tempPath);
}

public function afterHandler($path)
{
$this->tempPath = $path;
}
Expand Down

0 comments on commit 71bbf40

Please sign in to comment.