AdminTest.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016 Lukas Reschke <lukas@statuscode.ch>
  4. *
  5. * @author Lukas Reschke <lukas@statuscode.ch>
  6. *
  7. * @license GNU AGPL version 3 or any later version
  8. *
  9. * This program is free software: you can redistribute it and/or modify
  10. * it under the terms of the GNU Affero General Public License as
  11. * published by the Free Software Foundation, either version 3 of the
  12. * License, or (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU Affero General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU Affero General Public License
  20. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  21. *
  22. */
  23. namespace OCA\Encryption\Tests\Settings;
  24. use OCA\Encryption\Settings\Admin;
  25. use OCP\AppFramework\Http\TemplateResponse;
  26. use OCP\IConfig;
  27. use OCP\ISession;
  28. use OCP\IUserManager;
  29. use OCP\IUserSession;
  30. use OCP\IL10N;
  31. use OCP\ILogger;
  32. use Test\TestCase;
  33. class AdminTest extends TestCase {
  34. /** @var Admin */
  35. private $admin;
  36. /** @var IL10N */
  37. private $l;
  38. /** @var ILogger */
  39. private $logger;
  40. /** @var IUserSession */
  41. private $userSession;
  42. /** @var IConfig */
  43. private $config;
  44. /** @var IUserManager */
  45. private $userManager;
  46. /** @var ISession */
  47. private $session;
  48. public function setUp() {
  49. parent::setUp();
  50. $this->l = $this->getMockBuilder('\OCP\IL10N')->getMock();
  51. $this->logger = $this->getMockBuilder('\OCP\ILogger')->getMock();
  52. $this->userSession = $this->getMockBuilder('\OCP\IUserSession')->getMock();
  53. $this->config = $this->getMockBuilder('\OCP\IConfig')->getMock();
  54. $this->userManager = $this->getMockBuilder('\OCP\IUserManager')->getMock();
  55. $this->session = $this->getMockBuilder('\OCP\ISession')->getMock();
  56. $this->admin = new Admin(
  57. $this->l,
  58. $this->logger,
  59. $this->userSession,
  60. $this->config,
  61. $this->userManager,
  62. $this->session
  63. );
  64. }
  65. public function testGetForm() {
  66. $this->config
  67. ->expects($this->at(0))
  68. ->method('getAppValue')
  69. ->with('encryption', 'recoveryAdminEnabled', '0')
  70. ->willReturn(1);
  71. $this->config
  72. ->expects($this->at(1))
  73. ->method('getAppValue')
  74. ->with('encryption', 'encryptHomeStorage', '1')
  75. ->willReturn(1);
  76. $params = [
  77. 'recoveryEnabled' => 1,
  78. 'initStatus' => '0',
  79. 'encryptHomeStorage' => false,
  80. 'masterKeyEnabled' => false
  81. ];
  82. $expected = new TemplateResponse('encryption', 'settings-admin', $params, '');
  83. $this->assertEquals($expected, $this->admin->getForm());
  84. }
  85. public function testGetSection() {
  86. $this->assertSame('encryption', $this->admin->getSection());
  87. }
  88. public function testGetPriority() {
  89. $this->assertSame(5, $this->admin->getPriority());
  90. }
  91. }