/**
  * Test execute
  *
  * @return void
  */
 public function testExecute()
 {
     $data = ['comment' => 'test comment'];
     $invoiceId = 2;
     $response = 'some result';
     $this->requestMock->expects($this->at(0))->method('getParam')->with('id')->willReturn($invoiceId);
     $this->requestMock->expects($this->at(1))->method('setParam');
     $this->requestMock->expects($this->at(2))->method('getPost')->with('comment')->willReturn($data);
     $this->requestMock->expects($this->at(3))->method('getParam')->with('invoice_id')->willReturn($invoiceId);
     $invoiceMock = $this->getMockBuilder('Magento\\Sales\\Model\\Order\\Invoice')->disableOriginalConstructor()->setMethods([])->getMock();
     $invoiceMock->expects($this->once())->method('addComment')->with($data['comment'], false, false);
     $invoiceMock->expects($this->once())->method('save');
     $invoiceMock->expects($this->once())->method('load')->willReturnSelf();
     $this->objectManagerMock->expects($this->once())->method('create')->with('Magento\\Sales\\Model\\Order\\Invoice')->willReturn($invoiceMock);
     $commentsBlockMock = $this->getMockBuilder('Magento\\Sales\\Block\\Adminhtml\\Order\\Invoice\\View\\Comments')->disableOriginalConstructor()->setMethods([])->getMock();
     $commentsBlockMock->expects($this->once())->method('toHtml')->will($this->returnValue($response));
     $layoutMock = $this->getMockBuilder('Magento\\Framework\\View\\Layout')->disableOriginalConstructor()->setMethods([])->getMock();
     $layoutMock->expects($this->once())->method('getBlock')->with('invoice_comments')->will($this->returnValue($commentsBlockMock));
     $this->resultPageFactoryMock->expects($this->once())->method('create')->will($this->returnValue($this->resultPageMock));
     $this->resultPageMock->expects($this->any())->method('getLayout')->will($this->returnValue($layoutMock));
     $this->commentSenderMock->expects($this->once())->method('send')->with($invoiceMock, false, $data['comment']);
     $resultRaw = $this->getMockBuilder('Magento\\Framework\\Controller\\Result\\Raw')->disableOriginalConstructor()->setMethods([])->getMock();
     $resultRaw->expects($this->once())->method('setContents')->with($response);
     $this->resultRawFactoryMock->expects($this->once())->method('create')->will($this->returnValue($resultRaw));
     $this->assertSame($resultRaw, $this->controller->execute());
 }
 /**
  * Test execute
  *
  * @return void
  */
 public function testExecute()
 {
     $orderId = 1;
     $invoiceData = ['comment_text' => 'test'];
     $response = 'test data';
     $this->requestMock->expects($this->at(0))->method('getParam')->with('order_id')->will($this->returnValue($orderId));
     $this->requestMock->expects($this->at(1))->method('getParam')->with('invoice', [])->will($this->returnValue($invoiceData));
     $invoiceMock = $this->getMockBuilder('Magento\\Sales\\Model\\Order\\Invoice')->disableOriginalConstructor()->setMethods([])->getMock();
     $invoiceMock->expects($this->once())->method('getTotalQty')->willReturn(2);
     $orderMock = $this->getMockBuilder('Magento\\Sales\\Model\\Order')->disableOriginalConstructor()->setMethods(['load', 'getId', 'canInvoice'])->getMock();
     $orderMock->expects($this->once())->method('load')->with($orderId)->willReturnSelf();
     $orderMock->expects($this->once())->method('getId')->willReturn($orderId);
     $orderMock->expects($this->once())->method('canInvoice')->willReturn(true);
     $this->invoiceServiceMock->expects($this->once())->method('prepareInvoice')->with($orderMock, [])->willReturn($invoiceMock);
     $this->objectManagerMock->expects($this->at(0))->method('create')->with('Magento\\Sales\\Model\\Order')->willReturn($orderMock);
     $blockItemMock = $this->getMockBuilder('Magento\\Sales\\Block\\Order\\Items')->disableOriginalConstructor()->setMethods([])->getMock();
     $blockItemMock->expects($this->once())->method('toHtml')->will($this->returnValue($response));
     $layoutMock = $this->getMockBuilder('Magento\\Framework\\View\\Layout')->disableOriginalConstructor()->setMethods([])->getMock();
     $layoutMock->expects($this->once())->method('getBlock')->with('order_items')->will($this->returnValue($blockItemMock));
     $this->resultPageMock->expects($this->once())->method('getLayout')->will($this->returnValue($layoutMock));
     $this->resultPageMock->expects($this->once())->method('getConfig')->will($this->returnValue($this->pageConfigMock));
     $this->pageConfigMock->expects($this->once())->method('getTitle')->will($this->returnValue($this->titleMock));
     $this->resultPageFactoryMock->expects($this->once())->method('create')->will($this->returnValue($this->resultPageMock));
     $resultRaw = $this->getMockBuilder('Magento\\Framework\\Controller\\Result\\Raw')->disableOriginalConstructor()->setMethods([])->getMock();
     $resultRaw->expects($this->once())->method('setContents')->with($response);
     $this->resultRawFactoryMock->expects($this->once())->method('create')->will($this->returnValue($resultRaw));
     $this->assertSame($resultRaw, $this->controller->execute());
 }
