ConfigurableTest.php 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Swatches\Test\Unit\Model\Plugin;
  7. class ConfigurableTest extends \PHPUnit\Framework\TestCase
  8. {
  9. /** @var \Magento\Eav\Model\Config|\PHPUnit_Framework_MockObject_MockObject */
  10. private $eavConfig;
  11. /** @var \Magento\Swatches\Helper\Data|\PHPUnit_Framework_MockObject_MockObject */
  12. private $swatchHelper;
  13. /** @var \Magento\Swatches\Model\Plugin\Configurable|\Magento\Framework\TestFramework\Unit\Helper\ObjectManager */
  14. protected $pluginModel;
  15. protected function setUp()
  16. {
  17. $this->eavConfig = $this->createPartialMock(
  18. \Magento\Eav\Model\Config::class,
  19. ['getEntityAttributeCodes', 'getAttribute']
  20. );
  21. $this->swatchHelper = $this->createPartialMock(
  22. \Magento\Swatches\Helper\Data::class,
  23. ['isVisualSwatch', 'isTextSwatch']
  24. );
  25. $objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
  26. $this->pluginModel = $objectManager->getObject(
  27. \Magento\Swatches\Model\Plugin\Configurable::class,
  28. [
  29. 'eavConfig' => $this->eavConfig,
  30. 'swatchHelper' => $this->swatchHelper,
  31. ]
  32. );
  33. }
  34. public function testAfterGetUsedProductCollection()
  35. {
  36. $product = $this->getMockBuilder(\Magento\Catalog\Api\Data\ProductInterface::class)->getMock();
  37. $subject = $this->createPartialMock(
  38. \Magento\ConfigurableProduct\Model\Product\Type\Configurable::class,
  39. ['getUsedProductAttributes']
  40. );
  41. $result = $this->createPartialMock(
  42. \Magento\ConfigurableProduct\Model\ResourceModel\Product\Type\Configurable\Product\Collection::class,
  43. ['getEntity', 'addAttributeToSelect']
  44. );
  45. $attribute = $this->createMock(\Magento\Catalog\Model\ResourceModel\Eav\Attribute::class);
  46. $subject->expects($this->once())->method('getUsedProductAttributes')->with($product)
  47. ->willReturn(['size' => $attribute, 'color' => $attribute, 'swatch1' => $attribute]);
  48. $attribute->expects($this->any())
  49. ->method('getData')
  50. ->with('additional_data')
  51. ->willReturn(true);
  52. $this->swatchHelper->expects($this->exactly(3))->method('isVisualSwatch')->with($attribute)->willReturn(true);
  53. $result->expects($this->once())->method('addAttributeToSelect')
  54. ->with($this->identicalTo(['image', 'size', 'color', 'swatch1']))->willReturn($result);
  55. $result = $this->pluginModel->afterGetUsedProductCollection($subject, $result, $product);
  56. $this->assertInstanceOf(
  57. \Magento\ConfigurableProduct\Model\ResourceModel\Product\Type\Configurable\Product\Collection::class,
  58. $result
  59. );
  60. }
  61. }