예제 #1
0
 /**
  * @dataProvider attributeValueDataProvider
  */
 public function testValidate($data)
 {
     $this->_attribute->expects($this->atLeastOnce())->method('getAttributeCode')->will($this->returnValue('code'));
     $product = new \Magento\Framework\DataObject(['code' => $data]);
     $this->_model->validate($product);
     $this->assertEquals('1,2,3', $product->getCode());
 }
예제 #2
0
 protected function setUp()
 {
     $this->product = $this->getMock('Magento\\Catalog\\Model\\Product', [], [], '', false);
     $this->attribute = $this->getMock('Magento\\Eav\\Model\\Entity\\Attribute', [], [], '', false);
     $this->attribute->expects($this->any())->method('getAttributeCode')->willReturn('media_gallery');
     $this->resourceModel = $this->getMock('Magento\\Catalog\\Model\\ResourceModel\\Product\\Gallery', [], [], '', false);
     $this->mediaGalleryReadHandler = $this->getMock('Magento\\Catalog\\Model\\Product\\Gallery\\ReadHandler', [], [], '', false);
     $objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
     $this->subject = $objectManager->getObject('Magento\\ProductVideo\\Model\\Plugin\\Catalog\\Product\\Gallery\\ReadHandler', ['resourceModel' => $this->resourceModel]);
 }
예제 #3
0
 public function testGetPrefixes()
 {
     $entityTypeId = 3;
     /** @var \Magento\Eav\Model\Entity\Type|\PHPUnit_Framework_MockObject_MockObject $entityType */
     $entityType = $this->getMockBuilder('Magento\\Eav\\Model\\Entity\\Type')->disableOriginalConstructor()->getMock();
     $entityType->expects($this->once())->method('getId')->will($this->returnValue($entityTypeId));
     /** @var AbstractFrontend|\PHPUnit_Framework_MockObject_MockObject $frontend */
     $frontend = $this->getMockBuilder('Magento\\Eav\\Model\\Entity\\Attribute\\Frontend\\AbstractFrontend')->setMethods(['getLabel'])->disableOriginalConstructor()->getMockForAbstractClass();
     $frontend->expects($this->once())->method('getLabel')->will($this->returnValue('testLabel'));
     $this->attributeCollection->expects($this->once())->method('setEntityTypeFilter')->with($this->equalTo($entityTypeId));
     $this->attributeCollection->expects($this->once())->method('setFrontendInputTypeFilter')->with($this->equalTo('media_image'));
     $this->attribute->expects($this->once())->method('getAttributeCode')->will($this->returnValue('attributeCode'));
     $this->attribute->expects($this->once())->method('getFrontend')->will($this->returnValue($frontend));
     $this->attributeCollection->expects($this->any())->method('getIterator')->will($this->returnValue(new \ArrayIterator([$this->attribute])));
     $this->eavConfig->expects($this->any())->method('getEntityType')->with($this->equalTo(Product::ENTITY))->will($this->returnValue($entityType));
     $this->assertEquals([['field' => 'attributeCode_', 'label' => 'testLabel']], $this->model->getPrefixes());
 }
 public function setUp()
 {
     $this->productFactoryMock = $this->getMock('\\Magento\\Catalog\\Model\\ResourceModel\\ProductFactory', ['create'], [], '', false);
     $this->productMock = $this->getMock('\\Magento\\Catalog\\Model\\Product', [], [], '', false);
     $this->fileStorageDbMock = $this->getMock('\\Magento\\MediaStorage\\Helper\\File\\Storage\\Database', [], [], '', false);
     $this->jsonHelperMock = $this->getMock('\\Magento\\Framework\\Json\\Helper\\Data', [], [], '', false);
     $this->mediaConfigMock = $this->getMock('\\Magento\\Catalog\\Model\\Product\\Media\\Config', [], [], '', false);
     $this->filesystemMock = $this->getMock('\\Magento\\Framework\\Filesystem', [], [], '', false);
     $write = $this->getMock('\\Magento\\Framework\\Filesystem\\Directory\\Write', [], [], '', false);
     $this->filesystemMock->expects($this->any())->method('getDirectoryWrite')->with('media')->willReturn($write);
     $this->resourceEntryMediaGalleryMock = $this->getMock('\\Magento\\Catalog\\Model\\ResourceModel\\Product\\Attribute\\Backend\\Media', [], [], '', false);
     $this->attributeMock = $this->getMock('\\Magento\\Eav\\Model\\Entity\\Attribute', [], [], '', false);
     $this->attributeMock->expects($this->any())->method('getAttributeCode')->willReturn('media_gallery');
     $this->mediaBackendModel = $this->getMock('Magento\\Catalog\\Model\\Product\\Attribute\\Backend\\Media', [], [], '', false);
     $objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
     $this->modelObject = $objectManager->getObject('\\Magento\\ProductVideo\\Model\\Plugin\\ExternalVideoEntryProcessor', ['productFactory' => $this->productFactoryMock, 'fileStorageDb' => $this->fileStorageDbMock, 'jsonHelper' => $this->jsonHelperMock, 'mediaConfig' => $this->mediaConfigMock, 'filesystem' => $this->filesystemMock, 'resourceEntryMediaGallery' => $this->resourceEntryMediaGalleryMock]);
 }
