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.

AdminSettingsControllerTest.php 3.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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\Settings\Tests\Controller;
  24. use OCA\Settings\Personal\ServerDevNotice;
  25. use OCA\Settings\Controller\AdminSettingsController;
  26. use OCP\AppFramework\Http\TemplateResponse;
  27. use OCP\Group\ISubAdmin;
  28. use OCP\IGroupManager;
  29. use OCP\INavigationManager;
  30. use OCP\IRequest;
  31. use OCP\IUser;
  32. use OCP\IUserSession;
  33. use OCP\Settings\IManager;
  34. use PHPUnit\Framework\MockObject\MockObject;
  35. use Test\TestCase;
  36. /**
  37. * Class AdminSettingsControllerTest
  38. *
  39. * @group DB
  40. *
  41. * @package Tests\Settings\Controller
  42. */
  43. class AdminSettingsControllerTest extends TestCase {
  44. /** @var AdminSettingsController */
  45. private $adminSettingsController;
  46. /** @var IRequest|MockObject */
  47. private $request;
  48. /** @var INavigationManager|MockObject */
  49. private $navigationManager;
  50. /** @var IManager|MockObject */
  51. private $settingsManager;
  52. /** @var IUserSession|MockObject */
  53. private $userSession;
  54. /** @var IGroupManager|MockObject */
  55. private $groupManager;
  56. /** @var ISubAdmin|MockObject */
  57. private $subAdmin;
  58. /** @var string */
  59. private $adminUid = 'lololo';
  60. public function setUp() {
  61. parent::setUp();
  62. $this->request = $this->createMock(IRequest::class);
  63. $this->navigationManager = $this->createMock(INavigationManager::class);
  64. $this->settingsManager = $this->createMock(IManager::class);
  65. $this->userSession = $this->createMock(IUserSession::class);
  66. $this->groupManager = $this->createMock(IGroupManager::class);
  67. $this->subAdmin = $this->createMock(ISubAdmin::class);
  68. $this->adminSettingsController = new AdminSettingsController(
  69. 'settings',
  70. $this->request,
  71. $this->navigationManager,
  72. $this->settingsManager,
  73. $this->userSession,
  74. $this->groupManager,
  75. $this->subAdmin
  76. );
  77. $user = \OC::$server->getUserManager()->createUser($this->adminUid, 'olo');
  78. \OC_User::setUserId($user->getUID());
  79. \OC::$server->getGroupManager()->createGroup('admin')->addUser($user);
  80. }
  81. public function tearDown() {
  82. \OC::$server->getUserManager()->get($this->adminUid)->delete();
  83. parent::tearDown();
  84. }
  85. public function testIndex() {
  86. $user = $this->createMock(IUser::class);
  87. $this->userSession
  88. ->method('getUser')
  89. ->willReturn($user);
  90. $user->method('getUID')->willReturn('user123');
  91. $this->groupManager
  92. ->method('isAdmin')
  93. ->with('user123')
  94. ->willReturn(true);
  95. $this->subAdmin
  96. ->method('isSubAdmin')
  97. ->with($user)
  98. ->willReturn(false);
  99. $this->settingsManager
  100. ->expects($this->once())
  101. ->method('getAdminSections')
  102. ->willReturn([]);
  103. $this->settingsManager
  104. ->expects($this->once())
  105. ->method('getPersonalSections')
  106. ->willReturn([]);
  107. $this->settingsManager
  108. ->expects($this->once())
  109. ->method('getAdminSettings')
  110. ->with('test')
  111. ->willReturn([5 => new ServerDevNotice()]);
  112. $idx = $this->adminSettingsController->index('test');
  113. $expected = new TemplateResponse('settings', 'settings/frame', ['forms' => ['personal' => [], 'admin' => []], 'content' => '']);
  114. $this->assertEquals($expected, $idx);
  115. }
  116. }