Esempio n. 1
0
 public function testRender()
 {
     $content = '<content>test</content>';
     $this->raw->setContents($content);
     $this->response->expects($this->once())->method('setBody')->with($content);
     $this->assertSame($this->raw, $this->raw->renderResult($this->response));
 }
Esempio n. 2
0
 public function testExecute()
 {
     $this->_getTreeBlock();
     $testHtml = '<div>Some test html</div>';
     $this->chooserBlockMock->expects($this->once())->method('toHtml')->will($this->returnValue($testHtml));
     $this->resultRaw->expects($this->once())->method('setContents')->with($testHtml);
     $this->controller->executeInternal();
 }
Esempio n. 3
0
    /**
     * Test execute
     *
     * @return void
     */
    public function testExecute()
    {
        $comment = 'Test comment';
        $data = ['comment' => $comment];
        $html = 'test output';

        $creditmemoMock = $this->getMockBuilder('Magento\Sales\Model\Order\Creditmemo')
            ->disableOriginalConstructor()
            ->getMock();
        $commentMock = $this->getMockBuilder('Magento\Sales\Model\Order\Creditmemo\Comment')
            ->disableOriginalConstructor()
            ->getMock();
        $layoutMock = $this->getMockBuilder('Magento\Framework\View\Layout')
            ->disableOriginalConstructor()
            ->getMock();
        $blockMock = $this->getMockBuilder('Magento\Sales\Block\Adminhtml\Order\Creditmemo\View\Comments')
            ->disableOriginalConstructor()
            ->getMock();

        $this->requestMock->expects($this->once())
            ->method('getPost')
            ->with('comment')
            ->willReturn($data);
        $this->requestMock->expects($this->any())
            ->method('getParam')
            ->willReturnArgument(0);
        $creditmemoMock->expects($this->once())
            ->method('addComment')
            ->willReturn($commentMock);
        $this->loaderMock->expects($this->once())
            ->method('load')
            ->willReturn($creditmemoMock);
        $this->resultPageFactoryMock->expects($this->once())
            ->method('create')
            ->willReturn($this->resultPageMock);
        $this->resultPageMock->expects($this->atLeastOnce())
            ->method('getLayout')
            ->willReturn($layoutMock);
        $layoutMock->expects($this->once())
            ->method('getBlock')
            ->with('creditmemo_comments')
            ->willReturn($blockMock);
        $blockMock->expects($this->once())
            ->method('toHtml')
            ->willReturn($html);
        $this->resultRawFactoryMock->expects($this->once())
            ->method('create')
            ->willReturn($this->resultRawMock);
        $this->resultRawMock->expects($this->once())
            ->method('setContents')
            ->with($html)
            ->willReturnSelf();

        $this->assertInstanceOf(
            'Magento\Framework\Controller\Result\Raw',
            $this->controller->executeInternal()
        );
    }
Esempio n. 4
0
 /**
  * {@inheritdoc}
  */
 public function renderResult(\Magento\Framework\App\ResponseInterface $response)
 {
     $pluginInfo = $this->pluginList->getNext($this->subjectType, 'renderResult');
     if (!$pluginInfo) {
         return parent::renderResult($response);
     } else {
         return $this->___callPlugins('renderResult', func_get_args(), $pluginInfo);
     }
 }
Esempio n. 5
0
    public function testExecute()
    {
        $selectedCategories = '1';
        $isAnchorOnly = true;
        $hash = '7e6baeca2d76ca0efc3a299986d31bdc9cd796fb';
        $content = 'block_content';

        $this->request->expects($this->any())->method('getParam')->willReturnMap(
            [
                ['selected', '', $selectedCategories],
                ['is_anchor_only', 0, $isAnchorOnly]
            ]
        );

        $this->mathRandom->expects($this->once())->method('getUniqueHash')->with('categories')->willReturn($hash);

        $this->chooser->expects($this->once())->method('setUseMassaction')->with()->willReturnSelf();
        $this->chooser->expects($this->once())->method('setId')->with($hash)->willReturnSelf();
        $this->chooser->expects($this->once())->method('setIsAnchorOnly')->with($isAnchorOnly)->willReturnSelf();
        $this->chooser->expects($this->once())
            ->method('setSelectedCategories')
            ->with(explode(',', $selectedCategories))
            ->willReturnSelf();
        $this->chooser->expects($this->once())->method('toHtml')->willReturn($content);

        $this->layout->expects($this->once())
            ->method('createBlock')
            ->with($this->blockClass)
            ->willReturn($this->chooser);

        $this->resultRaw->expects($this->once())->method('setContents')->with($content)->willReturnSelf();

        $this->resultFactory->expects($this->once())
            ->method('create')
            ->with(\Magento\Framework\Controller\ResultFactory::TYPE_RAW)
            ->willReturn($this->resultRaw);

        $this->context->expects($this->once())->method('getRequest')->willReturn($this->request);
        $this->context->expects($this->once())->method('getResultFactory')->willReturn($this->resultFactory);

        /** @var \Magento\Widget\Controller\Adminhtml\Widget\Instance\Categories $controller */
        $this->controller = (new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this))
            ->getObject(
                'Magento\Widget\Controller\Adminhtml\Widget\Instance\Categories',
                [
                    'context' => $this->context,
                    'mathRandom' => $this->mathRandom,
                    'layout' => $this->layout
                ]
            );
        $this->assertSame($this->resultRaw, $this->controller->executeInternal());
    }
