AdminSettingsControllerTest.php 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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 Tests\Settings\Controller;
  24. use OC\Settings\Personal\ServerDevNotice;
  25. use OC\Settings\Controller\AdminSettingsController;
  26. use OCP\AppFramework\Http\TemplateResponse;
  27. use OCP\INavigationManager;
  28. use OCP\IRequest;
  29. use OCP\Settings\IManager;
  30. use Test\TestCase;
  31. /**
  32. * Class AdminSettingsControllerTest
  33. *
  34. * @group DB
  35. *
  36. * @package Tests\Settings\Controller
  37. */
  38. class AdminSettingsControllerTest extends TestCase {
  39. /** @var AdminSettingsController */
  40. private $adminSettingsController;
  41. /** @var IRequest */
  42. private $request;
  43. /** @var INavigationManager */
  44. private $navigationManager;
  45. /** @var IManager|\PHPUnit_Framework_MockObject_MockObject */
  46. private $settingsManager;
  47. /** @var string */
  48. private $adminUid = 'lololo';
  49. public function setUp() {
  50. parent::setUp();
  51. $this->request = $this->getMockBuilder(IRequest::class)->getMock();
  52. $this->navigationManager = $this->getMockBuilder(INavigationManager::class)->getMock();
  53. $this->settingsManager = $this->getMockBuilder(IManager::class)->getMock();
  54. $this->adminSettingsController = new AdminSettingsController(
  55. 'settings',
  56. $this->request,
  57. $this->navigationManager,
  58. $this->settingsManager
  59. );
  60. $user = \OC::$server->getUserManager()->createUser($this->adminUid, 'olo');
  61. \OC_User::setUserId($user->getUID());
  62. \OC::$server->getGroupManager()->createGroup('admin')->addUser($user);
  63. }
  64. public function tearDown() {
  65. \OC::$server->getUserManager()->get($this->adminUid)->delete();
  66. parent::tearDown();
  67. }
  68. public function testIndex() {
  69. $this->settingsManager
  70. ->expects($this->once())
  71. ->method('getAdminSections')
  72. ->willReturn([]);
  73. $this->settingsManager
  74. ->expects($this->once())
  75. ->method('getPersonalSections')
  76. ->willReturn([]);
  77. $this->settingsManager
  78. ->expects($this->once())
  79. ->method('getAdminSettings')
  80. ->with('test')
  81. ->willReturn([5 => new ServerDevNotice()]);
  82. $expected = new TemplateResponse('settings', 'settings/frame', ['forms' => ['personal' => [], 'admin' => []], 'content' => '']);
  83. $this->assertEquals($expected, $this->adminSettingsController->index('test'));
  84. }
  85. }