1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);
namespace Magento\SalesRule\Test\Unit\Model\Quote;
use Magento\SalesRule\Model\Quote\ChildrenValidationLocator;
use Magento\Quote\Model\Quote\Item\AbstractItem as QuoteItem;
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
use Magento\Catalog\Model\Product;
/**
* Test for Magento\SalesRule\Model\Quote\ChildrenValidationLocator
*/
class ChildrenValidationLocatorTest extends \PHPUnit\Framework\TestCase
{
/**
* @var array
*/
private $productTypeChildrenValidationMap;
/**
* @var ObjectManager
*/
private $objectManager;
/**
* @var ChildrenValidationLocator
*/
private $model;
/**
* @var QuoteItem|\PHPUnit_Framework_MockObject_MockObject
*/
private $quoteItemMock;
/**
* @var Product|\PHPUnit_Framework_MockObject_MockObject
*/
private $productMock;
protected function setUp()
{
$this->objectManager = new ObjectManager($this);
$this->productTypeChildrenValidationMap = [
'type1' => true,
'type2' => false,
];
$this->quoteItemMock = $this->getMockBuilder(QuoteItem::class)
->disableOriginalConstructor()
->setMethods(['getProduct'])
->getMockForAbstractClass();
$this->productMock = $this->getMockBuilder(Product::class)
->disableOriginalConstructor()
->setMethods(['getTypeId'])
->getMock();
$this->model = $this->objectManager->getObject(
ChildrenValidationLocator::class,
[
'productTypeChildrenValidationMap' => $this->productTypeChildrenValidationMap,
]
);
}
/**
* @dataProvider productTypeDataProvider
* @param string $type
* @param bool $expected
*
* @return void
*/
public function testIsChildrenValidationRequired(string $type, bool $expected): void
{
$this->quoteItemMock->expects($this->once())
->method('getProduct')
->willReturn($this->productMock);
$this->productMock->expects($this->once())
->method('getTypeId')
->willReturn($type);
$this->assertEquals($this->model->isChildrenValidationRequired($this->quoteItemMock), $expected);
}
/**
* @return array
*/
public function productTypeDataProvider(): array
{
return [
['type1', true],
['type2', false],
['type3', true],
];
}
}