Exemplo n.º 1
0
 /**
  * @dataProvider dataFormat
  *
  * @param string $user
  * @param string $parameter
  * @param bool $isDir
  * @param array $info
  * @param bool $allowHtml
  * @param bool $verbose
  * @param string $expected
  */
 public function testFormat($user, $parameter, $isDir, array $info, $allowHtml, $verbose, $expected)
 {
     /** @var \OCP\Activity\IEvent|\PHPUnit_Framework_MockObject_MockObject $event */
     $event = $this->getMockBuilder('OCP\\Activity\\IEvent')->disableOriginalConstructor()->getMock();
     if (!empty($info)) {
         $event->expects($this->once())->method('getObjectType')->willReturn('files');
         $event->expects($this->once())->method('getObjectName')->willReturn($parameter);
         $event->expects($this->once())->method('getObjectId')->willReturn(42);
     }
     $this->urlGenerator->expects($allowHtml ? $this->once() : $this->never())->method('linkTo')->with('files', 'index.php', $this->anything())->willReturnCallback(function ($app, $file, $parameters) {
         $paramList = [];
         foreach ($parameters as $key => $value) {
             $paramList[] = $key . '=' . urlencode($value);
         }
         return $app . '/' . $file . '?' . implode('&', $paramList);
     });
     $formatter = $this->getFormatter(['fixLegacyFilename'], $user);
     $formatter->expects($this->once())->method('fixLegacyFilename')->willReturnArgument(0);
     if (!empty($info)) {
         $this->infoCache->expects($this->once())->method('getInfoById')->with($user, 42, $parameter)->willReturn($info);
     } else {
         $this->infoCache->expects($this->once())->method('getInfoByPath')->with($user, $parameter)->willReturn(['path' => $parameter, 'is_dir' => $isDir, 'exists' => true, 'view' => '']);
     }
     $this->assertSame($expected, $formatter->format($event, $parameter, $allowHtml, $verbose));
 }
Exemplo n.º 2
0
 public function testIndexWithIE8RedirectAndViewAndDirDefined()
 {
     $this->request->expects($this->once())->method('isUserAgent')->with(['/MSIE 8.0/'])->will($this->returnValue(true));
     $this->urlGenerator->expects($this->once())->method('linkToRoute')->with('files.view.index')->will($this->returnValue('/apps/files/'));
     $expected = new RedirectResponse('/apps/files/#?dir=MyDir&view=MyView');
     $this->assertEquals($expected, $this->viewController->index('MyDir', 'MyView'));
 }
Exemplo n.º 3
0
 public function testLogoutWithToken()
 {
     $this->request->expects($this->once())->method('getCookie')->with('oc_token')->willReturn('MyLoginToken');
     $user = $this->getMock('\\OCP\\IUser');
     $user->expects($this->once())->method('getUID')->willReturn('JohnDoe');
     $this->userSession->expects($this->once())->method('getUser')->willReturn($user);
     $this->config->expects($this->once())->method('deleteUserValue')->with('JohnDoe', 'login_token', 'MyLoginToken');
     $this->urlGenerator->expects($this->once())->method('linkToRouteAbsolute')->with('core.login.showLoginForm')->willReturn('/login');
     $expected = new RedirectResponse('/login');
     $this->assertEquals($expected, $this->loginController->logout());
 }
Exemplo n.º 4
0
 public function testAppNavigation()
 {
     $this->navigationManager->expects($this->once())->method('add')->willReturnCallback(function ($closure) {
         $this->assertInstanceOf('\\Closure', $closure);
         $navigation = $closure();
         $this->assertInternalType('array', $navigation);
         $this->assertCount(5, $navigation);
         $this->assertSame(['id' => 'announcementcenter', 'order' => 10, 'href' => '/apps/announcementcenter/announcement', 'icon' => '/apps/announcementcenter/img/announcementcenter.svg', 'name' => 'Announcements'], $navigation);
     });
     $this->urlGenerator->expects($this->once())->method('linkToRoute')->with('announcementcenter.page.index')->willReturn('/apps/announcementcenter/announcement');
     $this->urlGenerator->expects($this->once())->method('imagePath')->with('announcementcenter', 'announcementcenter.svg')->willReturn('/apps/announcementcenter/img/announcementcenter.svg');
     $this->languageFactory->expects($this->once())->method('get')->with('announcementcenter')->willReturn($this->language);
     include __DIR__ . '/../../appinfo/app.php';
 }
