Exemple #1
0
 /**
  * @dataProvider dataCanShare
  *
  * @param bool $expected
  * @param string $sharingEnabled
  * @param bool $disabledForUser
  */
 public function testCanShare($expected, $sharingEnabled, $disabledForUser)
 {
     $this->config->method('getAppValue')->will($this->returnValueMap([['core', 'shareapi_enabled', 'yes', $sharingEnabled]]));
     $manager = $this->createManagerMock()->setMethods(['isSharingDisabledForUser'])->getMock();
     $manager->method('isSharingDisabledForUser')->willReturn($disabledForUser);
     $user = $this->getMock('\\OCP\\IUser');
     $share = new \OC\Share20\Share();
     $share->setSharedBy($user);
     $res = $this->invokePrivate($manager, 'canShare', [$share]);
     $this->assertEquals($expected, $res);
 }
 public function testCreateLinkShare()
 {
     $share = new \OC\Share20\Share();
     $shareOwner = $this->getMock('\\OCP\\IUser');
     $shareOwner->method('getUID')->willReturn('shareOwner');
     $path = $this->getMock('\\OCP\\Files\\Folder');
     $path->method('getId')->willReturn(100);
     $path->method('getOwner')->willReturn($shareOwner);
     $ownerFolder = $this->getMock('OCP\\Files\\Folder');
     $userFolder = $this->getMock('OCP\\Files\\Folder');
     $this->rootFolder->method('getUserFolder')->will($this->returnValueMap([['sharedBy', $userFolder], ['shareOwner', $ownerFolder]]));
     $userFolder->method('getById')->with(100)->willReturn([$path]);
     $ownerFolder->method('getById')->with(100)->willReturn([$path]);
     $share->setShareType(\OCP\Share::SHARE_TYPE_LINK);
     $share->setSharedBy('sharedBy');
     $share->setShareOwner('shareOwner');
     $share->setNode($path);
     $share->setPermissions(1);
     $share->setPassword('password');
     $share->setToken('token');
     $expireDate = new \DateTime();
     $share->setExpirationDate($expireDate);
     $share->setTarget('/target');
     $share2 = $this->provider->create($share);
     $this->assertNotNull($share2->getId());
     $this->assertSame('ocinternal:' . $share2->getId(), $share2->getFullId());
     $this->assertSame(\OCP\Share::SHARE_TYPE_LINK, $share2->getShareType());
     $this->assertSame('sharedBy', $share2->getSharedBy());
     $this->assertSame('shareOwner', $share2->getShareOwner());
     $this->assertSame(1, $share2->getPermissions());
     $this->assertSame('/target', $share2->getTarget());
     $this->assertLessThanOrEqual(new \DateTime(), $share2->getShareTime());
     $this->assertSame($path, $share2->getNode());
     $this->assertSame('password', $share2->getPassword());
     $this->assertSame('token', $share2->getToken());
     $this->assertEquals($expireDate, $share2->getExpirationDate());
 }
Exemple #3
0
 /**
  * @dataProvider dataCanShare
  *
  * @param bool $expected
  * @param string $sharingEnabled
  * @param bool $disabledForUser
  */
 public function testCanShare($expected, $sharingEnabled, $disabledForUser)
 {
     $this->config->method('getAppValue')->will($this->returnValueMap([['core', 'shareapi_enabled', 'yes', $sharingEnabled]]));
     $manager = $this->getMockBuilder('\\OC\\Share20\\Manager')->setConstructorArgs([$this->logger, $this->config, $this->defaultProvider, $this->secureRandom, $this->hasher, $this->mountManager, $this->groupManager, $this->l])->setMethods(['isSharingDisabledForUser'])->getMock();
     $manager->method('isSharingDisabledForUser')->willReturn($disabledForUser);
     $user = $this->getMock('\\OCP\\IUser');
     $share = new \OC\Share20\Share();
     $share->setSharedBy($user);
     $res = $this->invokePrivate($manager, 'canShare', [$share]);
     $this->assertEquals($expected, $res);
 }