diff --git a/app/code/Magento/SalesRule/Test/Unit/Model/CouponGeneratorTest.php b/app/code/Magento/SalesRule/Test/Unit/Model/CouponGeneratorTest.php new file mode 100644 index 0000000000000..24ea8f2ab5efb --- /dev/null +++ b/app/code/Magento/SalesRule/Test/Unit/Model/CouponGeneratorTest.php @@ -0,0 +1,74 @@ +generationSpecFactoryMock = $this->getMockBuilder(CouponGenerationSpecInterfaceFactory::class) + ->disableOriginalConstructor()->setMethods(['create'])->getMock(); + $this->couponManagementServiceMock = $this->createMock(CouponManagementService::class); + $this->generationSpecMock = $this->createMock(CouponGenerationSpecInterface::class); + $this->couponGenerator = new CouponGenerator( + $this->couponManagementServiceMock, + $this->generationSpecFactoryMock + ); + } + + /** + * Test beforeSave method + * + * @return void + */ + public function testBeforeSave() + { + $expected = ['test']; + $this->generationSpecFactoryMock->expects($this->once())->method('create') + ->willReturn($this->generationSpecMock); + $this->couponManagementServiceMock->expects($this->once())->method('generate') + ->with($this->generationSpecMock)->willReturn($expected); + $actual = $this->couponGenerator->generateCodes([]); + self::assertEquals($expected, $actual); + } +} diff --git a/app/code/Magento/SalesRule/Test/Unit/Model/Quote/ChildrenValidationLocatorTest.php b/app/code/Magento/SalesRule/Test/Unit/Model/Quote/ChildrenValidationLocatorTest.php new file mode 100644 index 0000000000000..5bf4def83fc81 --- /dev/null +++ b/app/code/Magento/SalesRule/Test/Unit/Model/Quote/ChildrenValidationLocatorTest.php @@ -0,0 +1,87 @@ + false, + 'bundle' => true, + ]; + + /** + * Set Up + * + * @return void + */ + protected function setUp() + { + $this->itemMock = $this->createMock(QuoteItem::class); + $this->productMock = $this->createMock(Product::class); + $this->childrenValidationLocator = new ChildrenValidationLocator($this->productTypeChildrenValidationMap); + } + + /** + * Test isChildrenValidationRequired method + * + * @dataProvider childrenValidationDataProvider + * + * @param string $typeId + * @param bool $isValidationRequired + * + * @return void + */ + public function testIsChildrenValidationRequired($typeId, $isValidationRequired) + { + $this->productMock->expects($this->once())->method('getTypeId')->willReturn($typeId); + $this->itemMock->expects($this->once())->method('getProduct')->willReturn($this->productMock); + $actual = $this->childrenValidationLocator->isChildrenValidationRequired($this->itemMock); + $expected = $isValidationRequired; + self::assertEquals($expected, $actual); + } + + /** + * @return array + */ + public function childrenValidationDataProvider() + { + return [ + ['simple', $this->productTypeChildrenValidationMap['simple']], + ['bundle', $this->productTypeChildrenValidationMap['bundle']], + ['configurable', true], + ]; + } +}