Skip to content

Commit c2c236e

Browse files
ENGCOM-6444: [Catalog] Cover Price Validation Result class by Unit Test #25982
2 parents c08041b + 86e97a0 commit c2c236e

File tree

1 file changed

+91
-0
lines changed
  • app/code/Magento/Catalog/Test/Unit/Model/Product/Price/Validation

1 file changed

+91
-0
lines changed
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
declare(strict_types=1);
8+
9+
namespace Magento\Catalog\Test\Unit\Model\Product\Price\Validation;
10+
11+
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager as ObjectManagerHelper;
12+
use Magento\Catalog\Model\Product\Price\Validation\Result;
13+
use PHPUnit\Framework\TestCase;
14+
use Magento\Catalog\Api\Data\PriceUpdateResultInterface;
15+
use Magento\Catalog\Api\Data\PriceUpdateResultInterfaceFactory;
16+
17+
class ResultTest extends TestCase
18+
{
19+
/**
20+
* @var Result
21+
*/
22+
private $model;
23+
24+
/**
25+
* @var PriceUpdateResultInterfaceFactory|PHPUnit_Framework_MockObject_MockObject
26+
*/
27+
private $priceUpdateResultFactory;
28+
29+
/**
30+
* @var ObjectManagerHelper|PHPUnit_Framework_MockObject_MockObject
31+
*/
32+
private $objectManager;
33+
34+
/**
35+
* Setup environment for test
36+
*/
37+
protected function setUp()
38+
{
39+
$this->priceUpdateResultFactory = $this->getMockBuilder(PriceUpdateResultInterfaceFactory::class)
40+
->disableOriginalConstructor()
41+
->setMethods(['create'])
42+
->getMock();
43+
44+
$this->objectManager = new ObjectManagerHelper($this);
45+
$this->model = $this->objectManager->getObject(
46+
Result::class,
47+
[
48+
'priceUpdateResultFactory' => $this->priceUpdateResultFactory
49+
]
50+
);
51+
52+
$this->model->addFailedItem(1, 'Invalid attribute color = 1', ['SKU' => 'ABC', 'storeId' => 1]);
53+
$this->model->addFailedItem(2, 'Invalid attribute size = M', ['SKU' => 'DEF', 'storeId' => 1]);
54+
}
55+
56+
/**
57+
* Test getFailedRowIds() function
58+
*/
59+
public function testGetFailedRowIds()
60+
{
61+
$this->assertEquals([1, 2], $this->model->getFailedRowIds());
62+
}
63+
64+
/**
65+
* Test getFailedItems() function
66+
*/
67+
public function testGetFailedItems()
68+
{
69+
$priceUpdateResult1 = $this->createMock(PriceUpdateResultInterface::class);
70+
$priceUpdateResult2 = $this->createMock(PriceUpdateResultInterface::class);
71+
72+
$this->priceUpdateResultFactory->expects($this->at(0))
73+
->method('create')
74+
->willReturn($priceUpdateResult1);
75+
$this->priceUpdateResultFactory->expects($this->at(1))
76+
->method('create')
77+
->willReturn($priceUpdateResult2);
78+
79+
$priceUpdateResult1->expects($this->once())->method('setMessage')
80+
->with('Invalid attribute color = 1');
81+
$priceUpdateResult1->expects($this->once())->method('setParameters')
82+
->with(['SKU' => 'ABC', 'storeId' => 1]);
83+
84+
$priceUpdateResult2->expects($this->once())->method('setMessage')
85+
->with('Invalid attribute size = M');
86+
$priceUpdateResult2->expects($this->once())->method('setParameters')
87+
->with(['SKU' => 'DEF', 'storeId' => 1]);
88+
89+
$this->assertEquals([$priceUpdateResult1, $priceUpdateResult2], $this->model->getFailedItems());
90+
}
91+
}

0 commit comments

Comments
 (0)