ApplicationTest.php 3.5 KB

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