Example #1
0
 /**
  * @dataProvider dataForExecute
  */
 public function testExecute($fileResult, $expectedResult)
 {
     $this->uploaderFactoryMock->expects($this->once())->method('create')->willReturn($this->uploaderMock);
     $this->adapterFactoryMock->expects($this->once())->method('create')->willReturn($this->adapterMock);
     $this->filesystemMock->expects($this->once())->method('getDirectoryRead')->with('media')->willReturn($this->mediaDirectoryMock);
     $this->uploaderMock->expects($this->once())->method('save')->willReturn($fileResult);
     $this->configMock->expects($this->once())->method('getTmpMediaUrl')->with($fileResult['file'])->willReturn('http://domain.com/tpm_dir/m/a/magento.png');
     $this->swatchHelperMock->expects($this->once())->method('moveImageFromTmp')->with('/m/a/magento.png.tmp')->willReturn('/m/a/magento.png');
     $this->swatchHelperMock->expects($this->once())->method('generateSwatchVariations');
     $this->swatchHelperMock->expects($this->once())->method('getSwatchMediaUrl')->willReturn('http://domain.com/media/path/');
     $this->responseMock->expects($this->once())->method('setBody')->willReturn(json_encode($expectedResult));
     $this->controller->execute();
 }
Example #2
0
 public function testGetImagesJson()
 {
     $url = [['file_1.jpg', 'url_to_the_image/image_1.jpg'], ['file_2.jpg', 'url_to_the_image/image_2.jpg']];
     $mediaPath = [['file_1.jpg', 'catalog/product/image_1.jpg'], ['file_2.jpg', 'catalog/product/image_2.jpg']];
     $sizeMap = [['catalog/product/image_1.jpg', ['size' => 399659]], ['catalog/product/image_2.jpg', ['size' => 879394]]];
     $imagesResult = [['value_id' => '2', 'file' => 'file_2.jpg', 'media_type' => 'image', 'position' => '0', 'url' => 'url_to_the_image/image_2.jpg', 'size' => 879394], ['value_id' => '1', 'file' => 'file_1.jpg', 'media_type' => 'image', 'position' => '1', 'url' => 'url_to_the_image/image_1.jpg', 'size' => 399659]];
     $images = ['images' => [['value_id' => '1', 'file' => 'file_1.jpg', 'media_type' => 'image', 'position' => '1'], ['value_id' => '2', 'file' => 'file_2.jpg', 'media_type' => 'image', 'position' => '0']]];
     $this->content->setElement($this->galleryMock);
     $this->galleryMock->expects($this->once())->method('getImages')->willReturn($images);
     $this->fileSystemMock->expects($this->once())->method('getDirectoryRead')->willReturn($this->readMock);
     $this->mediaConfigMock->expects($this->any())->method('getMediaUrl')->willReturnMap($url);
     $this->mediaConfigMock->expects($this->any())->method('getMediaPath')->willReturnMap($mediaPath);
     $this->readMock->expects($this->any())->method('stat')->willReturnMap($sizeMap);
     $this->jsonEncoderMock->expects($this->once())->method('encode')->willReturnCallback('json_encode');
     $this->assertSame(json_encode($imagesResult), $this->content->getImagesJson());
 }
 public function testGetImagesJson()
 {
     $url = [['file_1.jpg', 'url_to_the_image/image_1.jpg'], ['file_2.jpg', 'url_to_the_image/image_2.jpg']];
     $mediaPath = [['file_1.jpg', 'catalog/product/image_1.jpg'], ['file_2.jpg', 'catalog/product/image_2.jpg']];
     // @codingStandardsIgnoreStart
     $encodedString = '[{"value_id":"1","file":"image_1.jpg","media_type":"image","url":"http:\\/\\/magento2.dev\\/pub\\/media\\/catalog\\/product\\/image_1.jpg","size":879394},{"value_id":"2","file":"image_2.jpg","media_type":"image","url":"http:\\/\\/magento2.dev\\/pub\\/media\\/catalog\\/product\\/image`_2.jpg","size":399659}]';
     // @codingStandardsIgnoreEnd
     $images = ['images' => [['value_id' => '1', 'file' => 'file_1.jpg', 'media_type' => 'image'], ['value_id' => '2', 'file' => 'file_2.jpg', 'media_type' => 'image']]];
     $firstStat = ['size' => 879394];
     $secondStat = ['size' => 399659];
     $this->content->setElement($this->galleryMock);
     $this->galleryMock->expects($this->any())->method('getImages')->willReturn($images);
     $this->fileSystemMock->expects($this->once())->method('getDirectoryRead')->willReturn($this->readMock);
     $this->mediaConfigMock->expects($this->any())->method('getMediaUrl')->willReturnMap($url);
     $this->mediaConfigMock->expects($this->any())->method('getMediaPath')->willReturn($mediaPath);
     $this->readMock->expects($this->at(0))->method('stat')->willReturn($firstStat);
     $this->readMock->expects($this->at(1))->method('stat')->willReturn($secondStat);
     $this->jsonEncoderMock->expects($this->once())->method('encode')->willReturn($encodedString);
     $this->assertSame($encodedString, $this->content->getImagesJson());
 }