Exemplo n.º 5
0
 public function testRescanFailedIntegrityCheck()
 {
     $this->checker->expects($this->once())->method('runInstanceVerification');
     $this->urlGenerator->expects($this->once())->method('linkToRoute')->with('settings_admin')->will($this->returnValue('/admin'));
     $expected = new RedirectResponse('/admin');
     $this->assertEquals($expected, $this->checkSetupController->rescanFailedIntegrityCheck());
 }
Exemplo n.º 6
0
 /**
  * @dataProvider dataCheckAppUpdates
  *
  * @param string[] $apps
  * @param array $isUpdateAvailable
  * @param array $notifications
  */
 public function testCheckAppUpdates(array $apps, array $isUpdateAvailable, array $notifications)
 {
     $job = $this->getJob(['isUpdateAvailable', 'createNotifications']);
     $this->appManager->expects($this->once())->method('getInstalledApps')->willReturn($apps);
     $job->expects($this->exactly(sizeof($apps)))->method('isUpdateAvailable')->willReturnMap($isUpdateAvailable);
     $this->urlGenerator->expects($this->exactly(sizeof($notifications)))->method('linkToRouteAbsolute')->with('settings.AppSettings.viewApps')->willReturn('apps-url');
     $mockedMethod = $job->expects($this->exactly(sizeof($notifications)))->method('createNotifications');
     call_user_func_array([$mockedMethod, 'withConsecutive'], $notifications);
     $this->invokePrivate($job, 'checkAppUpdates');
 }
 public function testCheck()
 {
     $this->config->expects($this->at(0))->method('getSystemValue')->with('has_internet_connection', true)->will($this->returnValue(true));
     $this->config->expects($this->at(1))->method('getSystemValue')->with('memcache.local', null)->will($this->returnValue('SomeProvider'));
     $client = $this->getMockBuilder('\\OCP\\Http\\Client\\IClient')->disableOriginalConstructor()->getMock();
     $client->expects($this->at(0))->method('get')->with('https://www.owncloud.org/', []);
     $client->expects($this->at(1))->method('get')->with('http://www.owncloud.org/', [])->will($this->throwException(new \Exception()));
     $this->clientService->expects($this->once())->method('newClient')->will($this->returnValue($client));
     $this->util->expects($this->once())->method('isHtaccessWorking')->will($this->returnValue(true));
     $this->urlGenerator->expects($this->once())->method('linkToDocs')->with('admin-performance')->willReturn('http://doc.owncloud.org/server/go.php?to=admin-performance');
     $expected = new DataResponse(['serverHasInternetConnection' => false, 'dataDirectoryProtected' => true, 'isMemcacheConfigured' => true, 'memcacheDocs' => 'http://doc.owncloud.org/server/go.php?to=admin-performance']);
     $this->assertEquals($expected, $this->checkSetupController->check());
 }
 public function testCheck()
 {
     $this->config->expects($this->at(0))->method('getSystemValue')->with('has_internet_connection', true)->will($this->returnValue(true));
     $this->config->expects($this->at(1))->method('getSystemValue')->with('memcache.local', null)->will($this->returnValue('SomeProvider'));
     $this->config->expects($this->at(2))->method('getSystemValue')->with('trusted_proxies', [])->willReturn(['1.2.3.4']);
     $this->request->expects($this->once())->method('getRemoteAddress')->willReturn('4.3.2.1');
     $client = $this->getMockBuilder('\\OCP\\Http\\Client\\IClient')->disableOriginalConstructor()->getMock();
     $client->expects($this->at(0))->method('get')->with('https://www.owncloud.org/', []);
     $client->expects($this->at(1))->method('get')->with('http://www.owncloud.org/', [])->will($this->throwException(new \Exception()));
     $this->clientService->expects($this->once())->method('newClient')->will($this->returnValue($client));
     $this->util->expects($this->once())->method('isHtaccessWorking')->will($this->returnValue(true));
     $this->urlGenerator->expects($this->at(0))->method('linkToDocs')->with('admin-performance')->willReturn('http://doc.owncloud.org/server/go.php?to=admin-performance');
     $this->urlGenerator->expects($this->at(1))->method('linkToDocs')->with('admin-security')->willReturn('https://doc.owncloud.org/server/8.1/admin_manual/configuration_server/hardening.html');
     self::$version_compare = -1;
     $this->urlGenerator->expects($this->at(2))->method('linkToDocs')->with('admin-reverse-proxy')->willReturn('reverse-proxy-doc-link');
     $expected = new DataResponse(['serverHasInternetConnection' => false, 'dataDirectoryProtected' => true, 'isMemcacheConfigured' => true, 'memcacheDocs' => 'http://doc.owncloud.org/server/go.php?to=admin-performance', 'isUrandomAvailable' => self::invokePrivate($this->checkSetupController, 'isUrandomAvailable'), 'securityDocs' => 'https://doc.owncloud.org/server/8.1/admin_manual/configuration_server/hardening.html', 'isUsedTlsLibOutdated' => '', 'phpSupported' => ['eol' => true, 'version' => PHP_VERSION], 'forwardedForHeadersWorking' => true, 'reverseProxyDocs' => 'reverse-proxy-doc-link']);
     $this->assertEquals($expected, $this->checkSetupController->check());
 }