Esempio n. 6
0
 /**
  * Test execute
  *
  * @return void
  */
 public function testExecute()
 {
     $response = 'output';
     $this->requestMock->expects($this->any())->method('getParam')->withAnyParameters()->willReturnArgument(0);
     $layoutMock = $this->getMockBuilder('Magento\\Framework\\View\\Layout')->disableOriginalConstructor()->getMock();
     $blockMock = $this->getMockBuilder('Magento\\Sales\\Block\\Order\\Items')->disableOriginalConstructor()->getMock();
     $this->resultPageFactoryMock->expects($this->once())->method('create')->willReturn($this->resultPageMock);
     $this->resultPageMock->expects($this->atLeastOnce())->method('getLayout')->willReturn($layoutMock);
     $blockMock->expects($this->once())->method('toHtml')->willReturn($response);
     $layoutMock->expects($this->once())->method('getBlock')->with('order_items')->willReturn($blockMock);
     $this->resultRawFactoryMock->expects($this->once())->method('create')->willReturn($this->resultRawMock);
     $this->resultRawMock->expects($this->once())->method('setContents')->with($response)->willReturnSelf();
     $this->assertInstanceOf('Magento\\Framework\\Controller\\Result\\Raw', $this->controller->execute());
 }
Esempio n. 7
0
 /**
  * @covers \Magento\Cms\Controller\Adminhtml\Wysiwyg\Directive::executeInternal
  */
 public function testExecuteException()
 {
     $exception = new \Exception('epic fail');
     $placeholderPath = 'pub/static/adminhtml/Magento/backend/en_US/Magento_Cms/images/wysiwyg_skin_image.png';
     $mimeType = 'image/png';
     $imageBody = '0123456789abcdefghijklmnopqrstuvwxyz';
     $this->prepareExecuteTest();
     $this->imageAdapterMock->expects($this->at(0))->method('open')->with(self::IMAGE_PATH)->willThrowException($exception);
     $this->wysiwygConfigMock->expects($this->once())->method('getSkinImagePlaceholderPath')->willReturn($placeholderPath);
     $this->imageAdapterMock->expects($this->at(1))->method('open')->with($placeholderPath);
     $this->imageAdapterMock->expects($this->once())->method('getMimeType')->willReturn($mimeType);
     $this->rawMock->expects($this->once())->method('setHeader')->with('Content-Type', $mimeType)->willReturnSelf();
     $this->rawMock->expects($this->once())->method('setContents')->with($imageBody)->willReturnSelf();
     $this->imageAdapterMock->expects($this->once())->method('getImage')->willReturn($imageBody);
     $this->loggerMock->expects($this->once())->method('critical')->with($exception);
     $this->rawFactoryMock->expects($this->any())->method('create')->willReturn($this->rawMock);
     $this->assertSame($this->rawMock, $this->wysiwygDirective->executeInternal());
 }
Esempio n. 8
0
 public function execute()
 {
     $skipFraudDetection = false;
     \Paynl\Config::setApiToken($this->_config->getApiToken());
     $params = $this->getRequest()->getParams();
     if (!isset($params['order_id'])) {
         $this->_logger->critical('Exchange: order_id is not set in the request', $params);
         return $this->_result->setContents('FALSE| order_id is not set in the request');
     }
     try {
         $transaction = \Paynl\Transaction::get($params['order_id']);
     } catch (\Exception $e) {
         $this->_logger->critical($e, $params);
         return $this->_result->setContents('FALSE| Error fetching transaction. ' . $e->getMessage());
     }
     if ($transaction->isPending()) {
         return $this->_result->setContents("TRUE| Ignoring pending");
     }
     $orderId = $transaction->getDescription();
     $order = $this->_orderFactory->create()->loadByIncrementId($orderId);
     if (empty($order)) {
         $this->_logger->critical('Cannot load order: ' . $orderId);
         return $this->_result->setContents('FALSE| Cannot load order');
     }
     if ($order->getTotalDue() <= 0) {
         $this->_logger->debug('Total due <= 0, so iam not touching the status of the order: ' . $orderId);
         return $this->_result->setContents('TRUE| Total due <= 0, so iam not touching the status of the order');
     }
     if ($transaction->isPaid()) {
         $payment = $order->getPayment();
         $payment->setTransactionId($transaction->getId());
         $payment->setCurrencyCode($transaction->getPaidCurrency());
         $payment->setIsTransactionClosed(0);
         $payment->registerCaptureNotification($transaction->getPaidCurrencyAmount(), $skipFraudDetection);
         $order->save();
         // notify customer
         $invoice = $payment->getCreatedInvoice();
         if ($invoice && !$order->getEmailSent()) {
             $this->_orderSender->send($order);
             $order->addStatusHistoryComment(__('New order email sent'))->setIsCustomerNotified(true)->save();
         }
         if ($invoice && !$invoice->getEmailSent()) {
             $this->_invoiceSender->send($invoice);
             $order->addStatusHistoryComment(__('You notified customer about invoice #%1.', $invoice->getIncrementId()))->setIsCustomerNotified(true)->save();
         }
         return $this->_result->setContents("TRUE| PAID");
     } elseif ($transaction->isCanceled()) {
         $order->cancel()->save();
         return $this->_result->setContents("TRUE| CANCELED");
     }
 }
