1
0

RegistryTest.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. <?php
  2. /**
  3. * @author Morris Jobke <hey@morrisjobke.de>
  4. *
  5. * @license GNU AGPL version 3 or any later version
  6. *
  7. * This program is free software: you can redistribute it and/or modify
  8. * it under the terms of the GNU Affero General Public License as
  9. * published by the Free Software Foundation, either version 3 of the
  10. * License, or (at your option) any later version.
  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
  18. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  19. *
  20. */
  21. namespace Test\Support\Subscription;
  22. use OC\Support\Subscription\Registry;
  23. use OCP\Support\Subscription\ISubscription;
  24. use OCP\Support\Subscription\ISupportedApps;
  25. use Test\TestCase;
  26. class RegistryTest extends TestCase {
  27. /** @var Registry */
  28. private $registry;
  29. protected function setUp() {
  30. parent::setUp();
  31. $this->registry = new Registry();
  32. }
  33. /**
  34. * Doesn't assert anything, just checks whether anything "explodes"
  35. */
  36. public function testDelegateToNone() {
  37. $this->registry->delegateHasValidSubscription();
  38. $this->addToAssertionCount(1);
  39. }
  40. /**
  41. * @expectedException \OCP\Support\Subscription\Exception\AlreadyRegisteredException
  42. */
  43. public function testDoubleRegistration() {
  44. /* @var ISubscription $subscription1 */
  45. $subscription1 = $this->createMock(ISubscription::class);
  46. /* @var ISubscription $subscription2 */
  47. $subscription2 = $this->createMock(ISubscription::class);
  48. $this->registry->register($subscription1);
  49. $this->registry->register($subscription2);
  50. }
  51. public function testNoSupportApp() {
  52. $this->assertSame([], $this->registry->delegateGetSupportedApps());
  53. $this->assertSame(false, $this->registry->delegateHasValidSubscription());
  54. }
  55. public function testDelegateHasValidSubscription() {
  56. /* @var ISubscription|\PHPUnit_Framework_MockObject_MockObject $subscription */
  57. $subscription = $this->createMock(ISubscription::class);
  58. $subscription->expects($this->once())
  59. ->method('hasValidSubscription')
  60. ->willReturn(true);
  61. $this->registry->register($subscription);
  62. $this->assertSame(true, $this->registry->delegateHasValidSubscription());
  63. }
  64. public function testDelegateHasExtendedSupport() {
  65. /* @var ISubscription|\PHPUnit_Framework_MockObject_MockObject $subscription */
  66. $subscription = $this->createMock(ISubscription::class);
  67. $subscription->expects($this->once())
  68. ->method('hasExtendedSupport')
  69. ->willReturn(true);
  70. $this->registry->register($subscription);
  71. $this->assertSame(true, $this->registry->delegateHasExtendedSupport());
  72. }
  73. public function testDelegateGetSupportedApps() {
  74. /* @var ISupportedApps|\PHPUnit_Framework_MockObject_MockObject $subscription */
  75. $subscription = $this->createMock(ISupportedApps::class);
  76. $subscription->expects($this->once())
  77. ->method('getSupportedApps')
  78. ->willReturn(['abc']);
  79. $this->registry->register($subscription);
  80. $this->assertSame(['abc'], $this->registry->delegateGetSupportedApps());
  81. }
  82. }