|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * Copyright © 2016 Magento. All rights reserved. |
| 4 | + * See COPYING.txt for license details. |
| 5 | + */ |
| 6 | +namespace Magento\Catalog\Test\Unit\Model\Product\Gallery; |
| 7 | + |
| 8 | +/** |
| 9 | + * Unit test for catalog product Media Gallery ReadHandler |
| 10 | + */ |
| 11 | +class ReadHandlerTest extends \PHPUnit_Framework_TestCase |
| 12 | +{ |
| 13 | + /** @var \Magento\Catalog\Model\Product\Gallery\ReadHandler */ |
| 14 | + protected $model; |
| 15 | + |
| 16 | + /** |
| 17 | + * @var \Magento\Framework\TestFramework\Unit\Helper\ObjectManager |
| 18 | + */ |
| 19 | + protected $objectHelper; |
| 20 | + |
| 21 | + /** |
| 22 | + * @var \Magento\Catalog\Model\Product\Attribute\Repository|\PHPUnit_Framework_MockObject_MockObject |
| 23 | + */ |
| 24 | + protected $attributeRepository; |
| 25 | + |
| 26 | + protected function setUp() |
| 27 | + { |
| 28 | + $this->objectHelper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this); |
| 29 | + |
| 30 | + $this->attributeRepository = $this->getMock( |
| 31 | + 'Magento\Catalog\Model\Product\Attribute\Repository', |
| 32 | + ['get'], |
| 33 | + [], |
| 34 | + '', |
| 35 | + false |
| 36 | + ); |
| 37 | + $this->model = $this->objectHelper->getObject( |
| 38 | + \Magento\Catalog\Model\Product\Gallery\ReadHandler::class, |
| 39 | + [ |
| 40 | + 'attributeRepository' => $this->attributeRepository, |
| 41 | + ] |
| 42 | + ); |
| 43 | + } |
| 44 | + |
| 45 | + public function testAddMediaDataToProduct() |
| 46 | + { |
| 47 | + $attribute = $this->getMockBuilder(\Magento\Eav\Model\Entity\Attribute::class) |
| 48 | + ->disableOriginalConstructor() |
| 49 | + ->getMock(); |
| 50 | + |
| 51 | + $attribute->expects($this->any())->method('getAttributeCode')->will($this->returnValue('image')); |
| 52 | + |
| 53 | + $this->attributeRepository->expects($this->once()) |
| 54 | + ->method('get') |
| 55 | + ->with('media_gallery') |
| 56 | + ->willReturn($attribute); |
| 57 | + |
| 58 | + $product = $this->getMockBuilder(\Magento\Catalog\Model\Product::class) |
| 59 | + ->disableOriginalConstructor() |
| 60 | + ->getMock(); |
| 61 | + $product->expects($this->once())->method('setData')->with( |
| 62 | + 'image', |
| 63 | + [ |
| 64 | + 'images' =>[ |
| 65 | + 10 => ['value_id' => 10,] |
| 66 | + ], |
| 67 | + 'values' => [] |
| 68 | + ] |
| 69 | + ); |
| 70 | + $this->model->addMediaDataToProduct($product, [['value_id' => 10]]); |
| 71 | + } |
| 72 | +} |
0 commit comments