Example #1
0
 public function testGetLinkData()
 {
     $expectingFileData = ['file' => ['file' => 'file/link.gif', 'name' => '<a href="final_url">link.gif</a>', 'size' => '1.1', 'status' => 'old'], 'sample_file' => ['file' => 'file/sample.gif', 'name' => '<a href="final_url">sample.gif</a>', 'size' => '1.1', 'status' => 'old']];
     $this->productModel->expects($this->any())->method('getTypeId')->will($this->returnValue('downloadable'));
     $this->productModel->expects($this->any())->method('getTypeInstance')->will($this->returnValue($this->downloadableProductModel));
     $this->productModel->expects($this->any())->method('getStoreId')->will($this->returnValue(0));
     $this->downloadableProductModel->expects($this->any())->method('getLinks')->will($this->returnValue([$this->downloadableLinkModel]));
     $this->coreRegistry->expects($this->any())->method('registry')->will($this->returnValue($this->productModel));
     $this->downloadableLinkModel->expects($this->any())->method('getId')->will($this->returnValue(1));
     $this->downloadableLinkModel->expects($this->any())->method('getTitle')->will($this->returnValue('Link Title'));
     $this->downloadableLinkModel->expects($this->any())->method('getPrice')->will($this->returnValue('10'));
     $this->downloadableLinkModel->expects($this->any())->method('getNumberOfDownloads')->will($this->returnValue('6'));
     $this->downloadableLinkModel->expects($this->any())->method('getLinkUrl')->will($this->returnValue(null));
     $this->downloadableLinkModel->expects($this->any())->method('getLinkType')->will($this->returnValue('file'));
     $this->downloadableLinkModel->expects($this->any())->method('getSampleFile')->will($this->returnValue('file/sample.gif'));
     $this->downloadableLinkModel->expects($this->any())->method('getSampleType')->will($this->returnValue('file'));
     $this->downloadableLinkModel->expects($this->any())->method('getSortOrder')->will($this->returnValue(0));
     $this->downloadableLinkModel->expects($this->any())->method('getLinkFile')->will($this->returnValue('file/link.gif'));
     $this->downloadableLinkModel->expects($this->any())->method('getStoreTitle')->will($this->returnValue('Store Title'));
     $this->escaper->expects($this->any())->method('escapeHtml')->will($this->returnValue('Link Title'));
     $this->fileHelper->expects($this->any())->method('getFilePath')->will($this->returnValue('/file/path/link.gif'));
     $this->fileHelper->expects($this->any())->method('ensureFileInFilesystem')->will($this->returnValue(true));
     $this->fileHelper->expects($this->any())->method('getFileSize')->will($this->returnValue('1.1'));
     $this->urlBuilder->expects($this->any())->method('getUrl')->will($this->returnValue('final_url'));
     $linkData = $this->block->getLinkData();
     foreach ($linkData as $link) {
         $fileSave = $link->getFileSave(0);
         $sampleFileSave = $link->getSampleFileSave(0);
         $this->assertEquals($expectingFileData['file'], $fileSave);
         $this->assertEquals($expectingFileData['sample_file'], $sampleFileSave);
     }
 }
 /**
  * Set up
  */
 protected function setUp()
 {
     $this->objectManagerHelper = new ObjectManagerHelper($this);
     $this->rowCustomizerMock = $this->objectManagerHelper->getObject('\\Magento\\BundleImportExport\\Model\\Export\\RowCustomizer');
     $this->productResourceCollection = $this->getMock('\\Magento\\Catalog\\Model\\ResourceModel\\Product\\Collection', ['addAttributeToFilter', 'getIterator'], [], '', false);
     $this->product = $this->getMock('\\Magento\\Catalog\\Model\\Product', ['getId', 'getPriceType', 'getSkuType', 'getPriceView', 'getWeightType', 'getTypeInstance', 'getOptionsCollection', 'getSelectionsCollection'], [], '', false);
     $this->product->expects($this->any())->method('getId')->willReturn(1);
     $this->product->expects($this->any())->method('getPriceType')->willReturn(1);
     $this->product->expects($this->any())->method('getSkuType')->willReturn(1);
     $this->product->expects($this->any())->method('getPriceView')->willReturn(1);
     $this->product->expects($this->any())->method('getWeightType')->willReturn(1);
     $this->product->expects($this->any())->method('getTypeInstance')->willReturnSelf();
     $this->optionsCollection = $this->getMock('\\Magento\\Bundle\\Model\\ResourceModel\\Option\\Collection', ['setOrder', 'getIterator'], [], '', false);
     $this->product->expects($this->any())->method('getOptionsCollection')->willReturn($this->optionsCollection);
     $this->optionsCollection->expects($this->any())->method('setOrder')->willReturnSelf();
     $this->option = $this->getMock('\\Magento\\Bundle\\Model\\Option', ['getId', 'getTitle', 'getType', 'getRequired'], [], '', false);
     $this->option->expects($this->any())->method('getId')->willReturn(1);
     $this->option->expects($this->any())->method('getTitle')->willReturn('title');
     $this->option->expects($this->any())->method('getType')->willReturn(1);
     $this->option->expects($this->any())->method('getRequired')->willReturn(1);
     $this->optionsCollection->expects($this->any())->method('getIterator')->will($this->returnValue(new \ArrayIterator([$this->option])));
     $this->selection = $this->getMock('\\Magento\\Catalog\\Model\\Product', ['getSku', 'getSelectionPriceValue', 'getIsDefault', 'getSelectionQty', 'getSelectionPriceType'], [], '', false);
     $this->selection->expects($this->any())->method('getSku')->willReturn(1);
     $this->selection->expects($this->any())->method('getSelectionPriceValue')->willReturn(1);
     $this->selection->expects($this->any())->method('getSelectionQty')->willReturn(1);
     $this->selection->expects($this->any())->method('getSelectionPriceType')->willReturn(1);
     $this->selectionsCollection = $this->getMock('\\Magento\\Bundle\\Model\\ResourceModel\\Selection\\Collection', ['getIterator', 'addAttributeToSort'], [], '', false);
     $this->selectionsCollection->expects($this->any())->method('getIterator')->will($this->returnValue(new \ArrayIterator([$this->selection])));
     $this->selectionsCollection->expects($this->any())->method('addAttributeToSort')->willReturnSelf();
     $this->product->expects($this->any())->method('getSelectionsCollection')->willReturn($this->selectionsCollection);
     $this->productResourceCollection->expects($this->any())->method('addAttributeToFilter')->willReturnSelf();
     $this->productResourceCollection->expects($this->any())->method('getIterator')->will($this->returnValue(new \ArrayIterator([$this->product])));
 }
