ManagerTest.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. <?php
  2. /**
  3. * @copyright 2018, Georg Ehrke <oc.list@georgehrke.com>
  4. *
  5. * @author Georg Ehrke <oc.list@georgehrke.com>
  6. *
  7. * @license GNU AGPL version 3 or any later version
  8. *
  9. * This program is free software: you can redistribute it and/or modify
  10. * it under the terms of the GNU Affero General Public License as
  11. * published by the Free Software Foundation, either version 3 of the
  12. * License, or (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU Affero General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU Affero General Public License
  20. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  21. *
  22. */
  23. namespace Test\Calendar\Resource;
  24. use \OC\Calendar\Resource\Manager;
  25. use \OCP\Calendar\Resource\IBackend;
  26. use OCP\IServerContainer;
  27. use \Test\TestCase;
  28. class ManagerTest extends TestCase {
  29. /** @var Manager */
  30. private $manager;
  31. /** @var IServerContainer */
  32. private $server;
  33. protected function setUp() {
  34. parent::setUp();
  35. $this->server = $this->createMock(IServerContainer::class);
  36. $this->manager = new Manager($this->server);
  37. }
  38. public function testRegisterUnregisterBackend() {
  39. $backend1 = $this->createMock(IBackend::class);
  40. $backend1->method('getBackendIdentifier')->will($this->returnValue('backend_1'));
  41. $this->server->expects($this->at(0))
  42. ->method('query')
  43. ->with('calendar_resource_backend1')
  44. ->will($this->returnValue($backend1));
  45. $backend2 = $this->createMock(IBackend::class);
  46. $backend2->method('getBackendIdentifier')->will($this->returnValue('backend_2'));
  47. $this->server->expects($this->at(1))
  48. ->method('query')
  49. ->with('calendar_resource_backend2')
  50. ->will($this->returnValue($backend2));
  51. $this->manager->registerBackend('calendar_resource_backend1');
  52. $this->manager->registerBackend('calendar_resource_backend2');
  53. $this->assertEquals([
  54. $backend1, $backend2
  55. ], $this->manager->getBackends());
  56. $this->manager->unregisterBackend('calendar_resource_backend1');
  57. $this->assertEquals([
  58. $backend2
  59. ], $this->manager->getBackends());
  60. }
  61. public function testGetBackend() {
  62. $backend1 = $this->createMock(IBackend::class);
  63. $backend1->method('getBackendIdentifier')->will($this->returnValue('backend_1'));
  64. $this->server->expects($this->at(0))
  65. ->method('query')
  66. ->with('calendar_resource_backend1')
  67. ->will($this->returnValue($backend1));
  68. $backend2 = $this->createMock(IBackend::class);
  69. $backend2->method('getBackendIdentifier')->will($this->returnValue('backend_2'));
  70. $this->server->expects($this->at(1))
  71. ->method('query')
  72. ->with('calendar_resource_backend2')
  73. ->will($this->returnValue($backend2));
  74. $this->manager->registerBackend('calendar_resource_backend1');
  75. $this->manager->registerBackend('calendar_resource_backend2');
  76. $this->assertEquals($backend1, $this->manager->getBackend('backend_1'));
  77. $this->assertEquals($backend2, $this->manager->getBackend('backend_2'));
  78. }
  79. public function testClear() {
  80. $backend1 = $this->createMock(IBackend::class);
  81. $backend1->method('getBackendIdentifier')->will($this->returnValue('backend_1'));
  82. $this->server->expects($this->at(0))
  83. ->method('query')
  84. ->with('calendar_resource_backend1')
  85. ->will($this->returnValue($backend1));
  86. $backend2 = $this->createMock(IBackend::class);
  87. $backend2->method('getBackendIdentifier')->will($this->returnValue('backend_2'));
  88. $this->server->expects($this->at(1))
  89. ->method('query')
  90. ->with('calendar_resource_backend2')
  91. ->will($this->returnValue($backend2));
  92. $this->manager->registerBackend('calendar_resource_backend1');
  93. $this->manager->registerBackend('calendar_resource_backend2');
  94. $this->assertEquals([
  95. $backend1, $backend2
  96. ], $this->manager->getBackends());
  97. $this->manager->clear();
  98. $this->assertEquals([], $this->manager->getBackends());
  99. }
  100. }