|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * Copyright © Magento, Inc. All rights reserved. |
| 4 | + * See COPYING.txt for license details. |
| 5 | + */ |
| 6 | +namespace Magento\ConfigurableProduct\Test\Unit\Model\Plugin; |
| 7 | + |
| 8 | +use Magento\ConfigurableProduct\Model\Plugin\ProductIdentitiesExtender; |
| 9 | +use Magento\ConfigurableProduct\Model\Product\Type\Configurable; |
| 10 | +use Magento\Catalog\Api\ProductRepositoryInterface; |
| 11 | +use Magento\Catalog\Model\Product; |
| 12 | + |
| 13 | +/** |
| 14 | + * Class ProductIdentitiesExtenderTest |
| 15 | + */ |
| 16 | +class ProductIdentitiesExtenderTest extends \PHPUnit_Framework_TestCase |
| 17 | +{ |
| 18 | + /** |
| 19 | + * @var \PHPUnit_Framework_MockObject_MockObject|Configurable |
| 20 | + */ |
| 21 | + private $configurableTypeMock; |
| 22 | + |
| 23 | + /** |
| 24 | + * @var \PHPUnit_Framework_MockObject_MockObject|ProductRepositoryInterface |
| 25 | + */ |
| 26 | + private $productRepositoryMock; |
| 27 | + |
| 28 | + /** |
| 29 | + * @var ProductIdentitiesExtender |
| 30 | + */ |
| 31 | + private $plugin; |
| 32 | + |
| 33 | + protected function setUp() |
| 34 | + { |
| 35 | + $this->configurableTypeMock = $this->getMockBuilder(Configurable::class) |
| 36 | + ->disableOriginalConstructor() |
| 37 | + ->getMock(); |
| 38 | + $this->productRepositoryMock = $this->getMockBuilder(ProductRepositoryInterface::class) |
| 39 | + ->getMock(); |
| 40 | + |
| 41 | + $this->plugin = new ProductIdentitiesExtender($this->configurableTypeMock, $this->productRepositoryMock); |
| 42 | + } |
| 43 | + |
| 44 | + public function testAroundGetIdentities() |
| 45 | + { |
| 46 | + $productIdentity = 'cache_tag_1'; |
| 47 | + $productMock = $this->getMockBuilder(Product::class) |
| 48 | + ->disableOriginalConstructor() |
| 49 | + ->getMock(); |
| 50 | + $proceed = function () use ($productIdentity) { |
| 51 | + return [$productIdentity]; |
| 52 | + }; |
| 53 | + |
| 54 | + $productId = 1; |
| 55 | + $parentProductId = 2; |
| 56 | + $parentProductIdentity = 'cache_tag_2'; |
| 57 | + $productMock->expects($this->once()) |
| 58 | + ->method('getId') |
| 59 | + ->willReturn($productId); |
| 60 | + $this->configurableTypeMock->expects($this->once()) |
| 61 | + ->method('getParentIdsByChild') |
| 62 | + ->with($productId) |
| 63 | + ->willReturn([$parentProductId]); |
| 64 | + $parentProductMock = $this->getMockBuilder(Product::class) |
| 65 | + ->disableOriginalConstructor() |
| 66 | + ->getMock(); |
| 67 | + $this->productRepositoryMock->expects($this->once()) |
| 68 | + ->method('getById') |
| 69 | + ->with($parentProductId) |
| 70 | + ->willReturn($parentProductMock); |
| 71 | + $parentProductMock->expects($this->once()) |
| 72 | + ->method('getIdentities') |
| 73 | + ->willReturn([$parentProductIdentity]); |
| 74 | + |
| 75 | + $productIdentities = $this->plugin->aroundGetIdentities($productMock, $proceed); |
| 76 | + $this->assertEquals([$productIdentity, $parentProductIdentity], $productIdentities); |
| 77 | + } |
| 78 | +} |
0 commit comments