diff options
Diffstat (limited to 'apps/provisioning_api/tests/Controller/AppsControllerTest.php')
-rw-r--r-- | apps/provisioning_api/tests/Controller/AppsControllerTest.php | 60 |
1 files changed, 36 insertions, 24 deletions
diff --git a/apps/provisioning_api/tests/Controller/AppsControllerTest.php b/apps/provisioning_api/tests/Controller/AppsControllerTest.php index 66c873e5327..f95daeae7d3 100644 --- a/apps/provisioning_api/tests/Controller/AppsControllerTest.php +++ b/apps/provisioning_api/tests/Controller/AppsControllerTest.php @@ -7,10 +7,17 @@ */ namespace OCA\Provisioning_API\Tests\Controller; +use OC\Installer; use OCA\Provisioning_API\Controller\AppsController; +use OCA\Provisioning_API\Tests\TestCase; use OCP\App\IAppManager; +use OCP\AppFramework\OCS\OCSException; +use OCP\IAppConfig; +use OCP\IGroupManager; use OCP\IRequest; use OCP\IUserSession; +use OCP\Server; +use PHPUnit\Framework\MockObject\MockObject; /** * Class AppsTest @@ -19,47 +26,52 @@ use OCP\IUserSession; * * @package OCA\Provisioning_API\Tests */ -class AppsControllerTest extends \OCA\Provisioning_API\Tests\TestCase { - /** @var IAppManager */ - private $appManager; - /** @var AppsController */ - private $api; - /** @var IUserSession */ - private $userSession; +class AppsControllerTest extends TestCase { + private IAppManager $appManager; + private IAppConfig&MockObject $appConfig; + private Installer&MockObject $installer; + private AppsController $api; + private IUserSession $userSession; protected function setUp(): void { parent::setUp(); - $this->appManager = \OC::$server->getAppManager(); - $this->groupManager = \OC::$server->getGroupManager(); - $this->userSession = \OC::$server->getUserSession(); + $this->appManager = Server::get(IAppManager::class); + $this->groupManager = Server::get(IGroupManager::class); + $this->userSession = Server::get(IUserSession::class); + $this->appConfig = $this->createMock(IAppConfig::class); + $this->installer = $this->createMock(Installer::class); - $request = $this->getMockBuilder(IRequest::class) - ->disableOriginalConstructor() - ->getMock(); + $request = $this->createMock(IRequest::class); $this->api = new AppsController( 'provisioning_api', $request, - $this->appManager + $this->appManager, + $this->installer, + $this->appConfig, ); } - public function testGetAppInfo() { + protected function tearDown(): void { + $this->userSession->setUser(null); + } + + public function testGetAppInfo(): void { $result = $this->api->getAppInfo('provisioning_api'); $expected = $this->appManager->getAppInfo('provisioning_api'); $this->assertEquals($expected, $result->getData()); } - - public function testGetAppInfoOnBadAppID() { - $this->expectException(\OCP\AppFramework\OCS\OCSException::class); + + public function testGetAppInfoOnBadAppID(): void { + $this->expectException(OCSException::class); $this->expectExceptionCode(998); $this->api->getAppInfo('not_provisioning_api'); } - public function testGetApps() { + public function testGetApps(): void { $user = $this->generateUsers(); $this->groupManager->get('admin')->addUser($user); $this->userSession->setUser($user); @@ -70,13 +82,13 @@ class AppsControllerTest extends \OCA\Provisioning_API\Tests\TestCase { $this->assertEquals(count((new \OC_App())->listAllApps()), count($data['apps'])); } - public function testGetAppsEnabled() { + public function testGetAppsEnabled(): void { $result = $this->api->getApps('enabled'); $data = $result->getData(); $this->assertEquals(count(\OC_App::getEnabledApps()), count($data['apps'])); } - public function testGetAppsDisabled() { + public function testGetAppsDisabled(): void { $result = $this->api->getApps('disabled'); $data = $result->getData(); $apps = (new \OC_App)->listAllApps(); @@ -88,9 +100,9 @@ class AppsControllerTest extends \OCA\Provisioning_API\Tests\TestCase { $this->assertEquals(count($disabled), count($data['apps'])); } - - public function testGetAppsInvalidFilter() { - $this->expectException(\OCP\AppFramework\OCS\OCSException::class); + + public function testGetAppsInvalidFilter(): void { + $this->expectException(OCSException::class); $this->expectExceptionCode(101); $this->api->getApps('foo'); |