diff options
author | Robin Appelman <icewind@owncloud.com> | 2013-07-08 16:45:19 +0200 |
---|---|---|
committer | Robin Appelman <icewind@owncloud.com> | 2013-07-08 16:45:19 +0200 |
commit | 925d09cb0e3aed2ab89a11d636111ba699cc403f (patch) | |
tree | 9f1288fbbbb74261840e1d58b8e30dcb605bb22b /tests/lib | |
parent | 8d8f99fbc49b2747895743dc55d9ddf8c3aa842a (diff) | |
download | nextcloud-server-925d09cb0e3aed2ab89a11d636111ba699cc403f.tar.gz nextcloud-server-925d09cb0e3aed2ab89a11d636111ba699cc403f.zip |
add forwarding emitter for agregating multiple emitters
Diffstat (limited to 'tests/lib')
-rw-r--r-- | tests/lib/hooks/forwardingemitter.php | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/tests/lib/hooks/forwardingemitter.php b/tests/lib/hooks/forwardingemitter.php new file mode 100644 index 00000000000..0686ebece9f --- /dev/null +++ b/tests/lib/hooks/forwardingemitter.php @@ -0,0 +1,62 @@ +<?php +/** + * Copyright (c) 2013 Robin Appelman <icewind@owncloud.com> + * This file is licensed under the Affero General Public License version 3 or + * later. + * See the COPYING-README file. + */ + +namespace Test\Hooks; +use OC\Hooks\PublicEmitter; + +class DummyForwardingEmitter extends \OC\Hooks\ForwardingEmitter { + public function emitEvent($scope, $method, $arguments = array()) { + $this->emit($scope, $method, $arguments); + } + + /** + * @param \OC\Hooks\Emitter $emitter + */ + public function forward($emitter) { + parent::forward($emitter); + } +} + +/** + * Class ForwardingEmitter + * + * allows forwarding all listen calls to other emitters + * + * @package OC\Hooks + */ +class ForwardingEmitter extends BasicEmitter { + public function testSingleForward() { + $baseEmitter = new PublicEmitter(); + $forwardingEmitter = new DummyForwardingEmitter(); + $forwardingEmitter->forward($baseEmitter); + $hookCalled = false; + $forwardingEmitter->listen('Test', 'test', function () use (&$hookCalled) { + $hookCalled = true; + }); + $baseEmitter->emit('Test', 'test'); + $this->assertTrue($hookCalled); + } + + public function testMultipleForwards() { + $baseEmitter1 = new PublicEmitter(); + $baseEmitter2 = new PublicEmitter(); + $forwardingEmitter = new DummyForwardingEmitter(); + $forwardingEmitter->forward($baseEmitter1); + $forwardingEmitter->forward($baseEmitter2); + $hookCalled = 0; + $forwardingEmitter->listen('Test', 'test1', function () use (&$hookCalled) { + $hookCalled++; + }); + $forwardingEmitter->listen('Test', 'test2', function () use (&$hookCalled) { + $hookCalled++; + }); + $baseEmitter1->emit('Test', 'test1'); + $baseEmitter1->emit('Test', 'test2'); + $this->assertEquals(2, $hookCalled); + } +} |