/** * deleteSessionsOlderThen() test * * @magentoDataFixture Magento/Security/_files/adminsession.php */ public function testDeleteSessionsOlderThen() { $startTime = strtotime('2016-01-19 15:42:13'); $this->collectionModel->deleteSessionsOlderThen($startTime); $this->collectionModel->load(); $this->assertGreaterThanOrEqual(1, $this->collectionModel->getSize()); }
/** * @return void */ public function testUpdateActiveSessionsStatus() { $status = 2; $userId = 10; $sessionIdToExclude = '20'; $updateOlderThen = 12345; $result = 1; $this->resourceMock->expects($this->any())->method('updateStatusByUserId')->with($status, $userId, [\Magento\Security\Model\AdminSessionInfo::LOGGED_IN], [$sessionIdToExclude], $updateOlderThen)->willReturn($result); $this->assertEquals($result, $this->collectionMock->updateActiveSessionsStatus($status, $userId, $sessionIdToExclude, $updateOlderThen)); }
/** * @return void */ public function testLogoutOtherUserSessions() { $useId = 1; $sessionLifetime = 100; $sessionId = 50; $this->adminSessionInfoCollectionFactoryMock->expects($this->once())->method('create')->willReturn($this->adminSessionInfoCollectionMock); $this->authSessionMock->expects($this->once())->method('getUser')->willReturn($this->userMock); $this->authSessionMock->expects($this->once())->method('getSessionId')->willReturn($sessionId); $this->userMock->expects($this->once())->method('getId')->willReturn($useId); $this->adminSessionInfoCollectionMock->expects($this->once())->method('filterByUser')->with($useId, \Magento\Security\Model\AdminSessionInfo::LOGGED_IN, $sessionId)->willReturnSelf(); $this->securityConfigMock->expects($this->once())->method('getAdminSessionLifetime')->willReturn($sessionLifetime); $this->adminSessionInfoCollectionMock->expects($this->once())->method('filterExpiredSessions')->with($sessionLifetime)->willReturnSelf(); $this->adminSessionInfoCollectionMock->expects($this->once())->method('loadData')->willReturnSelf(); $this->adminSessionInfoCollectionMock->expects($this->once())->method('setDataToAll')->with($this->equalTo('status'), \Magento\Security\Model\AdminSessionInfo::LOGGED_OUT_MANUALLY)->willReturnSelf(); $this->adminSessionInfoCollectionMock->expects($this->once())->method('save'); $this->model->logoutOtherUserSessions(); }
/** * @param bool $expectedResult * @param int $sessionsNumber * @dataProvider dataProviderAreMultipleSessionsActive */ public function testAreMultipleSessionsActive($expectedResult, $sessionsNumber) { $this->sessionsManager->expects($this->once())->method('getSessionsForCurrentUser')->willReturn($this->collectionMock); $this->collectionMock->expects($this->any())->method('count')->willReturn($sessionsNumber); $this->assertEquals($expectedResult, $this->block->areMultipleSessionsActive()); }