HookManagerTest.php 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <?php
  2. /**
  3. * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
  4. * SPDX-FileCopyrightText: 2016 ownCloud, Inc.
  5. * SPDX-License-Identifier: AGPL-3.0-only
  6. */
  7. namespace OCA\Encryption\Tests;
  8. use OCA\Encryption\HookManager;
  9. use OCA\Encryption\Hooks\Contracts\IHook;
  10. use OCP\IConfig;
  11. use Test\TestCase;
  12. class HookManagerTest extends TestCase {
  13. /**
  14. * @var HookManager
  15. */
  16. private static $instance;
  17. public function testRegisterHookWithArray() {
  18. self::$instance->registerHook([
  19. $this->getMockBuilder(IHook::class)->disableOriginalConstructor()->getMock(),
  20. $this->getMockBuilder(IHook::class)->disableOriginalConstructor()->getMock(),
  21. $this->createMock(IConfig::class)
  22. ]);
  23. $hookInstances = self::invokePrivate(self::$instance, 'hookInstances');
  24. // Make sure our type checking works
  25. $this->assertCount(2, $hookInstances);
  26. }
  27. public static function setUpBeforeClass(): void {
  28. parent::setUpBeforeClass();
  29. // have to make instance static to preserve data between tests
  30. self::$instance = new HookManager();
  31. }
  32. public function testRegisterHooksWithInstance() {
  33. $mock = $this->getMockBuilder(IHook::class)->disableOriginalConstructor()->getMock();
  34. /** @var \OCA\Encryption\Hooks\Contracts\IHook $mock */
  35. self::$instance->registerHook($mock);
  36. $hookInstances = self::invokePrivate(self::$instance, 'hookInstances');
  37. $this->assertCount(3, $hookInstances);
  38. }
  39. }