legacyemitter.php 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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. public function setUp() {
  25. $this->emitter = new DummyLegacyEmitter();
  26. self::$emitted = false;
  27. \OC_Hook::clear('Test','test');
  28. }
  29. public static function staticLegacyCallBack() {
  30. self::$emitted = true;
  31. }
  32. public static function staticLegacyArgumentsCallBack($arguments) {
  33. if ($arguments['foo'] == 'foo' and $arguments['bar'] == 'bar')
  34. self::$emitted = true;
  35. }
  36. public function testLegacyHook() {
  37. \OC_Hook::connect('Test', 'test', '\Test\Hooks\LegacyEmitter', 'staticLegacyCallBack');
  38. $this->emitter->emitEvent('Test', 'test');
  39. $this->assertEquals(true, self::$emitted);
  40. }
  41. public function testLegacyArguments() {
  42. \OC_Hook::connect('Test', 'test', '\Test\Hooks\LegacyEmitter', 'staticLegacyArgumentsCallBack');
  43. $this->emitter->emitEvent('Test', 'test', array('foo' => 'foo', 'bar' => 'bar'));
  44. $this->assertEquals(true, self::$emitted);
  45. }
  46. }