コード例 #1
0
 public function testExecuteWithItems()
 {
     $this->request->expects($this->any())->method('getParam')->willReturnMap([['items', null, '1,2,3'], ['uenc', null, null]]);
     $this->decoderMock->expects($this->never())->method('decode');
     $this->catalogSession->expects($this->never())->method('setBeforeCompareUrl');
     $this->listCompareMock->expects($this->once())->method('addProducts')->with([1, 2, 3]);
     $redirect = $this->getMock('Magento\\Framework\\Controller\\Result\\Redirect', ['setPath'], [], '', false);
     $redirect->expects($this->once())->method('setPath')->with('*/*/*');
     $this->redirectFactoryMock->expects($this->once())->method('create')->willReturn($redirect);
     $this->index->execute();
 }
コード例 #2
0
 /**
  * @cover \Magento\Theme\Model\Wysiwyg\Storage::deleteFile
  */
 public function testDeleteFile()
 {
     $image = 'image.jpg';
     $this->_helperStorage->expects($this->once())->method('getCurrentPath')->will($this->returnValue($this->_storageRoot));
     $this->urlDecoder->expects($this->any())->method('decode')->with($image)->willReturnArgument(0);
     $this->directoryWrite->expects($this->at(0))->method('getRelativePath')->with($this->_storageRoot)->willReturn($this->_storageRoot);
     $this->directoryWrite->expects($this->at(1))->method('getRelativePath')->with($this->_storageRoot . '/' . $image)->willReturn($this->_storageRoot . '/' . $image);
     $this->_helperStorage->expects($this->once())->method('getStorageRoot')->willReturn('/');
     $this->directoryWrite->expects($this->any())->method('delete');
     $this->assertInstanceOf('Magento\\Theme\\Model\\Wysiwyg\\Storage', $this->_storageModel->deleteFile($image));
 }
コード例 #3
0
 protected function prepareExecuteTest()
 {
     $directiveParam = 'e3ttZWRpYSB1cmw9Ind5c2l3eWcvYnVubnkuanBnIn19';
     $directive = '{{media url="wysiwyg/image.jpg"}}';
     $this->requestMock->expects($this->once())->method('getParam')->with('___directive')->willReturn($directiveParam);
     $this->urlDecoderMock->expects($this->once())->method('decode')->with($directiveParam)->willReturn($directive);
     $this->objectManagerMock->expects($this->once())->method('create')->with('Magento\\Cms\\Model\\Template\\Filter')->willReturn($this->templateFilterMock);
     $this->templateFilterMock->expects($this->once())->method('filter')->with($directive)->willReturn(self::IMAGE_PATH);
     $this->objectManagerMock->expects($this->any())->method('get')->willReturnMap([['Magento\\Framework\\Image\\AdapterFactory', $this->imageAdapterFactoryMock], ['Magento\\Cms\\Model\\Wysiwyg\\Config', $this->wysiwygConfigMock], ['Psr\\Log\\LoggerInterface', $this->loggerMock]]);
     $this->imageAdapterFactoryMock->expects($this->once())->method('create')->willReturn($this->imageAdapterMock);
 }
コード例 #4
0
 public function testGetRelativeUrl()
 {
     $filename = base64_encode('filename.ext');
     $notRoot = base64_encode('not/a/root');
     $this->request->expects($this->any())->method('getParam')->willReturnMap(['type' => [\Magento\Theme\Helper\Storage::PARAM_CONTENT_TYPE, null, \Magento\Theme\Model\Wysiwyg\Storage::TYPE_IMAGE], 'node' => [\Magento\Theme\Helper\Storage::PARAM_NODE, null, $notRoot], 'filenaem' => [\Magento\Theme\Helper\Storage::PARAM_FILENAME, null, $filename]]);
     $decode = function ($value) {
         return base64_decode($value);
     };
     $this->urlDecoder->expects($this->at(0))->method('decode')->with($notRoot)->willReturnCallback($decode);
     $this->urlDecoder->expects($this->at(1))->method('decode')->with($filename)->willReturnCallback($decode);
     $this->assertEquals('../image/not/a/root/filename.ext', $this->helper->getRelativeUrl());
 }
コード例 #5
0
 public function testGetCustomerWithSession()
 {
     $customerId = 1;
     $data = $customerId . ',2';
     $this->urlDecoderMock->expects($this->any())->method('decode')->willReturnArgument(0);
     $this->requestMock->expects($this->once())->method('getParam')->with('data', null)->willReturn($data);
     $this->customerSessionMock->expects($this->once())->method('getCustomerId')->willReturn($customerId);
     $customer = $this->getMockBuilder('Magento\\Customer\\Api\\Data\\CustomerInterface')->disableOriginalConstructor()->getMock();
     $this->customerRepositoryMock->expects($this->once())->method('getById')->with($customerId)->willReturn($customer);
     $this->customerFactoryMock->expects($this->never())->method('create');
     $this->assertEquals($customer, $this->model->getCustomer());
     // Check that customer is cached
     $this->assertSame($customer, $this->model->getCustomer());
 }
コード例 #6
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());
 }