diff --git a/controller/pagecontroller.php b/controller/pagecontroller.php index 14192f0c5..18ea2551b 100644 --- a/controller/pagecontroller.php +++ b/controller/pagecontroller.php @@ -237,12 +237,14 @@ private function showPublicPage($token) { */ private function getServer2ServerProperties() { $server2ServerSharing = $this->appConfig->getAppValue( - 'files_sharing', 'outgoing_server2server_share_enabled', 'yes' + 'files_sharing', + 'outgoing_server2server_share_enabled', + 'yes' ); - $server2ServerSharing = ($server2ServerSharing === 'yes') ? true : false; - $password = $this->environment->getSharePassword(); - $passwordProtected = ($password) ? 'true' : 'false'; - return [$server2ServerSharing, $passwordProtected]; + return [ + ($server2ServerSharing === 'yes'), + ($this->environment->getSharePassword()) ? 'true' : 'false' + ]; } } diff --git a/tests/unit/controller/PageControllerTest.php b/tests/unit/controller/PageControllerTest.php index 189ec3e17..a044b817f 100644 --- a/tests/unit/controller/PageControllerTest.php +++ b/tests/unit/controller/PageControllerTest.php @@ -169,6 +169,39 @@ public function testPublicIndexWithFileToken() { $this->assertEquals($template->getRedirectURL(), $response->getRedirectURL()); } + /** + * @return array + */ + public function getServer2ServerPropertiesDataProvider() { + return [ + ['I am a password', 'yes', true, 'true'], + ['', 'yes', true, 'false'], + [null, 'yes', true, 'false'], + ]; + } + + /** + * @throws \ReflectionException + * @dataProvider getServer2ServerPropertiesDataProvider + */ + public function testGetServer2ServerProperties( + $password, + $server2ServerSharingEnabled, + $expectedSharing, + $expectedPasswordProtected + ) { + $this->mockGetSharePassword($password); + $this->mockGetAppValue($server2ServerSharingEnabled); + + $reflection = new \ReflectionClass(\get_class($this->controller)); + $method = $reflection->getMethod('getServer2ServerProperties'); + $method->setAccessible(true); + list($server2ServerSharing, $passwordProtected) = $method->invokeArgs($this->controller, []); + + $this->assertSame($expectedSharing, $server2ServerSharing, 'Incorrect server to server sharing result returned'); + $this->assertSame($expectedPasswordProtected, $passwordProtected, 'Incorrect password protected result returned'); + } + public function testErrorPage() { $message = 'Not found!'; $code = Http::STATUS_NOT_FOUND;