Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
ChildrenValidationLocatorTest.php
Go to the documentation of this file.
1 <?php
7 declare(strict_types=1);
8 
10 
15 
19 class ChildrenValidationLocatorTest extends \PHPUnit\Framework\TestCase
20 {
24  private $productTypeChildrenValidationMap;
25 
29  private $objectManager;
30 
34  private $model;
35 
39  private $quoteItemMock;
40 
44  private $productMock;
45 
46  protected function setUp()
47  {
48  $this->objectManager = new ObjectManager($this);
49 
50  $this->productTypeChildrenValidationMap = [
51  'type1' => true,
52  'type2' => false,
53  ];
54 
55  $this->quoteItemMock = $this->getMockBuilder(QuoteItem::class)
56  ->disableOriginalConstructor()
57  ->setMethods(['getProduct'])
58  ->getMockForAbstractClass();
59 
60  $this->productMock = $this->getMockBuilder(Product::class)
61  ->disableOriginalConstructor()
62  ->setMethods(['getTypeId'])
63  ->getMock();
64 
65  $this->model = $this->objectManager->getObject(
66  ChildrenValidationLocator::class,
67  [
68  'productTypeChildrenValidationMap' => $this->productTypeChildrenValidationMap,
69  ]
70  );
71  }
72 
80  public function testIsChildrenValidationRequired(string $type, bool $expected): void
81  {
82  $this->quoteItemMock->expects($this->once())
83  ->method('getProduct')
84  ->willReturn($this->productMock);
85 
86  $this->productMock->expects($this->once())
87  ->method('getTypeId')
88  ->willReturn($type);
89 
90  $this->assertEquals($this->model->isChildrenValidationRequired($this->quoteItemMock), $expected);
91  }
92 
96  public function productTypeDataProvider(): array
97  {
98  return [
99  ['type1', true],
100  ['type2', false],
101  ['type3', true],
102  ];
103  }
104 }
$type
Definition: item.phtml:13