Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify getserver2serverproperties method #799

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions controller/pagecontroller.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'
];
}
}
33 changes: 33 additions & 0 deletions tests/unit/controller/PageControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down