Example #1
0
 /**
  * @return void
  */
 public function testFilterByLifetime()
 {
     $lifetime = 600;
     $timestamp = time();
     $this->dateTimeMock->expects($this->once())->method('gmtTimestamp')->willReturn($timestamp);
     $this->collectionMock->expects($this->once())->method('addFieldToFilter')->with('created_at', ['gt' => $this->collectionMock->getConnection()->formatDate($timestamp - $lifetime)])->willReturnSelf();
     $this->assertEquals($this->collectionMock, $this->collectionMock->filterByLifetime($lifetime));
 }
Example #2
0
 /**
  * @return void
  */
 public function testFilterExpiredSessions()
 {
     $sessionLifeTime = '600';
     $timestamp = time();
     $this->dateTimeMock->expects($this->once())->method('gmtTimestamp')->willReturn($timestamp);
     $this->collectionMock->expects($this->once())->method('addFieldToFilter')->with('updated_at', ['gt' => $this->collectionMock->getConnection()->formatDate($timestamp - $sessionLifeTime)])->willReturnSelf();
     $this->assertEquals($this->collectionMock, $this->collectionMock->filterExpiredSessions($sessionLifeTime));
 }
 /**
  * @param bool $expectedResult
  * @param string $sessionLifetime
  * @dataProvider dataProviderSessionLifetime
  */
 public function testSessionExpired($expectedResult, $sessionLifetime)
 {
     $timestamp = time();
     $this->securityConfigMock->expects($this->once())->method('getAdminSessionLifetime')->will($this->returnValue($sessionLifetime));
     $this->dateTimeMock->expects($this->once())->method('gmtTimestamp')->willReturn($timestamp);
     $this->model->setUpdatedAt(date("Y-m-d H:i:s", $timestamp - 1));
     $this->assertEquals($expectedResult, $this->model->isSessionExpired());
 }
