/** * @return void */ public function testCleanExpiredRecords() { $timestamp = time(); $this->passwordResetRequestEventCollectionFactoryMock->expects($this->once())->method('create')->willReturn($this->passwordResetRequestEventCollectionMock); $this->securityConfigMock->expects($this->once())->method('getCurrentTimestamp')->willReturn($timestamp); $this->passwordResetRequestEventCollectionMock->expects($this->once())->method('deleteRecordsOlderThen')->with($timestamp - \Magento\Security\Model\SecurityManager::SECURITY_CONTROL_RECORDS_LIFE_TIME)->willReturnSelf(); $this->model->cleanExpiredRecords(); }
/** * Apply config filters * * @param RequestCollection $passwordResetRequestEventCollection * @param int $securityEventType * @param string $accountReference * @param int $longIp * @return RequestCollection */ protected function applyFiltersByConfig(RequestCollection $passwordResetRequestEventCollection, $securityEventType, $accountReference, $longIp) { $limitMethod = $this->securityConfig->getLimitPasswordResetRequestsMethod($this->getScopeByEventType($securityEventType)); switch ($limitMethod) { case ResetMethod::OPTION_BY_EMAIL: $passwordResetRequestEventCollection->filterByAccountReference($accountReference); break; case ResetMethod::OPTION_BY_IP: $passwordResetRequestEventCollection->filterByIp($longIp); break; case ResetMethod::OPTION_BY_IP_AND_EMAIL: $passwordResetRequestEventCollection->filterByIpOrAccountReference($longIp, $accountReference); break; } return $passwordResetRequestEventCollection; }
/** * @param int $requestsMethod * @param int $limitTimeBetweenPasswordResetRequests */ protected function prepareTestCheck($requestsMethod, $limitTimeBetweenPasswordResetRequests) { $this->securityConfigMock->expects($this->once())->method('getRemoteIp')->will($this->returnValue(12345)); $this->securityConfigMock->expects($this->any())->method('getLimitPasswordResetRequestsMethod')->will($this->returnValue($requestsMethod)); $this->securityConfigMock->expects($this->once())->method('getLimitTimeBetweenPasswordResetRequests')->will($this->returnValue($limitTimeBetweenPasswordResetRequests)); $this->securityConfigMock->expects($this->any())->method('getCustomerServiceEmail')->will($this->returnValue('*****@*****.**')); $this->passwordResetRequestEventCollectionFactoryMock->expects($this->once())->method('create')->willReturn($this->passwordResetRequestEventCollectionMock); $this->passwordResetRequestEventCollectionMock->expects($this->any())->method('addFieldToFilter')->willReturnSelf(); $this->passwordResetRequestEventCollectionMock->expects($this->once())->method('filterLastItem')->willReturnSelf(); }
/** * @return void */ public function testDeleteRecordsOlderThen() { $timestamp = time(); $this->resourceMock->expects($this->any())->method('deleteRecordsOlderThen')->with($timestamp); $this->collectionMock->deleteRecordsOlderThen($timestamp); }
/** * deleteRecordsOlderThen() test * * @magentoDataFixture Magento/Security/_files/password_reset_request_events.php */ public function testDeleteRecordsOlderThen() { $startTime = strtotime('2016-01-20 13:00:13'); $this->collectionModel->deleteRecordsOlderThen($startTime)->load(); $this->assertGreaterThanOrEqual(1, $this->collectionModel->getSize()); }