public function testGetList()
 {
     $productSku = 'testProductSku';
     $this->productRepositoryMock->expects($this->once())->method('get')->with($productSku)->willReturn($this->productMock);
     $entryMock = $this->getMock('\\Magento\\Catalog\\Api\\Data\\ProductAttributeMediaGalleryEntryInterface');
     $this->productMock->expects($this->once())->method('getMediaGalleryEntries')->willReturn([$entryMock]);
     $this->assertEquals([$entryMock], $this->model->getList($productSku));
 }
Exemplo n.º 2
0
 public function testGetList()
 {
     $productSku = 'testProductSku';
     $attributeMock = $this->getMock('\\Magento\\Catalog\\Api\\Data\\ProductAttributeInterface');
     $objectMock = new \Magento\Framework\Object(['attribute' => $attributeMock]);
     $gallery = [['value_id' => 42, 'label_default' => 'defaultLabel', 'file' => 'code', 'disabled_default' => false, 'position_default' => 1]];
     $this->productRepositoryMock->expects($this->once())->method('get')->with($productSku)->willReturn($this->productMock);
     $this->attributeRepositoryMock->expects($this->once())->method('get')->with('media_gallery')->willReturn($attributeMock);
     $this->mediaGalleryMock->expects($this->once())->method('loadGallery')->with($this->productMock, $objectMock)->willReturn($gallery);
     $this->productMock->expects($this->once())->method('getMediaAttributes')->willReturn(['code' => 0]);
     $this->productMock->expects($this->once())->method('getData')->with('code')->willReturn('codeValue');
     $this->entryBuilderMock->expects($this->once())->method('setId')->with($gallery[0]['value_id']);
     $this->entryBuilderMock->expects($this->once())->method('setLabel')->with($gallery[0]['label_default']);
     $this->entryBuilderMock->expects($this->once())->method('setTypes')->with([]);
     $this->entryBuilderMock->expects($this->once())->method('setIsDisabled')->with($gallery[0]['disabled_default']);
     $this->entryBuilderMock->expects($this->once())->method('setPosition')->with($gallery[0]['position_default']);
     $this->entryBuilderMock->expects($this->once())->method('setFile')->with($gallery[0]['file']);
     $this->entryBuilderMock->expects($this->once())->method('create')->willReturn($gallery[0]);
     $this->assertEquals($gallery, $this->model->getList($productSku));
 }