15 private $mediaGallery;
18 private $swatchHelperMock;
21 private $productModelFactoryMock;
33 private $resultFactory;
39 private $objectManager;
46 $this->mediaGallery = [
47 'image' =>
'/m/a/magento.png',
48 'small_image' =>
'/m/a/magento.png',
49 'thumbnail' =>
'/m/a/magento.png',
50 'swatch_image' =>
'/m/a/magento.png',
53 $this->objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
55 $this->swatchHelperMock = $this->createMock(\
Magento\Swatches\Helper\Data::class);
56 $this->productModelFactoryMock = $this->createPartialMock(
57 \
Magento\Catalog\Model\ProductFactory::class,
60 $this->productMock = $this->createMock(\
Magento\Catalog\Model\Product::class);
61 $this->contextMock = $this->createMock(\
Magento\Framework\
App\Action\Context::class);
63 $this->requestMock = $this->createMock(\
Magento\Framework\
App\RequestInterface::class);
64 $this->contextMock->method(
'getRequest')->willReturn($this->requestMock);
65 $this->resultFactory = $this->createPartialMock(\
Magento\Framework\Controller\ResultFactory::class, [
'create']);
66 $this->contextMock->method(
'getResultFactory')->willReturn($this->resultFactory);
68 $this->jsonMock = $this->createMock(\
Magento\Framework\Controller\Result\Json::class);
69 $this->resultFactory->expects($this->once())->method(
'create')->with(
'json')->willReturn($this->jsonMock);
71 $this->controller = $this->objectManager->getObject(
72 \
Magento\Swatches\Controller\Ajax\Media::class,
74 'context' => $this->contextMock,
75 'swatchHelper' => $this->swatchHelperMock,
76 'productModelFactory' => $this->productModelFactoryMock
83 $this->requestMock->expects($this->any())->method(
'getParam')->with(
'product_id')->willReturn(59);
85 ->expects($this->once())
88 ->willReturn($this->productMock);
90 $this->productModelFactoryMock
91 ->expects($this->once())
93 ->willReturn($this->productMock);
95 $this->swatchHelperMock
96 ->expects($this->once())
97 ->method(
'getProductMediaGallery')
98 ->with($this->productMock)
99 ->willReturn($this->mediaGallery);
102 ->expects($this->once())
104 ->with($this->mediaGallery)
105 ->will($this->returnSelf());
107 $result = $this->controller->execute();
109 $this->assertInstanceOf(\
Magento\Framework\Controller\Result\Json::class,
$result);