123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172 |
- <?php
- namespace Test\Encryption;
- use OC\Encryption\Manager;
- use Test\TestCase;
- class ManagerTest extends TestCase {
- public function testManagerIsDisabled() {
- $config = $this->getMock('\OCP\IConfig');
- $m = new Manager($config);
- $this->assertFalse($m->isEnabled());
- }
- public function testManagerIsDisabledIfEnabledButNoModules() {
- $config = $this->getMock('\OCP\IConfig');
- $config->expects($this->any())->method('getAppValue')->willReturn(true);
- $m = new Manager($config);
- $this->assertFalse($m->isEnabled());
- }
- public function testManagerIsDisabledIfDisabledButModules() {
- $config = $this->getMock('\OCP\IConfig');
- $config->expects($this->any())->method('getAppValue')->willReturn(false);
- $em = $this->getMock('\OCP\Encryption\IEncryptionModule');
- $em->expects($this->any())->method('getId')->willReturn(0);
- $em->expects($this->any())->method('getDisplayName')->willReturn('TestDummyModule0');
- $m = new Manager($config);
- $m->registerEncryptionModule($em);
- $this->assertFalse($m->isEnabled());
- }
- public function testManagerIsEnabled() {
- $config = $this->getMock('\OCP\IConfig');
- $config->expects($this->any())->method('getSystemValue')->willReturn(true);
- $config->expects($this->any())->method('getAppValue')->willReturn('yes');
- $m = new Manager($config);
- $this->assertTrue($m->isEnabled());
- }
- /**
- * @expectedException \OC\Encryption\Exceptions\ModuleAlreadyExistsException
- * @expectedExceptionMessage Id "0" already used by encryption module "TestDummyModule0"
- */
- public function testModuleRegistration() {
- $config = $this->getMock('\OCP\IConfig');
- $config->expects($this->any())->method('getAppValue')->willReturn('yes');
- $em = $this->getMock('\OCP\Encryption\IEncryptionModule');
- $em->expects($this->any())->method('getId')->willReturn(0);
- $em->expects($this->any())->method('getDisplayName')->willReturn('TestDummyModule0');
- $m = new Manager($config);
- $m->registerEncryptionModule($em);
- $this->assertSame(1, count($m->getEncryptionModules()));
- $m->registerEncryptionModule($em);
- }
- public function testModuleUnRegistration() {
- $config = $this->getMock('\OCP\IConfig');
- $config->expects($this->any())->method('getAppValue')->willReturn(true);
- $em = $this->getMock('\OCP\Encryption\IEncryptionModule');
- $em->expects($this->any())->method('getId')->willReturn(0);
- $em->expects($this->any())->method('getDisplayName')->willReturn('TestDummyModule0');
- $m = new Manager($config);
- $m->registerEncryptionModule($em);
- $this->assertSame(1,
- count($m->getEncryptionModules())
- );
- $m->unregisterEncryptionModule($em);
- $this->assertEmpty($m->getEncryptionModules());
- }
- /**
- * @expectedException \OC\Encryption\Exceptions\ModuleDoesNotExistsException
- * @expectedExceptionMessage Module with id: unknown does not exists.
- */
- public function testGetEncryptionModuleUnknown() {
- $config = $this->getMock('\OCP\IConfig');
- $config->expects($this->any())->method('getAppValue')->willReturn(true);
- $em = $this->getMock('\OCP\Encryption\IEncryptionModule');
- $em->expects($this->any())->method('getId')->willReturn(0);
- $em->expects($this->any())->method('getDisplayName')->willReturn('TestDummyModule0');
- $m = new Manager($config);
- $m->registerEncryptionModule($em);
- $this->assertSame(1, count($m->getEncryptionModules()));
- $m->getEncryptionModule('unknown');
- }
- public function testGetEncryptionModule() {
- $config = $this->getMock('\OCP\IConfig');
- $config->expects($this->any())->method('getAppValue')->willReturn(true);
- $em = $this->getMock('\OCP\Encryption\IEncryptionModule');
- $em->expects($this->any())->method('getId')->willReturn(0);
- $em->expects($this->any())->method('getDisplayName')->willReturn('TestDummyModule0');
- $m = new Manager($config);
- $m->registerEncryptionModule($em);
- $this->assertSame(1, count($m->getEncryptionModules()));
- $en0 = $m->getEncryptionModule(0);
- $this->assertEquals(0, $en0->getId());
- }
- public function testGetDefaultEncryptionModule() {
- $config = $this->getMock('\OCP\IConfig');
- $config->expects($this->any())->method('getAppValue')->willReturn(true);
- $em = $this->getMock('\OCP\Encryption\IEncryptionModule');
- $em->expects($this->any())->method('getId')->willReturn(0);
- $em->expects($this->any())->method('getDisplayName')->willReturn('TestDummyModule0');
- $m = new Manager($config);
- $m->registerEncryptionModule($em);
- $this->assertSame(1, count($m->getEncryptionModules()));
- $en0 = $m->getEncryptionModule(0);
- $this->assertEquals(0, $en0->getId());
- }
- // /**
- // * @expectedException \OC\Encryption\Exceptions\ModuleAlreadyExistsException
- // * @expectedExceptionMessage Id "0" already used by encryption module "TestDummyModule0"
- // */
- // public function testModuleRegistration() {
- // $config = $this->getMock('\OCP\IConfig');
- // $config->expects($this->any())->method('getSystemValue')->willReturn(true);
- // $em = $this->getMock('\OCP\Encryption\IEncryptionModule');
- // $em->expects($this->any())->method('getId')->willReturn(0);
- // $em->expects($this->any())->method('getDisplayName')->willReturn('TestDummyModule0');
- // $m = new Manager($config);
- // $m->registerEncryptionModule($em);
- // $this->assertTrue($m->isEnabled());
- // $m->registerEncryptionModule($em);
- // }
- //
- // public function testModuleUnRegistration() {
- // $config = $this->getMock('\OCP\IConfig');
- // $config->expects($this->any())->method('getSystemValue')->willReturn(true);
- // $em = $this->getMock('\OCP\Encryption\IEncryptionModule');
- // $em->expects($this->any())->method('getId')->willReturn(0);
- // $em->expects($this->any())->method('getDisplayName')->willReturn('TestDummyModule0');
- // $m = new Manager($config);
- // $m->registerEncryptionModule($em);
- // $this->assertTrue($m->isEnabled());
- // $m->unregisterEncryptionModule($em);
- // $this->assertFalse($m->isEnabled());
- // }
- //
- // /**
- // * @expectedException \OC\Encryption\Exceptions\ModuleDoesNotExistsException
- // * @expectedExceptionMessage Module with id: unknown does not exists.
- // */
- // public function testGetEncryptionModuleUnknown() {
- // $config = $this->getMock('\OCP\IConfig');
- // $config->expects($this->any())->method('getSystemValue')->willReturn(true);
- // $em = $this->getMock('\OCP\Encryption\IEncryptionModule');
- // $em->expects($this->any())->method('getId')->willReturn(0);
- // $em->expects($this->any())->method('getDisplayName')->willReturn('TestDummyModule0');
- // $m = new Manager($config);
- // $m->registerEncryptionModule($em);
- // $this->assertTrue($m->isEnabled());
- // $m->getEncryptionModule('unknown');
- // }
- //
- // public function testGetEncryptionModule() {
- // $config = $this->getMock('\OCP\IConfig');
- // $config->expects($this->any())->method('getSystemValue')->willReturn(true);
- // $em = $this->getMock('\OCP\Encryption\IEncryptionModule');
- // $em->expects($this->any())->method('getId')->willReturn(0);
- // $em->expects($this->any())->method('getDisplayName')->willReturn('TestDummyModule0');
- // $m = new Manager($config);
- // $m->registerEncryptionModule($em);
- // $this->assertTrue($m->isEnabled());
- // $en0 = $m->getEncryptionModule(0);
- // $this->assertEquals(0, $en0->getId());
- // }
- }
|