2013-05-07 18:34:09 +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;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Class DummyLegacyEmitter
|
|
|
|
*
|
|
|
|
* class to make LegacyEmitter::emit publicly available
|
|
|
|
*
|
|
|
|
* @package Test\Hooks
|
|
|
|
*/
|
|
|
|
class DummyLegacyEmitter extends \OC\Hooks\LegacyEmitter {
|
2020-03-26 11:30:18 +03:00
|
|
|
public function emitEvent($scope, $method, $arguments = []) {
|
2013-05-07 18:34:09 +04:00
|
|
|
$this->emit($scope, $method, $arguments);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-20 16:38:20 +03:00
|
|
|
class LegacyEmitterTest extends BasicEmitterTest {
|
2013-05-07 18:34:09 +04:00
|
|
|
|
|
|
|
//we can't use exceptions here since OC_Hooks catches all exceptions
|
|
|
|
private static $emitted = false;
|
|
|
|
|
2019-11-21 18:40:38 +03:00
|
|
|
protected function setUp(): void {
|
2014-11-11 01:30:38 +03:00
|
|
|
parent::setUp();
|
|
|
|
|
2013-05-07 18:34:09 +04:00
|
|
|
$this->emitter = new DummyLegacyEmitter();
|
|
|
|
self::$emitted = false;
|
|
|
|
\OC_Hook::clear('Test','test');
|
|
|
|
}
|
|
|
|
|
|
|
|
public static function staticLegacyCallBack() {
|
|
|
|
self::$emitted = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static function staticLegacyArgumentsCallBack($arguments) {
|
|
|
|
if ($arguments['foo'] == 'foo' and $arguments['bar'] == 'bar')
|
|
|
|
self::$emitted = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testLegacyHook() {
|
2016-05-20 16:38:20 +03:00
|
|
|
\OC_Hook::connect('Test', 'test', '\Test\Hooks\LegacyEmitterTest', 'staticLegacyCallBack');
|
2013-05-07 18:34:09 +04:00
|
|
|
$this->emitter->emitEvent('Test', 'test');
|
|
|
|
$this->assertEquals(true, self::$emitted);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testLegacyArguments() {
|
2016-05-20 16:38:20 +03:00
|
|
|
\OC_Hook::connect('Test', 'test', '\Test\Hooks\LegacyEmitterTest', 'staticLegacyArgumentsCallBack');
|
2020-03-26 11:30:18 +03:00
|
|
|
$this->emitter->emitEvent('Test', 'test', ['foo' => 'foo', 'bar' => 'bar']);
|
2013-05-07 18:34:09 +04:00
|
|
|
$this->assertEquals(true, self::$emitted);
|
|
|
|
}
|
|
|
|
}
|