diff options
author | Roeland Jago Douma <rullzer@users.noreply.github.com> | 2019-09-11 13:14:06 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-09-11 13:14:06 +0200 |
commit | 2187f856ce4eadeee88bd8b9ff47719df52ea025 (patch) | |
tree | 9df95fb0db015c0f597237c105ee7c5838396a97 /tests | |
parent | 0cc780ec0a94e6ea2103ee667b111cc38fe81f12 (diff) | |
parent | 228cb240bcfe18410a2ce53a35531cdba98b014d (diff) | |
download | nextcloud-server-2187f856ce4eadeee88bd8b9ff47719df52ea025.tar.gz nextcloud-server-2187f856ce4eadeee88bd8b9ff47719df52ea025.zip |
Merge pull request #16682 from nextcloud/enh/12790/workflow-backend
workflow overhaul
Diffstat (limited to 'tests')
-rw-r--r-- | tests/lib/Files/Node/HookConnectorTest.php | 89 |
1 files changed, 66 insertions, 23 deletions
diff --git a/tests/lib/Files/Node/HookConnectorTest.php b/tests/lib/Files/Node/HookConnectorTest.php index 765bb647a1a..0d67fada3c0 100644 --- a/tests/lib/Files/Node/HookConnectorTest.php +++ b/tests/lib/Files/Node/HookConnectorTest.php @@ -9,12 +9,15 @@ namespace Test\Files\Node; use OC\Files\Filesystem; +use OC\Files\Node\HookConnector; use OC\Files\Node\Root; use OC\Files\Storage\Temporary; use OC\Files\View; use OCP\Files\Node; use OCP\ILogger; use OCP\IUserManager; +use Symfony\Component\EventDispatcher\EventDispatcherInterface; +use Symfony\Component\EventDispatcher\GenericEvent; use Test\TestCase; use Test\Traits\MountProviderTrait; use Test\Traits\UserTrait; @@ -29,6 +32,9 @@ use Test\Traits\UserTrait; class HookConnectorTest extends TestCase { use UserTrait; use MountProviderTrait; + /** @var \PHPUnit\Framework\MockObject\MockObject */ + /** @var EventDispatcherInterface */ + protected $eventDispatcher; /** * @var View @@ -60,6 +66,7 @@ class HookConnectorTest extends TestCase { $this->createMock(ILogger::class), $this->createMock(IUserManager::class) ); + $this->eventDispatcher = \OC::$server->getEventDispatcher(); } public function tearDown() { @@ -72,50 +79,50 @@ class HookConnectorTest extends TestCase { return [ [function () { Filesystem::file_put_contents('test.txt', 'asd'); - }, 'preWrite'], + }, 'preWrite', '\OCP\Files::preWrite'], [function () { Filesystem::file_put_contents('test.txt', 'asd'); - }, 'postWrite'], + }, 'postWrite', '\OCP\Files::postWrite'], [function () { Filesystem::file_put_contents('test.txt', 'asd'); - }, 'preCreate'], + }, 'preCreate', '\OCP\Files::preCreate'], [function () { Filesystem::file_put_contents('test.txt', 'asd'); - }, 'postCreate'], + }, 'postCreate', '\OCP\Files::postCreate'], [function () { Filesystem::mkdir('test.txt'); - }, 'preCreate'], + }, 'preCreate', '\OCP\Files::preCreate'], [function () { Filesystem::mkdir('test.txt'); - }, 'postCreate'], + }, 'postCreate', '\OCP\Files::postCreate'], [function () { Filesystem::touch('test.txt'); - }, 'preTouch'], + }, 'preTouch', '\OCP\Files::preTouch'], [function () { Filesystem::touch('test.txt'); - }, 'postTouch'], + }, 'postTouch', '\OCP\Files::postTouch'], [function () { Filesystem::touch('test.txt'); - }, 'preCreate'], + }, 'preCreate', '\OCP\Files::preCreate'], [function () { Filesystem::touch('test.txt'); - }, 'postCreate'], + }, 'postCreate', '\OCP\Files::postCreate'], [function () { Filesystem::file_put_contents('test.txt', 'asd'); Filesystem::unlink('test.txt'); - }, 'preDelete'], + }, 'preDelete', '\OCP\Files::preDelete'], [function () { Filesystem::file_put_contents('test.txt', 'asd'); Filesystem::unlink('test.txt'); - }, 'postDelete'], + }, 'postDelete', '\OCP\Files::postDelete'], [function () { Filesystem::mkdir('test.txt'); Filesystem::rmdir('test.txt'); - }, 'preDelete'], + }, 'preDelete', '\OCP\Files::preDelete'], [function () { Filesystem::mkdir('test.txt'); Filesystem::rmdir('test.txt'); - }, 'postDelete'], + }, 'postDelete', '\OCP\Files::postDelete'], ]; } @@ -124,8 +131,8 @@ class HookConnectorTest extends TestCase { * @param string $expectedHook * @dataProvider viewToNodeProvider */ - public function testViewToNode(callable $operation, $expectedHook) { - $connector = new \OC\Files\Node\HookConnector($this->root, $this->view); + public function testViewToNode(callable $operation, $expectedHook, $expectedEvent) { + $connector = new HookConnector($this->root, $this->view, $this->eventDispatcher); $connector->viewToNode(); $hookCalled = false; /** @var Node $hookNode */ @@ -136,10 +143,21 @@ class HookConnectorTest extends TestCase { $hookNode = $node; }); + $dispatcherCalled = false; + /** @var Node $dispatcherNode */ + $dispatcherNode = null; + $this->eventDispatcher->addListener($expectedEvent, function (GenericEvent $event) use (&$dispatcherCalled, &$dispatcherNode) { + $dispatcherCalled = true; + $dispatcherNode = $event->getSubject(); + }); + $operation(); $this->assertTrue($hookCalled); $this->assertEquals('/' . $this->userId . '/files/test.txt', $hookNode->getPath()); + + $this->assertTrue($dispatcherCalled); + $this->assertEquals('/' . $this->userId . '/files/test.txt', $dispatcherNode->getPath()); } public function viewToNodeProviderCopyRename() { @@ -147,19 +165,19 @@ class HookConnectorTest extends TestCase { [function () { Filesystem::file_put_contents('source', 'asd'); Filesystem::rename('source', 'target'); - }, 'preRename'], + }, 'preRename', '\OCP\Files::preRename'], [function () { Filesystem::file_put_contents('source', 'asd'); Filesystem::rename('source', 'target'); - }, 'postRename'], + }, 'postRename', '\OCP\Files::postRename'], [function () { Filesystem::file_put_contents('source', 'asd'); Filesystem::copy('source', 'target'); - }, 'preCopy'], + }, 'preCopy', '\OCP\Files::preCopy'], [function () { Filesystem::file_put_contents('source', 'asd'); Filesystem::copy('source', 'target'); - }, 'postCopy'], + }, 'postCopy', '\OCP\Files::postCopy'], ]; } @@ -168,8 +186,8 @@ class HookConnectorTest extends TestCase { * @param string $expectedHook * @dataProvider viewToNodeProviderCopyRename */ - public function testViewToNodeCopyRename(callable $operation, $expectedHook) { - $connector = new \OC\Files\Node\HookConnector($this->root, $this->view); + public function testViewToNodeCopyRename(callable $operation, $expectedHook, $expectedEvent) { + $connector = new HookConnector($this->root, $this->view, $this->eventDispatcher); $connector->viewToNode(); $hookCalled = false; /** @var Node $hookSourceNode */ @@ -183,15 +201,29 @@ class HookConnectorTest extends TestCase { $hookTargetNode = $targetNode; }); + $dispatcherCalled = false; + /** @var Node $dispatcherSourceNode */ + $dispatcherSourceNode = null; + /** @var Node $dispatcherTargetNode */ + $dispatcherTargetNode = null; + $this->eventDispatcher->addListener($expectedEvent, function (GenericEvent $event) use (&$dispatcherSourceNode, &$dispatcherTargetNode, &$dispatcherCalled) { + $dispatcherCalled = true; + list($dispatcherSourceNode, $dispatcherTargetNode) = $event->getSubject(); + }); + $operation(); $this->assertTrue($hookCalled); $this->assertEquals('/' . $this->userId . '/files/source', $hookSourceNode->getPath()); $this->assertEquals('/' . $this->userId . '/files/target', $hookTargetNode->getPath()); + + $this->assertTrue($dispatcherCalled); + $this->assertEquals('/' . $this->userId . '/files/source', $dispatcherSourceNode->getPath()); + $this->assertEquals('/' . $this->userId . '/files/target', $dispatcherTargetNode->getPath()); } public function testPostDeleteMeta() { - $connector = new \OC\Files\Node\HookConnector($this->root, $this->view); + $connector = new HookConnector($this->root, $this->view, $this->eventDispatcher); $connector->viewToNode(); $hookCalled = false; /** @var Node $hookNode */ @@ -202,11 +234,22 @@ class HookConnectorTest extends TestCase { $hookNode = $node; }); + $dispatcherCalled = false; + /** @var Node $dispatcherNode */ + $dispatcherNode = null; + $this->eventDispatcher->addListener('\OCP\Files::postDelete', function (GenericEvent $event) use (&$dispatcherCalled, &$dispatcherNode) { + $dispatcherCalled = true; + $dispatcherNode = $event->getSubject(); + }); + Filesystem::file_put_contents('test.txt', 'asd'); $info = Filesystem::getFileInfo('test.txt'); Filesystem::unlink('test.txt'); $this->assertTrue($hookCalled); $this->assertEquals($hookNode->getId(), $info->getId()); + + $this->assertTrue($dispatcherCalled); + $this->assertEquals($dispatcherNode->getId(), $info->getId()); } } |