Test improvements

This commit is contained in:
Robin Appelman 2015-02-02 15:47:54 +01:00
parent 409453bc60
commit 4d805b52cc
2 changed files with 16 additions and 37 deletions

View File

@ -1,4 +1,5 @@
<?php <?php
/** /**
* Copyright (c) 2012 Bernhard Posselt <dev@bernhard-posselt.com> * Copyright (c) 2012 Bernhard Posselt <dev@bernhard-posselt.com>
* Copyright (c) 2014 Vincent Petry <pvince81@owncloud.com> * Copyright (c) 2014 Vincent Petry <pvince81@owncloud.com>
@ -6,12 +7,8 @@
* later. * later.
* See the COPYING-README file. * See the COPYING-README file.
*/ */
class Test_App extends \Test\TestCase { class Test_App extends \Test\TestCase {
private $oldAppConfigService;
private $oldAppManagerService;
const TEST_USER1 = 'user1'; const TEST_USER1 = 'user1';
const TEST_USER2 = 'user2'; const TEST_USER2 = 'user2';
const TEST_USER3 = 'user3'; const TEST_USER3 = 'user3';
@ -399,10 +396,9 @@ class Test_App extends \Test\TestCase {
'appforgroup12' => '["group2","group1"]', 'appforgroup12' => '["group2","group1"]',
) )
) )
); );
$apps = \OC_App::getEnabledApps(true, $forceAll); $apps = \OC_App::getEnabledApps(true, $forceAll);
$this->assertEquals($expectedApps, $apps);
$this->restoreAppConfig(); $this->restoreAppConfig();
\OC_User::setUserId(null); \OC_User::setUserId(null);
@ -413,6 +409,8 @@ class Test_App extends \Test\TestCase {
$group1->delete(); $group1->delete();
$group2->delete(); $group2->delete();
$this->assertEquals($expectedApps, $apps);
} }
/** /**
@ -433,7 +431,7 @@ class Test_App extends \Test\TestCase {
'app2' => 'no', 'app2' => 'no',
) )
) )
); );
$apps = \OC_App::getEnabledApps(true); $apps = \OC_App::getEnabledApps(true);
$this->assertEquals(array('files', 'app3'), $apps); $this->assertEquals(array('files', 'app3'), $apps);
@ -448,30 +446,6 @@ class Test_App extends \Test\TestCase {
$user1->delete(); $user1->delete();
} }
/**
* Tests that the apps list is re-requested (not cached) when
* no user is set.
*/
public function testEnabledAppsNoCache() {
$this->setupAppConfigMock()->expects($this->exactly(2))
->method('getValues')
->will($this->returnValue(
array(
'app3' => 'yes',
'app2' => 'no',
)
)
);
$apps = \OC_App::getEnabledApps(true);
$this->assertEquals(array('files', 'app3'), $apps);
// mock should be called again here
$apps = \OC_App::getEnabledApps(false);
$this->assertEquals(array('files', 'app3'), $apps);
$this->restoreAppConfig();
}
private function setupAppConfigMock() { private function setupAppConfigMock() {
$appConfig = $this->getMock( $appConfig = $this->getMock(
@ -488,11 +462,10 @@ class Test_App extends \Test\TestCase {
/** /**
* Register an app config mock for testing purposes. * Register an app config mock for testing purposes.
*
* @param $appConfig app config mock * @param $appConfig app config mock
*/ */
private function registerAppConfig($appConfig) { private function registerAppConfig($appConfig) {
$this->oldAppConfigService = \OC::$server->query('AppConfig');
$this->oldAppManagerService = \OC::$server->query('AppManager');
\OC::$server->registerService('AppConfig', function ($c) use ($appConfig) { \OC::$server->registerService('AppConfig', function ($c) use ($appConfig) {
return $appConfig; return $appConfig;
}); });
@ -505,11 +478,11 @@ class Test_App extends \Test\TestCase {
* Restore the original app config service. * Restore the original app config service.
*/ */
private function restoreAppConfig() { private function restoreAppConfig() {
\OC::$server->registerService('AppConfig', function ($c){ \OC::$server->registerService('AppConfig', function ($c) {
return $this->oldAppConfigService; return new \OC\AppConfig(\OC_DB::getConnection());
}); });
\OC::$server->registerService('AppManager', function ($c) { \OC::$server->registerService('AppManager', function (\OC\Server $c) {
return $this->oldAppManagerService; return new \OC\App\AppManager($c->getUserSession(), $c->getAppConfig(), $c->getGroupManager());
}); });
// Remove the cache of the mocked apps list with a forceRefresh // Remove the cache of the mocked apps list with a forceRefresh

View File

@ -11,6 +11,12 @@ class Test_Appconfig extends \Test\TestCase {
public static function setUpBeforeClass() { public static function setUpBeforeClass() {
parent::setUpBeforeClass(); parent::setUpBeforeClass();
$query = \OC_DB::prepare('DELETE FROM `*PREFIX*appconfig` WHERE `appid` = ?');
$query->execute(array('testapp'));
$query->execute(array('someapp'));
$query->execute(array('123456'));
$query->execute(array('anotherapp'));
$query = \OC_DB::prepare('INSERT INTO `*PREFIX*appconfig` VALUES (?, ?, ?)'); $query = \OC_DB::prepare('INSERT INTO `*PREFIX*appconfig` VALUES (?, ?, ?)');
$query->execute(array('testapp', 'enabled', 'true')); $query->execute(array('testapp', 'enabled', 'true'));