Esempio n. 9
0
 /**
  * @covers \Magento\Backup\Controller\Adminhtml\Index\Download::execute
  */
 public function testExecuteBackupFound()
 {
     $time = 1;
     $type = 'db';
     $filename = 'filename';
     $size = 10;
     $output = 'test';
     $this->backupModelMock->expects($this->atLeastOnce())->method('getTime')->willReturn($time);
     $this->backupModelMock->expects($this->atLeastOnce())->method('exists')->willReturn(true);
     $this->backupModelMock->expects($this->atLeastOnce())->method('getSize')->willReturn($size);
     $this->backupModelMock->expects($this->atLeastOnce())->method('output')->willReturn($output);
     $this->requestMock->expects($this->any())->method('getParam')->willReturnMap([['time', null, $time], ['type', null, $type]]);
     $this->backupModelFactoryMock->expects($this->once())->method('create')->with($time, $type)->willReturn($this->backupModelMock);
     $this->dataHelperMock->expects($this->once())->method('generateBackupDownloadName')->with($this->backupModelMock)->willReturn($filename);
     $this->objectManagerMock->expects($this->once())->method('get')->with('Magento\\Backup\\Helper\\Data')->willReturn($this->dataHelperMock);
     $this->fileFactoryMock->expects($this->once())->method('create')->with($filename, null, DirectoryList::VAR_DIR, 'application/octet-stream', $size)->willReturn($this->responseMock);
     $this->resultRawMock->expects($this->once())->method('setContents')->with($output);
     $this->resultRawFactoryMock->expects($this->once())->method('create')->willReturn($this->resultRawMock);
     $this->assertSame($this->resultRawMock, $this->downloadController->execute());
 }
Esempio n. 10
0
 public function testExecuteGetParamImage()
 {
     $decodedFile = 'decoded_file';
     $file = 'file';
     $fileName = 'customer/' . $file;
     $path = 'path';
     $stat = ['size' => 10, 'mtime' => 10];
     $this->requestMock->expects($this->any())->method('getParam')->willReturnMap([['file', null, null], ['image', null, $decodedFile]]);
     $this->directoryMock->expects($this->once())->method('getAbsolutePath')->with($fileName)->willReturn($path);
     $this->directoryMock->expects($this->once())->method('stat')->with($path)->willReturn($stat);
     $this->fileSystemMock->expects($this->once())->method('getDirectoryRead')->with(\Magento\Framework\App\Filesystem\DirectoryList::MEDIA)->willReturn($this->directoryMock);
     $this->storage->expects($this->once())->method('processStorageFile')->with($path)->willReturn(true);
     $this->objectManager->expects($this->any())->method('get')->willReturnMap([['Magento\\Framework\\Filesystem', $this->fileSystemMock], ['Magento\\MediaStorage\\Helper\\File\\Storage', $this->storage]]);
     $this->urlDecoderMock->expects($this->once())->method('decode')->with($decodedFile)->willReturn($file);
     $this->resultRawMock->expects($this->once())->method('setHttpResponseCode')->with(200)->willReturnSelf();
     $this->resultRawMock->expects($this->any())->method('setHeader')->willReturnMap([['Pragma', 'public', true, $this->resultRawMock], ['Content-type', 'application/octet-stream', true, $this->resultRawMock], ['Content-Length', $stat['size'], false, $this->resultRawMock], ['Pragma', 'public', true, $this->resultRawMock]]);
     $this->resultRawFactoryMock = $this->getMock('Magento\\Framework\\Controller\\Result\\RawFactory', ['create'], [], '', false);
     $this->resultRawFactoryMock->expects($this->once())->method('create')->willReturn($this->resultRawMock);
     /** @var \Magento\Customer\Controller\Adminhtml\Index\Viewfile $controller */
     $controller = (new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this))->getObject('Magento\\Customer\\Controller\\Adminhtml\\Index\\Viewfile', ['context' => $this->contextMock, 'urlDecoder' => $this->urlDecoderMock, 'resultRawFactory' => $this->resultRawFactoryMock]);
     $this->assertSame($this->resultRawMock, $controller->execute());
 }