diff options
author | Joas Schilling <coding@schilljs.com> | 2016-11-03 12:57:40 +0100 |
---|---|---|
committer | Joas Schilling <coding@schilljs.com> | 2016-11-03 12:57:40 +0100 |
commit | c4775a5bce4f2b804fa4bd15cdf77698d3831d7a (patch) | |
tree | 3f6ec814ba4e3fddeabdccb740e0c6c648333e6f /apps/dav/tests | |
parent | e8f82c6b61ec293c354c417762d4279a877372a4 (diff) | |
download | nextcloud-server-c4775a5bce4f2b804fa4bd15cdf77698d3831d7a.tar.gz nextcloud-server-c4775a5bce4f2b804fa4bd15cdf77698d3831d7a.zip |
Start unit tests for the activity listener
Signed-off-by: Joas Schilling <coding@schilljs.com>
Diffstat (limited to 'apps/dav/tests')
-rw-r--r-- | apps/dav/tests/unit/CalDAV/Activity/BackendTest.php | 100 |
1 files changed, 100 insertions, 0 deletions
diff --git a/apps/dav/tests/unit/CalDAV/Activity/BackendTest.php b/apps/dav/tests/unit/CalDAV/Activity/BackendTest.php new file mode 100644 index 00000000000..60afeee8c02 --- /dev/null +++ b/apps/dav/tests/unit/CalDAV/Activity/BackendTest.php @@ -0,0 +1,100 @@ +<?php +/** + * @copyright Copyright (c) 2016 Joas Schilling <coding@schilljs.com> + * + * @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 <http://www.gnu.org/licenses/>. + * + */ + +namespace OCA\DAV\Tests\unit\CalDAV\Activity; + +use OCA\DAV\CalDAV\Activity\Backend; +use OCA\DAV\CalDAV\Activity\Extension; +use OCP\Activity\IManager; +use OCP\IGroupManager; +use OCP\IUserSession; +use Test\TestCase; + +class BackendTest extends TestCase { + + /** @var IManager */ + protected $activityManager; + + /** @var IGroupManager */ + protected $groupManager; + + /** @var IUserSession */ + protected $userSession; + + protected function setUp() { + parent::setUp(); + $this->activityManager = $this->createMock(IManager::class); + $this->groupManager = $this->createMock(IGroupManager::class); + $this->userSession = $this->createMock(IUserSession::class); + } + + /** + * @param array $methods + * @return Backend|\PHPUnit_Framework_MockObject_MockObject + */ + protected function getBackend(array $methods = []) { + if (empty($methods)) { + return new Backend( + $this->activityManager, + $this->groupManager, + $this->userSession + ); + } else { + return $this->getMockBuilder(Backend::class) + ->setConstructorArgs([ + $this->activityManager, + $this->groupManager, + $this->userSession, + ]) + ->setMethods($methods) + ->getMock(); + } + } + + public function dataCallTriggerCalendarActivity() { + return [ + ['onCalendarAdd', [['data']], Extension::SUBJECT_ADD, [['data'], [], []]], + ['onCalendarUpdate', [['data'], ['shares'], ['properties']], Extension::SUBJECT_UPDATE, [['data'], ['shares'], ['properties']]], + ['onCalendarDelete', [['data'], ['shares']], Extension::SUBJECT_DELETE, [['data'], ['shares'], []]], + ]; + } + + /** + * @dataProvider dataCallTriggerCalendarActivity + * + * @param string $method + * @param array $payload + * @param string $expectedSubject + * @param array $expectedPayload + */ + public function testCallTriggerCalendarActivity($method, array $payload, $expectedSubject, array $expectedPayload) { + $backend = $this->getBackend(['triggerCalendarActivity']); + $backend->expects($this->once()) + ->method('triggerCalendarActivity') + ->willReturnCallback(function() use($expectedPayload, $expectedSubject) { + $arguments = func_get_args(); + $this->assertSame($expectedSubject, array_shift($arguments)); + $this->assertEquals($expectedPayload, $arguments); + }); + + call_user_func_array([$backend, $method], $payload); + } +} |