diff options
author | Joas Schilling <nickvergessen@owncloud.com> | 2015-04-17 07:57:32 +0200 |
---|---|---|
committer | Joas Schilling <nickvergessen@owncloud.com> | 2015-04-27 11:03:50 +0200 |
commit | b35379515cbac1b0163ee220104d9e0963f73346 (patch) | |
tree | 1533f4299d7e3be38c91c0cf78345f2ebe4d388a /tests/lib/encryption | |
parent | f6d4bdb1fd936741252802b8e0bc79a7bd4c3905 (diff) | |
download | nextcloud-server-b35379515cbac1b0163ee220104d9e0963f73346.tar.gz nextcloud-server-b35379515cbac1b0163ee220104d9e0963f73346.zip |
Add a test that the default module is returned before we fall back
Diffstat (limited to 'tests/lib/encryption')
-rw-r--r-- | tests/lib/encryption/managertest.php | 36 |
1 files changed, 35 insertions, 1 deletions
diff --git a/tests/lib/encryption/managertest.php b/tests/lib/encryption/managertest.php index 13f5d47b083..32b1eb6df10 100644 --- a/tests/lib/encryption/managertest.php +++ b/tests/lib/encryption/managertest.php @@ -21,7 +21,6 @@ class ManagerTest extends TestCase { $this->config = $this->getMock('\OCP\IConfig'); $this->logger = $this->getMock('\OCP\ILogger'); $this->manager = new Manager($this->config, $this->logger); - } public function testManagerIsDisabled() { @@ -92,6 +91,27 @@ class ManagerTest extends TestCase { $this->manager->getEncryptionModule('unknown'); } + public function testGetEncryptionModuleEmpty() { + global $defaultId; + $defaultId = null; + + $this->config->expects($this->any()) + ->method('getAppValue') + ->with('core', 'default_encryption_module') + ->willReturnCallback(function() { global $defaultId; return $defaultId; }); + + $this->addNewEncryptionModule($this->manager, 0); + $this->assertCount(1, $this->manager->getEncryptionModules()); + $this->addNewEncryptionModule($this->manager, 1); + $this->assertCount(2, $this->manager->getEncryptionModules()); + + // Should return the default module + $defaultId = 'ID0'; + $this->assertEquals('ID0', $this->manager->getEncryptionModule()->getId()); + $defaultId = 'ID1'; + $this->assertEquals('ID1', $this->manager->getEncryptionModule()->getId()); + } + public function testGetEncryptionModule() { $this->config->expects($this->any())->method('getAppValue')->willReturn(true); $em = $this->getMock('\OCP\Encryption\IEncryptionModule'); @@ -171,4 +191,18 @@ class ManagerTest extends TestCase { // $en0 = $m->getEncryptionModule(0); // $this->assertEquals(0, $en0->getId()); // } + + protected function addNewEncryptionModule(Manager $manager, $id) { + $encryptionModule = $this->getMock('\OCP\Encryption\IEncryptionModule'); + $encryptionModule->expects($this->any()) + ->method('getId') + ->willReturn('ID' . $id); + $encryptionModule->expects($this->any()) + ->method('getDisplayName') + ->willReturn('TestDummyModule' . $id); + /** @var \OCP\Encryption\IEncryptionModule $encryptionModule */ + $manager->registerEncryptionModule('ID' . $id, 'TestDummyModule' . $id, function() use ($encryptionModule) { + return $encryptionModule; + }); + } } |