Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
TypeTransitionManagerTest.php
Go to the documentation of this file.
1 <?php
7 
8 class TypeTransitionManagerTest extends \PHPUnit\Framework\TestCase
9 {
13  protected $model;
14 
18  protected $productMock;
19 
23  protected $weightResolver;
24 
25  protected function setUp()
26  {
27  $this->productMock = $this->createPartialMock(
28  \Magento\Catalog\Model\Product::class,
29  ['getTypeId', 'setTypeId', 'setTypeInstance']
30  );
31  $this->weightResolver = $this->createMock(\Magento\Catalog\Model\Product\Edit\WeightResolver::class);
32  $this->model = (new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this))
33  ->getObject(
34  \Magento\Catalog\Model\Product\TypeTransitionManager::class,
35  [
36  'weightResolver' => $this->weightResolver,
37  'compatibleTypes' => [
38  'simple' => \Magento\Catalog\Model\Product\Type::TYPE_SIMPLE,
39  'virtual' => \Magento\Catalog\Model\Product\Type::TYPE_VIRTUAL,
40  ]
41  ]
42  );
43  }
44 
51  public function testProcessProduct($hasWeight, $currentTypeId, $expectedTypeId)
52  {
53  $this->productMock->expects($this->once())->method('getTypeId')->will($this->returnValue($currentTypeId));
54  $this->productMock->expects($this->once())->method('setTypeInstance')->with(null);
55  $this->weightResolver->expects($this->once())->method('resolveProductHasWeight')->willReturn($hasWeight);
56  $this->productMock->expects($this->once())->method('setTypeId')->with($expectedTypeId);
57  $this->model->processProduct($this->productMock);
58  }
59 
64  {
65  $this->productMock->expects($this->once())->method('getTypeId')->will($this->returnValue('wrong-type'));
66  $this->weightResolver->expects($this->never())->method('resolveProductHasWeight');
67  $this->model->processProduct($this->productMock);
68  }
69 
73  public function processProductDataProvider()
74  {
75  return [
76  [
77  true,
78  \Magento\Catalog\Model\Product\Type::TYPE_VIRTUAL,
79  \Magento\Catalog\Model\Product\Type::TYPE_SIMPLE,
80  ],
81  [
82  true,
83  \Magento\Catalog\Model\Product\Type::TYPE_SIMPLE,
84  \Magento\Catalog\Model\Product\Type::TYPE_SIMPLE,
85  ],
86  [
87  false,
88  \Magento\Catalog\Model\Product\Type::TYPE_SIMPLE,
89  \Magento\Catalog\Model\Product\Type::TYPE_VIRTUAL,
90  ],
91  [
92  false,
93  \Magento\Catalog\Model\Product\Type::TYPE_VIRTUAL,
94  \Magento\Catalog\Model\Product\Type::TYPE_VIRTUAL,
95  ]
96  ];
97  }
98 }