|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * Copyright © Magento, Inc. All rights reserved. |
| 4 | + * See COPYING.txt for license details. |
| 5 | + */ |
| 6 | +declare(strict_types=1); |
| 7 | + |
| 8 | +namespace Magento\SalesRule\Test\Unit\Model\Quote; |
| 9 | + |
| 10 | +use Magento\Catalog\Model\Product; |
| 11 | +use Magento\Quote\Model\Quote\Item\AbstractItem as QuoteItem; |
| 12 | +use Magento\SalesRule\Api\Data\CouponGenerationSpecInterfaceFactory; |
| 13 | +use Magento\SalesRule\Model\Quote\ChildrenValidationLocator; |
| 14 | + |
| 15 | +/** |
| 16 | + * @covers \Magento\SalesRule\Model\Quote\ChildrenValidationLocator |
| 17 | + */ |
| 18 | +class ChildrenValidationLocatorTest extends \PHPUnit\Framework\TestCase |
| 19 | +{ |
| 20 | + /** |
| 21 | + * Testable Object |
| 22 | + * |
| 23 | + * @var ChildrenValidationLocator |
| 24 | + */ |
| 25 | + private $childrenValidationLocator; |
| 26 | + |
| 27 | + /** |
| 28 | + * @var QuoteItem|\PHPUnit_Framework_MockObject_MockObject |
| 29 | + */ |
| 30 | + private $itemMock; |
| 31 | + |
| 32 | + /** |
| 33 | + * @var Product|\PHPUnit_Framework_MockObject_MockObject |
| 34 | + */ |
| 35 | + private $productMock; |
| 36 | + |
| 37 | + /** |
| 38 | + * @var array |
| 39 | + */ |
| 40 | + private $productTypeChildrenValidationMap = [ |
| 41 | + 'simple' => false, |
| 42 | + 'bundle' => true, |
| 43 | + ]; |
| 44 | + |
| 45 | + /** |
| 46 | + * Set Up |
| 47 | + * |
| 48 | + * @return void |
| 49 | + */ |
| 50 | + protected function setUp() |
| 51 | + { |
| 52 | + $this->itemMock = $this->createMock(QuoteItem::class); |
| 53 | + $this->productMock = $this->createMock(Product::class); |
| 54 | + $this->childrenValidationLocator = new ChildrenValidationLocator($this->productTypeChildrenValidationMap); |
| 55 | + } |
| 56 | + |
| 57 | + /** |
| 58 | + * Test isChildrenValidationRequired method |
| 59 | + * |
| 60 | + * @dataProvider childrenValidationDataProvider |
| 61 | + * |
| 62 | + * @param string $typeId |
| 63 | + * @param bool $isValidationRequired |
| 64 | + * |
| 65 | + * @return void |
| 66 | + */ |
| 67 | + public function testIsChildrenValidationRequired($typeId, $isValidationRequired) |
| 68 | + { |
| 69 | + $this->productMock->expects($this->once())->method('getTypeId')->willReturn($typeId); |
| 70 | + $this->itemMock->expects($this->once())->method('getProduct')->willReturn($this->productMock); |
| 71 | + $actual = $this->childrenValidationLocator->isChildrenValidationRequired($this->itemMock); |
| 72 | + $expected = $isValidationRequired; |
| 73 | + self::assertEquals($expected, $actual); |
| 74 | + } |
| 75 | + |
| 76 | + /** |
| 77 | + * @return array |
| 78 | + */ |
| 79 | + public function childrenValidationDataProvider() |
| 80 | + { |
| 81 | + return [ |
| 82 | + ['simple', $this->productTypeChildrenValidationMap['simple']], |
| 83 | + ['bundle', $this->productTypeChildrenValidationMap['bundle']], |
| 84 | + ['configurable', true], |
| 85 | + ]; |
| 86 | + } |
| 87 | +} |
0 commit comments