Test against php8

Signed-off-by: Christoph Wurst <christoph@winzerhof-wurst.at>
This commit is contained in:
Christoph Wurst 2021-01-11 14:35:22 +01:00
parent 8fd845fef5
commit 8db55b6710
No known key found for this signature in database
GPG Key ID: CC42AC2A7F0E56D8
14 changed files with 1726 additions and 1090 deletions

View File

@ -11,12 +11,17 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
php-versions: ['7.2', '7.3', '7.4']
php-versions: ['7.3', '7.4']
nextcloud-versions: ['stable20', 'master']
exclude:
include:
- php-versions: '7.2'
nextcloud-versions: 'stable20'
- php-versions: '8.0'
nextcloud-versions: 'master'
name: php${{ matrix.php-versions }} on ${{ matrix.nextcloud-versions }} unit tests
env:
CI: true
XDEBUG_MODE: coverage
steps:
- name: Set up php${{ matrix.php-versions }}
uses: shivammathur/setup-php@master
@ -26,12 +31,20 @@ jobs:
coverage: xdebug
- name: Checkout Nextcloud
run: git clone https://github.com/nextcloud/server.git --recursive --depth 1 -b ${{ matrix.nextcloud-versions }} nextcloud
- name: Run tests
- name: Install Nextcloud
run: php -f nextcloud/occ maintenance:install --database-name oc_autotest --database-user oc_autotest --admin-user admin --admin-pass admin --database sqlite --database-pass=''
- name: Checkout
- name: Checkout the app
uses: actions/checkout@master
with:
path: nextcloud/apps/calendar
- name: Fix php-parser on stable20 incompatibility with phpunit 9.3+
if: ${{ matrix.nextcloud-versions == 'stable20' }}
working-directory: nextcloud/3rdparty
run: composer require nikic/php-parser:4.10
- name: Downgrade phpunit for php7.2
if: ${{ matrix.php-versions == '7.2' }}
working-directory: nextcloud/apps/calendar
run: composer update christophwurst/nextcloud_testing -W
- name: Install dependencies
working-directory: nextcloud/apps/calendar
run: composer install
@ -39,5 +52,6 @@ jobs:
working-directory: nextcloud/apps/calendar
run: composer run test
- name: Upload coverage to Codecov
if: ${{ matrix.nextcloud-versions == 'master' }}
working-directory: nextcloud/apps/calendar
run: curl -s https://codecov.io/bash | bash -s - -t ${{ secrets.CODECOV_TOKEN }} -F php -f clover.unit.xml -Z

2
.gitignore vendored
View File

