|
| 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