HookManagerTest.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016, ownCloud, Inc.
  4. *
  5. * @author Clark Tomlinson <fallen013@gmail.com>
  6. * @author Joas Schilling <coding@schilljs.com>
  7. *
  8. * @license AGPL-3.0
  9. *
  10. * This code is free software: you can redistribute it and/or modify
  11. * it under the terms of the GNU Affero General Public License, version 3,
  12. * as published by the Free Software Foundation.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU Affero General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU Affero General Public License, version 3,
  20. * along with this program. If not, see <http://www.gnu.org/licenses/>
  21. *
  22. */
  23. namespace OCA\Encryption\Tests;
  24. use OCA\Encryption\HookManager;
  25. use OCP\IConfig;
  26. use Test\TestCase;
  27. class HookManagerTest extends TestCase {
  28. /**
  29. * @var HookManager
  30. */
  31. private static $instance;
  32. /**
  33. *
  34. */
  35. public function testRegisterHookWithArray() {
  36. self::$instance->registerHook([
  37. $this->getMockBuilder('OCA\Encryption\Hooks\Contracts\IHook')->disableOriginalConstructor()->getMock(),
  38. $this->getMockBuilder('OCA\Encryption\Hooks\Contracts\IHook')->disableOriginalConstructor()->getMock(),
  39. $this->createMock(IConfig::class)
  40. ]);
  41. $hookInstances = self::invokePrivate(self::$instance, 'hookInstances');
  42. // Make sure our type checking works
  43. $this->assertCount(2, $hookInstances);
  44. }
  45. /**
  46. *
  47. */
  48. public static function setUpBeforeClass() {
  49. parent::setUpBeforeClass();
  50. // have to make instance static to preserve data between tests
  51. self::$instance = new HookManager();
  52. }
  53. /**
  54. *
  55. */
  56. public function testRegisterHooksWithInstance() {
  57. $mock = $this->getMockBuilder('OCA\Encryption\Hooks\Contracts\IHook')->disableOriginalConstructor()->getMock();
  58. /** @var \OCA\Encryption\Hooks\Contracts\IHook $mock */
  59. self::$instance->registerHook($mock);
  60. $hookInstances = self::invokePrivate(self::$instance, 'hookInstances');
  61. $this->assertCount(3, $hookInstances);
  62. }
  63. }