diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/Core/Command/Apps/AppsEnableTest.php | 1 | ||||
-rw-r--r-- | tests/Core/Controller/SvgControllerTest.php | 65 | ||||
-rw-r--r-- | tests/data/svg/files-app-red.svg | 1 | ||||
-rw-r--r-- | tests/data/svg/settings-admin-red.svg | 1 | ||||
-rw-r--r-- | tests/lib/App/AppManagerTest.php | 29 | ||||
-rw-r--r-- | tests/lib/AppFramework/Routing/RoutingTest.php | 141 | ||||
-rw-r--r-- | tests/lib/Authentication/Login/FinishRememberedLoginCommandTest.php | 25 | ||||
-rw-r--r-- | tests/lib/Share20/ManagerTest.php | 1 |
8 files changed, 170 insertions, 94 deletions
diff --git a/tests/Core/Command/Apps/AppsEnableTest.php b/tests/Core/Command/Apps/AppsEnableTest.php index a8aa4c434f0..b5d781aa125 100644 --- a/tests/Core/Command/Apps/AppsEnableTest.php +++ b/tests/Core/Command/Apps/AppsEnableTest.php @@ -75,6 +75,7 @@ class AppsEnableTest extends TestCase { $data = [ [['admin_audit'], null, 0, 'admin_audit enabled'], [['comments'], null, 0, 'comments enabled'], + [['comments', 'comments'], null, 0, "comments enabled\ncomments already enabled"], [['invalid_app'], null, 1, 'Could not download app invalid_app'], [['admin_audit', 'comments'], null, 0, "admin_audit enabled\ncomments enabled"], diff --git a/tests/Core/Controller/SvgControllerTest.php b/tests/Core/Controller/SvgControllerTest.php index 76d04d1af32..f6208d6f6c4 100644 --- a/tests/Core/Controller/SvgControllerTest.php +++ b/tests/Core/Controller/SvgControllerTest.php @@ -28,6 +28,7 @@ namespace Tests\Core\Controller; use OC\AppFramework\Http; use OC\Core\Controller\SvgController; use OC\Template\IconsCacher; +use OCP\App\AppPathNotFoundException; use OCP\App\IAppManager; use OCP\AppFramework\Utility\ITimeFactory; use OCP\IRequest; @@ -46,6 +47,9 @@ class SvgControllerTest extends TestCase { self::TEST_IMAGE_RECT, ]; + /** @var IAppManager|\PHPUnit_Framework_MockObject_MockObject */ + private $appManager; + /** * @var SvgController */ @@ -87,17 +91,20 @@ class SvgControllerTest extends TestCase { * @return void */ public function setupSvgController() { + /** @var IRequest */ $request = $this->getMockBuilder(IRequest::class)->getMock(); + /** @var ITimeFactory $timeFactory */ $timeFactory = $this->getMockBuilder(ITimeFactory::class)->getMock(); - $appManager = $this->getMockBuilder(IAppManager::class)->getMock(); + /** @var IAppManager */ + $this->appManager = $this->getMockBuilder(IAppManager::class)->getMock(); + /** @var IconsCacher $iconsCacher */ $iconsCacher = $this->getMockBuilder(IconsCacher::class)->disableOriginalConstructor()->setMethods(['__construct'])->getMock(); - $this->svgController = new SvgController('core', $request, $timeFactory, $appManager, $iconsCacher); + $this->svgController = new SvgController('core', $request, $timeFactory, $this->appManager, $iconsCacher); } /** * Checks that requesting an unknown image results in a 404. * - * @test * @return void */ public function testGetSvgFromCoreNotFound() { @@ -120,7 +127,6 @@ class SvgControllerTest extends TestCase { /** * Tests that retrieving a colored SVG works. * - * @test * @dataProvider provideGetSvgFromCoreTestData * @param string $name The requested svg name * @param string $color The requested color @@ -138,4 +144,55 @@ class SvgControllerTest extends TestCase { self::assertEquals($expected, $response->getData()); } + + /** + * Checks that requesting an unknown image results in a 404. + */ + public function testGetSvgFromAppNotFound(): void { + $this->appManager->expects($this->once()) + ->method('getAppPath') + ->with('invalid_app') + ->willThrowException(new AppPathNotFoundException('Could not find path for invalid_app')); + + $response = $this->svgController->getSvgFromApp('invalid_app', 'some-icon', '#ff0000'); + self::assertEquals(Http::STATUS_NOT_FOUND, $response->getStatus()); + } + + /** + * Provides svg coloring test data. + * + * @return array + */ + public function provideGetSvgFromAppTestData(): array { + return [ + 'settings admin' => ['settings', 'admin', 'f00', file_get_contents(self::TEST_IMAGES_SOURCE_PATH . '/settings-admin-red.svg')], + 'files app' => ['files', 'app', 'f00', file_get_contents(self::TEST_IMAGES_SOURCE_PATH . '/files-app-red.svg')], + ]; + } + + /** + * Tests that retrieving a colored SVG works. + * + * @dataProvider provideGetSvgFromAppTestData + * @param string $appName + * @param string $name The requested svg name + * @param string $color The requested color + * @param string $expected + */ + public function testGetSvgFromApp(string $appName, string $name, string $color, string $expected): void { + $this->appManager->expects($this->once()) + ->method('getAppPath') + ->with($appName) + ->willReturn(__DIR__ . '/../../../apps/' . $appName); + + $response = $this->svgController->getSvgFromApp($appName, $name, $color); + + self::assertEquals(Http::STATUS_OK, $response->getStatus()); + + $headers = $response->getHeaders(); + self::assertArrayHasKey('Content-Type', $headers); + self::assertEquals($headers['Content-Type'], 'image/svg+xml'); + + self::assertEquals($expected, $response->getData()); + } } diff --git a/tests/data/svg/files-app-red.svg b/tests/data/svg/files-app-red.svg new file mode 100644 index 00000000000..81d7fca1472 --- /dev/null +++ b/tests/data/svg/files-app-red.svg @@ -0,0 +1 @@ +<svg xmlns="http://www.w3.org/2000/svg" height="32" viewBox="0 0 32 32" width="32" version="1.1"><path fill="#f00" d="m3 4c-0.5 0-1 0.5-1 1v22c0 0.52 0.48 1 1 1h26c0.52 0 1-0.482 1-1v-18c0-0.5-0.5-1-1-1h-13l-4-4z"/></svg> diff --git a/tests/data/svg/settings-admin-red.svg b/tests/data/svg/settings-admin-red.svg new file mode 100644 index 00000000000..54d7d3a9b15 --- /dev/null +++ b/tests/data/svg/settings-admin-red.svg @@ -0,0 +1 @@ +<svg xmlns="http://www.w3.org/2000/svg" viewbox="0 0 16 16" height="16" width="16" version="1.1"><path color="#000" d="m1 1v4h4v-4h-4zm5 1v2h8v-2h-8zm-5 4v4h4v-4h-4zm5 1v2h8v-2h-8zm-5 4v4h4v-4h-4zm1 1h2v2h-2v-2zm4 0v2h8v-2h-8z" fill="#f00"/></svg> diff --git a/tests/lib/App/AppManagerTest.php b/tests/lib/App/AppManagerTest.php index 1a5d6c648a1..5b6fedb1cc2 100644 --- a/tests/lib/App/AppManagerTest.php +++ b/tests/lib/App/AppManagerTest.php @@ -338,6 +338,35 @@ class AppManagerTest extends TestCase { $this->assertEquals(\OC::$SERVERROOT . '/apps/files', $this->manager->getAppPath('files')); } + public function testGetAppPathSymlink() { + $fakeAppDirname = sha1(uniqid('test', true)); + $fakeAppPath = sys_get_temp_dir() . '/' . $fakeAppDirname; + $fakeAppLink = \OC::$SERVERROOT . '/' . $fakeAppDirname; + + mkdir($fakeAppPath); + if (symlink($fakeAppPath, $fakeAppLink) === false) { + $this->markTestSkipped('Failed to create symlink'); + } + + // Use the symlink as the app path + \OC::$APPSROOTS[] = [ + 'path' => $fakeAppLink, + 'url' => \OC::$WEBROOT . '/' . $fakeAppDirname, + 'writable' => false, + ]; + + $fakeTestAppPath = $fakeAppPath . '/' . 'test-test-app'; + mkdir($fakeTestAppPath); + + $generatedAppPath = $this->manager->getAppPath('test-test-app'); + + rmdir($fakeTestAppPath); + unlink($fakeAppLink); + rmdir($fakeAppPath); + + $this->assertEquals($fakeAppLink . '/test-test-app', $generatedAppPath); + } + public function testGetAppPathFail() { $this->expectException(AppPathNotFoundException::class); $this->manager->getAppPath('testnotexisting'); diff --git a/tests/lib/AppFramework/Routing/RoutingTest.php b/tests/lib/AppFramework/Routing/RoutingTest.php index 1aef757720b..34aaff82310 100644 --- a/tests/lib/AppFramework/Routing/RoutingTest.php +++ b/tests/lib/AppFramework/Routing/RoutingTest.php @@ -5,6 +5,7 @@ namespace Test\AppFramework\Routing; use OC\AppFramework\DependencyInjection\DIContainer; use OC\AppFramework\Routing\RouteActionHandler; use OC\AppFramework\Routing\RouteConfig; +use OC\Route\Route; use OC\Route\Router; use OCP\ILogger; use OCP\Route\IRouter; @@ -16,7 +17,15 @@ class RoutingTest extends \Test\TestCase { ['name' => 'folders#open', 'url' => '/folders/{folderId}/open', 'verb' => 'GET'] ]]; - $this->assertSimpleRoute($routes, 'folders.open', 'GET', '/folders/{folderId}/open', 'FoldersController', 'open'); + $this->assertSimpleRoute($routes, 'folders.open', 'GET', '/apps/app1/folders/{folderId}/open', 'FoldersController', 'open'); + } + + public function testSimpleRouteWithUnderScoreNames() { + $routes = ['routes' => [ + ['name' => 'admin_folders#open_current', 'url' => '/folders/{folderId}/open', 'verb' => 'delete', 'root' => ''] + ]]; + + $this->assertSimpleRoute($routes, 'admin_folders.open_current', 'DELETE', '/folders/{folderId}/open', 'AdminFoldersController', 'openCurrent', [], [], '', true); } public function testSimpleOCSRoute() { @@ -33,7 +42,7 @@ class RoutingTest extends \Test\TestCase { ['name' => 'folders#open', 'url' => '/folders/{folderId}/open'] ]]; - $this->assertSimpleRoute($routes, 'folders.open', 'GET', '/folders/{folderId}/open', 'FoldersController', 'open'); + $this->assertSimpleRoute($routes, 'folders.open', 'GET', '/apps/app1/folders/{folderId}/open', 'FoldersController', 'open'); } public function testSimpleOCSRouteWithMissingVerb() { @@ -50,7 +59,7 @@ class RoutingTest extends \Test\TestCase { ['name' => 'folders#open', 'url' => '/folders/{folderId}/open', 'verb' => 'delete'] ]]; - $this->assertSimpleRoute($routes, 'folders.open', 'DELETE', '/folders/{folderId}/open', 'FoldersController', 'open'); + $this->assertSimpleRoute($routes, 'folders.open', 'DELETE', '/apps/app1/folders/{folderId}/open', 'FoldersController', 'open'); } public function testSimpleOCSRouteWithLowercaseVerb() { @@ -67,7 +76,7 @@ class RoutingTest extends \Test\TestCase { ['name' => 'folders#open', 'url' => '/folders/{folderId}/open', 'verb' => 'delete', 'requirements' => ['something']] ]]; - $this->assertSimpleRoute($routes, 'folders.open', 'DELETE', '/folders/{folderId}/open', 'FoldersController', 'open', ['something']); + $this->assertSimpleRoute($routes, 'folders.open', 'DELETE', '/apps/app1/folders/{folderId}/open', 'FoldersController', 'open', ['something']); } public function testSimpleOCSRouteWithRequirements() { @@ -84,7 +93,7 @@ class RoutingTest extends \Test\TestCase { ['name' => 'folders#open', 'url' => '/folders/{folderId}/open', 'verb' => 'delete', [], 'defaults' => ['param' => 'foobar']] ]]; - $this->assertSimpleRoute($routes, 'folders.open', 'DELETE', '/folders/{folderId}/open', 'FoldersController', 'open', [], ['param' => 'foobar']); + $this->assertSimpleRoute($routes, 'folders.open', 'DELETE', '/apps/app1/folders/{folderId}/open', 'FoldersController', 'open', [], ['param' => 'foobar']); } @@ -102,7 +111,7 @@ class RoutingTest extends \Test\TestCase { ['name' => 'folders#open', 'url' => '/folders/{folderId}/open', 'verb' => 'delete', 'postfix' => '_something'] ]]; - $this->assertSimpleRoute($routes, 'folders.open', 'DELETE', '/folders/{folderId}/open', 'FoldersController', 'open', [], [], '_something'); + $this->assertSimpleRoute($routes, 'folders.open', 'DELETE', '/apps/app1/folders/{folderId}/open', 'FoldersController', 'open', [], [], '_something'); } public function testSimpleOCSRouteWithPostfix() { @@ -114,7 +123,7 @@ class RoutingTest extends \Test\TestCase { $this->assertSimpleOCSRoute($routes, 'folders.open', 'DELETE', '/apps/app1/folders/{folderId}/open', 'FoldersController', 'open', [], [], '_something'); } - + public function testSimpleRouteWithBrokenName() { $this->expectException(\UnexpectedValueException::class); @@ -122,10 +131,10 @@ class RoutingTest extends \Test\TestCase { ['name' => 'folders_open', 'url' => '/folders/{folderId}/open', 'verb' => 'delete'] ]]; - // router mock - $router = $this->getMockBuilder('\OC\Route\Router') - ->setMethods(['create']) - ->setConstructorArgs([$this->getMockBuilder(ILogger::class)->getMock()]) + /** @var IRouter|MockObject $router */ + $router = $this->getMockBuilder(Router::class) + ->onlyMethods(['create']) + ->setConstructorArgs([$this->createMock(ILogger::class)]) ->getMock(); // load route configuration @@ -135,7 +144,7 @@ class RoutingTest extends \Test\TestCase { $config->register(); } - + public function testSimpleOCSRouteWithBrokenName() { $this->expectException(\UnexpectedValueException::class); @@ -143,10 +152,10 @@ class RoutingTest extends \Test\TestCase { ['name' => 'folders_open', 'url' => '/folders/{folderId}/open', 'verb' => 'delete'] ]]; - // router mock - $router = $this->getMockBuilder('\OC\Route\Router') - ->setMethods(['create']) - ->setConstructorArgs([$this->getMockBuilder(ILogger::class)->getMock()]) + /** @var IRouter|MockObject $router */ + $router = $this->getMockBuilder(Router::class) + ->onlyMethods(['create']) + ->setConstructorArgs([$this->createMock(ILogger::class)]) ->getMock(); // load route configuration @@ -156,14 +165,6 @@ class RoutingTest extends \Test\TestCase { $config->register(); } - public function testSimpleRouteWithUnderScoreNames() { - $routes = ['routes' => [ - ['name' => 'admin_folders#open_current', 'url' => '/folders/{folderId}/open', 'verb' => 'delete'] - ]]; - - $this->assertSimpleRoute($routes, 'admin_folders.open_current', 'DELETE', '/folders/{folderId}/open', 'AdminFoldersController', 'openCurrent'); - } - public function testSimpleOCSRouteWithUnderScoreNames() { $routes = ['ocs' => [ ['name' => 'admin_folders#open_current', 'url' => '/folders/{folderId}/open', 'verb' => 'delete'] @@ -193,23 +194,16 @@ class RoutingTest extends \Test\TestCase { public function testResource() { $routes = ['resources' => ['account' => ['url' => '/accounts']]]; - $this->assertResource($routes, 'account', '/accounts', 'AccountController', 'id'); + $this->assertResource($routes, 'account', '/apps/app1/accounts', 'AccountController', 'id'); } public function testResourceWithUnderScoreName() { $routes = ['resources' => ['admin_accounts' => ['url' => '/admin/accounts']]]; - $this->assertResource($routes, 'admin_accounts', '/admin/accounts', 'AdminAccountsController', 'id'); + $this->assertResource($routes, 'admin_accounts', '/apps/app1/admin/accounts', 'AdminAccountsController', 'id'); } - /** - * @param string $name - * @param string $verb - * @param string $url - * @param string $controllerName - * @param string $actionName - */ - private function assertSimpleRoute($routes, $name, $verb, $url, $controllerName, $actionName, array $requirements=[], array $defaults=[], $postfix='') { + private function assertSimpleRoute($routes, $name, $verb, $url, $controllerName, $actionName, array $requirements = [], array $defaults = [], $postfix = '', $allowRootUrl = false): void { if ($postfix) { $name .= $postfix; } @@ -218,10 +212,10 @@ class RoutingTest extends \Test\TestCase { $container = new DIContainer('app1'); $route = $this->mockRoute($container, $verb, $controllerName, $actionName, $requirements, $defaults); - // router mock - $router = $this->getMockBuilder('\OC\Route\Router') - ->setMethods(['create']) - ->setConstructorArgs([$this->getMockBuilder(ILogger::class)->getMock()]) + /** @var IRouter|MockObject $router */ + $router = $this->getMockBuilder(Router::class) + ->onlyMethods(['create']) + ->setConstructorArgs([$this->createMock(ILogger::class)]) ->getMock(); // we expect create to be called once: @@ -233,6 +227,9 @@ class RoutingTest extends \Test\TestCase { // load route configuration $config = new RouteConfig($container, $router, $routes); + if ($allowRootUrl) { + self::invokePrivate($config, 'rootUrlApps', [['app1']]); + } $config->register(); } @@ -265,10 +262,10 @@ class RoutingTest extends \Test\TestCase { $container = new DIContainer('app1'); $route = $this->mockRoute($container, $verb, $controllerName, $actionName, $requirements, $defaults); - // router mock - $router = $this->getMockBuilder('\OC\Route\Router') - ->setMethods(['create']) - ->setConstructorArgs([$this->getMockBuilder(ILogger::class)->getMock()]) + /** @var IRouter|MockObject $router */ + $router = $this->getMockBuilder(Router::class) + ->onlyMethods(['create']) + ->setConstructorArgs([$this->createMock(ILogger::class)]) ->getMock(); // we expect create to be called once: @@ -294,8 +291,8 @@ class RoutingTest extends \Test\TestCase { private function assertOCSResource($yaml, $resourceName, $url, $controllerName, $paramName): void { /** @var IRouter|MockObject $router */ $router = $this->getMockBuilder(Router::class) - ->setMethods(['create']) - ->setConstructorArgs([$this->getMockBuilder(ILogger::class)->getMock()]) + ->onlyMethods(['create']) + ->setConstructorArgs([$this->createMock(ILogger::class)]) ->getMock(); // route mocks @@ -352,10 +349,10 @@ class RoutingTest extends \Test\TestCase { * @param string $paramName */ private function assertResource($yaml, $resourceName, $url, $controllerName, $paramName) { - // router mock - $router = $this->getMockBuilder('\OC\Route\Router') - ->setMethods(['create']) - ->setConstructorArgs([$this->getMockBuilder(ILogger::class)->getMock()]) + /** @var IRouter|MockObject $router */ + $router = $this->getMockBuilder(Router::class) + ->onlyMethods(['create']) + ->setConstructorArgs([$this->createMock(ILogger::class)]) ->getMock(); // route mocks @@ -412,7 +409,7 @@ class RoutingTest extends \Test\TestCase { * @param string $actionName * @param array $requirements * @param array $defaults - * @return \PHPUnit_Framework_MockObject_MockObject + * @return MockObject */ private function mockRoute( DIContainer $container, @@ -422,25 +419,25 @@ class RoutingTest extends \Test\TestCase { array $requirements=[], array $defaults=[] ) { - $route = $this->getMockBuilder('\OC\Route\Route') - ->setMethods(['method', 'action', 'requirements', 'defaults']) + $route = $this->getMockBuilder(Route::class) + ->onlyMethods(['method', 'action', 'requirements', 'defaults']) ->disableOriginalConstructor() ->getMock(); $route - ->expects($this->exactly(1)) + ->expects($this->once()) ->method('method') ->with($this->equalTo($verb)) ->willReturn($route); $route - ->expects($this->exactly(1)) + ->expects($this->once()) ->method('action') ->with($this->equalTo(new RouteActionHandler($container, $controllerName, $actionName))) ->willReturn($route); if (count($requirements) > 0) { $route - ->expects($this->exactly(1)) + ->expects($this->once()) ->method('requirements') ->with($this->equalTo($requirements)) ->willReturn($route); @@ -448,7 +445,7 @@ class RoutingTest extends \Test\TestCase { if (count($defaults) > 0) { $route - ->expects($this->exactly(1)) + ->expects($this->once()) ->method('defaults') ->with($this->equalTo($defaults)) ->willReturn($route); @@ -457,37 +454,3 @@ class RoutingTest extends \Test\TestCase { return $route; } } - -/* -# -# sample routes.yaml for ownCloud -# -# the section simple describes one route - -routes: - - name: folders#open - url: /folders/{folderId}/open - verb: GET - # controller: name.split()[0] - # action: name.split()[1] - -# for a resource following actions will be generated: -# - index -# - create -# - show -# - update -# - destroy -# - new -resources: - accounts: - url: /accounts - - folders: - url: /accounts/{accountId}/folders - # actions can be used to define additional actions on the resource - actions: - - name: validate - verb: GET - on-collection: false - - * */ diff --git a/tests/lib/Authentication/Login/FinishRememberedLoginCommandTest.php b/tests/lib/Authentication/Login/FinishRememberedLoginCommandTest.php index 98df129771a..7b461219456 100644 --- a/tests/lib/Authentication/Login/FinishRememberedLoginCommandTest.php +++ b/tests/lib/Authentication/Login/FinishRememberedLoginCommandTest.php @@ -27,20 +27,25 @@ namespace lib\Authentication\Login; use OC\Authentication\Login\FinishRememberedLoginCommand; use OC\User\Session; +use OCP\IConfig; use PHPUnit\Framework\MockObject\MockObject; class FinishRememberedLoginCommandTest extends ALoginCommandTest { /** @var Session|MockObject */ private $userSession; + /** @var IConfig|MockObject */ + private $config; protected function setUp(): void { parent::setUp(); $this->userSession = $this->createMock(Session::class); + $this->config = $this->createMock(IConfig::class); $this->cmd = new FinishRememberedLoginCommand( - $this->userSession + $this->userSession, + $this->config ); } @@ -57,6 +62,10 @@ class FinishRememberedLoginCommandTest extends ALoginCommandTest { public function testProcess() { $data = $this->getLoggedInLoginData(); + $this->config->expects($this->once()) + ->method('getSystemValue') + ->with('auto_logout', false) + ->willReturn(false); $this->userSession->expects($this->once()) ->method('createRememberMeToken') ->with($this->user); @@ -65,4 +74,18 @@ class FinishRememberedLoginCommandTest extends ALoginCommandTest { $this->assertTrue($result->isSuccess()); } + + public function testProcessNotRemeberedLoginWithAutologout() { + $data = $this->getLoggedInLoginData(); + $this->config->expects($this->once()) + ->method('getSystemValue') + ->with('auto_logout', false) + ->willReturn(true); + $this->userSession->expects($this->never()) + ->method('createRememberMeToken'); + + $result = $this->cmd->process($data); + + $this->assertTrue($result->isSuccess()); + } } diff --git a/tests/lib/Share20/ManagerTest.php b/tests/lib/Share20/ManagerTest.php index d43777f0379..615b5358c9e 100644 --- a/tests/lib/Share20/ManagerTest.php +++ b/tests/lib/Share20/ManagerTest.php @@ -808,6 +808,7 @@ class ManagerTest extends \Test\TestCase { ['core', 'shareapi_enforce_expire_date', 'no', 'yes'], ['core', 'shareapi_expire_after_n_days', '7', '3'], ['core', 'shareapi_default_expire_date', 'no', 'yes'], + ['core', 'link_defaultExpDays', 3, '3'], ]); $expected = new \DateTime(); |