1
0

AdminTest.php 3.0 KB

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