Skip to content

Commit cee874a

Browse files
🔃 [EngCom] Public Pull Requests - 2.2-develop
Accepted Public Pull Requests: - #17710: Sales Rule: Add unit tests for model classes (by @dmytro-ch) - #17701: Message list component fix: the message type is always error when parameters specified (by @dmytro-ch) Fixed GitHub Issues: - #17700: Message list component: the message type is always error when parameters specified (reported by @dmytro-ch) has been fixed in #17701 by @dmytro-ch in 2.2-develop branch Related commits: 1. d438e9b
2 parents 764b00c + 4716f81 commit cee874a

File tree

3 files changed

+162
-1
lines changed

3 files changed

+162
-1
lines changed
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
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;
9+
10+
use Magento\SalesRule\Api\Data\CouponGenerationSpecInterface;
11+
use Magento\SalesRule\Api\Data\CouponGenerationSpecInterfaceFactory;
12+
use Magento\SalesRule\Model\CouponGenerator;
13+
use Magento\SalesRule\Model\Service\CouponManagementService;
14+
15+
/**
16+
* @covers \Magento\SalesRule\Model\CouponGenerator
17+
*/
18+
class CouponGeneratorTest extends \PHPUnit\Framework\TestCase
19+
{
20+
/**
21+
* Testable Object
22+
*
23+
* @var CouponGenerator
24+
*/
25+
private $couponGenerator;
26+
27+
/**
28+
* @var CouponManagementService|\PHPUnit_Framework_MockObject_MockObject
29+
*/
30+
private $couponManagementServiceMock;
31+
32+
/**
33+
* @var CouponGenerationSpecInterfaceFactory|\PHPUnit_Framework_MockObject_MockObject
34+
*/
35+
private $generationSpecFactoryMock;
36+
37+
/**
38+
* @var CouponGenerationSpecInterface|\PHPUnit_Framework_MockObject_MockObject
39+
*/
40+
private $generationSpecMock;
41+
42+
/**
43+
* Set Up
44+
*
45+
* @return void
46+
*/
47+
protected function setUp()
48+
{
49+
$this->generationSpecFactoryMock = $this->getMockBuilder(CouponGenerationSpecInterfaceFactory::class)
50+
->disableOriginalConstructor()->setMethods(['create'])->getMock();
51+
$this->couponManagementServiceMock = $this->createMock(CouponManagementService::class);
52+
$this->generationSpecMock = $this->createMock(CouponGenerationSpecInterface::class);
53+
$this->couponGenerator = new CouponGenerator(
54+
$this->couponManagementServiceMock,
55+
$this->generationSpecFactoryMock
56+
);
57+
}
58+
59+
/**
60+
* Test beforeSave method
61+
*
62+
* @return void
63+
*/
64+
public function testBeforeSave()
65+
{
66+
$expected = ['test'];
67+
$this->generationSpecFactoryMock->expects($this->once())->method('create')
68+
->willReturn($this->generationSpecMock);
69+
$this->couponManagementServiceMock->expects($this->once())->method('generate')
70+
->with($this->generationSpecMock)->willReturn($expected);
71+
$actual = $this->couponGenerator->generateCodes([]);
72+
self::assertEquals($expected, $actual);
73+
}
74+
}
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
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+
}

app/code/Magento/Ui/view/frontend/web/js/model/messages.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ define([
5555
return messageObj.parameters.shift();
5656
});
5757
this.clear();
58-
this.errorMessages.push(message);
58+
type.push(message);
5959

6060
return true;
6161
},

0 commit comments

Comments
 (0)