/**
  * @expectedException \Exception
  * @expectedExceptionMessage Owner of the share does not exist anymore
  */
 public function testShowShareWithNotExistingUser()
 {
     $this->container['UserManager']->expects($this->once())->method('userExists')->with($this->user)->will($this->returnValue(false));
     $linkItem = Share::getShareByToken($this->token, false);
     \OC::$server->getSession()->set('public_link_authenticated', $linkItem['id']);
     $this->shareController->showShare($this->token);
 }
 public function testShowShare()
 {
     $owner = $this->getMock('OCP\\IUser');
     $owner->method('getDisplayName')->willReturn('ownerDisplay');
     $owner->method('getUID')->willReturn('ownerUID');
     $file = $this->getMock('OCP\\Files\\File');
     $file->method('getName')->willReturn('file1.txt');
     $file->method('getMimetype')->willReturn('text/plain');
     $file->method('getSize')->willReturn(33);
     $share = $this->getMock('\\OC\\Share20\\IShare');
     $share->method('getId')->willReturn('42');
     $share->method('getPassword')->willReturn('password');
     $share->method('getShareOwner')->willReturn($owner);
     $share->method('getPath')->willReturn($file);
     $share->method('getTarget')->willReturn('/file1.txt');
     $this->session->method('exists')->with('public_link_authenticated')->willReturn(true);
     $this->session->method('get')->with('public_link_authenticated')->willReturn('42');
     $this->previewManager->method('isMimeSupported')->with('text/plain')->willReturn(true);
     $this->config->method('getSystemValue')->willReturnMap([['max_filesize_animated_gifs_public_sharing', 10, 10], ['enable_previews', true, true]]);
     $shareTmpl['maxSizeAnimateGif'] = $this->config->getSystemValue('max_filesize_animated_gifs_public_sharing', 10);
     $shareTmpl['previewEnabled'] = $this->config->getSystemValue('enable_previews', true);
     $this->shareManager->expects($this->once())->method('getShareByToken')->with('token')->willReturn($share);
     $response = $this->shareController->showShare('token');
     $sharedTmplParams = array('displayName' => 'ownerDisplay', 'owner' => 'ownerUID', 'filename' => 'file1.txt', 'directory_path' => '/file1.txt', 'mimetype' => 'text/plain', 'dirToken' => 'token', 'sharingToken' => 'token', 'server2serversharing' => true, 'protected' => 'true', 'dir' => '', 'downloadURL' => null, 'fileSize' => '33 B', 'nonHumanFileSize' => 33, 'maxSizeAnimateGif' => 10, 'previewSupported' => true, 'previewEnabled' => true);
     $csp = new \OCP\AppFramework\Http\ContentSecurityPolicy();
     $csp->addAllowedFrameDomain('\'self\'');
     $expectedResponse = new TemplateResponse($this->appName, 'public', $sharedTmplParams, 'base');
     $expectedResponse->setContentSecurityPolicy($csp);
     $this->assertEquals($expectedResponse, $response);
 }
 public function testShowShare()
 {
     // Test without a not existing token
     $response = $this->shareController->showShare('ThisTokenShouldHopefullyNeverExistSoThatTheUnitTestWillAlwaysPass :)');
     $expectedResponse = new TemplateResponse('core', '404', array(), 'guest');
     $this->assertEquals($expectedResponse, $response);
     // Test with a password protected share and no authentication
     $response = $this->shareController->showShare($this->token);
     $expectedResponse = new RedirectResponse($this->urlGenerator->linkToRoute('files_sharing.sharecontroller.authenticate', array('token' => $this->token)));
     $this->assertEquals($expectedResponse, $response);
     // Test with password protected share and authentication
     $linkItem = Share::getShareByToken($this->token, false);
     \OC::$server->getSession()->set('public_link_authenticated', $linkItem['id']);
     $response = $this->shareController->showShare($this->token);
     $sharedTmplParams = array('displayName' => $this->user, 'filename' => 'file1.txt', 'directory_path' => '/file1.txt', 'mimetype' => 'text/plain', 'dirToken' => $this->token, 'sharingToken' => $this->token, 'server2serversharing' => true, 'protected' => 'true', 'dir' => '', 'downloadURL' => null, 'fileSize' => '33 B', 'nonHumanFileSize' => 33, 'maxSizeAnimateGif' => 10);
     $expectedResponse = new TemplateResponse($this->container['AppName'], 'public', $sharedTmplParams, 'base');
     $this->assertEquals($expectedResponse, $response);
 }
 /**
  * @expectedException \OCP\Files\NotFoundException
  */
 public function testShowShareInvalid()
 {
     $owner = $this->getMock('OCP\\IUser');
     $owner->method('getDisplayName')->willReturn('ownerDisplay');
     $owner->method('getUID')->willReturn('ownerUID');
     $file = $this->getMock('OCP\\Files\\File');
     $file->method('getName')->willReturn('file1.txt');
     $file->method('getMimetype')->willReturn('text/plain');
     $file->method('getSize')->willReturn(33);
     $file->method('isShareable')->willReturn(false);
     $file->method('isReadable')->willReturn(true);
     $share = \OC::$server->getShareManager()->newShare();
     $share->setId(42);
     $share->setPassword('password')->setShareOwner('ownerUID')->setNode($file)->setTarget('/file1.txt');
     $this->session->method('exists')->with('public_link_authenticated')->willReturn(true);
     $this->session->method('get')->with('public_link_authenticated')->willReturn('42');
     $this->previewManager->method('isMimeSupported')->with('text/plain')->willReturn(true);
     $this->config->method('getSystemValue')->willReturnMap([['max_filesize_animated_gifs_public_sharing', 10, 10], ['enable_previews', true, true]]);
     $shareTmpl['maxSizeAnimateGif'] = $this->config->getSystemValue('max_filesize_animated_gifs_public_sharing', 10);
     $shareTmpl['previewEnabled'] = $this->config->getSystemValue('enable_previews', true);
     $this->shareManager->expects($this->once())->method('getShareByToken')->with('token')->willReturn($share);
     $this->userManager->method('get')->with('ownerUID')->willReturn($owner);
     $this->shareController->showShare('token');
 }