Example #3
0
 public function testGetImages()
 {
     $mediaGallery = ['images' => [['value_id' => '1', 'file' => 'image_1.jpg', 'media_type' => 'image'], ['value_id' => '2', 'file' => 'image_2.jpg', 'media_type' => 'image']]];
     $this->registryMock->expects($this->once())->method('registry')->willReturn($this->productMock);
     $this->productMock->expects($this->once())->method('getData')->willReturn($mediaGallery);
     $this->assertSame($mediaGallery, $this->gallery->getImages());
 }
 public function testGetSampleData()
 {
     $expectingFileData = array('sample_file' => array('file' => 'file/sample.gif', 'name' => '<a href="final_url">sample.gif</a>', 'size' => '1.1', 'status' => 'old'));
     $this->productModel->expects($this->any())->method('getTypeId')->will($this->returnValue('downloadable'));
     $this->productModel->expects($this->any())->method('getTypeInstance')->will($this->returnValue($this->downloadableProductModel));
     $this->productModel->expects($this->any())->method('getStoreId')->will($this->returnValue(0));
     $this->downloadableProductModel->expects($this->any())->method('getSamples')->will($this->returnValue(array($this->downloadableSampleModel)));
     $this->coreRegistry->expects($this->any())->method('registry')->will($this->returnValue($this->productModel));
     $this->downloadableSampleModel->expects($this->any())->method('getId')->will($this->returnValue(1));
     $this->downloadableSampleModel->expects($this->any())->method('getTitle')->will($this->returnValue('Sample Title'));
     $this->downloadableSampleModel->expects($this->any())->method('getSampleUrl')->will($this->returnValue(null));
     $this->downloadableSampleModel->expects($this->any())->method('getSampleFile')->will($this->returnValue('file/sample.gif'));
     $this->downloadableSampleModel->expects($this->any())->method('getSampleType')->will($this->returnValue('file'));
     $this->downloadableSampleModel->expects($this->any())->method('getSortOrder')->will($this->returnValue(0));
     $this->escaper->expects($this->any())->method('escapeHtml')->will($this->returnValue('Sample Title'));
     $this->fileHelper->expects($this->any())->method('getFilePath')->will($this->returnValue('/file/path/sample.gif'));
     $this->fileHelper->expects($this->any())->method('ensureFileInFilesystem')->will($this->returnValue(true));
     $this->fileHelper->expects($this->any())->method('getFileSize')->will($this->returnValue('1.1'));
     $this->urlBuilder->expects($this->any())->method('getUrl')->will($this->returnValue('final_url'));
     $sampleData = $this->block->getSampleData();
     foreach ($sampleData as $sample) {
         $fileSave = $sample->getFileSave(0);
         $this->assertEquals($expectingFileData['sample_file'], $fileSave);
     }
 }
