You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

135 lines
4.1 KiB

10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016 Lukas Reschke <lukas@statuscode.ch>
  4. *
  5. * @author Arthur Schiwon <blizzz@arthur-schiwon.de>
  6. * @author Christoph Wurst <christoph@winzerhof-wurst.at>
  7. * @author Julius Härtl <jus@bitgrid.net>
  8. * @author Lukas Reschke <lukas@statuscode.ch>
  9. * @author Roeland Jago Douma <roeland@famdouma.nl>
  10. *
  11. * @license GNU AGPL version 3 or any later version
  12. *
  13. * This program is free software: you can redistribute it and/or modify
  14. * it under the terms of the GNU Affero General Public License as
  15. * published by the Free Software Foundation, either version 3 of the
  16. * License, or (at your option) any later version.
  17. *
  18. * This program is distributed in the hope that it will be useful,
  19. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  20. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  21. * GNU Affero General Public License for more details.
  22. *
  23. * You should have received a copy of the GNU Affero General Public License
  24. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  25. *
  26. */
  27. namespace OCA\Settings\Tests\Controller;
  28. use OCA\Settings\Controller\AdminSettingsController;
  29. use OCA\Settings\Settings\Personal\ServerDevNotice;
  30. use OCP\AppFramework\Http\TemplateResponse;
  31. use OCP\Group\ISubAdmin;
  32. use OCP\IGroupManager;
  33. use OCP\INavigationManager;
  34. use OCP\IRequest;
  35. use OCP\IUser;
  36. use OCP\IUserSession;
  37. use OCP\Settings\IManager;
  38. use OCP\Support\Subscription\IRegistry;
  39. use PHPUnit\Framework\MockObject\MockObject;
  40. use Test\TestCase;
  41. /**
  42. * Class AdminSettingsControllerTest
  43. *
  44. * @group DB
  45. *
  46. * @package Tests\Settings\Controller
  47. */
  48. class AdminSettingsControllerTest extends TestCase {
  49. /** @var AdminSettingsController */
  50. private $adminSettingsController;
  51. /** @var IRequest|MockObject */
  52. private $request;
  53. /** @var INavigationManager|MockObject */
  54. private $navigationManager;
  55. /** @var IManager|MockObject */
  56. private $settingsManager;
  57. /** @var IUserSession|MockObject */
  58. private $userSession;
  59. /** @var IGroupManager|MockObject */
  60. private $groupManager;
  61. /** @var ISubAdmin|MockObject */
  62. private $subAdmin;
  63. /** @var string */
  64. private $adminUid = 'lololo';
  65. protected function setUp(): void {
  66. parent::setUp();
  67. $this->request = $this->createMock(IRequest::class);
  68. $this->navigationManager = $this->createMock(INavigationManager::class);
  69. $this->settingsManager = $this->createMock(IManager::class);
  70. $this->userSession = $this->createMock(IUserSession::class);
  71. $this->groupManager = $this->createMock(IGroupManager::class);
  72. $this->subAdmin = $this->createMock(ISubAdmin::class);
  73. $this->adminSettingsController = new AdminSettingsController(
  74. 'settings',
  75. $this->request,
  76. $this->navigationManager,
  77. $this->settingsManager,
  78. $this->userSession,
  79. $this->groupManager,
  80. $this->subAdmin
  81. );
  82. $user = \OC::$server->getUserManager()->createUser($this->adminUid, 'olo');
  83. \OC_User::setUserId($user->getUID());
  84. \OC::$server->getGroupManager()->createGroup('admin')->addUser($user);
  85. }
  86. protected function tearDown(): void {
  87. \OC::$server->getUserManager()->get($this->adminUid)->delete();
  88. parent::tearDown();
  89. }
  90. public function testIndex() {
  91. $user = $this->createMock(IUser::class);
  92. $registry = $this->createMock(IRegistry::class);
  93. $this->userSession
  94. ->method('getUser')
  95. ->willReturn($user);
  96. $user->method('getUID')->willReturn('user123');
  97. $this->groupManager
  98. ->method('isAdmin')
  99. ->with('user123')
  100. ->willReturn(true);
  101. $this->subAdmin
  102. ->method('isSubAdmin')
  103. ->with($user)
  104. ->willReturn(false);
  105. $this->settingsManager
  106. ->expects($this->once())
  107. ->method('getAdminSections')
  108. ->willReturn([]);
  109. $this->settingsManager
  110. ->expects($this->once())
  111. ->method('getPersonalSections')
  112. ->willReturn([]);
  113. $this->settingsManager
  114. ->expects($this->once())
  115. ->method('getAdminSettings')
  116. ->with('test')
  117. ->willReturn([5 => new ServerDevNotice($registry)]);
  118. $idx = $this->adminSettingsController->index('test');
  119. $expected = new TemplateResponse('settings', 'settings/frame', ['forms' => ['personal' => [], 'admin' => []], 'content' => '']);
  120. $this->assertEquals($expected, $idx);
  121. }
  122. }