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.

ApplicationTest.php 3.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016, Joas Schilling <coding@schilljs.com>
  4. *
  5. * @author Joas Schilling <coding@schilljs.com>
  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;
  24. use OC\Settings\Application;
  25. use OC\Settings\Controller\AdminSettingsController;
  26. use OC\Settings\Controller\AppSettingsController;
  27. use OC\Settings\Controller\AuthSettingsController;
  28. use OC\Settings\Controller\CertificateController;
  29. use OC\Settings\Controller\CheckSetupController;
  30. use OC\Settings\Controller\EncryptionController;
  31. use OC\Settings\Controller\GroupsController;
  32. use OC\Settings\Controller\LogSettingsController;
  33. use OC\Settings\Controller\MailSettingsController;
  34. use OC\Settings\Controller\SecuritySettingsController;
  35. use OC\Settings\Controller\UsersController;
  36. use OC\Settings\Middleware\SubadminMiddleware;
  37. use OCP\AppFramework\Controller;
  38. use OCP\AppFramework\Middleware;
  39. use OCP\IUser;
  40. use OCP\IUserSession;
  41. use Test\TestCase;
  42. /**
  43. * Class ApplicationTest
  44. *
  45. * @package Tests\Settings
  46. * @group DB
  47. */
  48. class ApplicationTest extends TestCase {
  49. /** @var \OC\Settings\Application */
  50. protected $app;
  51. /** @var \OCP\AppFramework\IAppContainer */
  52. protected $container;
  53. protected function setUp() {
  54. parent::setUp();
  55. $this->app = new Application();
  56. $this->container = $this->app->getContainer();
  57. }
  58. public function testContainerAppName() {
  59. $this->app = new Application();
  60. $this->assertEquals('settings', $this->container->getAppName());
  61. }
  62. public function dataContainerQuery() {
  63. return [
  64. [AdminSettingsController::class, Controller::class],
  65. [AppSettingsController::class, Controller::class],
  66. [AuthSettingsController::class, Controller::class],
  67. // Needs session: [CertificateController::class, Controller::class],
  68. [CheckSetupController::class, Controller::class],
  69. [EncryptionController::class, Controller::class],
  70. [GroupsController::class, Controller::class],
  71. [LogSettingsController::class, Controller::class],
  72. [MailSettingsController::class, Controller::class],
  73. [SecuritySettingsController::class, Controller::class],
  74. [UsersController::class, Controller::class],
  75. [SubadminMiddleware::class, Middleware::class],
  76. ];
  77. }
  78. /**
  79. * @dataProvider dataContainerQuery
  80. * @param string $service
  81. * @param string $expected
  82. */
  83. public function testContainerQuery($service, $expected) {
  84. $this->assertTrue($this->container->query($service) instanceof $expected);
  85. }
  86. public function dataContainerQueryRequiresSession() {
  87. return [
  88. [CertificateController::class, Controller::class],
  89. ];
  90. }
  91. /**
  92. * @dataProvider dataContainerQueryRequiresSession
  93. * @param string $service
  94. * @param string $expected
  95. */
  96. public function testContainerQueryRequiresSession($service, $expected) {
  97. $user = $this->createMock(IUser::class);
  98. $user->expects($this->once())
  99. ->method('getUID')
  100. ->willReturn('test');
  101. $session = $this->createMock(IUserSession::class);
  102. $session->expects($this->once())
  103. ->method('getUser')
  104. ->willReturn($user);
  105. $this->overwriteService('UserSession', $session);
  106. $this->assertTrue($this->container->query($service) instanceof $expected);
  107. $this->restoreService('UserSession');
  108. }
  109. }