1
0

managertest.php 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. <?php
  2. namespace Test\Encryption;
  3. use OC\Encryption\Manager;
  4. use Test\TestCase;
  5. class ManagerTest extends TestCase {
  6. public function testManagerIsDisabled() {
  7. $config = $this->getMock('\OCP\IConfig');
  8. $m = new Manager($config);
  9. $this->assertFalse($m->isEnabled());
  10. }
  11. public function testManagerIsDisabledIfEnabledButNoModules() {
  12. $config = $this->getMock('\OCP\IConfig');
  13. $config->expects($this->any())->method('getAppValue')->willReturn(true);
  14. $m = new Manager($config);
  15. $this->assertFalse($m->isEnabled());
  16. }
  17. public function testManagerIsDisabledIfDisabledButModules() {
  18. $config = $this->getMock('\OCP\IConfig');
  19. $config->expects($this->any())->method('getAppValue')->willReturn(false);
  20. $em = $this->getMock('\OCP\Encryption\IEncryptionModule');
  21. $em->expects($this->any())->method('getId')->willReturn(0);
  22. $em->expects($this->any())->method('getDisplayName')->willReturn('TestDummyModule0');
  23. $m = new Manager($config);
  24. $m->registerEncryptionModule($em);
  25. $this->assertFalse($m->isEnabled());
  26. }
  27. public function testManagerIsEnabled() {
  28. $config = $this->getMock('\OCP\IConfig');
  29. $config->expects($this->any())->method('getSystemValue')->willReturn(true);
  30. $config->expects($this->any())->method('getAppValue')->willReturn('yes');
  31. $m = new Manager($config);
  32. $this->assertTrue($m->isEnabled());
  33. }
  34. /**
  35. * @expectedException \OC\Encryption\Exceptions\ModuleAlreadyExistsException
  36. * @expectedExceptionMessage Id "0" already used by encryption module "TestDummyModule0"
  37. */
  38. public function testModuleRegistration() {
  39. $config = $this->getMock('\OCP\IConfig');
  40. $config->expects($this->any())->method('getAppValue')->willReturn('yes');
  41. $em = $this->getMock('\OCP\Encryption\IEncryptionModule');
  42. $em->expects($this->any())->method('getId')->willReturn(0);
  43. $em->expects($this->any())->method('getDisplayName')->willReturn('TestDummyModule0');
  44. $m = new Manager($config);
  45. $m->registerEncryptionModule($em);
  46. $this->assertSame(1, count($m->getEncryptionModules()));
  47. $m->registerEncryptionModule($em);
  48. }
  49. public function testModuleUnRegistration() {
  50. $config = $this->getMock('\OCP\IConfig');
  51. $config->expects($this->any())->method('getAppValue')->willReturn(true);
  52. $em = $this->getMock('\OCP\Encryption\IEncryptionModule');
  53. $em->expects($this->any())->method('getId')->willReturn(0);
  54. $em->expects($this->any())->method('getDisplayName')->willReturn('TestDummyModule0');
  55. $m = new Manager($config);
  56. $m->registerEncryptionModule($em);
  57. $this->assertSame(1,
  58. count($m->getEncryptionModules())
  59. );
  60. $m->unregisterEncryptionModule($em);
  61. $this->assertEmpty($m->getEncryptionModules());
  62. }
  63. /**
  64. * @expectedException \OC\Encryption\Exceptions\ModuleDoesNotExistsException
  65. * @expectedExceptionMessage Module with id: unknown does not exists.
  66. */
  67. public function testGetEncryptionModuleUnknown() {
  68. $config = $this->getMock('\OCP\IConfig');
  69. $config->expects($this->any())->method('getAppValue')->willReturn(true);
  70. $em = $this->getMock('\OCP\Encryption\IEncryptionModule');
  71. $em->expects($this->any())->method('getId')->willReturn(0);
  72. $em->expects($this->any())->method('getDisplayName')->willReturn('TestDummyModule0');
  73. $m = new Manager($config);
  74. $m->registerEncryptionModule($em);
  75. $this->assertSame(1, count($m->getEncryptionModules()));
  76. $m->getEncryptionModule('unknown');
  77. }
  78. public function testGetEncryptionModule() {
  79. $config = $this->getMock('\OCP\IConfig');
  80. $config->expects($this->any())->method('getAppValue')->willReturn(true);
  81. $em = $this->getMock('\OCP\Encryption\IEncryptionModule');
  82. $em->expects($this->any())->method('getId')->willReturn(0);
  83. $em->expects($this->any())->method('getDisplayName')->willReturn('TestDummyModule0');
  84. $m = new Manager($config);
  85. $m->registerEncryptionModule($em);
  86. $this->assertSame(1, count($m->getEncryptionModules()));
  87. $en0 = $m->getEncryptionModule(0);
  88. $this->assertEquals(0, $en0->getId());
  89. }
  90. public function testGetDefaultEncryptionModule() {
  91. $config = $this->getMock('\OCP\IConfig');
  92. $config->expects($this->any())->method('getAppValue')->willReturn(true);
  93. $em = $this->getMock('\OCP\Encryption\IEncryptionModule');
  94. $em->expects($this->any())->method('getId')->willReturn(0);
  95. $em->expects($this->any())->method('getDisplayName')->willReturn('TestDummyModule0');
  96. $m = new Manager($config);
  97. $m->registerEncryptionModule($em);
  98. $this->assertSame(1, count($m->getEncryptionModules()));
  99. $en0 = $m->getEncryptionModule(0);
  100. $this->assertEquals(0, $en0->getId());
  101. }
  102. // /**
  103. // * @expectedException \OC\Encryption\Exceptions\ModuleAlreadyExistsException
  104. // * @expectedExceptionMessage Id "0" already used by encryption module "TestDummyModule0"
  105. // */
  106. // public function testModuleRegistration() {
  107. // $config = $this->getMock('\OCP\IConfig');
  108. // $config->expects($this->any())->method('getSystemValue')->willReturn(true);
  109. // $em = $this->getMock('\OCP\Encryption\IEncryptionModule');
  110. // $em->expects($this->any())->method('getId')->willReturn(0);
  111. // $em->expects($this->any())->method('getDisplayName')->willReturn('TestDummyModule0');
  112. // $m = new Manager($config);
  113. // $m->registerEncryptionModule($em);
  114. // $this->assertTrue($m->isEnabled());
  115. // $m->registerEncryptionModule($em);
  116. // }
  117. //
  118. // public function testModuleUnRegistration() {
  119. // $config = $this->getMock('\OCP\IConfig');
  120. // $config->expects($this->any())->method('getSystemValue')->willReturn(true);
  121. // $em = $this->getMock('\OCP\Encryption\IEncryptionModule');
  122. // $em->expects($this->any())->method('getId')->willReturn(0);
  123. // $em->expects($this->any())->method('getDisplayName')->willReturn('TestDummyModule0');
  124. // $m = new Manager($config);
  125. // $m->registerEncryptionModule($em);
  126. // $this->assertTrue($m->isEnabled());
  127. // $m->unregisterEncryptionModule($em);
  128. // $this->assertFalse($m->isEnabled());
  129. // }
  130. //
  131. // /**
  132. // * @expectedException \OC\Encryption\Exceptions\ModuleDoesNotExistsException
  133. // * @expectedExceptionMessage Module with id: unknown does not exists.
  134. // */
  135. // public function testGetEncryptionModuleUnknown() {
  136. // $config = $this->getMock('\OCP\IConfig');
  137. // $config->expects($this->any())->method('getSystemValue')->willReturn(true);
  138. // $em = $this->getMock('\OCP\Encryption\IEncryptionModule');
  139. // $em->expects($this->any())->method('getId')->willReturn(0);
  140. // $em->expects($this->any())->method('getDisplayName')->willReturn('TestDummyModule0');
  141. // $m = new Manager($config);
  142. // $m->registerEncryptionModule($em);
  143. // $this->assertTrue($m->isEnabled());
  144. // $m->getEncryptionModule('unknown');
  145. // }
  146. //
  147. // public function testGetEncryptionModule() {
  148. // $config = $this->getMock('\OCP\IConfig');
  149. // $config->expects($this->any())->method('getSystemValue')->willReturn(true);
  150. // $em = $this->getMock('\OCP\Encryption\IEncryptionModule');
  151. // $em->expects($this->any())->method('getId')->willReturn(0);
  152. // $em->expects($this->any())->method('getDisplayName')->willReturn('TestDummyModule0');
  153. // $m = new Manager($config);
  154. // $m->registerEncryptionModule($em);
  155. // $this->assertTrue($m->isEnabled());
  156. // $en0 = $m->getEncryptionModule(0);
  157. // $this->assertEquals(0, $en0->getId());
  158. // }
  159. }