2013-07-08 18:45:19 +04:00
|
|
|
<?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 {
|
2020-03-26 11:30:18 +03:00
|
|
|
public function emitEvent($scope, $method, $arguments = []) {
|
2013-07-08 18:45:19 +04:00
|
|
|
$this->emit($scope, $method, $arguments);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param \OC\Hooks\Emitter $emitter
|
|
|
|
*/
|
2015-05-08 15:27:22 +03:00
|
|
|
public function forward(\OC\Hooks\Emitter $emitter) {
|
2013-07-08 18:45:19 +04:00
|
|
|
parent::forward($emitter);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Class ForwardingEmitter
|
|
|
|
*
|
|
|
|
* allows forwarding all listen calls to other emitters
|
|
|
|
*
|
|
|
|
* @package OC\Hooks
|
|
|
|
*/
|
2016-05-20 16:38:20 +03:00
|
|
|
class ForwardingEmitterTest extends BasicEmitterTest {
|
2013-07-08 18:45:19 +04:00
|
|
|
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);
|
|
|
|
}
|
2013-07-08 18:54:26 +04:00
|
|
|
|
|
|
|
public function testForwardExistingHooks() {
|
|
|
|
$baseEmitter = new PublicEmitter();
|
|
|
|
$forwardingEmitter = new DummyForwardingEmitter();
|
|
|
|
$hookCalled = false;
|
|
|
|
$forwardingEmitter->listen('Test', 'test', function () use (&$hookCalled) {
|
|
|
|
$hookCalled = true;
|
|
|
|
});
|
|
|
|
$forwardingEmitter->forward($baseEmitter);
|
|
|
|
$baseEmitter->emit('Test', 'test');
|
|
|
|
$this->assertTrue($hookCalled);
|
|
|
|
}
|
2013-07-08 18:45:19 +04:00
|
|
|
}
|