Exemple #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()
        );
    }
 /**
  * Set up
  */
 public function setUp()
 {
     $this->contextMock = $this->getMock('\\Magento\\Backend\\App\\Action\\Context', [], [], '', false);
     $this->rawFactoryMock = $this->getMock('\\Magento\\Framework\\Controller\\Result\\RawFactory', ['create'], [], '', false);
     $response = $this->getMock('\\Magento\\Framework\\Controller\\Result\\Raw', [], [], '', false);
     $this->rawFactoryMock->expects($this->once())->method('create')->willReturn($response);
     $this->configMock = $this->getMock('\\Magento\\Catalog\\Model\\Product\\Media\\Config', [], [], '', false);
     $this->filesystemMock = $this->getMock('\\Magento\\Framework\\Filesystem', [], [], '', false);
     $this->adapterMock = $this->getMock('\\Magento\\Framework\\Image', [], [], '', false);
     $this->adapterFactoryMock = $this->getMock('\\Magento\\Framework\\Image\\AdapterFactory', ['create'], [], '', false);
     $this->abstractAdapter = $this->getMock('\\Magento\\Framework\\Image\\Adapter\\AbstractAdapter', [], [], '', false);
     $this->adapterFactoryMock->expects($this->once())->method('create')->willReturn($this->abstractAdapter);
     $this->curlMock = $this->getMock('\\Magento\\Framework\\HTTP\\Adapter\\Curl', [], [], '', false);
     $this->storageFileMock = $this->getMock('\\Magento\\MediaStorage\\Model\\ResourceModel\\File\\Storage\\File', [], [], '', false);
     $this->request = $this->getMock('\\Magento\\Framework\\App\\RequestInterface');
     $this->contextMock->expects($this->any())->method('getRequest')->will($this->returnValue($this->request));
     $objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
     $this->image = $objectManager->getObject('\\Magento\\ProductVideo\\Controller\\Adminhtml\\Product\\Gallery\\RetrieveImage', ['context' => $this->contextMock, 'resultRawFactory' => $this->rawFactoryMock, 'mediaConfig' => $this->configMock, 'fileSystem' => $this->filesystemMock, 'imageAdapterFactory' => $this->adapterFactoryMock, 'curl' => $this->curlMock, 'fileUtility' => $this->storageFileMock]);
 }
 /**
  * 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());
 }
 /**
  * Set up
  */
 protected function setUp()
 {
     $this->request = $this->getMock('Magento\\Framework\\App\\Request\\Http', ['getParam'], [], '', false);
     $this->request->expects($this->any())->method('getParam')->with('filename')->willReturn('filename');
     $this->reportHelper = $this->getMock('Magento\\ImportExport\\Helper\\Report', ['importFileExists', 'getReportSize', 'getReportOutput'], [], '', false);
     $this->reportHelper->expects($this->any())->method('getReportSize')->willReturn(1);
     $this->reportHelper->expects($this->any())->method('getReportOutput')->willReturn('output');
     $this->objectManager = $this->getMock('Magento\\Framework\\ObjectManager\\ObjectManager', ['get'], [], '', false);
     $this->objectManager->expects($this->any())->method('get')->with('Magento\\ImportExport\\Helper\\Report')->willReturn($this->reportHelper);
     $this->context = $this->getMock('Magento\\Backend\\App\\Action\\Context', ['getRequest', 'getObjectManager', 'getResultRedirectFactory'], [], '', false);
     $this->fileFactory = $this->getMock('Magento\\Framework\\App\\Response\\Http\\FileFactory', ['create'], [], '', false);
     $this->resultRaw = $this->getMock('Magento\\Framework\\Controller\\Result\\Raw', ['setContents'], [], '', false);
     $this->resultRawFactory = $this->getMock('\\Magento\\Framework\\Controller\\Result\\RawFactory', ['create'], [], '', false);
     $this->resultRawFactory->expects($this->any())->method('create')->willReturn($this->resultRaw);
     $this->redirect = $this->getMock('\\Magento\\Backend\\Model\\View\\Result\\Redirect', ['setPath'], [], '', false);
     $this->resultRedirectFactory = $this->getMock('Magento\\Framework\\Controller\\Result\\RedirectFactory', ['create'], [], '', false);
     $this->resultRedirectFactory->expects($this->any())->method('create')->willReturn($this->redirect);
     $this->context->expects($this->any())->method('getRequest')->willReturn($this->request);
     $this->context->expects($this->any())->method('getObjectManager')->willReturn($this->objectManager);
     $this->context->expects($this->any())->method('getResultRedirectFactory')->willReturn($this->resultRedirectFactory);
     $this->objectManagerHelper = new ObjectManagerHelper($this);
     $this->downloadController = $this->objectManagerHelper->getObject('Magento\\ImportExport\\Controller\\Adminhtml\\History\\Download', ['context' => $this->context, 'fileFactory' => $this->fileFactory, 'resultRawFactory' => $this->resultRawFactory, 'reportHelper' => $this->reportHelper]);
 }
Exemple #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());
 }
 /**
  * @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());
 }
 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());
 }