Example #5
0
 public function testBeforeInitializeLinksProductIsReadonly()
 {
     $this->productMock->expects($this->once())->method('getTypeId')->will($this->returnValue(Grouped::TYPE_CODE));
     $this->productMock->expects($this->once())->method('getGroupedReadonly')->will($this->returnValue(true));
     $this->productMock->expects($this->never())->method('setGroupedLinkData');
     $this->model->beforeInitializeLinks($this->subjectMock, $this->productMock, ['associated' => 'value']);
 }
Example #6
0
 public function testSave()
 {
     $data = ['sample' => ['sampleData', 'link' => ['linkData']]];
     $this->product->expects($this->once())->method('getDownloadableData')->will($this->returnValue($data));
     $this->typeHandler->expects($this->once())->method('save')->with($this->product, $data);
     $this->target->save($this->product);
 }
 public function testAttributeSetIsObtainedFromGetWhenThereIsNoOneInPost()
 {
     $this->request->expects($this->any())->method('getParam')->willReturnMap([['set', null, 4]]);
     $this->request->expects($this->any())->method('getPost')->willReturnMap([['set', null, null]]);
     $this->product->expects($this->once())->method('setAttributeSetId')->with(4);
     $this->action->execute();
 }
 /**
  * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
  */
 public function testPrepareJsonAttributes()
 {
     $storeId = '1';
     $attributeId = 5;
     $attributeOptions = [['value_index' => 'option_id_1', 'label' => 'label_1'], ['value_index' => 'option_id_2', 'label' => 'label_2']];
     $position = 2;
     $expected = ['attributes' => [$attributeId => ['id' => $attributeId, 'code' => 'test_attribute', 'label' => 'Test', 'position' => $position, 'options' => [0 => ['id' => 'option_id_1', 'label' => 'label_1', 'products' => 'option_products_1'], 1 => ['id' => 'option_id_2', 'label' => 'label_2', 'products' => 'option_products_2']]]], 'defaultValues' => [$attributeId => 'option_id_1']];
     $options = [$attributeId => ['option_id_1' => 'option_products_1', 'option_id_2' => 'option_products_2']];
     $productAttributeMock = $this->getMockBuilder('Magento\\Catalog\\Model\\Entity\\Attribute')->disableOriginalConstructor()->setMethods(['getStoreLabel', '__wakeup', 'getAttributeCode', 'getId', 'getAttributeLabel'])->getMock();
     $productAttributeMock->expects($this->once())->method('getId')->willReturn($attributeId);
     $productAttributeMock->expects($this->once())->method('getAttributeCode')->willReturn($expected['attributes'][$attributeId]['code']);
     $attributeMock = $this->getMockBuilder('Magento\\ConfigurableProduct\\Model\\Product\\Type\\Configurable\\Attribute')->disableOriginalConstructor()->setMethods(['getProductAttribute', '__wakeup', 'getLabel', 'getOptions', 'getAttributeId', 'getPosition'])->getMock();
     $attributeMock->expects($this->once())->method('getProductAttribute')->willReturn($productAttributeMock);
     $attributeMock->expects($this->once())->method('getPosition')->willReturn($position);
     $this->product->expects($this->once())->method('getStoreId')->willReturn($storeId);
     $productAttributeMock->expects($this->once())->method('getStoreLabel')->with($storeId)->willReturn($expected['attributes'][$attributeId]['label']);
     $attributeMock->expects($this->atLeastOnce())->method('getAttributeId')->willReturn($attributeId);
     $attributeMock->expects($this->atLeastOnce())->method('getOptions')->willReturn($attributeOptions);
     $configurableProduct = $this->getMockBuilder('Magento\\ConfigurableProduct\\Model\\Product\\Type\\Configurable')->disableOriginalConstructor()->getMock();
     $configurableProduct->expects($this->once())->method('getConfigurableAttributes')->with($this->product)->willReturn([$attributeMock]);
     $configuredValueMock = $this->getMockBuilder('Magento\\Framework\\DataObject')->disableOriginalConstructor()->getMock();
     $configuredValueMock->expects($this->any())->method('getData')->willReturn($expected['defaultValues'][$attributeId]);
     $this->product->expects($this->once())->method('getTypeInstance')->willReturn($configurableProduct);
     $this->product->expects($this->once())->method('hasPreconfiguredValues')->willReturn(true);
     $this->product->expects($this->once())->method('getPreconfiguredValues')->willReturn($configuredValueMock);
     $this->assertEquals($expected, $this->configurableAttributeData->getAttributesData($this->product, $options));
 }
 public function testConvertTo()
 {
     $rowData = ['value_id' => '6', 'file' => '/s/a/sample-1_1.jpg', 'media_type' => 'image', 'entity_id' => '1', 'label' => '', 'position' => '5', 'disabled' => '0', 'label_default' => null, 'position_default' => '5', 'disabled_default' => '0'];
     $productImages = ['image' => '/s/a/sample_3.jpg', 'small_image' => '/s/a/sample-1_1.jpg', 'thumbnail' => '/s/a/sample-1_1.jpg', 'swatch_image' => '/s/a/sample_3.jpg'];
     $this->productMock->expects($this->any())->method('getMediaAttributeValues')->willReturn($productImages);
     $this->modelObject->convertTo($this->productMock, $rowData);
 }
