1
0

AdminTest.php 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. <?php
  2. /**
  3. * SPDX-FileCopyrightText: 2016 Nextcloud GmbH and Nextcloud contributors
  4. * SPDX-License-Identifier: AGPL-3.0-or-later
  5. */
  6. namespace OCA\Encryption\Tests\Settings;
  7. use OCA\Encryption\Settings\Admin;
  8. use OCP\AppFramework\Http\TemplateResponse;
  9. use OCP\IConfig;
  10. use OCP\IL10N;
  11. use OCP\ISession;
  12. use OCP\IUserManager;
  13. use OCP\IUserSession;
  14. use Psr\Log\LoggerInterface;
  15. use Test\TestCase;
  16. class AdminTest extends TestCase {
  17. /** @var Admin */
  18. private $admin;
  19. /** @var IL10N */
  20. private $l;
  21. /** @var LoggerInterface */
  22. private $logger;
  23. /** @var IUserSession */
  24. private $userSession;
  25. /** @var IConfig */
  26. private $config;
  27. /** @var IUserManager */
  28. private $userManager;
  29. /** @var ISession */
  30. private $session;
  31. protected function setUp(): void {
  32. parent::setUp();
  33. $this->l = $this->getMockBuilder(IL10N::class)->getMock();
  34. $this->logger = $this->getMockBuilder(LoggerInterface::class)->getMock();
  35. $this->userSession = $this->getMockBuilder(IUserSession::class)->getMock();
  36. $this->config = $this->getMockBuilder(IConfig::class)->getMock();
  37. $this->userManager = $this->getMockBuilder(IUserManager::class)->getMock();
  38. $this->session = $this->getMockBuilder(ISession::class)->getMock();
  39. $this->admin = new Admin(
  40. $this->l,
  41. $this->logger,
  42. $this->userSession,
  43. $this->config,
  44. $this->userManager,
  45. $this->session
  46. );
  47. }
  48. public function testGetForm(): void {
  49. $this->config
  50. ->method('getAppValue')
  51. ->will($this->returnCallback(function ($app, $key, $default) {
  52. if ($app === 'encryption' && $key === 'recoveryAdminEnabled' && $default === '0') {
  53. return '1';
  54. }
  55. if ($app === 'encryption' && $key === 'encryptHomeStorage' && $default === '1') {
  56. return '1';
  57. }
  58. return $default;
  59. }));
  60. $params = [
  61. 'recoveryEnabled' => '1',
  62. 'initStatus' => '0',
  63. 'encryptHomeStorage' => true,
  64. 'masterKeyEnabled' => true
  65. ];
  66. $expected = new TemplateResponse('encryption', 'settings-admin', $params, '');
  67. $this->assertEquals($expected, $this->admin->getForm());
  68. }
  69. public function testGetSection(): void {
  70. $this->assertSame('security', $this->admin->getSection());
  71. }
  72. public function testGetPriority(): void {
  73. $this->assertSame(11, $this->admin->getPriority());
  74. }
  75. }