@ -94,8 +94,10 @@ RCS/*
/.project
.php_cs.cache
.phpunit.result.cache
coverage/
js/public
css/public

View File

@ -1,11 +1,10 @@
{
"require": {
"php": ">=7.2",
"php": "^7.2|^8.0",
"nextcloud/coding-standard": "^0.5.0"
},
"require-dev": {
"christophwurst/nextcloud": "v20.0.4",
"christophwurst/nextcloud_testing": "0.10.0"
"christophwurst/nextcloud_testing": "0.12.1"
},
"scripts": {
"cs:fix": "php-cs-fixer fix",

1924
composer.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -122,7 +122,7 @@ class PublicViewController extends Controller {
$defaultSlotDuration = $this->config->getAppValue($this->appName, 'slotDuration', '00:30:00');
$defaultShowTasks = $this->config->getAppValue($this->appName, 'showTasks', 'yes');
$appVersion = $this->config->getAppValue($this->appName, 'installed_version');
$appVersion = $this->config->getAppValue($this->appName, 'installed_version', null);
$this->initialStateService->provideInitialState($this->appName, 'app_version', $appVersion);
$this->initialStateService->provideInitialState($this->appName, 'event_limit', ($defaultEventLimit === 'yes'));

View File

@ -96,7 +96,7 @@ class ViewController extends Controller {
$defaultSlotDuration = $this->config->getAppValue($this->appName, 'slotDuration', '00:30:00');
$defaultShowTasks = $this->config->getAppValue($this->appName, 'showTasks', 'yes');
$appVersion = $this->config->getAppValue($this->appName, 'installed_version');
$appVersion = $this->config->getAppValue($this->appName, 'installed_version', null);
$eventLimit = $this->config->getUserValue($this->userId, $this->appName, 'eventLimit', $defaultEventLimit) === 'yes';
$firstRun = $this->config->getUserValue($this->userId, $this->appName, 'firstRun', 'yes') === 'yes';
$initialView = $this->getView($this->config->getUserValue($this->userId, $this->appName, 'currentView', $defaultInitialView));

View File

@ -1,28 +1,17 @@
<?xml version="1.0" encoding="utf-8" ?>
<phpunit bootstrap="tests/php/unit/bootstrap.php"
<?xml version="1.0" encoding="utf-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
bootstrap="tests/php/unit/bootstrap.php"
verbose="true"
timeoutForSmallTests="900"
timeoutForMediumTests="900"
timeoutForLargeTests="900"
>
<testsuite name='Calendar app tests'>
<directory suffix='test.php'>./tests/php/unit</directory>
<directory suffix='Test.php'>./tests/php/unit</directory>
</testsuite>
<!-- filters for code coverage -->
<filter>
<whitelist>
<directory suffix=".php">./</directory>
<exclude>
<directory suffix=".php">./appinfo</directory>
<directory suffix=".php">./l10n</directory>
<directory suffix=".php">./templates</directory>
<directory suffix=".php">./tests</directory>
</exclude>
</whitelist>
</filter>
<logging>
<!-- and this is where your report will be written -->
<log type="coverage-clover" target="./clover.unit.xml"/>
</logging>
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/8.5/phpunit.xsd">
<testsuite name="unit">
<directory suffix="Test.php">./tests/php/unit</directory>
</testsuite>
<coverage>
<include>
<directory suffix=".php">./lib</directory>
</include>
<report>
<clover outputFile="./clover.unit.xml"/>
</report>
</coverage>
</phpunit>

View File

@ -27,16 +27,17 @@ use OCP\AppFramework\Http\JSONResponse;
use OCP\Contacts\IManager;
use OCP\IRequest;
use ChristophWurst\Nextcloud\Testing\TestCase;
use PHPUnit\Framework\MockObject\MockObject;
class ContactControllerTest extends TestCase {
/** @var string */
protected $appName;
/** @var IRequest|\PHPUnit_Framework_MockObject_MockObject */
/** @var IRequest|MockObject */
protected $request;
/** @var IManager|\PHPUnit_Framework_MockObject_MockObject */
/** @var IManager|MockObject */
protected $manager;
/** @var ContactController */
@ -69,12 +70,12 @@ class ContactControllerTest extends TestCase {
}
public function testSearchLocation():void {
$this->manager->expects($this->at(0))
$this->manager->expects(self::once())
->method('isEnabled')
->with()
->willReturn(true);
$this->manager->expects($this->at(1))
$this->manager->expects(self::once())
->method('search')
->with('search 123', ['FN', 'ADR'])
->willReturn([
@ -161,12 +162,12 @@ class ContactControllerTest extends TestCase {
}
public function testSearchAttendee():void {
$this->manager->expects($this->at(0))
$this->manager->expects(self::once())
->method('isEnabled')
->with()
->willReturn(true);
$this->manager->expects($this->at(1))
$this->manager->expects(self::once())
->method('search')
->with('search 123', ['FN', 'EMAIL'])
->willReturn([
@ -257,12 +258,12 @@ class ContactControllerTest extends TestCase {
}
public function testSearchPhoto():void {
$this->manager->expects($this->at(0))
$this->manager->expects(self::once())
->method('isEnabled')
->with()
->willReturn(true);
$this->manager->expects($this->at(1))
$this->manager->expects(self::once())
->method('search')
->with('foo3@example.com', ['EMAIL'])
->willReturn([

View File

@ -35,34 +35,35 @@ use OCP\Mail\IEMailTemplate;
use OCP\Mail\IMailer;
use OCP\Mail\IMessage;
use ChristophWurst\Nextcloud\Testing\TestCase;
use PHPUnit\Framework\MockObject\MockObject;
class EmailControllerTest extends TestCase {
/** @var string */
private $appName;
/** @var IRequest|\PHPUnit_Framework_MockObject_MockObject */
/** @var IRequest|MockObject */
private $request;
/** @var IConfig|\PHPUnit_Framework_MockObject_MockObject */
/** @var IConfig|MockObject */
private $config;
/** @var Defaults|\PHPUnit_Framework_MockObject_MockObject */
/** @var Defaults|MockObject */
private $defaults;
/** @var IL10N|\PHPUnit_Framework_MockObject_MockObject */
/** @var IL10N|MockObject */
private $l10n;
/** @var IMailer|\PHPUnit_Framework_MockObject_MockObject */
/** @var IMailer|MockObject */
private $mailer;
/** @var IUserSession|\PHPUnit_Framework_MockObject_MockObject */
/** @var IUserSession|MockObject */
private $userSession;
/** @var IURLGenerator|\PHPUnit_Framework_MockObject_MockObject */
/** @var IURLGenerator|MockObject */
private $urlGenerator;
/** @var IUser|\PHPUnit_Framework_MockObject_MockObject */
/** @var IUser|MockObject */
private $user;
/** @var EmailController */
@ -96,7 +97,7 @@ class EmailControllerTest extends TestCase {
}
public function testSendUserSessionExpired():void {
$this->userSession->expects($this->at(0))
$this->userSession->expects(self::once(0))
->method('getUser')
->with()
->willReturn(null);
@ -116,12 +117,12 @@ class EmailControllerTest extends TestCase {
}
public function testSendInvalidEmailAddress():void {
$this->userSession->expects($this->at(0))
$this->userSession->expects(self::once())
->method('getUser')
->with()
->willReturn($this->user);
$this->mailer->expects($this->at(0))
$this->mailer->expects(self::once())
->method('validateMailAddress')
->with('foo@bar.com')
->willReturn(false);
@ -139,31 +140,28 @@ class EmailControllerTest extends TestCase {
}
public function testSendWithMailerError() {
$this->userSession->expects($this->at(0))
$this->userSession->expects(self::once())
->method('getUser')
->with()
->willReturn($this->user);
$this->mailer->expects($this->at(0))
$this->mailer->expects(self::once())
->method('validateMailAddress')
->with('foo@bar.com')
->willReturn(true);
$this->config->expects($this->at(0))
$this->config->expects(self::exactly(2))
->method('getSystemValue')
->with('mail_domain', 'domain.org')
->willReturn('testdomain.org');
$this->config->expects($this->at(1))
->method('getSystemValue')
->with('mail_from_address', 'nextcloud')
->willReturn('nextcloud123');
->willReturnMap([
['mail_domain', 'domain.org', 'testdomain.org'],
['mail_from_address', 'nextcloud', 'nextcloud123'],
]);
$this->defaults->expects($this->at(0))
$this->defaults->expects(self::once())
->method('getName')
->with()
->willReturn('Example Cloud Inc.');
$this->urlGenerator->expects($this->at(0))
$this->urlGenerator->expects(self::once())
->method('linkToRouteAbsolute')
->with('calendar.publicView.public_index_with_branding', [
'token' => 'token123'
@ -171,54 +169,50 @@ class EmailControllerTest extends TestCase {
->willReturn('http://publicURL123');
$template = $this->createMock(IEMailTemplate::class);
$template->expects($this->at(0))
$template->expects(self::once())
->method('setSubject')
->with('TRANSLATED: User Displayname 123 has published the calendar »calendar name 456«')
->willReturn($template);
$template->expects($this->at(1))
$template->expects(self::once())
->method('addHeader')
->with()
->willReturn($template);
$template->expects($this->at(2))
$template->expects(self::once())
->method('addHeading')
->with('TRANSLATED: User Displayname 123 has published the calendar »calendar name 456«')
->willReturn($template);
$template->expects($this->at(3))
$template->expects(self::exactly(3))
->method('addBodyText')
->with('TRANSLATED: Hello,')
->willReturn($template);
$template->expects($this->at(4))
->method('addBodyText')
->with('TRANSLATED: We wanted to inform you that User Displayname 123 has published the calendar »calendar name 456«.')
->willReturn($template);
$template->expects($this->at(5))
->withConsecutive(
['TRANSLATED: Hello,'],
['TRANSLATED: We wanted to inform you that User Displayname 123 has published the calendar »calendar name 456«.'],
['TRANSLATED: Cheers!']
)
->willReturnSelf();
$template->expects(self::once())
->method('addBodyButton')
->with('TRANSLATED: Open »calendar name 456«', 'http://publicURL123')
->willReturn($template);
$template->expects($this->at(6))
->method('addBodyText')
->with('TRANSLATED: Cheers!')
->willReturn($template);
$template->expects($this->at(7))
->willReturnSelf();
$template->expects(self::once())
->method('addFooter')
->with()
->willReturn($template);
->willReturnSelf();
$message = $this->createMock(IMessage::class);
$message->expects($this->at(0))
$message->expects(self::once())
->method('setFrom')
->with(['nextcloud123@testdomain.org' => 'Example Cloud Inc.'])
->willReturn($message);
$message->expects($this->at(1))
$message->expects(self::once())
->method('setTo')
->with(['foo@bar.com' => 'foo@bar.com'])
->willReturn($message);
$message->expects($this->at(2))
$message->expects(self::once())
->method('useTemplate')
->with($template)
->willReturn($message);
$this->mailer->expects($this->at(1))
$this->mailer->expects(self::once())
->method('createEMailTemplate')
->with('calendar.PublicShareNotification', [
'displayname' => 'User Displayname 123',
@ -226,11 +220,11 @@ class EmailControllerTest extends TestCase {
'calendar_url' => 'http://publicURL123',
])
->willReturn($template);
$this->mailer->expects($this->at(2))
$this->mailer->expects(self::once())
->method('createMessage')
->with()
->willReturn($message);
$this->mailer->expects($this->at(3))
$this->mailer->expects(self::once())
->method('send')
->with($message)
->willThrowException(new \Exception('123'));
@ -245,31 +239,29 @@ class EmailControllerTest extends TestCase {
}
public function testSendMailerSuccess() {
$this->userSession->expects($this->at(0))
$this->userSession->expects(self::once())
->method('getUser')
->with()
->willReturn($this->user);
$this->mailer->expects($this->at(0))
$this->mailer->expects(self::once())
->method('validateMailAddress')
->with('foo@bar.com')
->willReturn(true);
$this->config->expects($this->at(0))
$this->config->expects(self::exactly(2))
->method('getSystemValue')
->with('mail_domain', 'domain.org')
->willReturn('testdomain.org');
$this->config->expects($this->at(1))
->method('getSystemValue')
->with('mail_from_address', 'nextcloud')
->willReturn('nextcloud123');
->willReturnMap([
['mail_domain', 'domain.org', 'testdomain.org'],
['mail_from_address', 'nextcloud', 'nextcloud123'],
]);
$this->defaults->expects($this->at(0))
$this->defaults->expects(self::once())
->method('getName')
->with()
->willReturn('Example Cloud Inc.');
$this->urlGenerator->expects($this->at(0))
$this->urlGenerator->expects(self::once())
->method('linkToRouteAbsolute')
->with('calendar.publicView.public_index_with_branding', [
'token' => 'token123'
@ -277,54 +269,50 @@ class EmailControllerTest extends TestCase {
->willReturn('http://publicURL123');
$template = $this->createMock(IEMailTemplate::class);
$template->expects($this->at(0))
$template->expects(self::once())
->method('setSubject')
->with('TRANSLATED: User Displayname 123 has published the calendar »calendar name 456«')
->willReturn($template);
$template->expects($this->at(1))
$template->expects(self::once())
->method('addHeader')
->with()
->willReturn($template);
$template->expects($this->at(2))
$template->expects(self::once())
->method('addHeading')
->with('TRANSLATED: User Displayname 123 has published the calendar »calendar name 456«')
->willReturn($template);
$template->expects($this->at(3))
$template->expects(self::exactly(3))
->method('addBodyText')
->with('TRANSLATED: Hello,')
->willReturn($template);
$template->expects($this->at(4))
->method('addBodyText')
->with('TRANSLATED: We wanted to inform you that User Displayname 123 has published the calendar »calendar name 456«.')
->willReturn($template);
$template->expects($this->at(5))
->withConsecutive(
['TRANSLATED: Hello,'],
['TRANSLATED: We wanted to inform you that User Displayname 123 has published the calendar »calendar name 456«.'],
['TRANSLATED: Cheers!']
)
->willReturnSelf();
$template->expects(self::once())
->method('addBodyButton')
->with('TRANSLATED: Open »calendar name 456«', 'http://publicURL123')
->willReturn($template);
$template->expects($this->at(6))
->method('addBodyText')
->with('TRANSLATED: Cheers!')
->willReturn($template);
$template->expects($this->at(7))
$template->expects(self::once())
->method('addFooter')
->with()
->willReturn($template);
$message = $this->createMock(IMessage::class);
$message->expects($this->at(0))
$message->expects(self::once())
->method('setFrom')
->with(['nextcloud123@testdomain.org' => 'Example Cloud Inc.'])
->willReturn($message);
$message->expects($this->at(1))
$message->expects(self::once())
->method('setTo')
->with(['foo@bar.com' => 'foo@bar.com'])
->willReturn($message);
$message->expects($this->at(2))
$message->expects(self::once())
->method('useTemplate')
->with($template)
->willReturn($message);
$this->mailer->expects($this->at(1))
$this->mailer->expects(self::once())
->method('createEMailTemplate')
->with('calendar.PublicShareNotification', [
'displayname' => 'User Displayname 123',
@ -332,11 +320,11 @@ class EmailControllerTest extends TestCase {
'calendar_url' => 'http://publicURL123',
])
->willReturn($template);
$this->mailer->expects($this->at(2))
$this->mailer->expects(self::once())
->method('createMessage')
->with()
->willReturn($message);
$this->mailer->expects($this->at(3))
$this->mailer->expects(self::once())
->method('send')
->with($message);

View File

@ -29,22 +29,23 @@ use OCP\IInitialStateService;
use OCP\IRequest;
use OCP\IURLGenerator;
use ChristophWurst\Nextcloud\Testing\TestCase;
use PHPUnit\Framework\MockObject\MockObject;
class PublicViewControllerTest extends TestCase {
/** @var string */
private $appName;
/** @var IRequest|\PHPUnit_Framework_MockObject_MockObject */
/** @var IRequest|MockObject */
private $request;
/** @var IConfig|\PHPUnit_Framework_MockObject_MockObject */
/** @var IConfig|MockObject */
private $config;
/** @var IInitialStateService|\PHPUnit_Framework_MockObject_MockObject */
/** @var IInitialStateService|MockObject */
private $initialStateService;
/** @var IURLGenerator|\PHPUnit_Framework_MockObject_MockObject */
/** @var IURLGenerator|MockObject */
private $urlGenerator;
/** @var ViewController */
@ -62,101 +63,58 @@ class PublicViewControllerTest extends TestCase {
}
public function testPublicIndexWithBranding():void {
$this->config->expects($this->at(0))
$this->config->expects(self::exactly(9))
->method('getAppValue')
->with('calendar', 'eventLimit', 'yes')
->willReturn('no');
$this->config->expects($this->at(1))
->method('getAppValue')
->with('calendar', 'currentView', 'dayGridMonth')
->willReturn('defaultCurrentView');
$this->config->expects($this->at(2))
->method('getAppValue')
->with('calendar', 'showWeekends', 'yes')
->willReturn('no');
$this->config->expects($this->at(3))
->method('getAppValue')
->with('calendar', 'showWeekNr', 'no')
->willReturn('yes');
$this->config->expects($this->at(4))
->method('getAppValue')
->with('calendar', 'skipPopover', 'yes')
->willReturn('yes');
$this->config->expects($this->at(5))
->method('getAppValue')
->with('calendar', 'timezone', 'automatic')
->willReturn('defaultTimezone');
$this->config->expects($this->at(6))
->method('getAppValue')
->with('calendar', 'slotDuration', '00:30:00')
->willReturn('defaultSlotDuration');
$this->config->expects($this->at(7))
->method('getAppValue')
->with('calendar', 'showTasks')
->willReturn('yes');
$this->config->expects($this->at(8))
->method('getAppValue')
->with('calendar', 'installed_version')
->willReturn('1.0.0');
->willReturnMap([
['calendar', 'eventLimit', 'yes', 'no'],
['calendar', 'currentView', 'dayGridMonth', 'defaultCurrentView'],
['calendar', 'showWeekends', 'yes', 'no'],
['calendar', 'showWeekNr', 'no', 'yes'],
['calendar', 'skipPopover', 'yes', 'yes'],
['calendar', 'timezone', 'automatic', 'defaultTimezone'],
['calendar', 'slotDuration', '00:30:00', 'defaultSlotDuration'],
['calendar', 'showTasks', 'yes', 'yes'],
['calendar', 'installed_version', null, '1.0.0']
]);
$this->request->expects($this->at(0))
$this->request->expects(self::once())
->method('getServerProtocol')
->with()
->willReturn('protocol');
$this->request->expects($this->at(1))
$this->request->expects(self::once())
->method('getServerHost')
->with()
->willReturn('host123');
$this->request->expects($this->at(2))
$this->request->expects(self::once())
->method('getRequestUri')
->with()
->willReturn('/456');
$this->urlGenerator->expects($this->at(0))
$this->urlGenerator->expects(self::once())
->method('imagePath')
->with('core', 'favicon-touch.png')
->willReturn('imagePath456');
$this->urlGenerator->expects($this->at(1))
$this->urlGenerator->expects(self::once())
->method('getAbsoluteURL')
->with('imagePath456')
->willReturn('absoluteImagePath456');
$this->initialStateService->expects($this->at(0))
$this->initialStateService->expects(self::exactly(12))
->method('provideInitialState')
->with('calendar', 'app_version', '1.0.0');
$this->initialStateService->expects($this->at(1))
->method('provideInitialState')
->with('calendar', 'event_limit', false);
$this->initialStateService->expects($this->at(2))
->method('provideInitialState')
->with('calendar', 'first_run', false);
$this->initialStateService->expects($this->at(3))
->method('provideInitialState')
->with('calendar', 'initial_view', 'defaultCurrentView');
$this->initialStateService->expects($this->at(4))
->method('provideInitialState')
->with('calendar', 'show_weekends', false);
$this->initialStateService->expects($this->at(5))
->method('provideInitialState')
->with('calendar', 'show_week_numbers', true);
$this->initialStateService->expects($this->at(6))
->method('provideInitialState')
->with('calendar', 'skip_popover', true);
$this->initialStateService->expects($this->at(7))
->method('provideInitialState')
->with('calendar', 'talk_enabled', false);
$this->initialStateService->expects($this->at(8))
->method('provideInitialState')
->with('calendar', 'timezone', 'defaultTimezone');
$this->initialStateService->expects($this->at(9))
->method('provideInitialState')
->with('calendar', 'slot_duration', 'defaultSlotDuration');
$this->initialStateService->expects($this->at(10))
->method('provideInitialState')
->with('calendar', 'show_tasks', true);
$this->initialStateService->expects($this->at(11))
->method('provideInitialState')
->with('calendar', 'tasks_enabled', false);
->withConsecutive(
['calendar', 'app_version', '1.0.0'],
['calendar', 'event_limit', false],
['calendar', 'first_run', false],
['calendar', 'initial_view', 'defaultCurrentView'],
['calendar', 'show_weekends', false],
['calendar', 'show_week_numbers', true],
['calendar', 'skip_popover', true],
['calendar', 'talk_enabled', false],
['calendar', 'timezone', 'defaultTimezone'],
['calendar', 'slot_duration', 'defaultSlotDuration'],
['calendar', 'show_tasks', true],
['calendar', 'tasks_enabled', false]
);
$response = $this->controller->publicIndexWithBranding('');
@ -170,101 +128,57 @@ class PublicViewControllerTest extends TestCase {
}
public function testPublicIndexForEmbedding():void {
$this->config->expects($this->at(0))
$this->config->expects(self::any())
->method('getAppValue')
->with('calendar', 'eventLimit', 'yes')
->willReturn('yes');
$this->config->expects($this->at(1))
->method('getAppValue')
->with('calendar', 'currentView', 'dayGridMonth')
->willReturn('defaultCurrentView');
$this->config->expects($this->at(2))
->method('getAppValue')
->with('calendar', 'showWeekends', 'yes')
->willReturn('no');
$this->config->expects($this->at(3))
->method('getAppValue')
->with('calendar', 'showWeekNr', 'no')
->willReturn('yes');
$this->config->expects($this->at(4))
->method('getAppValue')
->with('calendar', 'skipPopover', 'yes')
->willReturn('yes');
$this->config->expects($this->at(5))
->method('getAppValue')
->with('calendar', 'timezone', 'automatic')
->willReturn('defaultTimezone');
$this->config->expects($this->at(6))
->method('getAppValue')
->with('calendar', 'slotDuration', '00:30:00')
->willReturn('defaultSlotDuration');
$this->config->expects($this->at(7))
->method('getAppValue')
->with('calendar', 'showTasks', 'yes')
->willReturn('defaultShowTasks');
$this->config->expects($this->at(8))
->method('getAppValue')
->with('calendar', 'installed_version')
->willReturn('1.0.0');
$this->request->expects($this->at(0))
->willReturnMap([
['calendar', 'eventLimit', 'yes', 'yes'],
['calendar', 'currentView', 'dayGridMonth', 'defaultCurrentView'],
['calendar', 'showWeekends', 'yes', 'no'],
['calendar', 'showWeekNr', 'no', 'yes'],
['calendar', 'skipPopover', 'yes', 'yes'],
['calendar', 'timezone', 'automatic', 'defaultTimezone'],
['calendar', 'slotDuration', '00:30:00', 'defaultSlotDuration'],
['calendar', 'showTasks', 'yes', 'defaultShowTasks'],
['calendar', 'installed_version', null, '1.0.0']
]);
$this->request->expects(self::once())
->method('getServerProtocol')
->with()
->willReturn('protocol');
$this->request->expects($this->at(1))
$this->request->expects(self::once())
->method('getServerHost')
->with()
->willReturn('host123');
$this->request->expects($this->at(2))
$this->request->expects(self::once())
->method('getRequestUri')
->with()
->willReturn('/456');
$this->urlGenerator->expects($this->at(0))
$this->urlGenerator->expects(self::once())
->method('imagePath')
->with('core', 'favicon-touch.png')
->willReturn('imagePath456');
$this->urlGenerator->expects($this->at(1))
$this->urlGenerator->expects(self::once())
->method('getAbsoluteURL')
->with('imagePath456')
->willReturn('absoluteImagePath456');
$this->initialStateService->expects($this->at(0))
$this->initialStateService->expects(self::exactly(12))
->method('provideInitialState')
->with('calendar', 'app_version', '1.0.0');
$this->initialStateService->expects($this->at(1))
->method('provideInitialState')
->with('calendar', 'event_limit', true);
$this->initialStateService->expects($this->at(2))
->method('provideInitialState')
->with('calendar', 'first_run', false);
$this->initialStateService->expects($this->at(3))
->method('provideInitialState')
->with('calendar', 'initial_view', 'defaultCurrentView');
$this->initialStateService->expects($this->at(4))
->method('provideInitialState')
->with('calendar', 'show_weekends', false);
$this->initialStateService->expects($this->at(5))
->method('provideInitialState')
->with('calendar', 'show_week_numbers', true);
$this->initialStateService->expects($this->at(6))
->method('provideInitialState')
->with('calendar', 'skip_popover', true);
$this->initialStateService->expects($this->at(7))
->method('provideInitialState')
->with('calendar', 'talk_enabled', false);
$this->initialStateService->expects($this->at(8))
->method('provideInitialState')
->with('calendar', 'timezone', 'defaultTimezone');
$this->initialStateService->expects($this->at(9))
->method('provideInitialState')
->with('calendar', 'slot_duration', 'defaultSlotDuration');
$this->initialStateService->expects($this->at(10))
->method('provideInitialState')
->with('calendar', 'show_tasks', false);
$this->initialStateService->expects($this->at(11))
->method('provideInitialState')
->with('calendar', 'tasks_enabled', false);
->withConsecutive(
['calendar', 'app_version', '1.0.0'],
['calendar', 'event_limit', true],
['calendar', 'first_run', false],
['calendar', 'initial_view', 'defaultCurrentView'],
['calendar', 'show_weekends', false],
['calendar', 'show_week_numbers', true],
['calendar', 'skip_popover', true],
['calendar', 'talk_enabled', false],
['calendar', 'timezone', 'defaultTimezone'],
['calendar', 'slot_duration', 'defaultSlotDuration'],
['calendar', 'show_tasks', false],
['calendar', 'tasks_enabled', false]
);
$response = $this->controller->publicIndexForEmbedding('');

View File

@ -26,16 +26,17 @@ namespace OCA\Calendar\Controller;
use OCP\IConfig;
use OCP\IRequest;
use ChristophWurst\Nextcloud\Testing\TestCase;
use PHPUnit\Framework\MockObject\MockObject;
class SettingsControllerTest extends TestCase {
/** @var string */
private $appName;
/** @var IRequest|\PHPUnit_Framework_MockObject_MockObject */
/** @var IRequest|MockObject */
private $request;
/** @var IConfig|\PHPUnit_Framework_MockObject_MockObject */
/** @var IConfig|MockObject */
private $config;
/** @var string */

View File

@ -21,6 +21,7 @@ declare(strict_types=1);
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
*
*/
namespace OCA\Calendar\Controller;
use OCP\App\IAppManager;
@ -29,22 +30,23 @@ use OCP\IConfig;
use OCP\IInitialStateService;
use OCP\IRequest;
use ChristophWurst\Nextcloud\Testing\TestCase;
use PHPUnit\Framework\MockObject\MockObject;
class ViewControllerTest extends TestCase {
/** @var string */
private $appName;
/** @var IRequest|\PHPUnit_Framework_MockObject_MockObject */
/** @var IRequest|MockObject */
private $request;
/** @var IAppManager|\PHPUnit_Framework_MockObject_MockObject */
/** @var IAppManager|MockObject */
private $appManager;
/** @var IConfig|\PHPUnit_Framework_MockObject_MockObject */
/** @var IConfig|MockObject */
private $config;
/** @var IInitialStateService|\PHPUnit_Framework_MockObject_MockObject */
/** @var IInitialStateService|MockObject */
private $initialStateService;
/** @var string */
@ -53,7 +55,7 @@ class ViewControllerTest extends TestCase {
/** @var ViewController */
private $controller;
protected function setUp():void {
protected function setUp(): void {
$this->appName = 'calendar';
$this->request = $this->createMock(IRequest::class);
$this->appManager = $this->createMock(IAppManager::class);
@ -65,124 +67,56 @@ class ViewControllerTest extends TestCase {
$this->config, $this->initialStateService, $this->appManager, $this->userId);
}
public function testIndex():void {
$this->config->expects($this->at(0))
public function testIndex(): void {
$this->config
->method('getAppValue')
->with('calendar', 'eventLimit', 'yes')
->willReturn('defaultEventLimit');
$this->config->expects($this->at(1))
->method('getAppValue')
->with('calendar', 'currentView', 'dayGridMonth')
->willReturn('defaultCurrentView');
$this->config->expects($this->at(2))
->method('getAppValue')
->with('calendar', 'showWeekends', 'yes')
->willReturn('defaultShowWeekends');
$this->config->expects($this->at(3))
->method('getAppValue')
->with('calendar', 'showWeekNr', 'no')
->willReturn('defaultShowWeekNr');
$this->config->expects($this->at(4))
->method('getAppValue')
->with('calendar', 'skipPopover', 'no')
->willReturn('defaultSkipPopover');
$this->config->expects($this->at(5))
->method('getAppValue')
->with('calendar', 'timezone', 'automatic')
->willReturn('defaultTimezone');
$this->config->expects($this->at(6))
->method('getAppValue')
->with('calendar', 'slotDuration', '00:30:00')
->willReturn('defaultSlotDuration');
$this->config->expects($this->at(7))
->method('getAppValue')
->with('calendar', 'showTasks', 'yes')
->willReturn('defaultShowTasks');
$this->config->expects($this->at(8))
->method('getAppValue')
->with('calendar', 'installed_version')
->willReturn('1.0.0');
$this->config->expects($this->at(9))
->willReturnMap([
['calendar', 'eventLimit', 'yes', 'defaultEventLimit'],
['calendar', 'currentView', 'dayGridMonth', 'defaultCurrentView'],
['calendar', 'showWeekends', 'yes', 'defaultShowWeekends'],
['calendar', 'showWeekNr', 'no', 'defaultShowWeekNr'],
['calendar', 'skipPopover', 'no', 'defaultSkipPopover'],
['calendar', 'timezone', 'automatic', 'defaultTimezone'],
['calendar', 'slotDuration', '00:30:00', 'defaultSlotDuration'],
['calendar', 'showTasks', 'yes', 'defaultShowTasks'],
['calendar', 'installed_version', null, '1.0.0'],
]);
$this->config
->method('getUserValue')
->with('user123', 'calendar', 'eventLimit', 'defaultEventLimit')
->willReturn('yes');
$this->config->expects($this->at(10))
->method('getUserValue')
->with('user123', 'calendar', 'firstRun', 'yes')
->willReturn('yes');
$this->config->expects($this->at(11))
->method('getUserValue')
->with('user123', 'calendar', 'currentView', 'defaultCurrentView')
->willReturn('timeGridWeek');
$this->config->expects($this->at(12))
->method('getUserValue')
->with('user123', 'calendar', 'showWeekends', 'defaultShowWeekends')
->willReturn('yes');
$this->config->expects($this->at(13))
->method('getUserValue')
->with('user123', 'calendar', 'showWeekNr', 'defaultShowWeekNr')
->willReturn('yes');
$this->config->expects($this->at(14))
->method('getUserValue')
->with('user123', 'calendar', 'skipPopover', 'defaultSkipPopover')
->willReturn('yes');
$this->config->expects($this->at(15))
->method('getUserValue')
->with('user123', 'calendar', 'timezone', 'defaultTimezone')
->willReturn('Europe/Berlin');
$this->config->expects($this->at(16))
->method('getUserValue')
->with('user123', 'calendar', 'slotDuration', 'defaultSlotDuration')
->willReturn('00:15:00');
$this->config->expects($this->at(17))
->method('getUserValue')
->with('user123', 'calendar', 'showTasks', 'defaultShowTasks')
->willReturn('00:15:00');
$this->appManager->expects($this->at(0))
->willReturnMap([
['user123', 'calendar', 'eventLimit', 'defaultEventLimit', 'yes'],
['user123', 'calendar', 'firstRun', 'yes', 'yes'],
['user123', 'calendar', 'currentView', 'defaultCurrentView', 'timeGridWeek'],
['user123', 'calendar', 'showWeekends', 'defaultShowWeekends', 'yes'],
['user123', 'calendar', 'showWeekNr', 'defaultShowWeekNr', 'yes'],
['user123', 'calendar', 'skipPopover', 'defaultSkipPopover', 'yes'],
['user123', 'calendar', 'timezone', 'defaultTimezone', 'Europe/Berlin'],
['user123', 'calendar', 'slotDuration', 'defaultSlotDuration', '00:15:00'],
['user123', 'calendar', 'showTasks', 'defaultShowTasks', '00:15:00'],
]);
$this->appManager
->method('isEnabledForUser')
->with('spreed')
->willReturn(true);
$this->appManager->expects($this->at(1))
->method('isEnabledForUser')
->with('tasks')
->willReturn(true);
->willReturnMap([
['spreed', null, true],
['tasks', null, true]
]);
$this->initialStateService->expects($this->at(0))
$this->initialStateService
->method('provideInitialState')
->with('calendar', 'app_version', '1.0.0');
$this->initialStateService->expects($this->at(1))
->method('provideInitialState')
->with('calendar', 'event_limit', true);
$this->initialStateService->expects($this->at(2))
->method('provideInitialState')
->with('calendar', 'first_run', true);
$this->initialStateService->expects($this->at(3))
->method('provideInitialState')
->with('calendar', 'initial_view', 'timeGridWeek');
$this->initialStateService->expects($this->at(4))
->method('provideInitialState')
->with('calendar', 'show_weekends', true);
$this->initialStateService->expects($this->at(5))
->method('provideInitialState')
->with('calendar', 'show_week_numbers', true);
$this->initialStateService->expects($this->at(6))
->method('provideInitialState')
->with('calendar', 'skip_popover', true);
$this->initialStateService->expects($this->at(7))
->method('provideInitialState')
->with('calendar', 'talk_enabled', true);
$this->initialStateService->expects($this->at(8))
->method('provideInitialState')
->with('calendar', 'timezone', 'Europe/Berlin');
$this->initialStateService->expects($this->at(9))
->method('provideInitialState')
->with('calendar', 'slot_duration', '00:15:00');
$this->initialStateService->expects($this->at(10))
->method('provideInitialState')
->with('calendar', 'show_tasks', false);
$this->initialStateService->expects($this->at(11))
->method('provideInitialState')
->with('calendar', 'tasks_enabled', true);
->withConsecutive(
['calendar', 'app_version', '1.0.0'],
['calendar', 'event_limit', true],
['calendar', 'first_run', true],
['calendar', 'initial_view', 'timeGridWeek'],
['calendar', 'show_weekends', true],
['calendar', 'show_week_numbers', true],
['calendar', 'skip_popover', true],
['calendar', 'talk_enabled', true],
['calendar', 'timezone', 'Europe/Berlin'],
['calendar', 'slot_duration', '00:15:00'],
['calendar', 'show_tasks', false],
['calendar', 'tasks_enabled', true]
);
$response = $this->controller->index();
@ -198,124 +132,56 @@ class ViewControllerTest extends TestCase {
* @param string $savedView
* @param string $expectedView
*/
public function testIndexViewFix(string $savedView, string $expectedView):void {
$this->config->expects($this->at(0))
public function testIndexViewFix(string $savedView, string $expectedView): void {
$this->config
->method('getAppValue')
->with('calendar', 'eventLimit', 'yes')
->willReturn('defaultEventLimit');
$this->config->expects($this->at(1))
->method('getAppValue')
->with('calendar', 'currentView', 'dayGridMonth')
->willReturn('defaultCurrentView');
$this->config->expects($this->at(2))
->method('getAppValue')
->with('calendar', 'showWeekends', 'yes')
->willReturn('defaultShowWeekends');
$this->config->expects($this->at(3))
->method('getAppValue')
->with('calendar', 'showWeekNr', 'no')
->willReturn('defaultShowWeekNr');
$this->config->expects($this->at(4))
->method('getAppValue')
->with('calendar', 'skipPopover', 'no')
->willReturn('defaultSkipPopover');
$this->config->expects($this->at(5))
->method('getAppValue')
->with('calendar', 'timezone', 'automatic')
->willReturn('defaultTimezone');
$this->config->expects($this->at(6))
->method('getAppValue')
->with('calendar', 'slotDuration', '00:30:00')
->willReturn('defaultSlotDuration');
$this->config->expects($this->at(7))
->method('getAppValue')
->with('calendar', 'showTasks', 'yes')
->willReturn('defaultShowTasks');
$this->config->expects($this->at(8))
->method('getAppValue')
->with('calendar', 'installed_version')
->willReturn('1.0.0');
$this->config->expects($this->at(9))
->willReturnMap([
['calendar', 'eventLimit', 'yes', 'defaultEventLimit'],
['calendar', 'currentView', 'dayGridMonth', 'defaultCurrentView'],
['calendar', 'showWeekends', 'yes', 'defaultShowWeekends'],
['calendar', 'showWeekNr', 'no', 'defaultShowWeekNr'],
['calendar', 'skipPopover', 'no', 'defaultSkipPopover'],
['calendar', 'timezone', 'automatic', 'defaultTimezone'],
['calendar', 'slotDuration', '00:30:00', 'defaultSlotDuration'],
['calendar', 'showTasks', 'yes', 'defaultShowTasks'],
['calendar', 'installed_version', null, '1.0.0'],
]);
$this->config
->method('getUserValue')
->with('user123', 'calendar', 'eventLimit', 'defaultEventLimit')
->willReturn('yes');
$this->config->expects($this->at(10))
->method('getUserValue')
->with('user123', 'calendar', 'firstRun', 'yes')
->willReturn('yes');
$this->config->expects($this->at(11))
->method('getUserValue')
->with('user123', 'calendar', 'currentView', 'defaultCurrentView')
->willReturn($savedView);
$this->config->expects($this->at(12))
->method('getUserValue')
->with('user123', 'calendar', 'showWeekends', 'defaultShowWeekends')
->willReturn('yes');
$this->config->expects($this->at(13))
->method('getUserValue')
->with('user123', 'calendar', 'showWeekNr', 'defaultShowWeekNr')
->willReturn('yes');
$this->config->expects($this->at(14))
->method('getUserValue')
->with('user123', 'calendar', 'skipPopover', 'defaultSkipPopover')
->willReturn('yes');
$this->config->expects($this->at(15))
->method('getUserValue')
->with('user123', 'calendar', 'timezone', 'defaultTimezone')
->willReturn('Europe/Berlin');
$this->config->expects($this->at(16))
->method('getUserValue')
->with('user123', 'calendar', 'slotDuration', 'defaultSlotDuration')
->willReturn('00:15:00');
$this->config->expects($this->at(17))
->method('getUserValue')
->with('user123', 'calendar', 'showTasks', 'defaultShowTasks')
->willReturn('00:15:00');
$this->appManager->expects($this->at(0))
->willReturnMap([
['user123', 'calendar', 'eventLimit', 'defaultEventLimit', 'yes'],
['user123', 'calendar', 'firstRun', 'yes', 'yes'],
['user123', 'calendar', 'currentView', 'defaultCurrentView', $savedView],
['user123', 'calendar', 'showWeekends', 'defaultShowWeekends', 'yes'],
['user123', 'calendar', 'showWeekNr', 'defaultShowWeekNr', 'yes'],
['user123', 'calendar', 'skipPopover', 'defaultSkipPopover', 'yes'],
['user123', 'calendar', 'timezone', 'defaultTimezone', 'Europe/Berlin'],
['user123', 'calendar', 'slotDuration', 'defaultSlotDuration', '00:15:00'],
['user123', 'calendar', 'showTasks', 'defaultShowTasks', '00:15:00'],
]);
$this->appManager
->method('isEnabledForUser')
->with('spreed')
->willReturn(true);
$this->appManager->expects($this->at(1))
->method('isEnabledForUser')
->with('tasks')
->willReturn(false);
->willReturnMap([
['spreed', null, true],
['tasks', null, false]
]);
$this->initialStateService->expects($this->at(0))
$this->initialStateService
->method('provideInitialState')
->with('calendar', 'app_version', '1.0.0');
$this->initialStateService->expects($this->at(1))
->method('provideInitialState')
->with('calendar', 'event_limit', true);
$this->initialStateService->expects($this->at(2))
->method('provideInitialState')
->with('calendar', 'first_run', true);
$this->initialStateService->expects($this->at(3))
->method('provideInitialState')
->with('calendar', 'initial_view', $expectedView);
$this->initialStateService->expects($this->at(4))
->method('provideInitialState')
->with('calendar', 'show_weekends', true);
$this->initialStateService->expects($this->at(5))
->method('provideInitialState')
->with('calendar', 'show_week_numbers', true);
$this->initialStateService->expects($this->at(6))
->method('provideInitialState')
->with('calendar', 'skip_popover', true);
$this->initialStateService->expects($this->at(7))
->method('provideInitialState')
->with('calendar', 'talk_enabled', true);
$this->initialStateService->expects($this->at(8))
->method('provideInitialState')
->with('calendar', 'timezone', 'Europe/Berlin');
$this->initialStateService->expects($this->at(9))
->method('provideInitialState')
->with('calendar', 'slot_duration', '00:15:00');
$this->initialStateService->expects($this->at(10))
->method('provideInitialState')
->with('calendar', 'show_tasks', false);
$this->initialStateService->expects($this->at(11))
->method('provideInitialState')
->with('calendar', 'tasks_enabled', false);
->withConsecutive(
['calendar', 'app_version', '1.0.0'],
['calendar', 'event_limit', true],
['calendar', 'first_run', true],
['calendar', 'initial_view', $expectedView],
['calendar', 'show_weekends', true],
['calendar', 'show_week_numbers', true],
['calendar', 'skip_popover', true],
['calendar', 'talk_enabled', true],
['calendar', 'timezone', 'Europe/Berlin'],
['calendar', 'slot_duration', '00:15:00'],
['calendar', 'show_tasks', false],
['calendar', 'tasks_enabled', false]
);
$response = $this->controller->index();

View File

@ -94,57 +94,26 @@ class CurrentViewNameRepairStepTest extends TestCase {
return true;
}));
$this->config->expects($this->at(0))
$this->config
->method('getUserValue')
->with('user1', 'calendar', 'currentView', null)
->willReturn('agendaDay');
$this->config->expects($this->at(1))
->willReturnMap([
['user1', 'calendar', 'currentView', null, 'agendaDay'],
['user2', 'calendar', 'currentView', null, 'agendaWeek'],
['user3', 'calendar', 'currentView', null, 'month'],
['user4', 'calendar', 'currentView', null, 'otherView'],
['user5', 'calendar', 'currentView', null, null],
['user7', 'calendar', 'currentView', null, 'timeGridWeek'],
]);
$this->config
->method('setUserValue')
->with('user1', 'calendar', 'currentView', 'timeGridDay');
$this->config->expects($this->at(2))
->method('getUserValue')
->with('user2', 'calendar', 'currentView', null)
->willReturn('agendaWeek');
$this->config->expects($this->at(3))
->method('setUserValue')
->with('user2', 'calendar', 'currentView', 'timeGridWeek');
$this->config->expects($this->at(4))
->method('getUserValue')
->with('user3', 'calendar', 'currentView', null)
->willReturn('month');
$this->config->expects($this->at(5))
->method('setUserValue')
->with('user3', 'calendar', 'currentView', 'dayGridMonth');
$this->config->expects($this->at(6))
->method('getUserValue')
->with('user4', 'calendar', 'currentView', null)
->willReturn('otherView');
$this->config->expects($this->at(7))
->method('setUserValue')
->with('user4', 'calendar', 'currentView', 'dayGridMonth');
$this->config->expects($this->at(8))
->method('getUserValue')
->with('user5', 'calendar', 'currentView', null)
->willReturn(null);
$this->config->expects($this->at(9))
->method('getUserValue')
->with('user6', 'calendar', 'currentView', null)
->willReturn('timeGridDay');
$this->config->expects($this->at(10))
->method('getUserValue')
->with('user7', 'calendar', 'currentView', null)
->willReturn('timeGridWeek');
$this->config->expects($this->at(11))
->method('getUserValue')
->with('user8', 'calendar', 'currentView', null)
->willReturn('dayGridMonth');
->withConsecutive(
['user1', 'calendar', 'currentView', 'timeGridDay'],
['user2', 'calendar', 'currentView', 'timeGridWeek'],
['user3', 'calendar', 'currentView', 'dayGridMonth'],
['user4', 'calendar', 'currentView', 'dayGridMonth'],
['user6', 'calendar', 'currentView', null],
['user8', 'calendar', 'currentView', null, 'dayGridMonth']
);
$output = $this->createMock(IOutput::class);
$output->expects($this->never())

View File

@ -27,13 +27,14 @@ use ChristophWurst\Nextcloud\Testing\TestCase;
use OCP\IConfig;
use OCP\IUser;
use OCP\IUserSession;
use PHPUnit\Framework\MockObject\MockObject;
class JsDataServiceTest extends TestCase {
/** @var IConfig|\PHPUnit\Framework\MockObject\MockObject */
/** @var IConfig|MockObject */
private $config;
/** @var IUserSession|\PHPUnit\Framework\MockObject\MockObject */
/** @var IUserSession|MockObject */
private $userSession;
/** @var JSDataService */
@ -55,22 +56,18 @@ class JsDataServiceTest extends TestCase {
->method('getUser')
->willReturn($user);
$this->config->expects($this->at(0))
$this->config
->method('getAppValue')
->with('calendar', 'timezone', 'automatic')
->willReturn('default-app-value-timezone');
$this->config->expects($this->at(1))
->method('getAppValue')
->with('calendar', 'showTasks', 'yes')
->willReturn('default-app-value-showTasks');
$this->config->expects($this->at(2))
->willReturnMap([
['calendar', 'timezone', 'automatic', 'default-app-value-timezone'],
['calendar', 'showTasks', 'yes', 'default-app-value-showTasks']
]);
$this->config
->method('getUserValue')
->with('john.doe', 'calendar', 'timezone', 'default-app-value-timezone')
->willReturn('timezone-config-value');
$this->config->expects($this->at(3))
->method('getUserValue')
->with('john.doe', 'calendar', 'showTasks', 'default-app-value-showTasks')
->willReturn('yes');
->willReturnMap([
['john.doe', 'calendar', 'timezone', 'default-app-value-timezone', 'timezone-config-value'],
['john.doe', 'calendar', 'showTasks', 'default-app-value-showTasks', 'yes']
]);
$this->assertEquals([
'timezone' => 'timezone-config-value',