コード例 #1
0
 public function testExportVarnishConfigAction()
 {
     $fileContent = 'some conetnt';
     $filename = 'varnish.vcl';
     $responseMock = $this->getMockBuilder('Magento\\Framework\\App\\ResponseInterface')->disableOriginalConstructor()->getMock();
     $this->configMock->expects($this->once())->method('getVclFile')->will($this->returnValue($fileContent));
     $this->fileFactoryMock->expects($this->once())->method('create')->with($this->equalTo($filename), $this->equalTo($fileContent), $this->equalTo(DirectoryList::VAR_DIR))->will($this->returnValue($responseMock));
     $result = $this->action->executeInternal();
     $this->assertInstanceOf('Magento\\Framework\\App\\ResponseInterface', $result);
 }
コード例 #2
0
 /**
  * Run file create section
  *
  * @return string
  */
 protected function fileCreate()
 {
     $resultContent = 'result-pdf-content';
     $incrementId = '1000001';
     $this->shipmentMock->expects($this->once())->method('getIncrementId')->will($this->returnValue($incrementId));
     $this->fileFactoryMock->expects($this->once())->method('create')->will($this->returnValue($resultContent));
     return $resultContent;
 }
コード例 #3
0
    /**
     * Run test execute method
     */
    public function testExecute()
    {
        $date = '9999-99-99_77-77-77';
        $content = 'PDF content';

        $packagingMock = $this->getMock(
            'Magento\Shipping\Model\Order\Pdf\Packaging',
            ['getPdf'],
            [],
            '',
            false
        );
        $pdfMock = $this->getMock(
            'Zend_Pdf',
            ['render'],
            [],
            '',
            false
        );
        $dateTimeMock = $this->getMock(
            'Magento\Framework\Stdlib\DateTime\DateTime',
            ['date'],
            [],
            '',
            false
        );

        $this->shipmentLoaderMock->expects($this->once())
            ->method('load')
            ->will($this->returnValue($this->shipmentMock));
        $this->objectManagerMock->expects($this->once())
            ->method('create')
            ->with('Magento\Shipping\Model\Order\Pdf\Packaging')
            ->will($this->returnValue($packagingMock));
        $packagingMock->expects($this->once())
            ->method('getPdf')
            ->with($this->shipmentMock)
            ->will($this->returnValue($pdfMock));
        $this->objectManagerMock->expects($this->once())
            ->method('get')
            ->with('Magento\Framework\Stdlib\DateTime\DateTime')
            ->will($this->returnValue($dateTimeMock));
        $dateTimeMock->expects($this->once())->method('date')->with('Y-m-d_H-i-s')->will($this->returnValue($date));
        $pdfMock->expects($this->once())->method('render')->will($this->returnValue($content));
        $this->fileFactoryMock->expects($this->once())
            ->method('create')
            ->with(
                'packingslip' . $date . '.pdf',
                $content,
                DirectoryList::VAR_DIR,
                'application/pdf'
            )->will($this->returnValue('result-pdf-content'));

        $this->assertEquals('result-pdf-content', $this->controller->executeInternal());
    }
