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 runs-on: ubuntu-latest
strategy: strategy:
matrix: matrix:
php-versions: ['7.2', '7.3', '7.4'] php-versions: ['7.3', '7.4']
nextcloud-versions: ['stable20', 'master'] nextcloud-versions: ['stable20', 'master']
exclude: include:
- php-versions: '7.2' - php-versions: '7.2'
nextcloud-versions: 'stable20'
- php-versions: '8.0'
nextcloud-versions: 'master' nextcloud-versions: 'master'
name: php${{ matrix.php-versions }} on ${{ matrix.nextcloud-versions }} unit tests name: php${{ matrix.php-versions }} on ${{ matrix.nextcloud-versions }} unit tests
env:
CI: true
XDEBUG_MODE: coverage
steps: steps:
- name: Set up php${{ matrix.php-versions }} - name: Set up php${{ matrix.php-versions }}
uses: shivammathur/setup-php@master uses: shivammathur/setup-php@master
@ -26,12 +31,20 @@ jobs:
coverage: xdebug coverage: xdebug
- name: Checkout Nextcloud - name: Checkout Nextcloud
run: git clone https://github.com/nextcloud/server.git --recursive --depth 1 -b ${{ matrix.nextcloud-versions }} 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='' 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 uses: actions/checkout@master
with: with:
path: nextcloud/apps/calendar 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 - name: Install dependencies
working-directory: nextcloud/apps/calendar working-directory: nextcloud/apps/calendar
run: composer install run: composer install
@ -39,5 +52,6 @@ jobs:
working-directory: nextcloud/apps/calendar working-directory: nextcloud/apps/calendar
run: composer run test run: composer run test
- name: Upload coverage to Codecov - name: Upload coverage to Codecov
if: ${{ matrix.nextcloud-versions == 'master' }}
working-directory: nextcloud/apps/calendar 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 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 /.project
.php_cs.cache .php_cs.cache
.phpunit.result.cache
coverage/ coverage/
js/public js/public
css/public css/public

View File

@ -1,11 +1,10 @@
{ {
"require": { "require": {
"php": ">=7.2", "php": "^7.2|^8.0",
"nextcloud/coding-standard": "^0.5.0" "nextcloud/coding-standard": "^0.5.0"
}, },
"require-dev": { "require-dev": {
"christophwurst/nextcloud": "v20.0.4", "christophwurst/nextcloud_testing": "0.12.1"
"christophwurst/nextcloud_testing": "0.10.0"
}, },
"scripts": { "scripts": {
"cs:fix": "php-cs-fixer fix", "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'); $defaultSlotDuration = $this->config->getAppValue($this->appName, 'slotDuration', '00:30:00');
$defaultShowTasks = $this->config->getAppValue($this->appName, 'showTasks', 'yes'); $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, 'app_version', $appVersion);
$this->initialStateService->provideInitialState($this->appName, 'event_limit', ($defaultEventLimit === 'yes')); $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'); $defaultSlotDuration = $this->config->getAppValue($this->appName, 'slotDuration', '00:30:00');
$defaultShowTasks = $this->config->getAppValue($this->appName, 'showTasks', 'yes'); $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'; $eventLimit = $this->config->getUserValue($this->userId, $this->appName, 'eventLimit', $defaultEventLimit) === 'yes';
$firstRun = $this->config->getUserValue($this->userId, $this->appName, 'firstRun', 'yes') === 'yes'; $firstRun = $this->config->getUserValue($this->userId, $this->appName, 'firstRun', 'yes') === 'yes';
$initialView = $this->getView($this->config->getUserValue($this->userId, $this->appName, 'currentView', $defaultInitialView)); $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" ?> <?xml version="1.0" encoding="utf-8"?>
<phpunit bootstrap="tests/php/unit/bootstrap.php" <phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
bootstrap="tests/php/unit/bootstrap.php"
verbose="true" verbose="true"
timeoutForSmallTests="900" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/8.5/phpunit.xsd">
timeoutForMediumTests="900" <testsuite name="unit">
timeoutForLargeTests="900" <directory suffix="Test.php">./tests/php/unit</directory>
> </testsuite>
<testsuite name='Calendar app tests'> <coverage>
<directory suffix='test.php'>./tests/php/unit</directory> <include>
<directory suffix='Test.php'>./tests/php/unit</directory> <directory suffix=".php">./lib</directory>
</testsuite> </include>
<!-- filters for code coverage --> <report>
<filter> <clover outputFile="./clover.unit.xml"/>
<whitelist> </report>
<directory suffix=".php">./</directory> </coverage>
<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>
</phpunit> </phpunit>

View File

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

View File

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

View File

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

View File

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

View File

@ -94,57 +94,26 @@ class CurrentViewNameRepairStepTest extends TestCase {
return true; return true;
})); }));
$this->config->expects($this->at(0)) $this->config
->method('getUserValue') ->method('getUserValue')
->with('user1', 'calendar', 'currentView', null) ->willReturnMap([
->willReturn('agendaDay'); ['user1', 'calendar', 'currentView', null, 'agendaDay'],
$this->config->expects($this->at(1)) ['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') ->method('setUserValue')
->with('user1', 'calendar', 'currentView', 'timeGridDay'); ->withConsecutive(
['user1', 'calendar', 'currentView', 'timeGridDay'],
$this->config->expects($this->at(2)) ['user2', 'calendar', 'currentView', 'timeGridWeek'],
->method('getUserValue') ['user3', 'calendar', 'currentView', 'dayGridMonth'],
->with('user2', 'calendar', 'currentView', null) ['user4', 'calendar', 'currentView', 'dayGridMonth'],
->willReturn('agendaWeek'); ['user6', 'calendar', 'currentView', null],
$this->config->expects($this->at(3)) ['user8', 'calendar', 'currentView', null, 'dayGridMonth']
->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');
$output = $this->createMock(IOutput::class); $output = $this->createMock(IOutput::class);
$output->expects($this->never()) $output->expects($this->never())

View File

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