本文整理汇总了PHP中OCP\IUserSession::expects方法的典型用法代码示例。如果您正苦于以下问题:PHP IUserSession::expects方法的具体用法?PHP IUserSession::expects怎么用?PHP IUserSession::expects使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类OCP\IUserSession
的用法示例。
在下文中一共展示了IUserSession::expects方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testTagManagerWithoutUserReturnsNull
public function testTagManagerWithoutUserReturnsNull()
{
$this->userSession = $this->getMock('\\OCP\\IUserSession');
$this->userSession->expects($this->any())->method('getUser')->will($this->returnValue(null));
$this->tagMgr = new OC\TagManager($this->tagMapper, $this->userSession);
$this->assertNull($this->tagMgr->load($this->objectType));
}
示例2: testImpersonate
/**
* @dataProvider usersProvider
* @param $query
* @param $uid
*/
public function testImpersonate($query, $uid)
{
$user = $this->getMock('\\OCP\\IUser');
$user->expects($this->once())->method('getUID')->will($this->returnValue($uid));
$this->userManager->expects($this->once())->method('search')->with($query, 1, 0)->will($this->returnValue([$user]));
$this->userSession->expects($this->once())->method('setUser')->with($user);
$this->assertEquals(new JSONResponse(), $this->controller->impersonate($query));
}
示例3: prepareForInitCollections
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;
});
});
}
示例4: testUpdatePrivateKeyPasswordWrongNewPassword
/**
* test updatePrivateKeyPassword() if wrong new password was entered
*/
public function testUpdatePrivateKeyPasswordWrongNewPassword()
{
$oldPassword = 'old';
$newPassword = 'new';
$this->userSessionMock->expects($this->once())->method('getUID')->willReturn('uid');
$this->userManagerMock->expects($this->exactly(2))->method('checkPassword')->willReturn(false);
$result = $this->controller->updatePrivateKeyPassword($oldPassword, $newPassword);
$data = $result->getData();
$this->assertSame(Http::STATUS_BAD_REQUEST, $result->getStatus());
$this->assertSame('The current log-in password was not correct, please try again.', $data['message']);
}
示例5: setUp
public function setUp()
{
parent::setUp();
$this->tree = $this->getMockBuilder('\\Sabre\\DAV\\Tree')->disableOriginalConstructor()->getMock();
$this->server = new \Sabre\DAV\Server($this->tree);
$this->tagManager = $this->getMock('\\OCP\\SystemTag\\ISystemTagManager');
$this->groupManager = $this->getMock('\\OCP\\IGroupManager');
$this->user = $this->getMock('\\OCP\\IUser');
$this->userSession = $this->getMock('\\OCP\\IUserSession');
$this->userSession->expects($this->any())->method('getUser')->willReturn($this->user);
$this->userSession->expects($this->any())->method('isLoggedIn')->willReturn(true);
$this->plugin = new \OCA\DAV\SystemTag\SystemTagPlugin($this->tagManager, $this->groupManager, $this->userSession);
$this->plugin->initialize($this->server);
}
示例6: setUp
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->user = $this->getMock('\\OCP\\IUser');
$this->userSession->expects($this->any())->method('getUser')->will($this->returnValue($this->user));
$this->viewController = $this->getMockBuilder('\\OCA\\Files\\Controller\\ViewController')->setConstructorArgs(['files', $this->request, $this->urlGenerator, $this->navigationManager, $this->l10n, $this->config, $this->eventDispatcher, $this->userSession])->setMethods(['getStorageInfo', 'renderScript'])->getMock();
}
示例7: mockUserSession
protected function mockUserSession($user)
{
$mockUser = $this->getMockBuilder('\\OCP\\IUser')->disableOriginalConstructor()->getMock();
$mockUser->expects($this->any())->method('getUID')->willReturn($user);
$this->session->expects($this->any())->method('isLoggedIn')->willReturn(true);
$this->session->expects($this->any())->method('getUser')->willReturn($mockUser);
}
示例8: testLoadingJSAndCSS
/**
* @dataProvider dataLoadingJSAndCSS
* @param string $scriptName
* @param string $pathInfo
* @param IUser|null $user
* @param bool $scriptsAdded
*/
public function testLoadingJSAndCSS($scriptName, $pathInfo, $user, $scriptsAdded)
{
$this->request->expects($this->any())->method('getScriptName')->willReturn($scriptName);
$this->request->expects($this->any())->method('getPathInfo')->willReturn($pathInfo);
$this->session->expects($this->once())->method('getUser')->willReturn($user);
\OC_Util::$scripts = [];
\OC_Util::$styles = [];
include __DIR__ . '/../../appinfo/app.php';
if ($scriptsAdded) {
$this->assertNotEmpty(\OC_Util::$scripts);
$this->assertNotEmpty(\OC_Util::$styles);
} else {
$this->assertEmpty(\OC_Util::$scripts);
$this->assertEmpty(\OC_Util::$styles);
}
}
示例9: setUp
public function setUp()
{
parent::setUp();
$this->tree = $this->getMockBuilder('\\Sabre\\DAV\\Tree')->disableOriginalConstructor()->getMock();
$this->view = $this->getMockBuilder('\\OC\\Files\\View')->disableOriginalConstructor()->getMock();
$this->server = $this->getMockBuilder('\\Sabre\\DAV\\Server')->setConstructorArgs([$this->tree])->setMethods(['getRequestUri'])->getMock();
$this->groupManager = $this->getMockBuilder('\\OCP\\IGroupManager')->disableOriginalConstructor()->getMock();
$this->userFolder = $this->getMockBuilder('\\OCP\\Files\\Folder')->disableOriginalConstructor()->getMock();
$this->tagManager = $this->getMock('\\OCP\\SystemTag\\ISystemTagManager');
$this->tagMapper = $this->getMock('\\OCP\\SystemTag\\ISystemTagObjectMapper');
$this->userSession = $this->getMock('\\OCP\\IUserSession');
$user = $this->getMock('\\OCP\\IUser');
$user->expects($this->any())->method('getUID')->will($this->returnValue('testuser'));
$this->userSession->expects($this->any())->method('getUser')->will($this->returnValue($user));
$this->plugin = new FilesReportPluginImplementation($this->tree, $this->view, $this->tagManager, $this->tagMapper, $this->userSession, $this->groupManager, $this->userFolder);
}
示例10: testCreateCommentMessageTooLong
/**
* @expectedException \Sabre\DAV\Exception\BadRequest
* @expectedExceptionMessage Message exceeds allowed character limit of
*/
public function testCreateCommentMessageTooLong()
{
$commentData = ['actorType' => 'users', 'verb' => 'comment', 'message' => str_pad('', IComment::MAX_MESSAGE_LENGTH + 1, 'x')];
$comment = new Comment(['objectType' => 'files', 'objectId' => '42', 'actorType' => 'users', 'actorId' => 'alice', 'verb' => 'comment']);
$comment->setId('23');
$path = 'comments/files/42';
$requestData = json_encode($commentData);
$user = $this->getMock('OCP\\IUser');
$user->expects($this->once())->method('getUID')->will($this->returnValue('alice'));
$node = $this->getMockBuilder('\\OCA\\DAV\\Comments\\EntityCollection')->disableOriginalConstructor()->getMock();
$node->expects($this->once())->method('getName')->will($this->returnValue('files'));
$node->expects($this->once())->method('getId')->will($this->returnValue('42'));
$node->expects($this->never())->method('setReadMarker');
$this->commentsManager->expects($this->once())->method('create')->with('users', 'alice', 'files', '42')->will($this->returnValue($comment));
$this->userSession->expects($this->once())->method('getUser')->will($this->returnValue($user));
// technically, this is a shortcut. Inbetween EntityTypeCollection would
// be returned, but doing it exactly right would not be really
// unit-testing like, as it would require to haul in a lot of other
// things.
$this->tree->expects($this->any())->method('getNodeForPath')->with('/' . $path)->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('/' . $path));
$request->expects($this->once())->method('getBodyAsString')->will($this->returnValue($requestData));
$request->expects($this->once())->method('getHeader')->with('Content-Type')->will($this->returnValue('application/json'));
$response->expects($this->never())->method('setHeader');
$this->server->expects($this->any())->method('getRequestUri')->will($this->returnValue($path));
$this->plugin->initialize($this->server);
$this->plugin->httpPost($request, $response);
}
示例11: testReadParameterUserInvalid
/**
* @expectedException \OutOfBoundsException
*/
public function testReadParameterUserInvalid()
{
$this->data->expects($this->once())->method('validateFilter')->willReturnArgument(0);
$this->userSession->expects($this->once())->method('getUser')->willReturn(null);
$this->invokePrivate($this->controller, 'readParameters', [[]]);
$this->assertSame(null, $this->invokePrivate($this->controller, 'user'));
}
示例12: testIsEnabledForUserLoggedIn
public function testIsEnabledForUserLoggedIn()
{
$user = new User('user1', null);
$this->userSession->expects($this->once())->method('getUser')->will($this->returnValue($user));
$this->groupManager->expects($this->once())->method('getUserGroupIds')->with($user)->will($this->returnValue(array('foo', 'bar')));
$this->appConfig->setValue('test', 'enabled', '["foo"]');
$this->assertTrue($this->manager->isEnabledForUser('test'));
}
示例13: testAuthenticateInvalidCredentials
/**
* @expectedException \Sabre\DAV\Exception\NotAuthenticated
* @expectedExceptionMessage Username or password does not match
*/
public function testAuthenticateInvalidCredentials()
{
$server = $this->getMockBuilder('\\Sabre\\DAV\\Server')->disableOriginalConstructor()->getMock();
$server->httpRequest = $this->getMockBuilder('\\Sabre\\HTTP\\RequestInterface')->disableOriginalConstructor()->getMock();
$server->httpRequest->expects($this->once())->method('getHeader')->with('Authorization')->will($this->returnValue('basic dXNlcm5hbWU6cGFzc3dvcmQ='));
$server->httpResponse = $this->getMockBuilder('\\Sabre\\HTTP\\ResponseInterface')->disableOriginalConstructor()->getMock();
$this->userSession->expects($this->once())->method('login')->with('username', 'password')->will($this->returnValue(false));
$this->auth->authenticate($server, 'TestRealm');
}
示例14: testShowLoginFormForUserNamedNull
public function testShowLoginFormForUserNamedNull()
{
$this->userSession->expects($this->once())->method('isLoggedIn')->willReturn(false);
$this->config->expects($this->once())->method('getSystemValue')->with('lost_password_link')->willReturn(false);
$user = $this->getMock('\\OCP\\IUser');
$user->expects($this->once())->method('canChangePassword')->willReturn(false);
$this->userManager->expects($this->once())->method('get')->with('0')->willReturn($user);
$expectedResponse = new TemplateResponse('core', 'login', ['messages' => [], 'loginName' => '0', 'user_autofocus' => false, 'canResetPassword' => false, 'alt_login' => [], 'rememberLoginAllowed' => \OC_Util::rememberLoginAllowed(), 'rememberLoginState' => 0], 'guest');
$this->assertEquals($expectedResponse, $this->loginController->showLoginForm('0', '', ''));
}
示例15: testAuthenticateInvalidCredentials
public function testAuthenticateInvalidCredentials()
{
$server = $this->getMockBuilder('\\Sabre\\DAV\\Server')->disableOriginalConstructor()->getMock();
$server->httpRequest = $this->getMockBuilder('\\Sabre\\HTTP\\RequestInterface')->disableOriginalConstructor()->getMock();
$server->httpRequest->expects($this->at(0))->method('getHeader')->with('X-Requested-With')->will($this->returnValue(null));
$server->httpRequest->expects($this->at(1))->method('getHeader')->with('Authorization')->will($this->returnValue('basic dXNlcm5hbWU6cGFzc3dvcmQ='));
$server->httpResponse = $this->getMockBuilder('\\Sabre\\HTTP\\ResponseInterface')->disableOriginalConstructor()->getMock();
$this->userSession->expects($this->once())->method('login')->with('username', 'password')->will($this->returnValue(false));
$response = $this->auth->check($server->httpRequest, $server->httpResponse);
$this->assertEquals([false, 'Username or password was incorrect'], $response);
}