Exemplo n.º 9
0
 /**
  * @dataProvider showFileMethodProvider
  */
 public function testShowFileRouteWithTrashedFile($useShowFile)
 {
     $this->appManager->expects($this->once())->method('isEnabledForUser')->with('files_trashbin')->will($this->returnValue(true));
     $parentNode = $this->getMock('\\OCP\\Files\\Folder');
     $parentNode->expects($this->once())->method('getPath')->will($this->returnValue('testuser1/files_trashbin/files/test.d1462861890/sub'));
     $baseFolderFiles = $this->getMock('\\OCP\\Files\\Folder');
     $baseFolderTrash = $this->getMock('\\OCP\\Files\\Folder');
     $this->rootFolder->expects($this->at(0))->method('get')->with('testuser1/files/')->will($this->returnValue($baseFolderFiles));
     $this->rootFolder->expects($this->at(1))->method('get')->with('testuser1/files_trashbin/files/')->will($this->returnValue($baseFolderTrash));
     $baseFolderFiles->expects($this->once())->method('getById')->with(123)->will($this->returnValue([]));
     $node = $this->getMock('\\OCP\\Files\\File');
     $node->expects($this->once())->method('getParent')->will($this->returnValue($parentNode));
     $node->expects($this->once())->method('getName')->will($this->returnValue('somefile.txt'));
     $baseFolderTrash->expects($this->at(0))->method('getById')->with(123)->will($this->returnValue([$node]));
     $baseFolderTrash->expects($this->at(1))->method('getRelativePath')->with('testuser1/files_trashbin/files/test.d1462861890/sub')->will($this->returnValue('/test.d1462861890/sub'));
     $this->urlGenerator->expects($this->once())->method('linkToRoute')->with('files.view.index', ['view' => 'trashbin', 'dir' => '/test.d1462861890/sub', 'scrollto' => 'somefile.txt'])->will($this->returnValue('/apps/files/?view=trashbin&dir=/test.d1462861890/sub&scrollto=somefile.txt'));
     $expected = new Http\RedirectResponse('/apps/files/?view=trashbin&dir=/test.d1462861890/sub&scrollto=somefile.txt');
     if ($useShowFile) {
         $this->assertEquals($expected, $this->viewController->showFile(123));
     } else {
         $this->assertEquals($expected, $this->viewController->index('/whatever', '', '123'));
     }
 }
Exemplo n.º 10
0
 /**
  * @dataProvider dataGetPreviewLink
  *
  * @param string $path
  * @param bool $isDir
  * @param array $expected
  */
 public function testGetPreviewLink($path, $isDir, $expected)
 {
     $this->urlGenerator->expects($this->once())->method('linkTo')->with('files', 'index.php', $expected);
     $this->invokePrivate($this->controller, 'getPreviewLink', [$path, $isDir]);
 }
 /**
  * Mocks IURLGenerator->linkToRoute()
  *
  * @param int $code
  * @param string $url
  */
 private function mockUrlToErrorPage($code, $url)
 {
     $this->urlGenerator->expects($this->once())->method('linkToRoute')->with($this->appName . '.page.error_page', ['code' => $code])->willReturn($url);
 }
 private function mockUrlToDownloadPage($token, $fileId, $filename, $url)
 {
     $this->urlGenerator->expects($this->once())->method('linkToRoute')->with($this->appName . '.files_public.download', ['token' => $token, 'fileId' => $fileId, 'filename' => $filename])->willReturn($url);
 }