1
0

HookManagerTest.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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. /**
  36. *
  37. */
  38. public function testRegisterHookWithArray() {
  39. self::$instance->registerHook([
  40. $this->getMockBuilder(IHook::class)->disableOriginalConstructor()->getMock(),
  41. $this->getMockBuilder(IHook::class)->disableOriginalConstructor()->getMock(),
  42. $this->createMock(IConfig::class)
  43. ]);
  44. $hookInstances = self::invokePrivate(self::$instance, 'hookInstances');
  45. // Make sure our type checking works
  46. $this->assertCount(2, $hookInstances);
  47. }
  48. /**
  49. *
  50. */
  51. public static function setUpBeforeClass() {
  52. parent::setUpBeforeClass();
  53. // have to make instance static to preserve data between tests
  54. self::$instance = new HookManager();
  55. }
  56. /**
  57. *
  58. */
  59. public function testRegisterHooksWithInstance() {
  60. $mock = $this->getMockBuilder(IHook::class)->disableOriginalConstructor()->getMock();
  61. /** @var \OCA\Encryption\Hooks\Contracts\IHook $mock */
  62. self::$instance->registerHook($mock);
  63. $hookInstances = self::invokePrivate(self::$instance, 'hookInstances');
  64. $this->assertCount(3, $hookInstances);
  65. }
  66. }