From b35379515cbac1b0163ee220104d9e0963f73346 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Fri, 17 Apr 2015 07:57:32 +0200 Subject: [PATCH] Add a test that the default module is returned before we fall back --- tests/lib/encryption/managertest.php | 36 +++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/tests/lib/encryption/managertest.php b/tests/lib/encryption/managertest.php index 13f5d47b08..32b1eb6df1 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; + }); + } }