Example #10
0
 public function testGetAllowAttributes()
 {
     $typeInstanceMock = $this->getMock('Magento\\ConfigurableProduct\\Model\\Product\\Type\\Configurable', [], [], '', false);
     $typeInstanceMock->expects($this->once())->method('getConfigurableAttributes')->with($this->_productMock);
     $this->_productMock->expects($this->once())->method('getTypeInstance')->will($this->returnValue($typeInstanceMock));
     $this->_model->getAllowAttributes($this->_productMock);
 }
Example #11
0
 public function _testAttributeSetIsObtainedFromGetWhenThereIsNoOneInPost()
 {
     $this->request->expects($this->any())->method('getParam')->willReturnMap([['set', null, 4]]);
     $this->request->expects($this->any())->method('getPost')->willReturnMap([['set', null, null], ['product', [], []]]);
     $this->product->expects($this->once())->method('setAttributeSetId')->with(4);
     $this->initializationHelper->expects($this->any())->method('initializeFromData')->willReturn($this->product);
     $this->action->execute();
 }
Example #12
0
 public function testAfterExecuteNoVideo()
 {
     $mediaData = ['images' => [['value_id' => '7', 'file' => '/h/d/hd_image.jpg', 'media_type' => 'image', 'entity_id' => '1', 'label' => '', 'position' => '4', 'disabled' => '0', 'label_default' => null, 'position_default' => '4', 'disabled_default' => '0']], 'values' => []];
     $this->product->expects($this->once())->method('getData')->with('media_gallery')->willReturn($mediaData);
     $this->resourceModel->expects($this->never())->method('loadDataFromTableByValueId');
     $this->mediaGalleryReadHandler->expects($this->any())->method('getAttribute')->willReturn($this->attribute);
     $this->subject->afterExecute($this->mediaGalleryReadHandler, $this->product);
 }
Example #13
0
 public function testAroundHasOptionsForProductWithoutRecurringPayment()
 {
     $this->product->expects($this->once())->method('getIsRecurring')->will($this->returnValue(false));
     $closure = function ($product) {
         return $product;
     };
     $this->assertSame($this->product, $this->object->aroundHasOptions($this->subject, $closure, $this->product));
 }
Example #14
0
 public function testAfterDeleteScheduled()
 {
     $this->indexerMock->expects($this->once())->method('isScheduled')->will($this->returnValue(true));
     $this->indexerMock->expects($this->never())->method('reindexRow');
     $this->prepareIndexer();
     $this->subjectMock->expects($this->once())->method('getId')->will($this->returnValue(1));
     $this->assertEquals($this->subjectMock, $this->model->afterDelete($this->subjectMock));
 }
 public function testExecuteObtainsProductDataFromSession()
 {
     $this->action->getRequest()->expects($this->any())->method('getParam')->willReturn(true);
     $this->action->getRequest()->expects($this->any())->method('getFullActionName')->willReturn('catalog_product_new');
     $this->session->expects($this->any())->method('getProductData')->willReturn(['product' => ['name' => 'test-name']]);
     $this->product->expects($this->once())->method('addData')->with(['name' => 'test-name', 'stock_data' => null]);
     $this->action->execute();
 }
 /**
  * @return void
  */
 public function testValidateWithNoValue()
 {
     $this->product->setData('attribute', 'color');
     $this->product->setData('value_parsed', '1');
     $this->product->setData('operator', '!=');
     $this->productModel->expects($this->once())->method('getData')->with('color')->willReturn(null);
     $this->assertFalse($this->product->validate($this->productModel));
 }
