LegacyEmitterTest.php 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. <?php
  2. /**
  3. * Copyright (c) 2013 Robin Appelman <icewind@owncloud.com>
  4. * This file is licensed under the Affero General Public License version 3 or
  5. * later.
  6. * See the COPYING-README file.
  7. */
  8. namespace Test\Hooks;
  9. /**
  10. * Class DummyLegacyEmitter
  11. *
  12. * class to make LegacyEmitter::emit publicly available
  13. *
  14. * @package Test\Hooks
  15. */
  16. class DummyLegacyEmitter extends \OC\Hooks\LegacyEmitter {
  17. public function emitEvent($scope, $method, $arguments = []) {
  18. $this->emit($scope, $method, $arguments);
  19. }
  20. }
  21. class LegacyEmitterTest extends BasicEmitterTest {
  22. //we can't use exceptions here since OC_Hooks catches all exceptions
  23. private static $emitted = false;
  24. protected function setUp(): void {
  25. parent::setUp();
  26. $this->emitter = new DummyLegacyEmitter();
  27. self::$emitted = false;
  28. \OC_Hook::clear('Test','test');
  29. }
  30. public static function staticLegacyCallBack() {
  31. self::$emitted = true;
  32. }
  33. public static function staticLegacyArgumentsCallBack($arguments) {
  34. if ($arguments['foo'] == 'foo' and $arguments['bar'] == 'bar') {
  35. self::$emitted = true;
  36. }
  37. }
  38. public function testLegacyHook() {
  39. \OC_Hook::connect('Test', 'test', '\Test\Hooks\LegacyEmitterTest', 'staticLegacyCallBack');
  40. $this->emitter->emitEvent('Test', 'test');
  41. $this->assertEquals(true, self::$emitted);
  42. }
  43. public function testLegacyArguments() {
  44. \OC_Hook::connect('Test', 'test', '\Test\Hooks\LegacyEmitterTest', 'staticLegacyArgumentsCallBack');
  45. $this->emitter->emitEvent('Test', 'test', ['foo' => 'foo', 'bar' => 'bar']);
  46. $this->assertEquals(true, self::$emitted);
  47. }
  48. }