Example #4
0
 public function testSendPerSubscriberZeroSize()
 {
     $this->queue->setQueueStatus(1);
     $this->queue->setQueueStartAt(1);
     $this->subscribersCollection->expects($this->once())->method('getQueueJoinedFlag')->willReturn(false);
     $this->subscribersCollection->expects($this->once())->method('useQueue')->with($this->queue)->willReturnSelf();
     $this->subscribersCollection->expects($this->once())->method('getSize')->willReturn(0);
     $this->date->expects($this->once())->method('gmtDate')->willReturn('any_date');
     $this->assertEquals($this->queue, $this->queue->sendPerSubscriber());
 }
 public function testGenerate()
 {
     $orderId = '1';
     $orderIncrementId = '0000000001';
     $timestamp = 12345678;
     $try = 2;
     $order = $this->getOrderMock($orderId, $orderIncrementId);
     $this->transactionResource->expects($this->once())->method('getLastTryByOrderId')->with($this->equalTo($orderId))->willReturn($try);
     $this->dateTime->expects($this->once())->method('timestamp')->willReturn($timestamp);
     $this->assertEquals($orderIncrementId . ':' . $timestamp . ':' . ($try + 1), $this->model->generate($order));
 }
 public function testSave()
 {
     $productId = 1;
     $this->stockItemMock->expects($this->any())->method('getProductId')->willReturn($productId);
     $this->productMock->expects($this->once())->method('load')->with($productId)->willReturnSelf();
     $this->productMock->expects($this->once())->method('getId')->willReturn($productId);
     $this->productMock->expects($this->once())->method('getTypeId')->willReturn('typeId');
     $this->stockConfigurationMock->expects($this->once())->method('isQty')->with('typeId')->willReturn(true);
     $this->stockStateProviderMock->expects($this->once())->method('verifyStock')->with($this->stockItemMock)->willReturn(false);
     $this->stockItemMock->expects($this->once())->method('getManageStock')->willReturn(true);
     $this->stockItemMock->expects($this->once())->method('setIsInStock')->with(false)->willReturnSelf();
     $this->stockItemMock->expects($this->once())->method('setStockStatusChangedAutomaticallyFlag')->with(true)->willReturnSelf();
     $this->stockItemMock->expects($this->any())->method('setLowStockDate')->willReturnSelf();
     $this->stockStateProviderMock->expects($this->once())->method('verifyNotification')->with($this->stockItemMock)->willReturn(true);
     $this->dateTime->expects($this->once())->method('gmtDate');
     $this->stockItemMock->expects($this->atLeastOnce())->method('setStockStatusChangedAuto')->willReturnSelf();
     $this->stockItemMock->expects($this->once())->method('hasStockStatusChangedAutomaticallyFlag')->willReturn(true);
     $this->stockItemMock->expects($this->once())->method('getStockStatusChangedAutomaticallyFlag')->willReturn(true);
     $this->stockItemMock->expects($this->once())->method('getWebsiteId')->willReturn(1);
     $this->stockItemMock->expects($this->once())->method('setWebsiteId')->with(1)->willReturnSelf();
     $this->stockItemMock->expects($this->once())->method('getStockId')->willReturn(1);
     $this->stockItemMock->expects($this->once())->method('setStockId')->with(1)->willReturnSelf();
     $this->stockItemResourceMock->expects($this->once())->method('save')->with($this->stockItemMock)->willReturnSelf();
     $this->indexProcessorMock->expects($this->once())->method('reindexRow')->with($productId);
     $this->assertEquals($this->stockItemMock, $this->model->save($this->stockItemMock));
 }
 /**
  * @return void
  */
 public function testCleanExpiredSessions()
 {
     $timestamp = time();
     $this->adminSessionInfoCollectionFactoryMock->expects($this->once())->method('create')->willReturn($this->adminSessionInfoCollectionMock);
     $this->dateTimeMock->expects($this->once())->method('gmtTimestamp')->willReturn($timestamp);
     $this->adminSessionInfoCollectionMock->expects($this->once())->method('deleteSessionsOlderThen')->with($timestamp - AdminSessionsManager::ADMIN_SESSION_LIFETIME)->willReturnSelf();
     $this->model->cleanExpiredSessions();
 }
 /**
  * @return void
  */
 public function testCleanExpiredRecords()
 {
     $timestamp = time();
     $this->passwordResetRequestEventCollectionFactoryMock->expects($this->once())->method('create')->willReturn($this->passwordResetRequestEventCollectionMock);
     $this->dateTimeMock->expects($this->once())->method('gmtTimestamp')->willReturn($timestamp);
     $this->passwordResetRequestEventCollectionMock->expects($this->once())->method('deleteRecordsOlderThen')->with($timestamp - \Magento\Security\Model\SecurityManager::SECURITY_CONTROL_RECORDS_LIFE_TIME)->willReturnSelf();
     $this->model->cleanExpiredRecords();
 }
Example #9
0
 /**
  * @param int $securityEventType
  * @param int $requestsMethod
  * @dataProvider dataProviderSecurityEventTypeWithRequestsMethod
  * @expectedException \Magento\Framework\Exception\SecurityViolationException
  * @expectedExceptionMessage Too many password reset requests. Please wait and try again or contact test@host.com.
  */
 public function testCheckException($securityEventType, $requestsMethod)
 {
     $limitTimeBetweenPasswordResetRequests = 600;
     $timestamp = time();
     $this->prepareTestCheck($requestsMethod, $limitTimeBetweenPasswordResetRequests);
     $this->dateTimeMock->expects($this->once())->method('gmtTimestamp')->willReturn($timestamp);
     /** @var \Magento\Security\Model\PasswordResetRequestEvent $record */
     $record = $this->objectManager->getObject('\\Magento\\Security\\Model\\PasswordResetRequestEvent');
     $record->setCreatedAt(date("Y-m-d H:i:s", $timestamp - $limitTimeBetweenPasswordResetRequests + 1));
     $this->collectionMock->expects($this->once())->method('getFirstItem')->willReturn($record);
     $this->model->check($securityEventType);
 }