Example #17
0
 /**
  * Initialize base dependencies
  */
 protected function setUp()
 {
     $this->priceInfo = $this->getMock('Magento\\Framework\\Pricing\\PriceInfo\\Base', [], [], '', false);
     $this->product = $this->getMockBuilder('Magento\\Catalog\\Model\\Product')->setMethods(['getPriceInfo', 'hasCustomerGroupId', 'getCustomerGroupId', 'getResource', '__wakeup'])->disableOriginalConstructor()->getMock();
     $this->product->expects($this->any())->method('getPriceInfo')->will($this->returnValue($this->priceInfo));
     $this->calculator = $this->getMock('Magento\\Framework\\Pricing\\Adjustment\\Calculator', [], [], '', false);
     $objectHelper = new \Magento\TestFramework\Helper\ObjectManager($this);
     $this->model = $objectHelper->getObject('Magento\\Bundle\\Pricing\\Price\\TierPrice', ['saleableItem' => $this->product, 'calculator' => $this->calculator]);
 }
Example #18
0
 public function testGetValue()
 {
     $product1 = $this->getProductMock(10);
     $product2 = $this->getProductMock(20);
     $typeInstanceMock = $this->getMock('Magento\\GroupedProduct\\Model\\Product\\Type\\Grouped', [], [], '', false);
     $typeInstanceMock->expects($this->once())->method('getAssociatedProducts')->with($this->equalTo($this->saleableItemMock))->will($this->returnValue([$product1, $product2]));
     $this->saleableItemMock->expects($this->once())->method('getTypeInstance')->will($this->returnValue($typeInstanceMock));
     $this->assertEquals(10, $this->finalPrice->getValue());
 }
Example #19
0
 /**
  * @param string $exceptionType
  * @return void
  * @dataProvider exceptionTypeDataProvider
  */
 public function testExecuteSetsProductDataToSessionAndRedirectsToNewActionOnError($exceptionType)
 {
     $productData = ['product' => ['name' => 'test-name']];
     $this->request->expects($this->any())->method('getPostValue')->willReturn($productData);
     $this->initializationHelper->expects($this->any())->method('initialize')->willReturn($this->product);
     $this->product->expects($this->any())->method('getSku')->willThrowException(new $exceptionType(__('message')));
     $this->resultRedirect->expects($this->once())->method('setPath')->with('catalog/*/new');
     $this->action->execute();
 }
Example #20
0
 /**
  * Test method testGetDisplayValue
  */
 public function testGetAmount()
 {
     $priceValue = 77;
     $convertedPrice = 56.32;
     $amountValue = 88;
     $this->saleableItemMock->expects($this->once())->method('getPrice')->will($this->returnValue($priceValue));
     $this->priceCurrencyMock->expects($this->any())->method('convertAndRound')->with($priceValue)->will($this->returnValue($convertedPrice));
     $this->calculatorMock->expects($this->once())->method('getAmount')->with($this->equalTo($convertedPrice))->will($this->returnValue($amountValue));
     $this->assertEquals($amountValue, $this->regularPrice->getAmount());
 }
Example #21
0
 /**
  * test for convert method
  */
 public function testConvert()
 {
     $this->quoteItemMock->expects($this->exactly(2))->method('getProduct')->willReturn($this->productMock);
     $this->productMock->expects($this->once())->method('getTypeInstance')->willReturn($this->productTypeMock);
     $this->productTypeMock->expects($this->once())->method('getOrderOptions')->with($this->productMock)->willReturn(['option']);
     $this->objectCopyServiceMock->expects($this->at(0))->method('getDataFromFieldset')->with('quote_convert_item', 'to_order_item', $this->quoteItemMock)->willReturn([]);
     $this->objectCopyServiceMock->expects($this->at(1))->method('getDataFromFieldset')->with('quote_convert_item', 'to_order_item_discount', $this->quoteItemMock)->willReturn([]);
     $this->orderItemFactoryMock->expects($this->once())->method('create')->willReturn($this->orderItemMock);
     $this->assertInstanceOf('Magento\\Sales\\Model\\Order\\Item', $this->converter->convert($this->quoteItemMock, []));
 }
