[Pkg-owncloud-commits] [owncloud] 27/258: Added unit tests for cache of enabled apps
David Prévot
taffit at moszumanska.debian.org
Sat Oct 11 17:22:17 UTC 2014
This is an automated email from the git hooks/post-receive script.
taffit pushed a commit to branch master
in repository owncloud.
commit f268eee86c65b8409b1274fbaad04d460e1ecc8f
Author: Vincent Petry <pvince81 at owncloud.com>
Date: Wed Sep 3 11:01:59 2014 +0200
Added unit tests for cache of enabled apps
---
tests/lib/app.php | 84 ++++++++++++++++++++++++++++++++++++++++++++++++-------
1 file changed, 74 insertions(+), 10 deletions(-)
diff --git a/tests/lib/app.php b/tests/lib/app.php
index 9873d42..e538ebe 100644
--- a/tests/lib/app.php
+++ b/tests/lib/app.php
@@ -337,15 +337,7 @@ class Test_App extends PHPUnit_Framework_TestCase {
\OC_User::setUserId($user);
- $appConfig = $this->getMock(
- '\OC\AppConfig',
- array('getValues'),
- array(\OC_DB::getConnection()),
- '',
- false
- );
-
- $appConfig->expects($this->once())
+ $this->setupAppConfigMock()->expects($this->once())
->method('getValues')
->will($this->returnValue(
array(
@@ -358,7 +350,6 @@ class Test_App extends PHPUnit_Framework_TestCase {
)
)
);
- $this->registerAppConfig($appConfig);
$apps = \OC_App::getEnabledApps(true, $forceAll);
$this->assertEquals($expectedApps, $apps);
@@ -378,6 +369,79 @@ class Test_App extends PHPUnit_Framework_TestCase {
}
/**
+ * Test isEnabledApps() with cache, not re-reading the list of
+ * enabled apps more than once when a user is set.
+ */
+ public function testEnabledAppsCache() {
+ $userManager = \OC::$server->getUserManager();
+ $user1 = $userManager->createUser(self::TEST_USER1, self::TEST_USER1);
+
+ \OC_User::setUserId(self::TEST_USER1);
+
+ $this->setupAppConfigMock()->expects($this->once())
+ ->method('getValues')
+ ->will($this->returnValue(
+ array(
+ 'app3' => 'yes',
+ 'app2' => 'no',
+ )
+ )
+ );
+
+ $apps = \OC_App::getEnabledApps(true);
+ $this->assertEquals(array('files', 'app3'), $apps);
+
+ // mock should not be called again here
+ $apps = \OC_App::getEnabledApps(false);
+ $this->assertEquals(array('files', 'app3'), $apps);
+
+ $this->restoreAppConfig();
+ \OC_User::setUserId(null);
+
+ $user1->delete();
+ // clear user cache...
+ $userManager->delete(self::TEST_USER1);
+ }
+
+ /**
+ * 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() {
+ $appConfig = $this->getMock(
+ '\OC\AppConfig',
+ array('getValues'),
+ array(\OC_DB::getConnection()),
+ '',
+ false
+ );
+
+ $this->registerAppConfig($appConfig);
+ return $appConfig;
+ }
+
+ /**
* Register an app config mock for testing purposes.
* @param $appConfig app config mock
*/
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-owncloud/owncloud.git
More information about the Pkg-owncloud-commits
mailing list