1
0

legacyemitter.php 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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 = array()) {
  18. $this->emit($scope, $method, $arguments);
  19. }
  20. }
  21. class LegacyEmitter extends BasicEmitter {
  22. //we can't use exceptions here since OC_Hooks catches all exceptions
  23. private static $emitted = false;
  24. protected function setUp() {
  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. public function testLegacyHook() {
  38. \OC_Hook::connect('Test', 'test', '\Test\Hooks\LegacyEmitter', 'staticLegacyCallBack');
  39. $this->emitter->emitEvent('Test', 'test');
  40. $this->assertEquals(true, self::$emitted);
  41. }
  42. public function testLegacyArguments() {
  43. \OC_Hook::connect('Test', 'test', '\Test\Hooks\LegacyEmitter', 'staticLegacyArgumentsCallBack');
  44. $this->emitter->emitEvent('Test', 'test', array('foo' => 'foo', 'bar' => 'bar'));
  45. $this->assertEquals(true, self::$emitted);
  46. }
  47. }