From cba783f5df8b0129d6b95056ef299e504fed4094 Mon Sep 17 00:00:00 2001 From: Georg Ehrke Date: Tue, 19 Jun 2018 12:22:30 +0200 Subject: Calendar resource booking: unit tests / adding missing annotations Signed-off-by: Georg Ehrke --- tests/lib/Calendar/Resource/ManagerTest.php | 94 +++++++++++++++++++++++++++++ tests/lib/Calendar/Room/ManagerTest.php | 94 +++++++++++++++++++++++++++++ 2 files changed, 188 insertions(+) create mode 100644 tests/lib/Calendar/Resource/ManagerTest.php create mode 100644 tests/lib/Calendar/Room/ManagerTest.php (limited to 'tests/lib') diff --git a/tests/lib/Calendar/Resource/ManagerTest.php b/tests/lib/Calendar/Resource/ManagerTest.php new file mode 100644 index 00000000000..ccc6bbf182b --- /dev/null +++ b/tests/lib/Calendar/Resource/ManagerTest.php @@ -0,0 +1,94 @@ + + * + * @author Georg Ehrke + * + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + * + */ + +namespace Test\Calendar\Resource; + +use \OC\Calendar\Resource\Manager; +use \OCP\Calendar\Resource\IBackend; +use \Test\TestCase; + +class ManagerTest extends TestCase { + + /** @var Manager */ + private $manager; + + protected function setUp() { + parent::setUp(); + + $this->manager = new Manager(); + } + + public function testRegisterUnregisterBackend() { + $backend1 = $this->createMock(IBackend::class); + $backend1->method('getBackendIdentifier')->will($this->returnValue('backend_1')); + + $backend2 = $this->createMock(IBackend::class); + $backend2->method('getBackendIdentifier')->will($this->returnValue('backend_2')); + + $this->manager->registerBackend($backend1); + $this->manager->registerBackend($backend2); + + $this->assertEquals([ + $backend1, $backend2 + ], $this->manager->getBackends()); + + $this->manager->unregisterBackend($backend1); + + $this->assertEquals([ + $backend2 + ], $this->manager->getBackends()); + } + + public function testGetBackend() { + $backend1 = $this->createMock(IBackend::class); + $backend1->method('getBackendIdentifier')->will($this->returnValue('backend_1')); + + $backend2 = $this->createMock(IBackend::class); + $backend2->method('getBackendIdentifier')->will($this->returnValue('backend_2')); + + $this->manager->registerBackend($backend1); + $this->manager->registerBackend($backend2); + + $this->assertEquals($backend1, $this->manager->getBackend('backend_1')); + $this->assertEquals($backend2, $this->manager->getBackend('backend_2')); + } + + public function testClear() { + $backend1 = $this->createMock(IBackend::class); + $backend1->method('getBackendIdentifier')->will($this->returnValue('backend_1')); + + $backend2 = $this->createMock(IBackend::class); + $backend2->method('getBackendIdentifier')->will($this->returnValue('backend_2')); + + $this->manager->registerBackend($backend1); + $this->manager->registerBackend($backend2); + + $this->assertEquals([ + $backend1, $backend2 + ], $this->manager->getBackends()); + + $this->manager->clear(); + + $this->assertEquals([], $this->manager->getBackends()); + } +} diff --git a/tests/lib/Calendar/Room/ManagerTest.php b/tests/lib/Calendar/Room/ManagerTest.php new file mode 100644 index 00000000000..34d69d127e2 --- /dev/null +++ b/tests/lib/Calendar/Room/ManagerTest.php @@ -0,0 +1,94 @@ + + * + * @author Georg Ehrke + * + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + * + */ + +namespace Test\Calendar\Room; + +use \OC\Calendar\Room\Manager; +use \OCP\Calendar\Room\IBackend; +use \Test\TestCase; + +class ManagerTest extends TestCase { + + /** @var Manager */ + private $manager; + + protected function setUp() { + parent::setUp(); + + $this->manager = new Manager(); + } + + public function testRegisterUnregisterBackend() { + $backend1 = $this->createMock(IBackend::class); + $backend1->method('getBackendIdentifier')->will($this->returnValue('backend_1')); + + $backend2 = $this->createMock(IBackend::class); + $backend2->method('getBackendIdentifier')->will($this->returnValue('backend_2')); + + $this->manager->registerBackend($backend1); + $this->manager->registerBackend($backend2); + + $this->assertEquals([ + $backend1, $backend2 + ], $this->manager->getBackends()); + + $this->manager->unregisterBackend($backend1); + + $this->assertEquals([ + $backend2 + ], $this->manager->getBackends()); + } + + public function testGetBackend() { + $backend1 = $this->createMock(IBackend::class); + $backend1->method('getBackendIdentifier')->will($this->returnValue('backend_1')); + + $backend2 = $this->createMock(IBackend::class); + $backend2->method('getBackendIdentifier')->will($this->returnValue('backend_2')); + + $this->manager->registerBackend($backend1); + $this->manager->registerBackend($backend2); + + $this->assertEquals($backend1, $this->manager->getBackend('backend_1')); + $this->assertEquals($backend2, $this->manager->getBackend('backend_2')); + } + + public function testClear() { + $backend1 = $this->createMock(IBackend::class); + $backend1->method('getBackendIdentifier')->will($this->returnValue('backend_1')); + + $backend2 = $this->createMock(IBackend::class); + $backend2->method('getBackendIdentifier')->will($this->returnValue('backend_2')); + + $this->manager->registerBackend($backend1); + $this->manager->registerBackend($backend2); + + $this->assertEquals([ + $backend1, $backend2 + ], $this->manager->getBackends()); + + $this->manager->clear(); + + $this->assertEquals([], $this->manager->getBackends()); + } +} -- cgit v1.2.3