Example #4
0
 protected function setUp()
 {
     $this->context = $this->getMock('Magento\\Framework\\Model\\Context', [], [], '', false);
     $this->registry = $this->getMock('Magento\\Framework\\Registry');
     $this->storeManager = $this->getMockBuilder('Magento\\Store\\Model\\StoreManager')->disableOriginalConstructor()->setMethods(['getStore', 'getWebsite'])->getMock();
     $store = $this->getMockBuilder('\\Magento\\Store\\Model\\Store')->disableOriginalConstructor()->setMethods(['getId', '__sleep', '__wakeup', 'getBaseUrl'])->getMock();
     $store->expects($this->any())->method('getId')->will($this->returnValue(1));
     $store->expects($this->any())->method('getBaseUrl')->will($this->returnValue('http://magento.com/media/'));
     $this->storeManager->expects($this->any())->method('getStore')->will($this->returnValue($store));
     $this->config = $this->getMockBuilder('Magento\\Catalog\\Model\\Product\\Media\\Config')->setMethods(['getBaseMediaPath'])->disableOriginalConstructor()->getMock();
     $this->config->expects($this->any())->method('getBaseMediaPath')->will($this->returnValue('catalog/product'));
     $this->coreFileHelper = $this->getMockBuilder('Magento\\MediaStorage\\Helper\\File\\Storage\\Database')->setMethods(['saveFile', 'deleteFolder'])->disableOriginalConstructor()->getMock();
     $this->mediaDirectory = $this->getMockBuilder('Magento\\Framework\\Filesystem\\Directory\\Write')->disableOriginalConstructor()->setMethods(['create', 'isFile', 'isExist', 'getAbsolutePath'])->getMock();
     $this->mediaDirectory->expects($this->once())->method('create')->will($this->returnValue(true));
     $this->filesystem = $this->getMock('Magento\\Framework\\Filesystem', [], [], '', false);
     $this->filesystem->expects($this->once())->method('getDirectoryWrite')->with(DirectoryList::MEDIA)->will($this->returnValue($this->mediaDirectory));
     $this->factory = $this->getMock('Magento\\Framework\\Image\\Factory', [], [], '', false);
     $this->repository = $this->getMock('Magento\\Framework\\View\\Asset\\Repository', [], [], '', false);
     $this->fileSystem = $this->getMock('Magento\\Framework\\View\\FileSystem', [], [], '', false);
     $this->scopeConfigInterface = $this->getMock('Magento\\Framework\\App\\Config\\ScopeConfigInterface');
     $objectManagerHelper = new ObjectManagerHelper($this);
     $this->image = $objectManagerHelper->getObject('Magento\\Catalog\\Model\\Product\\Image', ['registry' => $this->registry, 'storeManager' => $this->storeManager, 'catalogProductMediaConfig' => $this->config, 'coreFileStorageDatabase' => $this->coreFileHelper, 'filesystem' => $this->filesystem, 'imageFactory' => $this->factory, 'assetRepo' => $this->repository, 'viewFileSystem' => $this->fileSystem, 'scopeConfig' => $this->scopeConfigInterface]);
 }