Skip to content

Commit fec1b6e

Browse files
committed
Fix tests and add some more tests if apps can be installed, updated and uninstalled
1 parent aa66107 commit fec1b6e

File tree

2 files changed

+43
-30
lines changed

2 files changed

+43
-30
lines changed

lib/MarketService.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,10 @@ public function getInstalledAppInfo($appId) {
255255
* @throws AppNotInstalledException
256256
*/
257257
public function updateApp($appId) {
258+
if (!$this->appManager->canInstall()) {
259+
throw new \Exception("Installing apps is not supported because the app folder is not writable.");
260+
}
261+
258262
try {
259263
$info = $this->getInstalledAppInfo($appId);
260264
if (is_null($info)) {
@@ -278,6 +282,10 @@ public function updateApp($appId) {
278282
* @throws AppManagerException
279283
*/
280284
public function uninstallApp($appId) {
285+
if (!$this->appManager->canInstall()) {
286+
throw new \Exception("Installing apps is not supported because the app folder is not writable.");
287+
}
288+
281289
if ($this->appManager->isShipped($appId)) {
282290
throw new AppManagerException($this->l10n->t('Shipped apps cannot be uninstalled'));
283291
}

tests/unit/MarketServiceTest.php

Lines changed: 35 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,26 @@
99

1010
class MarketServiceTest extends TestCase {
1111

12+
/** @var MarketService */
1213
private $marketService;
14+
/** @var boolean */
1315
private $hasInternetConnection;
16+
/** @var IAppManager | PHPUnit_Framework_MockObject_MockObject */
17+
private $appManager;
1418

1519
public function setUp(){
1620
$this->hasInternetConnection = true;
17-
$appManagerMock = $this->getMockBuilder(IAppManager::class)->getMock();
18-
$appManagerMock->method('getAllApps')->will($this->returnValue([]));
19-
21+
$this->appManager = $this->createMock(IAppManager::class);
22+
$this->appManager->method('getAllApps')->willReturn([]);
23+
24+
/** @var IConfig | PHPUnit_Framework_MockObject_MockObject $configMock */
2025
$configMock = $this->getConfigMock();
21-
$cacheFactoryMock = $this->getMockBuilder(ICacheFactory::class)->getMock();
22-
$l10nMock = $this->getMockBuilder(IL10N::class)->getMock();
26+
/** @var ICacheFactory | PHPUnit_Framework_MockObject_MockObject $cacheFactoryMock */
27+
$cacheFactoryMock = $this->createMock(ICacheFactory::class);
28+
/** @var IL10N | PHPUnit_Framework_MockObject_MockObject $l10nMock */
29+
$l10nMock = $this->createMock(IL10N::class);
2330
$this->marketService = new MarketService(
24-
$appManagerMock,
31+
$this->appManager,
2532
$configMock,
2633
$cacheFactoryMock,
2734
$l10nMock
@@ -33,6 +40,7 @@ public function setUp(){
3340
*/
3441
public function testInstallWithInternetConnectionDisabled(){
3542
$this->hasInternetConnection = false;
43+
$this->appManager->method('canInstall')->willReturn(true);
3644
$this->marketService->installApp('fubar');
3745
}
3846

@@ -41,8 +49,28 @@ public function testInstallWithInternetConnectionDisabled(){
4149
*/
4250
public function testUpdateWithInternetConnectionDisabled(){
4351
$this->hasInternetConnection = false;
52+
$this->appManager->method('canInstall')->willReturn(true);
4453
$this->marketService->updateApp('files');
4554
}
55+
56+
/**
57+
* @dataProvider providesMarketMethods
58+
* @expectedException \Exception
59+
* @expectedExceptionMessage Installing apps is not supported because the app folder is not writable.
60+
*/
61+
public function testInstallNotPossible($method) {
62+
$this->appManager->method('canInstall')->willReturn(false);
63+
64+
$this->marketService->$method('test');
65+
}
66+
67+
public function providesMarketMethods() {
68+
return [
69+
['installApp'],
70+
['uninstallApp'],
71+
['updateApp']
72+
];
73+
}
4674

4775
public function getSystemValue($configKey, $default = null){
4876
if ($configKey==='has_internet_connection'){
@@ -52,30 +80,7 @@ public function getSystemValue($configKey, $default = null){
5280
}
5381

5482
private function getConfigMock(){
55-
$config = $this->getMockBuilder(IConfig::class)
56-
->setMethods([
57-
'getSystemValue',
58-
'setSystemValue',
59-
'getSystemValues',
60-
'setSystemValues',
61-
'getFilteredSystemValue',
62-
'deleteSystemValue',
63-
'getAppKeys',
64-
'setAppValue',
65-
'getAppValue',
66-
'deleteAppValue',
67-
'deleteAppValues',
68-
'setUserValue',
69-
'getUserValue',
70-
'getUserValueForUsers',
71-
'getUserKeys',
72-
'deleteUserValue',
73-
'deleteAllUserValues',
74-
'deleteAppFromAllUsers',
75-
'getUsersForUserValue',
76-
])
77-
->getMock();
78-
83+
$config = $this->createMock(IConfig::class);
7984
$config->method('getSystemValue')
8085
->will($this->returnCallback([$this, 'getSystemValue']));
8186
return $config;

0 commit comments

Comments
 (0)