Example #10
0
    /**
     * @covers \Magento\Sales\Controller\Adminhtml\Order\Creditmemo\PrintAction::executeInternal
     */
    public function testExecute()
    {
        $creditmemoId = 2;
        $date = '2015-01-19_13-03-45';
        $fileName = 'creditmemo2015-01-19_13-03-45.pdf';
        $fileContents = 'pdf0123456789';
        $this->prepareTestExecute($creditmemoId);

        $this->objectManagerMock->expects($this->any())
            ->method('create')
            ->willReturnMap(
                [
                    ['Magento\Sales\Model\Order\Creditmemo', [], $this->creditmemoMock],
                    ['Magento\Sales\Model\Order\Pdf\Creditmemo', [], $this->creditmemoPdfMock]
                ]
            );
        $this->creditmemoRepositoryMock->expects($this->once())
            ->method('get')
            ->with($creditmemoId)
            ->willReturn($this->creditmemoMock);
        $this->creditmemoPdfMock->expects($this->once())
            ->method('getPdf')
            ->with([$this->creditmemoMock])
            ->willReturn($this->pdfMock);
        $this->objectManagerMock->expects($this->once())
            ->method('get')
            ->with('Magento\Framework\Stdlib\DateTime\DateTime')
            ->willReturn($this->dateTimeMock);
        $this->dateTimeMock->expects($this->once())
            ->method('date')
            ->with('Y-m-d_H-i-s')
            ->willReturn($date);
        $this->pdfMock->expects($this->once())
            ->method('render')
            ->willReturn($fileContents);
        $this->fileFactoryMock->expects($this->once())
            ->method('create')
            ->with(
                $fileName,
                $fileContents,
                \Magento\Framework\App\Filesystem\DirectoryList::VAR_DIR,
                'application/pdf'
            )
            ->willReturn($this->responseMock);

        $this->assertInstanceOf(
            'Magento\Framework\App\ResponseInterface',
            $this->printAction->executeInternal()
        );
    }
 /**
  * Cover createHistoryReport().
  *
  * @expectedException \Magento\Framework\Exception\LocalizedException
  * @expectedExceptionMessage Source file coping failed
  */
 public function testCreateHistoryReportThrowException()
 {
     $sourceFileRelative = null;
     $entity = '';
     $extension = '';
     $result = '';
     $gmtTimestamp = 1234567;
     $this->import->expects($this->once())->method('isReportEntityType')->with($entity)->willReturn(true);
     $this->_varDirectory->expects($this->never())->method('getRelativePath');
     $phrase = $this->getMock('\\Magento\\Framework\\Phrase', [], [], '', false);
     $this->_driver->expects($this->any())->method('fileGetContents')->willReturnCallback(function () use($phrase) {
         throw new \Magento\Framework\Exception\FileSystemException($phrase);
     });
     $this->dateTime->expects($this->once())->method('gmtTimestamp')->willReturn($gmtTimestamp);
     $args = [$sourceFileRelative, $entity, $extension, $result];
     $actualResult = $this->invokeMethod($this->import, 'createHistoryReport', $args);
     $this->assertEquals($this->import, $actualResult);
 }
Example #12
0
 public function testGetYears()
 {
     $this->date->expects($this->once())->method('date')->with('Y')->will($this->returnValue(self::CURRENT_YEAR));
     $this->assertEquals($this->_getPreparedYearsList(), $this->config->getYears());
 }
Example #13
0
 protected function _makeValidExpirationPeriod()
 {
     $this->_dateMock->expects($this->any())->method('timestamp')->will($this->returnValue(0));
     $this->_dataHelperMock->expects($this->once())->method('getConsumerExpirationPeriod')->will($this->returnValue(300));
 }