HookManagerTest.php 2.0 KB

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