Deduplicate module mock

This commit is contained in:
Joas Schilling 2015-04-17 12:23:04 +02:00
parent 4b7ae395f2
commit 4e97228cde
1 changed files with 34 additions and 41 deletions

View File

@ -47,32 +47,30 @@ class ManagerTest extends TestCase {
$this->assertTrue($this->manager->isEnabled()); $this->assertTrue($this->manager->isEnabled());
} }
/**
* @expectedException \OC\Encryption\Exceptions\ModuleAlreadyExistsException
* @expectedExceptionMessage Id "id" already used by encryption module "TestDummyModule0"
*/
public function testModuleRegistration() { public function testModuleRegistration() {
$this->config->expects($this->any())->method('getAppValue')->willReturn('yes'); $this->config->expects($this->any())->method('getAppValue')->willReturn('yes');
$em = $this->getMock('\OCP\Encryption\IEncryptionModule');
$em->expects($this->any())->method('getId')->willReturn('id');
$em->expects($this->any())->method('getDisplayName')->willReturn('TestDummyModule0');
$this->manager->registerEncryptionModule('id', 'TestDummyModule0', function () use ($em) { return $em;}); $this->addNewEncryptionModule($this->manager, 0);
$this->assertSame(1, count($this->manager->getEncryptionModules())); $this->assertCount(1, $this->manager->getEncryptionModules());
$this->manager->registerEncryptionModule('id', 'TestDummyModule0', function () use ($em) { return $em;});
return $this->manager;
}
/**
* @depends testModuleRegistration
* @expectedException \OC\Encryption\Exceptions\ModuleAlreadyExistsException
* @expectedExceptionMessage Id "ID0" already used by encryption module "TestDummyModule0"
*/
public function testModuleReRegistration($manager) {
$this->addNewEncryptionModule($manager, 0);
} }
public function testModuleUnRegistration() { public function testModuleUnRegistration() {
$this->config->expects($this->any())->method('getAppValue')->willReturn(true); $this->config->expects($this->any())->method('getAppValue')->willReturn(true);
$em = $this->getMock('\OCP\Encryption\IEncryptionModule'); $this->addNewEncryptionModule($this->manager, 0);
$em->expects($this->any())->method('getId')->willReturn('id'); $this->assertCount(1, $this->manager->getEncryptionModules());
$em->expects($this->any())->method('getDisplayName')->willReturn('TestDummyModule0');
$this->manager->registerEncryptionModule('id', 'TestDummyModule0', function () use ($em) { return $em;});
$this->assertSame(1,
count($this->manager->getEncryptionModules())
);
$this->manager->unregisterEncryptionModule('id'); $this->manager->unregisterEncryptionModule('ID0');
$this->assertEmpty($this->manager->getEncryptionModules()); $this->assertEmpty($this->manager->getEncryptionModules());
} }
@ -83,11 +81,8 @@ class ManagerTest extends TestCase {
*/ */
public function testGetEncryptionModuleUnknown() { public function testGetEncryptionModuleUnknown() {
$this->config->expects($this->any())->method('getAppValue')->willReturn(true); $this->config->expects($this->any())->method('getAppValue')->willReturn(true);
$em = $this->getMock('\OCP\Encryption\IEncryptionModule'); $this->addNewEncryptionModule($this->manager, 0);
$em->expects($this->any())->method('getId')->willReturn('id'); $this->assertCount(1, $this->manager->getEncryptionModules());
$em->expects($this->any())->method('getDisplayName')->willReturn('TestDummyModule0');
$this->manager->registerEncryptionModule('id', 'TestDummyModule0', function () use ($em) { return $em;});
$this->assertSame(1, count($this->manager->getEncryptionModules()));
$this->manager->getEncryptionModule('unknown'); $this->manager->getEncryptionModule('unknown');
} }
@ -113,25 +108,23 @@ class ManagerTest extends TestCase {
} }
public function testGetEncryptionModule() { public function testGetEncryptionModule() {
$this->config->expects($this->any())->method('getAppValue')->willReturn(true); global $defaultId;
$em = $this->getMock('\OCP\Encryption\IEncryptionModule'); $defaultId = null;
$em->expects($this->any())->method('getId')->willReturn('id');
$em->expects($this->any())->method('getDisplayName')->willReturn('TestDummyModule0');
$this->manager->registerEncryptionModule('id', 'TestDummyModule0', function () use ($em) { return $em;});
$this->assertSame(1, count($this->manager->getEncryptionModules()));
$en0 = $this->manager->getEncryptionModule('id');
$this->assertEquals('id', $en0->getId());
}
public function testGetDefaultEncryptionModule() { $this->config->expects($this->any())
$this->config->expects($this->any())->method('getAppValue')->willReturn(true); ->method('getAppValue')
$em = $this->getMock('\OCP\Encryption\IEncryptionModule'); ->with('core', 'default_encryption_module')
$em->expects($this->any())->method('getId')->willReturn('id'); ->willReturnCallback(function() { global $defaultId; return $defaultId; });
$em->expects($this->any())->method('getDisplayName')->willReturn('TestDummyModule0');
$this->manager->registerEncryptionModule('id', 'TestDummyModule0', function () use ($em) { return $em;}); $this->addNewEncryptionModule($this->manager, 0);
$this->assertSame(1, count($this->manager->getEncryptionModules())); $defaultId = 'ID0';
$en0 = $this->manager->getEncryptionModule('id'); $this->assertCount(1, $this->manager->getEncryptionModules());
$this->assertEquals('id', $en0->getId());
$en0 = $this->manager->getEncryptionModule('ID0');
$this->assertEquals('ID0', $en0->getId());
$en0 = $this->manager->getDefaultEncryptionModule();
$this->assertEquals('ID0', $en0->getId());
} }
public function testSetDefaultEncryptionModule() { public function testSetDefaultEncryptionModule() {