예제 #5
0
 /**
  * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
  */
 public function testGetItemsIfFacetedDataIsEmpty()
 {
     $attributeCode = 'attributeCode';
     $this->attribute->expects($this->atLeastOnce())->method('getAttributeCode')->willReturn($attributeCode);
     $this->attribute->expects($this->atLeastOnce())->method('getIsFilterable')->willReturn(0);
     $this->target->setAttributeModel($this->attribute);
     $this->fulltextCollection->expects($this->once())->method('getFacetedData')->willReturn([]);
     $this->itemDataBuilder->expects($this->once())->method('build')->willReturn([]);
     $this->assertEquals([], $this->target->getItems());
 }
예제 #6
0
 public function testApply()
 {
     $filter = '10-150';
     $requestVar = 'test_request_var';
     $this->target->setRequestVar($requestVar);
     $this->request->expects($this->exactly(1))->method('getParam')->will($this->returnCallback(function ($field) use($requestVar, $filter) {
         $this->assertTrue(in_array($field, [$requestVar, 'id']));
         return $filter;
     }));
     $attributeCode = 'AttributeCode';
     $this->attribute->expects($this->any())->method('getAttributeCode')->will($this->returnValue($attributeCode));
     $this->fulltextCollection->expects($this->once())->method('addFieldToFilter')->with($attributeCode)->will($this->returnSelf());
     $this->target->apply($this->request);
 }
예제 #7
0
 public function testGetItems()
 {
     $attributeCode = 'attributeCode';
     $attributeValue = 'attributeValue';
     $attributeLabel = 'attributeLabel';
     $this->attribute->expects($this->once())->method('getAttributeCode')->will($this->returnValue($attributeCode));
     $this->target->setAttributeModel($this->attribute);
     $this->request->expects($this->once())->method('getParam')->with($attributeCode)->will($this->returnValue($attributeValue));
     $this->frontend->expects($this->once())->method('getOption')->with($attributeValue)->will($this->returnValue($attributeLabel));
     $filterItem = $this->createFilterItem(0, $attributeLabel, $attributeValue, 0);
     $this->state->expects($this->once())->method('addFilter')->with($filterItem)->will($this->returnSelf());
     $expectedFilterItems = [];
     $result = $this->target->apply($this->request)->getItems();
     $this->assertEquals($expectedFilterItems, $result);
 }
 /**
  * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
  */
 public function testGetItemsWithoutApply()
 {
     $attributeCode = 'attributeCode';
     $selectedOptions = [['label' => 'selectedOptionLabel1', 'value' => 'selectedOptionValue1', 'count' => 25], ['label' => 'selectedOptionLabel2', 'value' => 'selectedOptionValue2', 'count' => 13], ['label' => 'selectedOptionLabel3', 'value' => 'selectedOptionValue3', 'count' => 10]];
     $facetedData = ['selectedOptionValue1' => ['count' => 10], 'selectedOptionValue2' => ['count' => 45], 'selectedOptionValue3' => ['count' => 50]];
     $builtData = [['label' => $selectedOptions[0]['label'], 'value' => $selectedOptions[0]['value'], 'count' => $facetedData[$selectedOptions[0]['value']]['count']], ['label' => $selectedOptions[1]['label'], 'value' => $selectedOptions[1]['value'], 'count' => $facetedData[$selectedOptions[1]['value']]['count']], ['label' => $selectedOptions[2]['label'], 'value' => $selectedOptions[2]['value'], 'count' => $facetedData[$selectedOptions[2]['value']]['count']]];
     $this->attribute->expects($this->exactly(2))->method('getAttributeCode')->will($this->returnValue($attributeCode));
     $this->target->setAttributeModel($this->attribute);
     $this->frontend->expects($this->once())->method('getSelectOptions')->will($this->returnValue($selectedOptions));
     $this->fulltextCollection->expects($this->once())->method('getFacetedData')->will($this->returnValue($facetedData));
     $this->itemDataBuilder->expects($this->at(0))->method('addItemData')->with($selectedOptions[0]['label'], $selectedOptions[0]['value'], $facetedData[$selectedOptions[0]['value']]['count'])->will($this->returnSelf());
     $this->itemDataBuilder->expects($this->at(1))->method('addItemData')->with($selectedOptions[1]['label'], $selectedOptions[1]['value'], $facetedData[$selectedOptions[1]['value']]['count'])->will($this->returnSelf());
     $this->itemDataBuilder->expects($this->once())->method('build')->will($this->returnValue($builtData));
     $this->fulltextCollection->expects($this->once())->method('getSize')->will($this->returnValue(50));
     $expectedFilterItems = [$this->createFilterItem(0, $builtData[0]['label'], $builtData[0]['value'], $builtData[0]['count']), $this->createFilterItem(1, $builtData[1]['label'], $builtData[1]['value'], $builtData[1]['count']), $this->createFilterItem(2, $builtData[2]['label'], $builtData[2]['value'], $builtData[2]['count'])];
     $result = $this->target->getItems();
     $this->assertEquals($expectedFilterItems, $result);
 }
예제 #9
0
 public function testGetItems()
 {
     $this->target->setAttributeModel($this->attribute);
     $attributeCode = 'attributeCode';
     $this->attribute->expects($this->any())->method('getAttributeCode')->will($this->returnValue($attributeCode));
     $this->fulltextCollection->expects($this->once())->method('getFacetedData')->with($attributeCode)->will($this->returnValue([]));
     $this->target->getItems();
 }
예제 #10
0
 public function testGetItems()
 {
     $this->target->setAttributeModel($this->attribute);
     $attributeCode = 'attributeCode';
     $this->attribute->expects($this->any())->method('getAttributeCode')->will($this->returnValue($attributeCode));
     $this->algorithm->expects($this->any())->method('getItemsData')->will($this->returnValue([]));
     $this->target->getItems();
 }