HookManagerTest.php 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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. * @author Morris Jobke <hey@morrisjobke.de>
  8. * @author Roeland Jago Douma <roeland@famdouma.nl>
  9. *
  10. * @license AGPL-3.0
  11. *
  12. * This code is free software: you can redistribute it and/or modify
  13. * it under the terms of the GNU Affero General Public License, version 3,
  14. * as published by the Free Software Foundation.
  15. *
  16. * This program is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU Affero General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU Affero General Public License, version 3,
  22. * along with this program. If not, see <http://www.gnu.org/licenses/>
  23. *
  24. */
  25. namespace OCA\Encryption\Tests;
  26. use OCA\Encryption\HookManager;
  27. use OCA\Encryption\Hooks\Contracts\IHook;
  28. use OCP\IConfig;
  29. use Test\TestCase;
  30. class HookManagerTest extends TestCase {
  31. /**
  32. * @var HookManager
  33. */
  34. private static $instance;
  35. public function testRegisterHookWithArray() {
  36. self::$instance->registerHook([
  37. $this->getMockBuilder(IHook::class)->disableOriginalConstructor()->getMock(),
  38. $this->getMockBuilder(IHook::class)->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. public static function setUpBeforeClass(): void {
  46. parent::setUpBeforeClass();
  47. // have to make instance static to preserve data between tests
  48. self::$instance = new HookManager();
  49. }
  50. public function testRegisterHooksWithInstance() {
  51. $mock = $this->getMockBuilder(IHook::class)->disableOriginalConstructor()->getMock();
  52. /** @var \OCA\Encryption\Hooks\Contracts\IHook $mock */
  53. self::$instance->registerHook($mock);
  54. $hookInstances = self::invokePrivate(self::$instance, 'hookInstances');
  55. $this->assertCount(3, $hookInstances);
  56. }
  57. }