diff options
author | Côme Chilliet <come.chilliet@nextcloud.com> | 2023-04-05 17:42:14 +0200 |
---|---|---|
committer | Côme Chilliet <come.chilliet@nextcloud.com> | 2023-04-05 17:42:14 +0200 |
commit | 8d5165e8dc40289b5d523523c4140f780b2fe293 (patch) | |
tree | b4d15f2bc67e16c94d7cdfdb893a773b415d2738 /tests/lib/App | |
parent | 426c0341ffff262f58d1b7f031de4f0c53c8bec5 (diff) | |
download | nextcloud-server-8d5165e8dc40289b5d523523c4140f780b2fe293.tar.gz nextcloud-server-8d5165e8dc40289b5d523523c4140f780b2fe293.zip |
Adapt tests to config value typing
Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com>
Diffstat (limited to 'tests/lib/App')
-rw-r--r-- | tests/lib/App/AppStore/Fetcher/AppFetcherTest.php | 47 | ||||
-rw-r--r-- | tests/lib/App/AppStore/Fetcher/CategoryFetcherTest.php | 4 | ||||
-rw-r--r-- | tests/lib/App/AppStore/Fetcher/FetcherBase.php | 100 |
3 files changed, 67 insertions, 84 deletions
diff --git a/tests/lib/App/AppStore/Fetcher/AppFetcherTest.php b/tests/lib/App/AppStore/Fetcher/AppFetcherTest.php index a2d56838b07..39b0a699092 100644 --- a/tests/lib/App/AppStore/Fetcher/AppFetcherTest.php +++ b/tests/lib/App/AppStore/Fetcher/AppFetcherTest.php @@ -1872,7 +1872,7 @@ EJL3BaQAQaASSsvFrcozYxrQG4VzEg== } public function testGetWithFilter() { - $this->config->method('getSystemValue') + $this->config->method('getSystemValueString') ->willReturnCallback(function ($key, $default) { if ($key === 'version') { return '11.0.0.2'; @@ -1884,8 +1884,7 @@ EJL3BaQAQaASSsvFrcozYxrQG4VzEg== }); $this->config ->method('getSystemValueBool') - ->with('appstoreenabled', true) - ->willReturn(true); + ->willReturnArgument(1); $file = $this->createMock(ISimpleFile::class); $folder = $this->createMock(ISimpleFolder::class); @@ -1957,7 +1956,7 @@ EJL3BaQAQaASSsvFrcozYxrQG4VzEg== public function testAppstoreDisabled() { $this->config - ->method('getSystemValue') + ->method('getSystemValueString') ->willReturnCallback(function ($var, $default) { if ($var === 'version') { return '11.0.0.2'; @@ -1966,8 +1965,14 @@ EJL3BaQAQaASSsvFrcozYxrQG4VzEg== }); $this->config ->method('getSystemValueBool') - ->with('appstoreenabled', true) - ->willReturn(false); + ->willReturnCallback(function ($var, $default) { + if ($var === 'has_internet_connection') { + return true; + } elseif ($var === 'appstoreenabled') { + return false; + } + return $default; + }); $this->appData ->expects($this->never()) ->method('getFolder'); @@ -1978,7 +1983,7 @@ EJL3BaQAQaASSsvFrcozYxrQG4VzEg== public function testNoInternet() { $this->config - ->method('getSystemValue') + ->method('getSystemValueString') ->willReturnCallback(function ($var, $default) { if ($var === 'has_internet_connection') { return false; @@ -1989,8 +1994,14 @@ EJL3BaQAQaASSsvFrcozYxrQG4VzEg== }); $this->config ->method('getSystemValueBool') - ->with('appstoreenabled', true) - ->willReturn(true); + ->willReturnCallback(function ($var, $default) { + if ($var === 'has_internet_connection') { + return false; + } elseif ($var === 'appstoreenabled') { + return true; + } + return $default; + }); $this->appData ->expects($this->never()) ->method('getFolder'); @@ -1999,7 +2010,7 @@ EJL3BaQAQaASSsvFrcozYxrQG4VzEg== } public function testSetVersion() { - $this->config->method('getSystemValue') + $this->config->method('getSystemValueString') ->willReturnCallback(function ($key, $default) { if ($key === 'version') { return '10.0.7.2'; @@ -2011,8 +2022,7 @@ EJL3BaQAQaASSsvFrcozYxrQG4VzEg== }); $this->config ->method('getSystemValueBool') - ->with('appstoreenabled', true) - ->willReturn(true); + ->willReturnArgument(1); $file = $this->createMock(ISimpleFile::class); $folder = $this->createMock(ISimpleFolder::class); @@ -2084,13 +2094,19 @@ EJL3BaQAQaASSsvFrcozYxrQG4VzEg== } public function testGetAppsAllowlist() { - $this->config->method('getSystemValue') + $this->config->method('getSystemValueString') ->willReturnCallback(function ($key, $default) { if ($key === 'version') { return '11.0.0.2'; } elseif ($key === 'appstoreurl' && $default === 'https://apps.nextcloud.com/api/v1') { return 'https://custom.appsstore.endpoint/api/v1'; - } elseif ($key === 'appsallowlist') { + } else { + return $default; + } + }); + $this->config->method('getSystemValue') + ->willReturnCallback(function ($key, $default) { + if ($key === 'appsallowlist') { return ['contacts']; } else { return $default; @@ -2098,8 +2114,7 @@ EJL3BaQAQaASSsvFrcozYxrQG4VzEg== }); $this->config ->method('getSystemValueBool') - ->with('appstoreenabled', true) - ->willReturn(true); + ->willReturnArgument(1); $file = $this->createMock(ISimpleFile::class); $folder = $this->createMock(ISimpleFolder::class); diff --git a/tests/lib/App/AppStore/Fetcher/CategoryFetcherTest.php b/tests/lib/App/AppStore/Fetcher/CategoryFetcherTest.php index b83e405db61..874a58fc6ba 100644 --- a/tests/lib/App/AppStore/Fetcher/CategoryFetcherTest.php +++ b/tests/lib/App/AppStore/Fetcher/CategoryFetcherTest.php @@ -41,7 +41,7 @@ class CategoryFetcherTest extends FetcherBase { public function testAppstoreDisabled() { $this->config - ->method('getSystemValue') + ->method('getSystemValueBool') ->willReturnCallback(function ($var, $default) { if ($var === 'appstoreenabled') { return false; @@ -57,7 +57,7 @@ class CategoryFetcherTest extends FetcherBase { public function testNoInternet() { $this->config - ->method('getSystemValue') + ->method('getSystemValueBool') ->willReturnCallback(function ($var, $default) { if ($var === 'has_internet_connection') { return false; diff --git a/tests/lib/App/AppStore/Fetcher/FetcherBase.php b/tests/lib/App/AppStore/Fetcher/FetcherBase.php index 42ad02ce6d8..dbc3f2a687c 100644 --- a/tests/lib/App/AppStore/Fetcher/FetcherBase.php +++ b/tests/lib/App/AppStore/Fetcher/FetcherBase.php @@ -76,20 +76,12 @@ abstract class FetcherBase extends TestCase { public function testGetWithAlreadyExistingFileAndUpToDateTimestampAndVersion() { $this->config - ->expects($this->once()) - ->method('getSystemValueBool') - ->with('appstoreenabled', true) - ->willReturn(true); - $this->config - ->expects($this->exactly(2)) - ->method('getSystemValue') - ->withConsecutive( - ['has_internet_connection', true], - [$this->equalTo('version'), $this->anything()], - )->willReturnOnConsecutiveCalls( - true, - '11.0.0.2', - ); + ->expects($this->exactly(1)) + ->method('getSystemValueString') + ->with($this->equalTo('version'), $this->anything()) + ->willReturn('11.0.0.2'); + $this->config->method('getSystemValueBool') + ->willReturnArgument(1); $folder = $this->createMock(ISimpleFolder::class); $file = $this->createMock(ISimpleFile::class); @@ -122,21 +114,17 @@ abstract class FetcherBase extends TestCase { public function testGetWithNotExistingFileAndUpToDateTimestampAndVersion() { $this->config - ->method('getSystemValue') + ->method('getSystemValueString') ->willReturnCallback(function ($var, $default) { - if ($var === 'has_internet_connection') { - return true; - } elseif ($var === 'appstoreurl') { + if ($var === 'appstoreurl') { return 'https://apps.nextcloud.com/api/v1'; } elseif ($var === 'version') { return '11.0.0.2'; } return $default; }); - $this->config - ->method('getSystemValueBool') - ->with('appstoreenabled', $this->anything()) - ->willReturn(true); + $this->config->method('getSystemValueBool') + ->willReturnArgument(1); $folder = $this->createMock(ISimpleFolder::class); $file = $this->createMock(ISimpleFile::class); @@ -200,7 +188,7 @@ abstract class FetcherBase extends TestCase { } public function testGetWithAlreadyExistingFileAndOutdatedTimestamp() { - $this->config->method('getSystemValue') + $this->config->method('getSystemValueString') ->willReturnCallback(function ($key, $default) { if ($key === 'version') { return '11.0.0.2'; @@ -208,10 +196,8 @@ abstract class FetcherBase extends TestCase { return $default; } }); - $this->config - ->method('getSystemValueBool') - ->with('appstoreenabled', true) - ->willReturn(true); + $this->config->method('getSystemValueBool') + ->willReturnArgument(1); $folder = $this->createMock(ISimpleFolder::class); $file = $this->createMock(ISimpleFile::class); @@ -277,21 +263,17 @@ abstract class FetcherBase extends TestCase { public function testGetWithAlreadyExistingFileAndNoVersion() { $this->config - ->method('getSystemValue') + ->method('getSystemValueString') ->willReturnCallback(function ($var, $default) { - if ($var === 'has_internet_connection') { - return true; - } elseif ($var === 'appstoreurl') { + if ($var === 'appstoreurl') { return 'https://apps.nextcloud.com/api/v1'; } elseif ($var === 'version') { return '11.0.0.2'; } return $default; }); - $this->config - ->method('getSystemValueBool') - ->with('appstoreenabled', true) - ->willReturn(true); + $this->config->method('getSystemValueBool') + ->willReturnArgument(1); $folder = $this->createMock(ISimpleFolder::class); $file = $this->createMock(ISimpleFile::class); @@ -354,21 +336,17 @@ abstract class FetcherBase extends TestCase { public function testGetWithAlreadyExistingFileAndOutdatedVersion() { $this->config - ->method('getSystemValue') + ->method('getSystemValueString') ->willReturnCallback(function ($var, $default) { - if ($var === 'has_internet_connection') { - return true; - } elseif ($var === 'appstoreurl') { + if ($var === 'appstoreurl') { return 'https://apps.nextcloud.com/api/v1'; } elseif ($var === 'version') { return '11.0.0.2'; } return $default; }); - $this->config - ->method('getSystemValueBool') - ->with('appstoreenabled', true) - ->willReturn(true); + $this->config->method('getSystemValueBool') + ->willReturnArgument(1); $folder = $this->createMock(ISimpleFolder::class); $file = $this->createMock(ISimpleFile::class); @@ -429,14 +407,10 @@ abstract class FetcherBase extends TestCase { } public function testGetWithExceptionInClient() { - $this->config->method('getSystemValue') - ->willReturnCallback(function ($key, $default) { - return $default; - }); - $this->config - ->method('getSystemValueBool') - ->with('appstoreenabled', true) - ->willReturn(true); + $this->config->method('getSystemValueString') + ->willReturnArgument(1); + $this->config->method('getSystemValueBool') + ->willReturnArgument(1); $folder = $this->createMock(ISimpleFolder::class); $file = $this->createMock(ISimpleFile::class); @@ -469,7 +443,7 @@ abstract class FetcherBase extends TestCase { } public function testGetMatchingETag() { - $this->config->method('getSystemValue') + $this->config->method('getSystemValueString') ->willReturnCallback(function ($key, $default) { if ($key === 'version') { return '11.0.0.2'; @@ -477,10 +451,8 @@ abstract class FetcherBase extends TestCase { return $default; } }); - $this->config - ->method('getSystemValueBool') - ->with('appstoreenabled', true) - ->willReturn(true); + $this->config->method('getSystemValueBool') + ->willReturnArgument(1); $folder = $this->createMock(ISimpleFolder::class); $file = $this->createMock(ISimpleFile::class); @@ -550,7 +522,7 @@ abstract class FetcherBase extends TestCase { } public function testGetNoMatchingETag() { - $this->config->method('getSystemValue') + $this->config->method('getSystemValueString') ->willReturnCallback(function ($key, $default) { if ($key === 'version') { return '11.0.0.2'; @@ -558,10 +530,8 @@ abstract class FetcherBase extends TestCase { return $default; } }); - $this->config - ->method('getSystemValueBool') - ->with('appstoreenabled', true) - ->willReturn(true); + $this->config->method('getSystemValueBool') + ->willReturnArgument(1); $folder = $this->createMock(ISimpleFolder::class); $file = $this->createMock(ISimpleFile::class); @@ -637,7 +607,7 @@ abstract class FetcherBase extends TestCase { public function testFetchAfterUpgradeNoETag() { - $this->config->method('getSystemValue') + $this->config->method('getSystemValueString') ->willReturnCallback(function ($key, $default) { if ($key === 'version') { return '11.0.0.3'; @@ -645,10 +615,8 @@ abstract class FetcherBase extends TestCase { return $default; } }); - $this->config - ->method('getSystemValueBool') - ->with('appstoreenabled', true) - ->willReturn(true); + $this->config->method('getSystemValueBool') + ->willReturnArgument(1); $folder = $this->createMock(ISimpleFolder::class); $file = $this->createMock(ISimpleFile::class); |