Skip to content

Commit 18ee49c

Browse files
committed
Add UserSubDomainsEnabled setter and getter to BaseServerConfig.
1 parent 2174d8e commit 18ee49c

4 files changed

Lines changed: 116 additions & 16 deletions

File tree

solid/lib/BaseServerConfig.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
use OCP\IConfig;
55

66
class BaseServerConfig {
7-
private IConfig $config;
7+
protected IConfig $config;
88

99
/**
1010
* @param IConfig $config
@@ -182,4 +182,12 @@ public function getClientRegistration($clientId) {
182182
$data = $this->config->getAppValue('solid', "client-" . $clientId, "{}");
183183
return json_decode($data, true);
184184
}
185+
186+
public function getUserSubDomainsEnabled(): bool {
187+
return $this->config->getAppValue('solid', 'userSubDomainsEnabled', false);
188+
}
189+
190+
public function setUserSubDomainsEnabled(bool $enabled) {
191+
$this->config->setAppValue('solid', 'userSubDomainsEnabled', $enabled);
192+
}
185193
}

solid/lib/Controller/GetStorageUrlTrait.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ protected function getStorageUrl($userId) {
4242
// (?) $storageUrl = preg_replace('/foo$/', '', $storageUrl);
4343
$storageUrl = preg_replace('/foo$/', '/', $storageUrl);
4444

45-
// @FIXME: $this->getUserSubDomainsEnabled should contain true/false from (?) somewhere
4645
if ($this->config->getUserSubDomainsEnabled()) {
4746
$url = parse_url($storageUrl);
4847

solid/lib/ServerConfig.php

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,24 +10,19 @@
1010
* @package OCA\Solid
1111
*/
1212
class ServerConfig extends BaseServerConfig {
13-
private IConfig $config;
1413
private IUrlGenerator $urlGenerator;
1514
private IUserManager $userManager;
16-
// private bool $userDomains;
1715

1816
/**
1917
* @param IConfig $config
2018
* @param IUrlGenerator $urlGenerator
2119
* @param IUserManager $userManager
22-
* @param bool $userDomains
2320
*/
24-
public function __construct(IConfig $config, IUrlGenerator $urlGenerator, IUserManager $userManager
25-
// , bool $userDomains
26-
) {
21+
public function __construct(IConfig $config, IUrlGenerator $urlGenerator, IUserManager $userManager) {
2722
$this->config = $config;
2823
$this->userManager = $userManager;
2924
$this->urlGenerator = $urlGenerator;
30-
// $this->userDomains = $userDomains;
25+
3126
parent::__construct($config);
3227
}
3328

@@ -67,11 +62,4 @@ public function setProfileData($userId, $profileData) {
6762
$user->setDisplayName($fields['name']);
6863
}
6964
}
70-
// public function getUserDomains() {
71-
// return $this->userDomains;
72-
// }
73-
// public function setUserDomains($userDomains) {
74-
// $this->userDomains = $userDomains;
75-
// }
76-
7765
}
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
<?php
2+
3+
namespace Unit;
4+
5+
use OCA\Solid\AppInfo\Application;
6+
use OCA\Solid\BaseServerConfig;
7+
use OCP\IConfig;
8+
use PHPUnit\Framework\TestCase;
9+
use TypeError;
10+
11+
/**
12+
* @coversDefaultClass \OCA\Solid\BaseServerConfig
13+
* @covers ::__construct
14+
*/
15+
class BaseServerConfigTest extends TestCase
16+
{
17+
/////////////////////////////////// TESTS \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
18+
19+
/**
20+
* @testdox BaseServerConfig should complain when called before given a Configuration
21+
* @covers ::__construct
22+
*/
23+
public function testConstructorWithoutConfig()
24+
{
25+
$this->expectException(TypeError::class);
26+
$this->expectExceptionMessage('Too few arguments to function');
27+
28+
new BaseServerConfig();
29+
}
30+
31+
/**
32+
* @testdox BaseServerConfig should be instantiated when given a valid Configuration
33+
* @covers ::__construct
34+
*/
35+
public function testConstructorWithValidConfig()
36+
{
37+
$configMock = $this->createMock(IConfig::class);
38+
39+
$baseServerConfig = new BaseServerConfig($configMock);
40+
41+
$this->assertInstanceOf(BaseServerConfig::class, $baseServerConfig);
42+
}
43+
44+
/**
45+
* @testdox BaseServerConfig should return a boolean when asked whether UserSubDomains are Enabled
46+
* @covers ::getUserSubDomainsEnabled
47+
* @dataProvider provideBooleans
48+
*/
49+
public function testGetUserSubDomainsEnabled($expected)
50+
{
51+
$configMock = $this->createMock(IConfig::class);
52+
$configMock->method('getAppValue')->willReturn($expected);
53+
54+
$baseServerConfig = new BaseServerConfig($configMock);
55+
$actual = $baseServerConfig->getUserSubDomainsEnabled();
56+
57+
$this->assertEquals($expected, $actual);
58+
}
59+
60+
/**
61+
* @testdox BaseServerConfig should get value from AppConfig when asked whether UserSubDomains are Enabled
62+
* @covers ::getUserSubDomainsEnabled
63+
*/
64+
public function testGetUserSubDomainsEnabledFromAppConfig()
65+
{
66+
$configMock = $this->createMock(IConfig::class);
67+
$configMock->expects($this->atLeast(1))
68+
->method('getAppValue')
69+
->with(Application::APP_ID, 'userSubDomainsEnabled', false)
70+
->willReturn(true);
71+
72+
$baseServerConfig = new BaseServerConfig($configMock);
73+
$actual = $baseServerConfig->getUserSubDomainsEnabled();
74+
75+
$this->assertTrue($actual);
76+
}
77+
78+
/**
79+
* @testdox BaseServerConfig should set value in AppConfig when asked to set UserSubDomainsEnabled
80+
* @covers ::setUserSubDomainsEnabled
81+
*
82+
* @dataProvider provideBooleans
83+
*/
84+
public function testSetUserSubDomainsEnabled($expected)
85+
{
86+
$configMock = $this->createMock(IConfig::class);
87+
$configMock->expects($this->atLeast(1))
88+
->method('setAppValue')
89+
->with(Application::APP_ID, 'userSubDomainsEnabled', $expected)
90+
;
91+
92+
$baseServerConfig = new BaseServerConfig($configMock);
93+
$baseServerConfig->setUserSubDomainsEnabled($expected);
94+
}
95+
96+
/////////////////////////////// DATAPROVIDERS \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
97+
98+
public function provideBooleans()
99+
{
100+
return [
101+
'false' => [false],
102+
'true' => [true],
103+
];
104+
}
105+
}

0 commit comments

Comments
 (0)