Skip to content

Commit

Permalink
Fix unit tests
Browse files Browse the repository at this point in the history
Signed-off-by: Joas Schilling <coding@schilljs.com>
  • Loading branch information
nickvergessen committed Oct 21, 2021
1 parent facb50e commit f24e821
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 41 deletions.
40 changes: 26 additions & 14 deletions tests/lib/App/AppStore/Fetcher/AppFetcherTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1868,16 +1868,18 @@ protected function setUp(): void {
public function testGetWithFilter() {
$this->config->method('getSystemValue')
->willReturnCallback(function ($key, $default) {
if ($key === 'appstoreenabled') {
return true;
} elseif ($key === 'version') {
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';
} else {
return $default;
}
});
$this->config
->method('getSystemValueBool')
->with('appstoreenabled', true)
->willReturn(true);

$file = $this->createMock(ISimpleFile::class);
$folder = $this->createMock(ISimpleFolder::class);
Expand Down Expand Up @@ -1951,13 +1953,15 @@ public function testAppstoreDisabled() {
$this->config
->method('getSystemValue')
->willReturnCallback(function ($var, $default) {
if ($var === 'appstoreenabled') {
return false;
} elseif ($var === 'version') {
if ($var === 'version') {
return '11.0.0.2';
}
return $default;
});
$this->config
->method('getSystemValueBool')
->with('appstoreenabled', true)
->willReturn(false);
$this->appData
->expects($this->never())
->method('getFolder');
Expand All @@ -1977,6 +1981,10 @@ public function testNoInternet() {
}
return $default;
});
$this->config
->method('getSystemValueBool')
->with('appstoreenabled', true)
->willReturn(true);
$this->appData
->expects($this->never())
->method('getFolder');
Expand All @@ -1987,16 +1995,18 @@ public function testNoInternet() {
public function testSetVersion() {
$this->config->method('getSystemValue')
->willReturnCallback(function ($key, $default) {
if ($key === 'appstoreenabled') {
return true;
} elseif ($key === 'version') {
if ($key === 'version') {
return '10.0.7.2';
} elseif ($key === 'appstoreurl' && $default === 'https://apps.nextcloud.com/api/v1') {
return 'https://custom.appsstore.endpoint/api/v1';
} else {
return $default;
}
});
$this->config
->method('getSystemValueBool')
->with('appstoreenabled', true)
->willReturn(true);

$file = $this->createMock(ISimpleFile::class);
$folder = $this->createMock(ISimpleFolder::class);
Expand Down Expand Up @@ -2070,9 +2080,7 @@ public function testSetVersion() {
public function testGetAppsAllowlist() {
$this->config->method('getSystemValue')
->willReturnCallback(function ($key, $default) {
if ($key === 'appstoreenabled') {
return true;
} elseif ($key === 'version') {
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';
Expand All @@ -2082,7 +2090,11 @@ public function testGetAppsAllowlist() {
return $default;
}
});

$this->config
->method('getSystemValueBool')
->with('appstoreenabled', true)
->willReturn(true);

$file = $this->createMock(ISimpleFile::class);
$folder = $this->createMock(ISimpleFolder::class);
$folder
Expand Down Expand Up @@ -2122,7 +2134,7 @@ public function testGetAppsAllowlist() {
->expects($this->once())
->method('getTime')
->willReturn(1234);

$this->registry
->expects($this->exactly(2))
->method('delegateHasValidSubscription')
Expand Down
68 changes: 41 additions & 27 deletions tests/lib/App/AppStore/Fetcher/FetcherBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ protected function setUp(): void {
public function testGetWithAlreadyExistingFileAndUpToDateTimestampAndVersion() {
$this->config
->expects($this->at(0))
->method('getSystemValue')
->method('getSystemValueBool')
->with('appstoreenabled', true)
->willReturn(true);
$this->config
Expand Down Expand Up @@ -126,9 +126,7 @@ public function testGetWithNotExistingFileAndUpToDateTimestampAndVersion() {
$this->config
->method('getSystemValue')
->willReturnCallback(function ($var, $default) {
if ($var === 'appstoreenabled') {
return true;
} elseif ($var === 'has_internet_connection') {
if ($var === 'has_internet_connection') {
return true;
} elseif ($var === 'appstoreurl') {
return 'https://apps.nextcloud.com/api/v1';
Expand All @@ -137,6 +135,10 @@ public function testGetWithNotExistingFileAndUpToDateTimestampAndVersion() {
}
return $default;
});
$this->config
->method('getSystemValueBool')
->with('appstoreenabled', $this->anything())
->willReturn(true);

$folder = $this->createMock(ISimpleFolder::class);
$file = $this->createMock(ISimpleFile::class);
Expand Down Expand Up @@ -202,14 +204,16 @@ public function testGetWithNotExistingFileAndUpToDateTimestampAndVersion() {
public function testGetWithAlreadyExistingFileAndOutdatedTimestamp() {
$this->config->method('getSystemValue')
->willReturnCallback(function ($key, $default) {
if ($key === 'appstoreenabled') {
return true;
} elseif ($key === 'version') {
if ($key === 'version') {
return '11.0.0.2';
} else {
return $default;
}
});
$this->config
->method('getSystemValueBool')
->with('appstoreenabled', true)
->willReturn(true);

$folder = $this->createMock(ISimpleFolder::class);
$file = $this->createMock(ISimpleFile::class);
Expand Down Expand Up @@ -279,9 +283,7 @@ public function testGetWithAlreadyExistingFileAndNoVersion() {
$this->config
->method('getSystemValue')
->willReturnCallback(function ($var, $default) {
if ($var === 'appstoreenabled') {
return true;
} elseif ($var === 'has_internet_connection') {
if ($var === 'has_internet_connection') {
return true;
} elseif ($var === 'appstoreurl') {
return 'https://apps.nextcloud.com/api/v1';
Expand All @@ -290,6 +292,10 @@ public function testGetWithAlreadyExistingFileAndNoVersion() {
}
return $default;
});
$this->config
->method('getSystemValueBool')
->with('appstoreenabled', true)
->willReturn(true);

$folder = $this->createMock(ISimpleFolder::class);
$file = $this->createMock(ISimpleFile::class);
Expand Down Expand Up @@ -355,9 +361,7 @@ public function testGetWithAlreadyExistingFileAndOutdatedVersion() {
$this->config
->method('getSystemValue')
->willReturnCallback(function ($var, $default) {
if ($var === 'appstoreenabled') {
return true;
} elseif ($var === 'has_internet_connection') {
if ($var === 'has_internet_connection') {
return true;
} elseif ($var === 'appstoreurl') {
return 'https://apps.nextcloud.com/api/v1';
Expand All @@ -366,6 +370,10 @@ public function testGetWithAlreadyExistingFileAndOutdatedVersion() {
}
return $default;
});
$this->config
->method('getSystemValueBool')
->with('appstoreenabled', true)
->willReturn(true);

$folder = $this->createMock(ISimpleFolder::class);
$file = $this->createMock(ISimpleFile::class);
Expand Down Expand Up @@ -429,12 +437,12 @@ public function testGetWithAlreadyExistingFileAndOutdatedVersion() {
public function testGetWithExceptionInClient() {
$this->config->method('getSystemValue')
->willReturnCallback(function ($key, $default) {
if ($key === 'appstoreenabled') {
return true;
} else {
return $default;
}
return $default;
});
$this->config
->method('getSystemValueBool')
->with('appstoreenabled', true)
->willReturn(true);

$folder = $this->createMock(ISimpleFolder::class);
$file = $this->createMock(ISimpleFile::class);
Expand Down Expand Up @@ -469,14 +477,16 @@ public function testGetWithExceptionInClient() {
public function testGetMatchingETag() {
$this->config->method('getSystemValue')
->willReturnCallback(function ($key, $default) {
if ($key === 'appstoreenabled') {
return true;
} elseif ($key === 'version') {
if ($key === 'version') {
return '11.0.0.2';
} else {
return $default;
}
});
$this->config
->method('getSystemValueBool')
->with('appstoreenabled', true)
->willReturn(true);

$folder = $this->createMock(ISimpleFolder::class);
$file = $this->createMock(ISimpleFile::class);
Expand Down Expand Up @@ -550,14 +560,16 @@ public function testGetMatchingETag() {
public function testGetNoMatchingETag() {
$this->config->method('getSystemValue')
->willReturnCallback(function ($key, $default) {
if ($key === 'appstoreenabled') {
return true;
} elseif ($key === 'version') {
if ($key === 'version') {
return '11.0.0.2';
} else {
return $default;
}
});
$this->config
->method('getSystemValueBool')
->with('appstoreenabled', true)
->willReturn(true);

$folder = $this->createMock(ISimpleFolder::class);
$file = $this->createMock(ISimpleFile::class);
Expand Down Expand Up @@ -637,14 +649,16 @@ public function testGetNoMatchingETag() {
public function testFetchAfterUpgradeNoETag() {
$this->config->method('getSystemValue')
->willReturnCallback(function ($key, $default) {
if ($key === 'appstoreenabled') {
return true;
} elseif ($key === 'version') {
if ($key === 'version') {
return '11.0.0.3';
} else {
return $default;
}
});
$this->config
->method('getSystemValueBool')
->with('appstoreenabled', true)
->willReturn(true);

$folder = $this->createMock(ISimpleFolder::class);
$file = $this->createMock(ISimpleFile::class);
Expand Down

0 comments on commit f24e821

Please sign in to comment.