commit
12a57f2a86
8 changed files with 491 additions and 8 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -248,3 +248,4 @@ Various
|
|||
|
||||
build/
|
||||
coverage
|
||||
.phpunit.result.cache
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<phpunit bootstrap="tests/bootstrap.php"
|
||||
verbose="true"
|
||||
colors="true"
|
||||
colors="true"
|
||||
timeoutForSmallTests="900"
|
||||
timeoutForMediumTests="900"
|
||||
timeoutForLargeTests="900">
|
||||
<testsuite name='Contacts app integration tests'>
|
||||
<directory>./tests/integration</directory>
|
||||
<testsuite name='Tasks app integration tests'>
|
||||
<directory>./tests/integration</directory>
|
||||
</testsuite>
|
||||
<!-- filters for code coverage -->
|
||||
<filter>
|
||||
|
@ -19,4 +19,4 @@
|
|||
</exclude>
|
||||
</whitelist>
|
||||
</filter>
|
||||
</phpunit>
|
||||
</phpunit>
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<phpunit bootstrap="tests/bootstrap.php"
|
||||
verbose="true"
|
||||
colors="true"
|
||||
colors="true"
|
||||
timeoutForSmallTests="900"
|
||||
timeoutForMediumTests="900"
|
||||
timeoutForLargeTests="900">
|
||||
<testsuite name='Contacts app tests'>
|
||||
<directory>./tests/unit</directory>
|
||||
<testsuite name='Tasks app tests'>
|
||||
<directory>./tests/unit</directory>
|
||||
</testsuite>
|
||||
<!-- filters for code coverage -->
|
||||
<filter>
|
||||
|
@ -19,4 +19,4 @@
|
|||
</exclude>
|
||||
</whitelist>
|
||||
</filter>
|
||||
</phpunit>
|
||||
</phpunit>
|
||||
|
|
54
tests/integration/AppInfo/ApplicationTest.php
Normal file
54
tests/integration/AppInfo/ApplicationTest.php
Normal file
|
@ -0,0 +1,54 @@
|
|||
<?php
|
||||
/**
|
||||
* Nextcloud - Tasks
|
||||
*
|
||||
* @author Julius Härtl
|
||||
* @copyright 2016 Julius Härtl <jus@bitgrid.net>
|
||||
*
|
||||
* @author Raimund Schlüßler
|
||||
* @copyright 2019 Raimund Schlüßler <raimund.schluessler@mailbox.org>
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 3 of the License, or any later version.
|
||||
*
|
||||
* This library 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 library. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
use OCP\AppFramework\App;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class AppTest extends TestCase {
|
||||
|
||||
private $container;
|
||||
private $app;
|
||||
|
||||
public function setUp(): void {
|
||||
parent::setUp();
|
||||
$this->app = new \OCA\Tasks\AppInfo\Application();
|
||||
$this->container = $this->app->getContainer();
|
||||
}
|
||||
|
||||
public function testAppInstalled() {
|
||||
$appManager = $this->container->query('OCP\App\IAppManager');
|
||||
$this->assertTrue($appManager->isInstalled('tasks'));
|
||||
}
|
||||
|
||||
public function testNavigation() {
|
||||
$navigationManager = \OC::$server->getNavigationManager();
|
||||
$navigationManager->clear();
|
||||
$countBefore = count($navigationManager->getAll());
|
||||
require __DIR__ . '/../../../appinfo/app.php';
|
||||
// Test whether the navigation entry got added
|
||||
$this->assertCount($countBefore + 1, $navigationManager->getAll());
|
||||
}
|
||||
|
||||
}
|
87
tests/unit/Controller/CollectionsControllerTest.php
Normal file
87
tests/unit/Controller/CollectionsControllerTest.php
Normal file
|
@ -0,0 +1,87 @@
|
|||
<?php
|
||||
/**
|
||||
* Nextcloud - Tasks
|
||||
*
|
||||
* @author Raimund Schlüßler
|
||||
* @copyright 2019 Raimund Schlüßler <raimund.schluessler@mailbox.org>
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 3 of the License, or any later version.
|
||||
*
|
||||
* This library 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 library. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace OCA\Tasks\Tests\Unit\Controller;
|
||||
|
||||
use OCA\Tasks\Controller\CollectionsController;
|
||||
use OCA\Tasks\Service\CollectionsService;
|
||||
use OCP\IRequest;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
|
||||
class CollectionsControllerTest extends TestCase {
|
||||
|
||||
private $appName;
|
||||
private $collectionsService;
|
||||
private $request;
|
||||
private $controller;
|
||||
|
||||
use \OCA\Tasks\Controller\Response;
|
||||
|
||||
/**
|
||||
* Gets run before each test
|
||||
*/
|
||||
public function setUp(): void {
|
||||
$this->appName = 'tasks';
|
||||
$this->collectionsService = $this->getMockBuilder(CollectionsService::class)
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$this->request = $this->getMockBuilder(IRequest::class)
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$this->controller = new CollectionsController(
|
||||
$this->appName,
|
||||
$this->request,
|
||||
$this->collectionsService
|
||||
);
|
||||
}
|
||||
|
||||
public function testgetCollections() {
|
||||
$return = [[], []];
|
||||
$this->collectionsService->expects($this->once())
|
||||
->method('getAll')
|
||||
->will($this->returnValue($return));
|
||||
|
||||
$expected = $this->generateResponse(function () use ($return) {
|
||||
return ['collections' => $return];
|
||||
});
|
||||
$response = $this->controller->getCollections();
|
||||
$this->assertEquals($expected, $response);
|
||||
}
|
||||
|
||||
public function testSetVisibility() {
|
||||
$this->collectionsService->expects($this->once())
|
||||
->method('setVisibility')
|
||||
->with(
|
||||
'starred',
|
||||
$this->equalTo(0)
|
||||
)
|
||||
->will($this->returnValue(true));
|
||||
|
||||
$expected = $this->generateResponse(function () {
|
||||
return true;
|
||||
});
|
||||
$response = $this->controller->setVisibility('starred', 0);
|
||||
$this->assertEquals($expected, $response);
|
||||
}
|
||||
}
|
87
tests/unit/Controller/SettingsControllerTest.php
Normal file
87
tests/unit/Controller/SettingsControllerTest.php
Normal file
|
@ -0,0 +1,87 @@
|
|||
<?php
|
||||
/**
|
||||
* Nextcloud - Tasks
|
||||
*
|
||||
* @author Raimund Schlüßler
|
||||
* @copyright 2019 Raimund Schlüßler <raimund.schluessler@mailbox.org>
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 3 of the License, or any later version.
|
||||
*
|
||||
* This library 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 library. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace OCA\Tasks\Tests\Unit\Controller;
|
||||
|
||||
use OCA\Tasks\Controller\SettingsController;
|
||||
use OCA\Tasks\Service\SettingsService;
|
||||
use OCP\IRequest;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
|
||||
class SettingsControllerTest extends TestCase {
|
||||
|
||||
private $appName;
|
||||
private $settingsService;
|
||||
private $request;
|
||||
private $controller;
|
||||
|
||||
use \OCA\Tasks\Controller\Response;
|
||||
|
||||
/**
|
||||
* Gets run before each test
|
||||
*/
|
||||
public function setUp(): void {
|
||||
$this->appName = 'tasks';
|
||||
$this->settingsService = $this->getMockBuilder(SettingsService::class)
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$this->request = $this->getMockBuilder(IRequest::class)
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$this->controller = new SettingsController(
|
||||
$this->appName,
|
||||
$this->request,
|
||||
$this->settingsService
|
||||
);
|
||||
}
|
||||
|
||||
public function testGet() {
|
||||
$return = ['sortOrder' => 0];
|
||||
$this->settingsService->expects($this->once())
|
||||
->method('get')
|
||||
->will($this->returnValue($return));
|
||||
|
||||
$expected = $this->generateResponse(function () use ($return) {
|
||||
return ['settings' => $return];
|
||||
});
|
||||
$response = $this->controller->get();
|
||||
$this->assertEquals($expected, $response);
|
||||
}
|
||||
|
||||
public function testSet() {
|
||||
$this->settingsService->expects($this->once())
|
||||
->method('set')
|
||||
->with(
|
||||
'sortOrder',
|
||||
$this->equalTo(0)
|
||||
)
|
||||
->will($this->returnValue(true));
|
||||
|
||||
$expected = $this->generateResponse(function () {
|
||||
return true;
|
||||
});
|
||||
$response = $this->controller->set('sortOrder', 0);
|
||||
$this->assertEquals($expected, $response);
|
||||
}
|
||||
}
|
132
tests/unit/Service/CollectionsServiceTest.php
Normal file
132
tests/unit/Service/CollectionsServiceTest.php
Normal file
|
@ -0,0 +1,132 @@
|
|||
<?php
|
||||
/**
|
||||
* Nextcloud - Tasks
|
||||
*
|
||||
* @author Raimund Schlüßler
|
||||
* @copyright 2018 Raimund Schlüßler <raimund.schluessler@mailbox.org>
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 3 of the License, or any later version.
|
||||
*
|
||||
* This library 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 library. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace OCA\Tasks\Tests\Unit\Service;
|
||||
|
||||
use OCA\Tasks\Service\CollectionsService;
|
||||
use OCP\IConfig;
|
||||
use OCP\IL10N;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
|
||||
class CollectionsServiceTest extends TestCase {
|
||||
|
||||
private $collectionsService;
|
||||
private $settings;
|
||||
private $userId;
|
||||
private $l10n;
|
||||
private $appName;
|
||||
|
||||
/**
|
||||
* Gets run before each test
|
||||
*/
|
||||
protected function setUp(): void {
|
||||
$this->appName = 'tasks';
|
||||
$this->userId = 'admin';
|
||||
$this->settings = $this->getMockBuilder(IConfig::class)
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$this->l10n = $this->createMock(IL10N::class);
|
||||
$this->collectionsService = new CollectionsService(
|
||||
$this->userId,
|
||||
$this->l10n,
|
||||
$this->settings,
|
||||
$this->appName
|
||||
);
|
||||
}
|
||||
|
||||
public function testGetAll() {
|
||||
$return = array(
|
||||
array(
|
||||
'id' => "starred",
|
||||
'displayName' => 'Important',
|
||||
'show' => 2,
|
||||
'icon' => 'icon-task-star'),
|
||||
array(
|
||||
'id' => "today",
|
||||
'displayName' => 'Today',
|
||||
'show' => 2,
|
||||
'icon' => 'icon-calendar'),
|
||||
array(
|
||||
'id' => "week",
|
||||
'displayName' => 'Week',
|
||||
'show' => 2,
|
||||
'icon' => 'icon-calendar'),
|
||||
array(
|
||||
'id' => "all",
|
||||
'displayName' => 'All',
|
||||
'show' => 2,
|
||||
'icon' => 'icon-all'),
|
||||
array(
|
||||
'id' => "current",
|
||||
'displayName' => 'Current',
|
||||
'show' => 2,
|
||||
'icon' => 'icon-current'),
|
||||
array(
|
||||
'id' => "completed",
|
||||
'displayName' => 'Completed',
|
||||
'show' => 2,
|
||||
'icon' => 'icon-checkmark')
|
||||
);
|
||||
|
||||
$map = [
|
||||
['Important', [],'Important'],
|
||||
['Today', [], 'Today'],
|
||||
['Week', [], 'Week'],
|
||||
['All', [], 'All'],
|
||||
['Completed', [], 'Completed'],
|
||||
['Current', [], 'Current']
|
||||
];
|
||||
|
||||
$this->l10n->expects($this->any())
|
||||
->method('t')
|
||||
->will(
|
||||
$this->returnValueMap($map)
|
||||
);
|
||||
|
||||
$result = $this->collectionsService->getAll();
|
||||
|
||||
$this->assertEquals($return, $result);
|
||||
}
|
||||
|
||||
|
||||
public function testSetVisibility() {
|
||||
$return = true;
|
||||
|
||||
$this->settings->expects($this->once())
|
||||
->method('setUserValue')
|
||||
->with(
|
||||
$this->equalTo($this->userId),
|
||||
$this->equalTo($this->appName),
|
||||
'show_starred',
|
||||
0
|
||||
);
|
||||
|
||||
$result = $this->collectionsService->setVisibility('starred', 0);
|
||||
// These lines should not lead to a call of '$this->settings->setUserValue'
|
||||
$this->collectionsService->setVisibility('starred', -1);
|
||||
$this->collectionsService->setVisibility('starred', '3');
|
||||
|
||||
$this->assertEquals($return, $result);
|
||||
}
|
||||
}
|
122
tests/unit/Service/SettingsServiceTest.php
Normal file
122
tests/unit/Service/SettingsServiceTest.php
Normal file
|
@ -0,0 +1,122 @@
|
|||
<?php
|
||||
/**
|
||||
* Nextcloud - Tasks
|
||||
*
|
||||
* @author Raimund Schlüßler
|
||||
* @copyright 2018 Raimund Schlüßler <raimund.schluessler@mailbox.org>
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 3 of the License, or any later version.
|
||||
*
|
||||
* This library 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 library. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace OCA\Tasks\Tests\Unit\Service;
|
||||
|
||||
use OCA\Tasks\Service\SettingsService;
|
||||
use OCP\IConfig;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
|
||||
class SettingsServiceTest extends TestCase {
|
||||
|
||||
private $settingsService;
|
||||
private $settings;
|
||||
private $userId;
|
||||
private $appName;
|
||||
|
||||
/**
|
||||
* Gets run before each test
|
||||
*/
|
||||
protected function setUp(): void {
|
||||
$this->appName = 'tasks';
|
||||
$this->userId = 'admin';
|
||||
$this->settings = $this->getMockBuilder(IConfig::class)
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$this->settingsService = new SettingsService(
|
||||
$this->userId,
|
||||
$this->settings,
|
||||
$this->appName
|
||||
);
|
||||
}
|
||||
|
||||
public function testGet() {
|
||||
$return = [
|
||||
'defaultCalendarId' => 'personal',
|
||||
'showHidden' => 1,
|
||||
'sortOrder' => 'default',
|
||||
'sortDirection' => false,
|
||||
'userID' => $this->userId
|
||||
];
|
||||
|
||||
$map = [
|
||||
[
|
||||
$this->userId,
|
||||
$this->appName,
|
||||
'various_defaultCalendarId',
|
||||
'',
|
||||
'personal'
|
||||
],
|
||||
[
|
||||
$this->userId,
|
||||
$this->appName,
|
||||
'various_showHidden',
|
||||
'',
|
||||
1
|
||||
],
|
||||
[
|
||||
$this->userId,
|
||||
$this->appName,
|
||||
'various_sortOrder',
|
||||
'',
|
||||
'default'
|
||||
],
|
||||
[
|
||||
$this->userId,
|
||||
$this->appName,
|
||||
'various_sortDirection',
|
||||
'',
|
||||
false
|
||||
]
|
||||
];
|
||||
|
||||
$this->settings->expects($this->any())
|
||||
->method('getUserValue')
|
||||
->will(
|
||||
$this->returnValueMap($map)
|
||||
);
|
||||
|
||||
$result = $this->settingsService->get();
|
||||
|
||||
$this->assertEquals($return, $result);
|
||||
}
|
||||
|
||||
|
||||
public function testSet() {
|
||||
$return = true;
|
||||
|
||||
$this->settings->expects($this->once())
|
||||
->method('setUserValue')
|
||||
->with(
|
||||
$this->equalTo($this->userId),
|
||||
$this->equalTo($this->appName),
|
||||
'various_defaultCalendarId',
|
||||
'personal'
|
||||
);
|
||||
|
||||
$result = $this->settingsService->set('defaultCalendarId', 'personal');
|
||||
|
||||
$this->assertEquals($return, $result);
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue