From f8a5be6a9071b3b9704242ee65f8b3a21402abe9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=B4me=20Chilliet?= Date: Thu, 16 Jun 2022 15:55:05 +0200 Subject: [PATCH] Remove deprecated at matcher from theming tests MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Côme Chilliet --- .../Controller/ThemingControllerTest.php | 50 ++--- apps/theming/tests/ImageManagerTest.php | 35 ++-- apps/theming/tests/Settings/PersonalTest.php | 10 +- apps/theming/tests/ThemingDefaultsTest.php | 177 +++++++++--------- 4 files changed, 138 insertions(+), 134 deletions(-) diff --git a/apps/theming/tests/Controller/ThemingControllerTest.php b/apps/theming/tests/Controller/ThemingControllerTest.php index 511f7a6d528f3..9042a338fb7dd 100644 --- a/apps/theming/tests/Controller/ThemingControllerTest.php +++ b/apps/theming/tests/Controller/ThemingControllerTest.php @@ -208,12 +208,12 @@ public function testUpdateStylesheetError($setting, $value, $message) { public function testUpdateLogoNoData() { $this->request - ->expects($this->at(0)) + ->expects($this->once()) ->method('getParam') ->with('key') ->willReturn('logo'); $this->request - ->expects($this->at(1)) + ->expects($this->once()) ->method('getUploadedFile') ->with('image') ->willReturn(null); @@ -251,12 +251,12 @@ public function testUploadSVGFaviconWithoutImagemagick() { ->willReturn(false); $this->request - ->expects($this->at(0)) + ->expects($this->once()) ->method('getParam') ->with('key') ->willReturn('favicon'); $this->request - ->expects($this->at(1)) + ->expects($this->once()) ->method('getUploadedFile') ->with('image') ->willReturn([ @@ -292,12 +292,12 @@ public function testUploadSVGFaviconWithoutImagemagick() { public function testUpdateLogoInvalidMimeType() { $this->request - ->expects($this->at(0)) + ->expects($this->once()) ->method('getParam') ->with('key') ->willReturn('logo'); $this->request - ->expects($this->at(1)) + ->expects($this->once()) ->method('getUploadedFile') ->with('image') ->willReturn([ @@ -350,12 +350,12 @@ public function testUpdateLogoNormalLogoUpload($mimeType, $folderExists = true) touch($tmpLogo); copy(__DIR__ . '/../../../../tests/data/testimage.png', $tmpLogo); $this->request - ->expects($this->at(0)) + ->expects($this->once()) ->method('getParam') ->with('key') ->willReturn('logo'); $this->request - ->expects($this->at(1)) + ->expects($this->once()) ->method('getUploadedFile') ->with('image') ->willReturn([ @@ -401,12 +401,12 @@ public function testUpdateLogoLoginScreenUpload($folderExists) { touch($tmpLogo); copy(__DIR__ . '/../../../../tests/data/desktopapp.png', $tmpLogo); $this->request - ->expects($this->at(0)) + ->expects($this->once()) ->method('getParam') ->with('key') ->willReturn('background'); $this->request - ->expects($this->at(1)) + ->expects($this->once()) ->method('getUploadedFile') ->with('image') ->willReturn([ @@ -449,12 +449,12 @@ public function testUpdateLogoLoginScreenUploadWithInvalidImage() { touch($tmpLogo); file_put_contents($tmpLogo, file_get_contents(__DIR__ . '/../../../../tests/data/data.zip')); $this->request - ->expects($this->at(0)) + ->expects($this->once()) ->method('getParam') ->with('key') ->willReturn('logo'); $this->request - ->expects($this->at(1)) + ->expects($this->once()) ->method('getUploadedFile') ->with('image') ->willReturn([ @@ -504,12 +504,12 @@ public function dataPhpUploadErrors() { */ public function testUpdateLogoLoginScreenUploadWithInvalidImageUpload($error, $expectedErrorMessage) { $this->request - ->expects($this->at(0)) + ->expects($this->once()) ->method('getParam') ->with('key') ->willReturn('background'); $this->request - ->expects($this->at(1)) + ->expects($this->once()) ->method('getUploadedFile') ->with('image') ->willReturn([ @@ -543,12 +543,12 @@ public function testUpdateLogoLoginScreenUploadWithInvalidImageUpload($error, $e */ public function testUpdateLogoUploadWithInvalidImageUpload($error, $expectedErrorMessage) { $this->request - ->expects($this->at(0)) + ->expects($this->once()) ->method('getParam') ->with('key') ->willReturn('background'); $this->request - ->expects($this->at(1)) + ->expects($this->once()) ->method('getUploadedFile') ->with('image') ->willReturn([ @@ -713,19 +713,19 @@ public function testGetManifest() { ->method('getName') ->willReturn('Nextcloud'); $this->urlGenerator - ->expects($this->at(0)) + ->expects($this->once()) ->method('getBaseUrl') ->willReturn('localhost'); $this->urlGenerator - ->expects($this->at(1)) + ->expects($this->exactly(2)) ->method('linkToRoute') - ->with('theming.Icon.getTouchIcon', ['app' => 'core']) - ->willReturn('touchicon'); - $this->urlGenerator - ->expects($this->at(2)) - ->method('linkToRoute') - ->with('theming.Icon.getFavicon', ['app' => 'core']) - ->willReturn('favicon'); + ->withConsecutive( + ['theming.Icon.getTouchIcon', ['app' => 'core']], + ['theming.Icon.getFavicon', ['app' => 'core']], + )->willReturnOnConsecutiveCalls( + 'touchicon', + 'favicon', + ); $response = new Http\JSONResponse([ 'name' => 'Nextcloud', 'start_url' => 'localhost', diff --git a/apps/theming/tests/ImageManagerTest.php b/apps/theming/tests/ImageManagerTest.php index 10faf6c1da16a..6a9b77234bb74 100644 --- a/apps/theming/tests/ImageManagerTest.php +++ b/apps/theming/tests/ImageManagerTest.php @@ -100,20 +100,21 @@ public function mockGetImage($key, $file) { $file->expects($this->once()) ->method('getContent') ->willReturn(file_get_contents(__DIR__ . '/../../../tests/data/testimage.png')); - $folder->expects($this->at(0)) + $folder->expects($this->exactly(2)) ->method('fileExists') - ->with('logo') - ->willReturn(true); - $folder->expects($this->at(1)) - ->method('fileExists') - ->with('logo.png') - ->willReturn(false); - $folder->expects($this->at(2)) + ->withConsecutive( + ['logo'], + ['logo.png'], + )->willReturnOnConsecutiveCalls( + true, + false, + ); + $folder->expects($this->once()) ->method('getFile') ->with('logo') ->willReturn($file); $newFile = $this->createMock(ISimpleFile::class); - $folder->expects($this->at(3)) + $folder->expects($this->once()) ->method('newFile') ->with('logo.png') ->willReturn($newFile); @@ -211,15 +212,15 @@ public function testGetCacheFolderCreate() { ->method('getAppValue') ->with('theming', 'cachebuster', '0') ->willReturn('0'); - $this->appData->expects($this->at(0)) + $this->appData->expects($this->exactly(2)) ->method('getFolder') - ->willThrowException(new NotFoundException()); - $this->appData->expects($this->at(1)) - ->method('newFolder') ->with('0') - ->willReturn($folder); - $this->appData->expects($this->at(2)) - ->method('getFolder') + ->willReturnOnConsecutiveCalls( + $this->throwException(new NotFoundException()), + $folder, + ); + $this->appData->expects($this->once()) + ->method('newFolder') ->with('0') ->willReturn($folder); $this->appData->expects($this->once()) @@ -290,7 +291,7 @@ private function setupCacheFolder() { ->method('getAppValue') ->with('theming', 'cachebuster', '0') ->willReturn('0'); - $this->appData->expects($this->at(0)) + $this->appData->expects($this->once()) ->method('getFolder') ->with('0') ->willReturn($folder); diff --git a/apps/theming/tests/Settings/PersonalTest.php b/apps/theming/tests/Settings/PersonalTest.php index 5f0585911bb66..a5409e5f57a52 100644 --- a/apps/theming/tests/Settings/PersonalTest.php +++ b/apps/theming/tests/Settings/PersonalTest.php @@ -110,12 +110,12 @@ public function testGetForm(string $enforcedTheme, $themesState) { ->with('enforce_theme', '') ->willReturn($enforcedTheme); - $this->initialStateService->expects($this->at(0)) + $this->initialStateService->expects($this->exactly(2)) ->method('provideInitialState') - ->with('themes', $themesState); - $this->initialStateService->expects($this->at(1)) - ->method('provideInitialState') - ->with('enforceTheme', $enforcedTheme); + ->withConsecutive( + ['themes', $themesState], + ['enforceTheme', $enforcedTheme], + ); $expected = new TemplateResponse('theming', 'settings-personal'); $this->assertEquals($expected, $this->admin->getForm()); diff --git a/apps/theming/tests/ThemingDefaultsTest.php b/apps/theming/tests/ThemingDefaultsTest.php index c8ef147dc94bc..20c153f1e96b5 100644 --- a/apps/theming/tests/ThemingDefaultsTest.php +++ b/apps/theming/tests/ThemingDefaultsTest.php @@ -437,27 +437,24 @@ public function testgetColorPrimaryWithCustom() { public function testSet() { $this->config - ->expects($this->at(0)) + ->expects($this->exactly(2)) ->method('setAppValue') - ->with('theming', 'MySetting', 'MyValue'); + ->withConsecutive( + ['theming', 'MySetting', 'MyValue'], + ['theming', 'cachebuster', 16], + ); $this->config - ->expects($this->at(1)) + ->expects($this->once()) ->method('getAppValue') ->with('theming', 'cachebuster', '0') ->willReturn('15'); - $this->config - ->expects($this->at(2)) - ->method('setAppValue') - ->with('theming', 'cachebuster', 16); $this->cacheFactory - ->expects($this->at(0)) + ->expects($this->exactly(2)) ->method('createDistributed') - ->with('theming-') - ->willReturn($this->cache); - $this->cacheFactory - ->expects($this->at(1)) - ->method('createDistributed') - ->with('imagePath') + ->withConsecutive( + ['theming-'], + ['imagePath'], + ) ->willReturn($this->cache); $this->cache ->expects($this->any()) @@ -468,108 +465,108 @@ public function testSet() { public function testUndoName() { $this->config - ->expects($this->at(0)) + ->expects($this->once()) ->method('deleteAppValue') ->with('theming', 'name'); $this->config - ->expects($this->at(1)) + ->expects($this->exactly(2)) ->method('getAppValue') - ->with('theming', 'cachebuster', '0') - ->willReturn('15'); + ->withConsecutive( + ['theming', 'cachebuster', '0'], + ['theming', 'name', 'Nextcloud'], + )->willReturnOnConsecutiveCalls( + '15', + 'Nextcloud', + ); $this->config - ->expects($this->at(2)) + ->expects($this->once()) ->method('setAppValue') ->with('theming', 'cachebuster', 16); - $this->config - ->expects($this->at(3)) - ->method('getAppValue') - ->with('theming', 'name', 'Nextcloud') - ->willReturn('Nextcloud'); $this->assertSame('Nextcloud', $this->template->undo('name')); } public function testUndoBaseUrl() { $this->config - ->expects($this->at(0)) + ->expects($this->once()) ->method('deleteAppValue') ->with('theming', 'url'); $this->config - ->expects($this->at(1)) + ->expects($this->exactly(2)) ->method('getAppValue') - ->with('theming', 'cachebuster', '0') - ->willReturn('15'); + ->withConsecutive( + ['theming', 'cachebuster', '0'], + ['theming', 'url', $this->defaults->getBaseUrl()], + )->willReturnOnConsecutiveCalls( + '15', + $this->defaults->getBaseUrl(), + ); $this->config - ->expects($this->at(2)) + ->expects($this->once()) ->method('setAppValue') ->with('theming', 'cachebuster', 16); - $this->config - ->expects($this->at(3)) - ->method('getAppValue') - ->with('theming', 'url', $this->defaults->getBaseUrl()) - ->willReturn($this->defaults->getBaseUrl()); $this->assertSame($this->defaults->getBaseUrl(), $this->template->undo('url')); } public function testUndoSlogan() { $this->config - ->expects($this->at(0)) + ->expects($this->once()) ->method('deleteAppValue') ->with('theming', 'slogan'); $this->config - ->expects($this->at(1)) + ->expects($this->exactly(2)) ->method('getAppValue') - ->with('theming', 'cachebuster', '0') - ->willReturn('15'); + ->withConsecutive( + ['theming', 'cachebuster', '0'], + ['theming', 'slogan', $this->defaults->getSlogan()], + )->willReturnOnConsecutiveCalls( + '15', + $this->defaults->getSlogan(), + ); $this->config - ->expects($this->at(2)) + ->expects($this->once()) ->method('setAppValue') ->with('theming', 'cachebuster', 16); - $this->config - ->expects($this->at(3)) - ->method('getAppValue') - ->with('theming', 'slogan', $this->defaults->getSlogan()) - ->willReturn($this->defaults->getSlogan()); $this->assertSame($this->defaults->getSlogan(), $this->template->undo('slogan')); } public function testUndoColor() { $this->config - ->expects($this->at(0)) + ->expects($this->once()) ->method('deleteAppValue') ->with('theming', 'color'); $this->config - ->expects($this->at(1)) + ->expects($this->exactly(2)) ->method('getAppValue') - ->with('theming', 'cachebuster', '0') - ->willReturn('15'); + ->withConsecutive( + ['theming', 'cachebuster', '0'], + ['theming', 'color', $this->defaults->getColorPrimary()], + )->willReturnOnConsecutiveCalls( + '15', + $this->defaults->getColorPrimary(), + ); $this->config - ->expects($this->at(2)) + ->expects($this->once()) ->method('setAppValue') ->with('theming', 'cachebuster', 16); - $this->config - ->expects($this->at(3)) - ->method('getAppValue') - ->with('theming', 'color', $this->defaults->getColorPrimary()) - ->willReturn($this->defaults->getColorPrimary()); $this->assertSame($this->defaults->getColorPrimary(), $this->template->undo('color')); } public function testUndoDefaultAction() { $this->config - ->expects($this->at(0)) + ->expects($this->once()) ->method('deleteAppValue') ->with('theming', 'defaultitem'); $this->config - ->expects($this->at(1)) + ->expects($this->once()) ->method('getAppValue') ->with('theming', 'cachebuster', '0') ->willReturn('15'); $this->config - ->expects($this->at(2)) + ->expects($this->once()) ->method('setAppValue') ->with('theming', 'cachebuster', 16); @@ -591,15 +588,15 @@ private function getLogoHelper($withName, $useSvg) { ->with('logo') ->willThrowException(new NotFoundException()); $this->config - ->expects($this->at(0)) - ->method('getAppValue') - ->with('theming', 'logoMime') - ->willReturn(''); - $this->config - ->expects($this->at(1)) + ->expects($this->exactly(2)) ->method('getAppValue') - ->with('theming', 'cachebuster', '0') - ->willReturn('0'); + ->withConsecutive( + ['theming', 'logoMime'], + ['theming', 'cachebuster', '0'], + )->willReturnOnConsecutiveCalls( + '', + '0' + ); $this->urlGenerator->expects($this->once()) ->method('imagePath') ->with('core', $withName) @@ -617,15 +614,15 @@ public function testGetLogoDefaultWithoutSvg() { public function testGetLogoCustom() { $this->config - ->expects($this->at(0)) - ->method('getAppValue') - ->with('theming', 'logoMime', false) - ->willReturn('image/svg+xml'); - $this->config - ->expects($this->at(1)) + ->expects($this->exactly(2)) ->method('getAppValue') - ->with('theming', 'cachebuster', '0') - ->willReturn('0'); + ->withConsecutive( + ['theming', 'logoMime', false], + ['theming', 'cachebuster', '0'], + )->willReturnOnConsecutiveCalls( + 'image/svg+xml', + '0', + ); $this->urlGenerator->expects($this->once()) ->method('linkToRoute') ->with('theming.Theming.getImage') @@ -644,16 +641,18 @@ public function testGetScssVariablesCached() { } public function testGetScssVariables() { - $this->config->expects($this->at(0))->method('getAppValue')->with('theming', 'cachebuster', '0')->willReturn('0'); - $this->config->expects($this->at(1))->method('getAppValue')->with('theming', 'logoMime', false)->willReturn('jpeg'); - $this->config->expects($this->at(2))->method('getAppValue')->with('theming', 'backgroundMime', false)->willReturn('jpeg'); - $this->config->expects($this->at(3))->method('getAppValue')->with('theming', 'logoheaderMime', false)->willReturn('jpeg'); - $this->config->expects($this->at(4))->method('getAppValue')->with('theming', 'faviconMime', false)->willReturn('jpeg'); - - $this->config->expects($this->at(5))->method('getAppValue')->with('theming', 'color', null)->willReturn($this->defaults->getColorPrimary()); - $this->config->expects($this->at(6))->method('getAppValue')->with('theming', 'color', $this->defaults->getColorPrimary())->willReturn($this->defaults->getColorPrimary()); - $this->config->expects($this->at(7))->method('getAppValue')->with('theming', 'color', $this->defaults->getColorPrimary())->willReturn($this->defaults->getColorPrimary()); - $this->config->expects($this->at(8))->method('getAppValue')->with('theming', 'color', $this->defaults->getColorPrimary())->willReturn($this->defaults->getColorPrimary()); + $this->config + ->expects($this->any()) + ->method('getAppValue') + ->willReturnMap([ + ['theming', 'cachebuster', '0', '0'], + ['theming', 'logoMime', '', 'jpeg'], + ['theming', 'backgroundMime', '', 'jpeg'], + ['theming', 'logoheaderMime', '', 'jpeg'], + ['theming', 'faviconMime', '', 'jpeg'], + ['theming', 'color', '', $this->defaults->getColorPrimary()], + ['theming', 'color', $this->defaults->getColorPrimary(), $this->defaults->getColorPrimary()], + ]); $this->util->expects($this->any())->method('invertTextColor')->with($this->defaults->getColorPrimary())->willReturn(false); $this->util->expects($this->any())->method('elementColor')->with($this->defaults->getColorPrimary())->willReturn('#aaaaaa'); @@ -662,10 +661,14 @@ public function testGetScssVariables() { ->with('theming-0-') ->willReturn($this->cache); $this->cache->expects($this->once())->method('get')->with('getScssVariables')->willReturn(null); - $this->imageManager->expects($this->at(0))->method('getImageUrl')->with('logo')->willReturn('custom-logo?v=0'); - $this->imageManager->expects($this->at(1))->method('getImageUrl')->with('logoheader')->willReturn('custom-logoheader?v=0'); - $this->imageManager->expects($this->at(2))->method('getImageUrl')->with('favicon')->willReturn('custom-favicon?v=0'); - $this->imageManager->expects($this->at(3))->method('getImageUrl')->with('background')->willReturn('custom-background?v=0'); + $this->imageManager->expects($this->exactly(4)) + ->method('getImageUrl') + ->willReturnMap([ + ['logo', true, 'custom-logo?v=0'], + ['logoheader', true, 'custom-logoheader?v=0'], + ['favicon', true, 'custom-favicon?v=0'], + ['background', true, 'custom-background?v=0'], + ]); $expected = [ 'theming-cachebuster' => '\'0\'',