コード例 #4
0
    public function testExecute()
    {
        $themeId = 1;
        $fileName = 'file.ext';
        $fullPath = 'path/to/file';

        $file = $this->getMockBuilder('Magento\Framework\View\Design\Theme\FileInterface')->getMock();
        $customization = $this->getMockBuilder('Magento\Framework\View\Design\Theme\Customization')
            ->disableOriginalConstructor()
            ->getMock();
        $theme = $this->getMockBuilder('Magento\Framework\View\Design\ThemeInterface')
            ->setMethods(['getCustomization'])
            ->getMockForAbstractClass();
        $file->expects($this->once())
            ->method('getContent')
            ->willReturn('some_content');
        $file->expects($this->once())
            ->method('getFilename')
            ->willReturn($fileName);
        $file->expects($this->once())
            ->method('getFullPath')
            ->willReturn($fullPath);
        $theme->expects($this->once())
            ->method('getCustomization')
            ->willReturn($customization);
        $customization->expects($this->once())
            ->method('getFilesByType')
            ->with(\Magento\Theme\Model\Theme\Customization\File\CustomCss::TYPE)
            ->willReturn([$file]);
        $this->request->expects($this->any())
            ->method('getParam')
            ->with('theme_id')
            ->willReturn($themeId);
        $themeFactory = $this->getMockBuilder('Magento\Framework\View\Design\Theme\FlyweightFactory')
            ->setMethods(['create'])
            ->disableOriginalConstructor()
            ->getMock();
        $this->objectManager->expects($this->any())
            ->method('create')
            ->with('Magento\Framework\View\Design\Theme\FlyweightFactory')
            ->willReturn($themeFactory);
        $themeFactory->expects($this->once())
            ->method('create')
            ->with($themeId)
            ->willReturn($theme);
        $this->fileFactory->expects($this->once())
            ->method('create')
            ->with($fileName, ['type' => 'filename', 'value' => $fullPath], DirectoryList::ROOT)
            ->willReturn($this->getMockBuilder('Magento\Framework\App\ResponseInterface')->getMock());

        $this->assertInstanceOf('Magento\Framework\App\ResponseInterface', $this->controller->executeInternal());
    }
コード例 #5
0
ファイル: PrintActionTest.php プロジェクト: nblair/magescotch
    /**
     * @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()
        );
    }
コード例 #6
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());
 }
コード例 #7
0
 public function testExecute()
 {
     $themeId = 1;
     $fileParam = '/path/to/file.ext';
     $fileId = 'fileId';
     $sourceFile = '/source/file.ext';
     $relPath = 'file.ext';
     $this->request->expects($this->any())->method('getParam')->willReturnMap([['theme_id', null, $themeId], ['file', null, $fileParam]]);
     $file = $this->getMockBuilder('Magento\\Framework\\View\\Asset\\File')->disableOriginalConstructor()->getMock();
     $theme = $this->getMockBuilder('Magento\\Framework\\View\\Design\\ThemeInterface')->setMethods(['getId', 'load'])->getMockForAbstractClass();
     $urlDecoder = $this->getMockBuilder('Magento\\Framework\\Url\\DecoderInterface')->getMock();
     $directoryRead = $this->getMockBuilder('Magento\\Framework\\Filesystem\\Directory\\ReadInterface')->getMock();
     $this->objectManager->expects($this->any())->method('get')->with('Magento\\Framework\\Url\\DecoderInterface')->willReturn($urlDecoder);
     $this->objectManager->expects($this->any())->method('create')->with('Magento\\Framework\\View\\Design\\ThemeInterface')->willReturn($theme);
     $urlDecoder->expects($this->once())->method('decode')->with($fileParam)->willReturn($fileId);
     $theme->expects($this->once())->method('load')->with($themeId)->willReturnSelf();
     $theme->expects($this->once())->method('getId')->willReturn($themeId);
     $this->repository->expects($this->once())->method('createAsset')->with($fileId, ['themeModel' => $theme])->willReturn($file);
     $this->filesystem->expects($this->once())->method('getDirectoryRead')->with(DirectoryList::ROOT)->willReturn($directoryRead);
     $file->expects($this->once())->method('getSourceFile')->willReturn($sourceFile);
     $directoryRead->expects($this->once())->method('getRelativePath')->with($sourceFile)->willReturn($relPath);
     $this->fileFactory->expects($this->once())->method('create')->with($relPath, ['type' => 'filename', 'value' => $relPath], DirectoryList::ROOT)->willReturn($this->getMockBuilder('Magento\\Framework\\App\\ResponseInterface')->getMock());
     $this->assertInstanceOf('Magento\\Framework\\App\\ResponseInterface', $this->controller->execute());
 }