Example #22
0
 /**
  * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
  */
 public function testBeforeExecute()
 {
     $mediaData = ['images' => ['72mljfhmasfilp9cuq' => ['position' => '3', 'media_type' => 'external-video', 'file' => '/i/n/index111111.jpg', 'value_id' => '4', 'label' => '', 'disabled' => '0', 'removed' => '', 'video_provider' => 'youtube', 'video_url' => 'https://www.youtube.com/watch?v=abcdefghij', 'video_title' => 'Some second title', 'video_description' => 'Description second', 'video_metadata' => 'meta two', 'role' => ''], 'w596fi79hv1p6wj21u' => ['position' => '4', 'media_type' => 'external-video', 'video_provider' => '', 'file' => '/h/d/hd_image.jpg', 'value_id' => '7', 'label' => '', 'disabled' => '0', 'removed' => '', 'video_url' => '', 'video_title' => '', 'video_description' => '', 'video_metadata' => '', 'role' => ''], 'tcodwd7e0dirifr64j' => ['position' => '4', 'media_type' => 'external-video', 'video_provider' => '', 'file' => '/h/d/hd_image.jpg', 'value_id' => '', 'label' => '', 'disabled' => '0', 'removed' => '', 'video_url' => '', 'video_title' => '', 'video_description' => '', 'video_metadata' => '', 'role' => '', 'save_data_from' => '7', 'new_file' => '/i/n/index_4.jpg']]];
     $this->product->expects($this->any())->method('getData')->with('media_gallery')->willReturn($mediaData);
     $this->product->expects($this->any())->method('getStoreId')->willReturn(0);
     $resourceEntryResult = [['value_id' => '4', 'store_id' => 1, 'video_provider_default' => 'youtube', 'video_url_default' => 'https://www.youtube.com/watch?v=abcdefghij', 'video_title_default' => 'Some first title', 'video_description_default' => 'Description first', 'video_metadata_default' => 'meta one', 'video_provider' => 'youtube', 'video_url' => 'https://www.youtube.com/watch?v=abcdefghij', 'video_title' => 'Some first title', 'video_description' => 'Description first', 'video_metadata' => 'meta one'], ['value_id' => '7', 'store_id' => 1, 'video_provider_default' => 'youtube', 'video_url_default' => 'https://www.youtube.com/watch?v=ab123456', 'video_title_default' => 'Some second title', 'video_description_default' => 'Description second', 'video_metadata_default' => 'meta two', 'video_provider' => 'youtube', 'video_url' => 'https://www.youtube.com/watch?v=ab123456', 'video_title' => 'Some second title', 'video_description' => 'Description second', 'video_metadata' => '']];
     $this->resourceModel->expects($this->once())->method('loadDataFromTableByValueId')->willReturn($resourceEntryResult);
     $this->mediaGalleryCreateHandler->expects($this->any())->method('getAttribute')->willReturn($this->attribute);
     $this->subject->beforeExecute($this->mediaGalleryCreateHandler, 'Magento\\Catalog\\Api\\Data\\ProductInterface', $this->product);
 }
Example #23
0
 /**
  * Test getMediaEmptyGalleryDataJson()
  */
 public function testGetMediaEmptyGalleryDataJson()
 {
     $mediaGalleryData = [];
     $this->coreRegistry->expects($this->any())->method('registry')->willReturn($this->productModelMock);
     $typeInstance = $this->getMock('\\Magento\\Catalog\\Model\\Product\\Type\\AbstractType', [], [], '', false);
     $typeInstance->expects($this->any())->method('getStoreFilter')->willReturn('_cache_instance_store_filter');
     $this->productModelMock->expects($this->any())->method('getTypeInstance')->willReturn($typeInstance);
     $this->productModelMock->expects($this->any())->method('getMediaGalleryImages')->willReturn($mediaGalleryData);
     $this->gallery->getMediaGalleryDataJson();
 }
