public function testGet() { $productSku = 'testProduct'; $imageId = 42; $this->productRepositoryMock->expects($this->once())->method('get')->with($productSku)->willReturn($this->productMock); $existingEntryMock = $this->getMock('\\Magento\\Catalog\\Api\\Data\\ProductAttributeMediaGalleryEntryInterface'); $existingEntryMock->expects($this->once())->method('getId')->willReturn(42); $this->productMock->expects($this->once())->method('getMediaGalleryEntries')->willReturn([$existingEntryMock]); $this->assertEquals($existingEntryMock, $this->model->get($productSku, $imageId)); }
public function testGet() { $productSku = 'testProduct'; $imageId = 42; $images = [['value_id' => 42, 'types' => [], 'file' => 'file.jpg']]; $this->productRepositoryMock->expects($this->once())->method('get')->with($productSku)->willReturn($this->productMock); $this->productMock->expects($this->once())->method('getMediaAttributes')->willReturn(['code' => 0]); $this->productMock->expects($this->once())->method('getData')->with('code')->willReturn('codeValue'); $this->productMock->expects($this->once())->method('getMediaGallery')->with('images')->willReturn($images); $this->entryBuilderMock->expects($this->once())->method('populateWithArray')->with($images[0])->willReturnSelf(); $this->entryBuilderMock->expects($this->once())->method('create')->willReturn([]); $this->assertEquals([], $this->model->get($productSku, $imageId)); }
public function testGet() { $productSku = 'testProduct'; $imageId = 42; $images = [['value_id' => 42, 'types' => [], 'file' => 'file.jpg']]; $this->productRepositoryMock->expects($this->once())->method('get')->with($productSku)->willReturn($this->productMock); $this->productMock->expects($this->once())->method('getMediaAttributes')->willReturn(['code' => 0]); $this->productMock->expects($this->once())->method('getData')->with('code')->willReturn('codeValue'); $this->productMock->expects($this->once())->method('getMediaGallery')->with('images')->willReturn($images); $entryMock = $this->getMock('\\Magento\\Catalog\\Api\\Data\\ProductAttributeMediaGalleryEntryInterface'); $this->dataObjectHelperMock->expects($this->once())->method('populateWithArray')->with($entryMock, $images[0], '\\Magento\\Catalog\\Api\\Data\\ProductAttributeMediaGalleryEntryInterface')->willReturnSelf(); $this->entryFactoryMock->expects($this->once())->method('create')->willReturn($entryMock); $this->assertEquals($entryMock, $this->model->get($productSku, $imageId)); }