public function setUp() { parent::setUp(); $this->server = new \Sabre\DAV\Server(); $this->tree = $this->getMockBuilder('\\Sabre\\DAV\\Tree')->disableOriginalConstructor()->getMock(); $userId = $this->getUniqueID('testcustompropertiesuser'); $this->user = $this->getMock('\\OCP\\IUser'); $this->user->expects($this->any())->method('getUID')->will($this->returnValue($userId)); $this->plugin = new \OCA\DAV\Connector\Sabre\CustomPropertiesBackend($this->tree, \OC::$server->getDatabaseConnection(), $this->user); }
protected function prepareForInitCollections() { $this->user->expects($this->any())->method('getUID')->will($this->returnValue('alice')); $this->userSession->expects($this->once())->method('getUser')->will($this->returnValue($this->user)); $this->dispatcher->addListener(CommentsEntityEvent::EVENT_ENTITY, function (CommentsEntityEvent $event) { $event->addEntityCollection('files', function () { return true; }); }); }
public function getNode($isAdmin = true) { $this->user = $this->getMock('\\OCP\\IUser'); $this->user->expects($this->any())->method('getUID')->will($this->returnValue('testuser')); $userSession = $this->getMock('\\OCP\\IUserSession'); $userSession->expects($this->any())->method('getUser')->will($this->returnValue($this->user)); $groupManager = $this->getMock('\\OCP\\IGroupManager'); $groupManager->expects($this->any())->method('isAdmin')->with('testuser')->will($this->returnValue($isAdmin)); return new \OCA\DAV\SystemTag\SystemTagsByIdCollection($this->tagManager, $userSession, $groupManager); }
public function setUp() { $this->request = $this->getMockBuilder('\\OCP\\IRequest')->disableOriginalConstructor()->getMock(); $this->user = $this->getMock('\\OCP\\IUser'); $this->user->expects($this->any())->method('getUID')->will($this->returnValue('user1')); $userSession = $this->getMock('\\OCP\\IUserSession'); $userSession->expects($this->any())->method('getUser')->will($this->returnValue($this->user)); $this->tagService = $this->getMockBuilder('\\OCA\\Files\\Service\\TagService')->disableOriginalConstructor()->getMock(); $this->shareManager = $this->getMockBuilder('\\OCP\\Share\\IManager')->disableOriginalConstructor()->getMock(); $this->preview = $this->getMockBuilder('\\OCP\\IPreview')->disableOriginalConstructor()->getMock(); $this->config = $this->getMock('\\OCP\\IConfig'); $this->apiController = new ApiController($this->appName, $this->request, $userSession, $this->tagService, $this->preview, $this->shareManager, $this->config); }
public function testSingleBucket() { $this->config->expects($this->once())->method('getSystemValue')->with($this->equalTo('objectstore'), '')->willReturn(['class' => 'Test\\Files\\Mount\\FakeObjectStore']); $this->user->expects($this->never())->method($this->anything()); $this->loader->expects($this->never())->method($this->anything()); $config = $this->invokePrivate($this->provider, 'getSingleBucketObjectStoreConfig', [$this->user, $this->loader]); $this->assertArrayHasKey('class', $config); $this->assertEquals($config['class'], 'Test\\Files\\Mount\\FakeObjectStore'); $this->assertArrayHasKey('arguments', $config); $this->assertArrayHasKey('user', $config['arguments']); $this->assertSame($this->user, $config['arguments']['user']); $this->assertArrayHasKey('objectstore', $config['arguments']); $this->assertInstanceOf('Test\\Files\\Mount\\FakeObjectStore', $config['arguments']['objectstore']); }
/** * Tests merging shares. * * Happens when sharing the same entry to a user through multiple ways, * like several groups and also direct shares at the same time. * * @dataProvider mergeSharesDataProvider * * @param array $userShares array of user share specs * @param array $groupShares array of group share specs * @param array $expectedShares array of expected supershare specs */ public function testMergeShares($userShares, $groupShares, $expectedShares) { $rootFolder = $this->getMock('\\OCP\\Files\\IRootFolder'); $userManager = $this->getMock('\\OCP\\IUserManager'); $userShares = array_map(function ($shareSpec) { return $this->makeMockShare($shareSpec[0], $shareSpec[1], $shareSpec[2], $shareSpec[3], $shareSpec[4]); }, $userShares); $groupShares = array_map(function ($shareSpec) { return $this->makeMockShare($shareSpec[0], $shareSpec[1], $shareSpec[2], $shareSpec[3], $shareSpec[4]); }, $groupShares); $this->user->expects($this->any())->method('getUID')->will($this->returnValue('user1')); $this->shareManager->expects($this->at(0))->method('getSharedWith')->with('user1', \OCP\Share::SHARE_TYPE_USER)->will($this->returnValue($userShares)); $this->shareManager->expects($this->at(1))->method('getSharedWith')->with('user1', \OCP\Share::SHARE_TYPE_GROUP, null, -1)->will($this->returnValue($groupShares)); $this->shareManager->expects($this->any())->method('newShare')->will($this->returnCallback(function () use($rootFolder, $userManager) { return new \OC\Share20\Share($rootFolder, $userManager); })); $mounts = $this->provider->getMountsForUser($this->user, $this->loader); $this->assertCount(count($expectedShares), $mounts); foreach ($mounts as $index => $mount) { $expectedShare = $expectedShares[$index]; $this->assertInstanceOf('OCA\\Files_Sharing\\SharedMount', $mount); // supershare $share = $mount->getShare(); $this->assertEquals($expectedShare[0], $share->getId()); $this->assertEquals($expectedShare[1], $share->getNodeId()); $this->assertEquals($expectedShare[2], $share->getShareOwner()); $this->assertEquals($expectedShare[3], $share->getTarget()); $this->assertEquals($expectedShare[4], $share->getPermissions()); } }
public function setUp() { parent::setUp(); $this->request = $this->getMock('\\OCP\\IRequest'); $this->urlGenerator = $this->getMock('\\OCP\\IURLGenerator'); $this->navigationManager = $this->getMock('\\OCP\\INavigationManager'); $this->l10n = $this->getMock('\\OCP\\IL10N'); $this->config = $this->getMock('\\OCP\\IConfig'); $this->eventDispatcher = $this->getMock('\\Symfony\\Component\\EventDispatcher\\EventDispatcherInterface'); $this->userSession = $this->getMock('\\OCP\\IUserSession'); $this->appManager = $this->getMock('\\OCP\\App\\IAppManager'); $this->user = $this->getMock('\\OCP\\IUser'); $this->user->expects($this->any())->method('getUID')->will($this->returnValue('testuser1')); $this->userSession->expects($this->any())->method('getUser')->will($this->returnValue($this->user)); $this->rootFolder = $this->getMock('\\OCP\\Files\\Folder'); $this->viewController = $this->getMockBuilder('\\OCA\\Files\\Controller\\ViewController')->setConstructorArgs(['files', $this->request, $this->urlGenerator, $this->navigationManager, $this->l10n, $this->config, $this->eventDispatcher, $this->userSession, $this->appManager, $this->rootFolder])->setMethods(['getStorageInfo', 'renderScript'])->getMock(); }
protected function setUp() { $this->existingUser = $this->getMockBuilder('OCP\\IUser')->disableOriginalConstructor()->getMock(); $this->existingUser->expects($this->any())->method('getEMailAddress')->willReturn('*****@*****.**'); $this->config = $this->getMockBuilder('\\OCP\\IConfig')->disableOriginalConstructor()->getMock(); $this->l10n = $this->getMockBuilder('\\OCP\\IL10N')->disableOriginalConstructor()->getMock(); $this->l10n->expects($this->any())->method('t')->will($this->returnCallback(function ($text, $parameters = array()) { return vsprintf($text, $parameters); })); $this->defaults = $this->getMockBuilder('\\OC_Defaults')->disableOriginalConstructor()->getMock(); $this->userManager = $this->getMockBuilder('\\OCP\\IUserManager')->disableOriginalConstructor()->getMock(); $this->urlGenerator = $this->getMockBuilder('\\OCP\\IURLGenerator')->disableOriginalConstructor()->getMock(); $this->mailer = $this->getMockBuilder('\\OCP\\Mail\\IMailer')->disableOriginalConstructor()->getMock(); $this->secureRandom = $this->getMockBuilder('\\OCP\\Security\\ISecureRandom')->disableOriginalConstructor()->getMock(); $this->timeFactory = $this->getMockBuilder('\\OCP\\AppFramework\\Utility\\ITimeFactory')->disableOriginalConstructor()->getMock(); $this->request = $this->getMockBuilder('OCP\\IRequest')->disableOriginalConstructor()->getMock(); $this->lostController = new LostController('Core', $this->request, $this->urlGenerator, $this->userManager, $this->defaults, $this->l10n, $this->config, $this->secureRandom, 'lostpassword-noreply@localhost', true, $this->mailer, $this->timeFactory); }
/** * @dataProvider nodeClassProvider * @expectedException \Sabre\DAV\Exception\Conflict */ public function testCreateTagConflict($nodeClass) { $this->user->expects($this->once())->method('getUID')->willReturn('admin'); $this->groupManager->expects($this->once())->method('isAdmin')->with('admin')->willReturn(true); $requestData = json_encode(['name' => 'Test', 'userVisible' => true, 'userAssignable' => false]); $node = $this->getMockBuilder($nodeClass)->disableOriginalConstructor()->getMock(); $this->tagManager->expects($this->once())->method('createTag')->with('Test', true, false)->will($this->throwException(new TagAlreadyExistsException('Tag already exists'))); $this->tree->expects($this->any())->method('getNodeForPath')->with('/systemtags')->will($this->returnValue($node)); $request = $this->getMockBuilder('Sabre\\HTTP\\RequestInterface')->disableOriginalConstructor()->getMock(); $response = $this->getMockBuilder('Sabre\\HTTP\\ResponseInterface')->disableOriginalConstructor()->getMock(); $request->expects($this->once())->method('getPath')->will($this->returnValue('/systemtags')); $request->expects($this->once())->method('getBodyAsString')->will($this->returnValue($requestData)); $request->expects($this->once())->method('getHeader')->with('Content-Type')->will($this->returnValue('application/json')); $this->plugin->httpPost($request, $response); }
public function testPrepareTwoFactorLogin() { $this->user->expects($this->once())->method('getUID')->will($this->returnValue('ferdinand')); $this->session->expects($this->once())->method('set')->with('two_factor_auth_uid', 'ferdinand'); $this->manager->prepareTwoFactorLogin($this->user); }