Example #24
0
 /**
  * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
  */
 protected function setUp()
 {
     $objectHelper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
     $eventManager = $this->getMock('Magento\\Framework\\Event\\ManagerInterface', [], [], '', false);
     $fileStorageDb = $this->getMockBuilder('Magento\\MediaStorage\\Helper\\File\\Storage\\Database')->disableOriginalConstructor()->getMock();
     $filesystem = $this->getMockBuilder('Magento\\Framework\\Filesystem')->disableOriginalConstructor()->getMock();
     $coreRegistry = $this->getMock('Magento\\Framework\\Registry', [], [], '', false);
     $logger = $this->getMock('Psr\\Log\\LoggerInterface');
     $productFactoryMock = $this->getMock('Magento\\Catalog\\Model\\ProductFactory', [], [], '', false);
     $sampleResFactory = $this->getMock('Magento\\Downloadable\\Model\\ResourceModel\\SampleFactory', [], [], '', false);
     $linkResource = $this->getMock('Magento\\Downloadable\\Model\\ResourceModel\\Link', [], [], '', false);
     $linksFactory = $this->getMock('Magento\\Downloadable\\Model\\ResourceModel\\Link\\CollectionFactory', [], [], '', false);
     $samplesFactory = $this->getMock('Magento\\Downloadable\\Model\\ResourceModel\\Sample\\CollectionFactory', [], [], '', false);
     $sampleFactory = $this->getMock('Magento\\Downloadable\\Model\\SampleFactory', [], [], '', false);
     $linkFactory = $this->getMock('Magento\\Downloadable\\Model\\LinkFactory', [], [], '', false);
     $entityTypeMock = $this->getMock('Magento\\Eav\\Model\\Entity\\Type', [], [], '', false);
     $resourceProductMock = $this->getMock('Magento\\Catalog\\Model\\ResourceModel\\Product', ['getEntityType'], [], '', false);
     $resourceProductMock->expects($this->any())->method('getEntityType')->will($this->returnValue($entityTypeMock));
     $this->product = $this->getMock('Magento\\Catalog\\Model\\Product', ['getResource', 'canAffectOptions', 'getLinksPurchasedSeparately', 'setTypeHasRequiredOptions', 'setRequiredOptions', 'getDownloadableData', 'setTypeHasOptions', 'setLinksExist', '__wakeup'], [], '', false);
     $this->product->expects($this->any())->method('getResource')->will($this->returnValue($resourceProductMock));
     $this->product->expects($this->any())->method('setTypeHasRequiredOptions')->with($this->equalTo(true))->will($this->returnSelf());
     $this->product->expects($this->any())->method('setRequiredOptions')->with($this->equalTo(true))->will($this->returnSelf());
     $this->product->expects($this->any())->method('setTypeHasOptions')->with($this->equalTo(false));
     $this->product->expects($this->any())->method('setLinksExist')->with($this->equalTo(false));
     $this->product->expects($this->any())->method('canAffectOptions')->with($this->equalTo(true));
     $this->product->expects($this->any())->method('getLinksPurchasedSeparately')->will($this->returnValue(true));
     $this->product->expects($this->any())->method('getLinksPurchasedSeparately')->will($this->returnValue(true));
     $eavConfigMock = $this->getMock('\\Magento\\Eav\\Model\\Config', ['getEntityAttributeCodes'], [], '', false);
     $eavConfigMock->expects($this->any())->method('getEntityAttributeCodes')->with($this->equalTo($entityTypeMock), $this->equalTo($this->product))->will($this->returnValue([]));
     $this->typeHandler = $this->getMockBuilder('\\Magento\\Downloadable\\Model\\Product\\TypeHandler\\TypeHandler')->disableOriginalConstructor()->setMethods(['save'])->getMock();
     $this->target = $objectHelper->getObject('Magento\\Downloadable\\Model\\Product\\Type', ['eventManager' => $eventManager, 'fileStorageDb' => $fileStorageDb, 'filesystem' => $filesystem, 'coreRegistry' => $coreRegistry, 'logger' => $logger, 'productFactory' => $productFactoryMock, 'sampleResFactory' => $sampleResFactory, 'linkResource' => $linkResource, 'linksFactory' => $linksFactory, 'samplesFactory' => $samplesFactory, 'sampleFactory' => $sampleFactory, 'linkFactory' => $linkFactory, 'eavConfig' => $eavConfigMock, 'typeHandler' => $this->typeHandler]);
 }
Example #25
0
 public function testExecuteNullProduct()
 {
     $this->productMock->expects($this->once())->method('load')->with(59)->willReturn($this->productMock);
     $this->productModelFactoryMock->expects($this->once())->method('create')->willReturn($this->productMock);
     $this->swatchHelperMock->expects($this->once())->method('getAttributesFromConfigurable')->with($this->productMock)->willReturn([$this->attributeMock]);
     $this->swatchHelperMock->expects($this->once())->method('loadVariationByFallback')->with($this->productMock, ['size' => 454])->willReturn(null);
     $this->swatchHelperMock->expects($this->once())->method('getProductMediaGallery')->with($this->productMock)->willReturn($this->mediaGallery);
     $this->jsonMock->expects($this->once())->method('setData')->with($this->mediaGallery)->will($this->returnSelf());
     $result = $this->controller->execute();
     $this->assertInstanceOf('\\Magento\\Framework\\Controller\\Result\\Json', $result);
 }
