Esempio n. 1
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. 2
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. 3
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. 4
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. 5
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. 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());
 }
Esempio n. 7
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());
 }