From 4b1e749d3181f637e8adaf5fbb6a7664dd0124e1 Mon Sep 17 00:00:00 2001 From: Daniel Kesselberg Date: Fri, 21 Feb 2020 22:34:31 +0100 Subject: [PATCH] Hide slide for app store if disabled Signed-off-by: Daniel Kesselberg --- lib/Controller/WizardController.php | 6 +++-- tests/Controller/WizardControllerTest.php | 32 ++++++++++++++++++----- 2 files changed, 29 insertions(+), 9 deletions(-) diff --git a/lib/Controller/WizardController.php b/lib/Controller/WizardController.php index ff36c0960..f317498fc 100644 --- a/lib/Controller/WizardController.php +++ b/lib/Controller/WizardController.php @@ -74,11 +74,13 @@ public function disable() { * @return JsonResponse */ public function show() { + $appStore = $this->config->getSystemValue('appstoreenabled', true); + $data = [ 'desktop' => $this->config->getSystemValue('customclient_desktop', $this->theming->getSyncClientUrl()), 'android' => $this->config->getSystemValue('customclient_android', $this->theming->getAndroidClientUrl()), 'ios' => $this->config->getSystemValue('customclient_ios', $this->theming->getiOSClientUrl()), - 'appStore' => $this->config->getSystemValue('appstoreenabled', true), + 'appStore' => $appStore, 'useTLS' => $this->request->getServerProtocol() === 'https', 'macOSProfile' => \OCP\Util::linkToRemote('dav') . 'provisioning/apple-provisioning.mobileconfig', ]; @@ -86,7 +88,7 @@ public function show() { $slides = [ $this->staticSlide('page.values', $data) ]; - if ($this->groupManager->isAdmin($this->userId)) { + if ($appStore && $this->groupManager->isAdmin($this->userId)) { $slides[] = $this->staticSlide('page.apps', $data); } $slides[] = $this->staticSlide('page.clients', $data); diff --git a/tests/Controller/WizardControllerTest.php b/tests/Controller/WizardControllerTest.php index d195fbc59..9400280ad 100644 --- a/tests/Controller/WizardControllerTest.php +++ b/tests/Controller/WizardControllerTest.php @@ -108,28 +108,46 @@ public function testShowUser() { $this->assertInstanceOf(JSONResponse::class, $response); $this->assertSame(Http::STATUS_OK, $response->getStatus()); - $this->assertEquals(3, count($response->getData())); + $this->assertCount(3, $response->getData()); } - public function testShowAdmin() { + /** + * @dataProvider dataShowAdmin + * @param bool $appstoreEnabled + * @param int $expectedSlidesCount + */ + public function testShowAdmin(bool $appstoreEnabled, int $expectedSlidesCount): void { $controller = $this->getController(); - $this->groupManager->expects($this->once()) - ->method('isAdmin') - ->willReturn(true); + if ($appstoreEnabled) { + $this->groupManager->expects($this->once()) + ->method('isAdmin') + ->willReturn(true); + } else { + $this->groupManager->expects($this->never()) + ->method('isAdmin'); + } + $this->config->expects($this->exactly(4)) ->method('getSystemValue') ->willReturnMap([ ['customclient_desktop', 'https://nextcloud.com/install/#install-clients', 'https://nextcloud.com/install/#install-clients'], ['customclient_android', 'https://play.google.com/store/apps/details?id=com.nextcloud.client', 'https://nextcloud.com/install/#install-clients'], ['customclient_ios', 'https://geo.itunes.apple.com/us/app/nextcloud/id1125420102?mt=8', 'https://nextcloud.com/install/#install-clients'], - ['appstoreenabled', true, true] + ['appstoreenabled', true, $appstoreEnabled] ]); $response = $controller->show(); $this->assertInstanceOf(JSONResponse::class, $response); $this->assertSame(Http::STATUS_OK, $response->getStatus()); - $this->assertEquals(4, count($response->getData())); + $this->assertCount($expectedSlidesCount, $response->getData()); + } + + public function dataShowAdmin(): array { + return [ + 'app store enabled' => [true, 4], + 'app store disabled' => [false, 3] + ]; } }