Example #26
0
 /**
  * @param bool $stockAlertAllowed
  * @param bool $productAvailable
  * @dataProvider setTemplateStockUrlNotAllowedDataProvider
  */
 public function testSetTemplateStockUrlNotAllowed($stockAlertAllowed, $productAvailable)
 {
     $this->_helper->expects($this->once())->method('isStockAlertAllowed')->will($this->returnValue($stockAlertAllowed));
     $this->_helper->expects($this->never())->method('getSaveUrl');
     $this->_product->expects($this->any())->method('isAvailable')->will($this->returnValue($productAvailable));
     $this->_registry->expects($this->any())->method('registry')->with('current_product')->will($this->returnValue($this->_product));
     $this->_block->setLayout($this->_layout);
     $this->_block->setTemplate('path/to/template.phtml');
     $this->assertEquals('', $this->_block->getTemplate());
     $this->assertNull($this->_block->getSignupUrl());
 }
Example #27
0
 public function testInitWithNonDecimalQty()
 {
     $quoteItemMock = $this->getMock('\\Magento\\Quote\\Model\\Quote\\Item', ['getStockId', 'getIsQtyDecimal', '__wakeup'], [], '', false);
     $this->productMock->expects($this->once())->method('getId')->will($this->returnSelf());
     $this->productMock->expects($this->never())->method('setIsQtyDecimal');
     $this->productMock->expects($this->once())->method('setCartQty')->will($this->returnSelf());
     $this->configMock->expects($this->exactly(2))->method('getQty')->will($this->returnValue(10));
     $this->configMock->expects($this->once())->method('setQty')->will($this->returnSelf());
     $this->quoteMock->expects($this->once())->method('addProduct')->will($this->returnValue($quoteItemMock));
     $this->assertInstanceOf('Magento\\Quote\\Model\\Quote\\Item', $this->model->init($this->quoteMock, $this->productMock, $this->configMock));
 }
Example #28
0
 public function testAfterGetIdentities()
 {
     $baseIdentities = ['SomeCacheId', 'AnotherCacheId'];
     $id = 12345;
     $parentIds = [1, 2, 5, 100500];
     $expectedIdentities = ['SomeCacheId', 'AnotherCacheId', Product::CACHE_TAG . '_' . 1, Product::CACHE_TAG . '_' . 2, Product::CACHE_TAG . '_' . 5, Product::CACHE_TAG . '_' . 100500];
     $this->product->expects($this->once())->method('getId')->will($this->returnValue($id));
     $this->type->expects($this->once())->method('getParentIdsByChild')->with($id)->will($this->returnValue($parentIds));
     $identities = $this->plugin->afterGetIdentities($this->product, $baseIdentities);
     $this->assertEquals($expectedIdentities, $identities);
 }
 /**
  * @dataProvider dataForTest
  */
 public function testBeforeGetImage($expected)
 {
     $this->productMock->expects($this->once())->method('getTypeId')->willReturn('configurable');
     $this->requestMock->expects($this->once())->method('getParams')->willReturn($expected['getParams']);
     $this->getFilterArray($expected);
     $this->canReplaceImageWithSwatch($expected);
     $this->swatchesHelperMock->expects($this->exactly($expected['loadVariationByFallback_count']))->method('loadVariationByFallback')->willReturn($expected['product']);
     $productImageMock = $this->getMock('Magento\\Catalog\\Block\\Product\\AbstractProduct', [], [], '', false);
     $result = $this->pluginModel->beforeGetImage($productImageMock, $this->productMock, $expected['page_handle']);
     $this->assertEquals([$this->productMock, $expected['page_handle'], []], $result);
 }
 public function testLoadBundleProduct()
 {
     $productId = 'test_id';
     $productSku = 'test_sku';
     $this->productRepository->expects($this->once())->method('get')->with($productId)->will($this->returnValue($this->product));
     $this->product->expects($this->once())->method('getTypeId')->will($this->returnValue(\Magento\Catalog\Model\Product\Type::TYPE_BUNDLE));
     $this->product->expects($this->once())->method('getSku')->will($this->returnValue($productSku));
     $optionCustomAttributeValue = ['a', 'b'];
     $this->optionReadService->expects($this->once())->method('getList')->with($productSku)->will($this->returnValue($optionCustomAttributeValue));
     $this->productBuilder->expects($this->at(0))->method('setCustomAttribute')->with('bundle_product_options', $optionCustomAttributeValue);
     $this->model->load($productId, $this->productBuilder);
 }