41 $this->calculatorFactory = $this->createMock(
42 \
Magento\SalesRule\Model\Rule\Action\Discount\CalculatorFactory::class
44 $this->eventManager = $this->createPartialMock(\
Magento\Framework\Event\Manager::class, [
'dispatch']);
45 $this->validatorUtility = $this->createPartialMock(
46 \
Magento\SalesRule\Model\Utility::class,
47 [
'canProcessRule',
'minFix',
'deltaRoundingFix',
'getItemQty']
49 $this->childrenValidationLocator = $this->createPartialMock(
50 \
Magento\SalesRule\Model\Quote\ChildrenValidationLocator::class,
51 [
'isChildrenValidationRequired']
53 $this->rulesApplier = new \Magento\SalesRule\Model\RulesApplier(
54 $this->calculatorFactory,
56 $this->validatorUtility,
57 $this->childrenValidationLocator
67 public function testApplyRulesWhenRuleWithStopRulesProcessingIsUsed($isChildren, $isContinue)
70 $skipValidation =
false;
71 $item = $this->getPreparedItem();
80 $ruleWithStopFurtherProcessing = $this->createPartialMock(
81 \
Magento\SalesRule\Model\Rule::class,
82 [
'getStoreLabel',
'getCouponType',
'getRuleId',
'__wakeup',
'getActions']
85 $ruleThatShouldNotBeRun = $this->createPartialMock(
86 \
Magento\SalesRule\Model\Rule::class,
87 [
'getStopRulesProcessing',
'__wakeup']
90 $actionMock = $this->createPartialMock(\
Magento\Rule\Model\Action\Collection::class, [
'validate']);
92 $ruleWithStopFurtherProcessing->setName(
'ruleWithStopFurtherProcessing');
93 $ruleThatShouldNotBeRun->setName(
'ruleThatShouldNotBeRun');
94 $rules = [$ruleWithStopFurtherProcessing, $ruleThatShouldNotBeRun];
96 $item->setDiscountCalculationPrice($positivePrice);
97 $item->setData(
'calculation_price', $positivePrice);
99 $this->childrenValidationLocator->expects($this->any())
100 ->method(
'isChildrenValidationRequired')
103 $this->validatorUtility->expects($this->atLeastOnce())
104 ->method(
'canProcessRule')
105 ->will($this->returnValue(
true));
107 $ruleWithStopFurtherProcessing->expects($this->atLeastOnce())
108 ->method(
'getActions')
109 ->willReturn($actionMock);
110 $actionMock->expects($this->at(0))
113 ->willReturn(!$isChildren);
117 $item->expects($this->atLeastOnce())
118 ->method(
'getChildren')
119 ->willReturn([
$item]);
120 $actionMock->expects($this->at(1))
123 ->willReturn(!$isContinue);
127 if (!$isContinue || !$isChildren) {
128 $ruleWithStopFurtherProcessing->expects($this->any())
129 ->method(
'getRuleId')
130 ->will($this->returnValue(
$ruleId));
134 $ruleWithStopFurtherProcessing->setStopRulesProcessing(
true);
135 $ruleThatShouldNotBeRun->expects($this->never())
136 ->method(
'getStopRulesProcessing');
140 $this->assertEquals($appliedRuleIds,
$result);
149 [
'isChildren' =>
true,
'isContinue' =>
false],
150 [
'isChildren' =>
false,
'isContinue' =>
true],
157 protected function getPreparedItem()
160 $address = $this->createPartialMock(\
Magento\Quote\Model\Quote\Address::class, [
167 $item = $this->createPartialMock(\
Magento\Quote\Model\Quote\Item::class, [
169 'setBaseDiscountAmount',
170 'setDiscountPercent',
176 $quote = $this->createPartialMock(\
Magento\Quote\Model\Quote::class, [
'getStore',
'__wakeUp']);
177 $item->expects($this->any())->method(
'getAddress')->will($this->returnValue(
$address));
180 ->will($this->returnValue(
$quote));
192 $discountCalc = $this->createPartialMock(
193 \
Magento\SalesRule\Model\Rule\Action\Discount\DiscountInterface::class,
194 [
'fixQuantity',
'calculate']
196 $discountData = $this->getMockBuilder(\
Magento\SalesRule\Model\Rule\Action\Discount\Data::class)
197 ->setConstructorArgs(
201 'originalAmount' => 30,
202 'baseOriginalAmount' => 30
206 $this->validatorUtility->expects($this->any())
207 ->method(
'getItemQty')
208 ->with($this->anything(), $this->anything())
209 ->will($this->returnValue($qty));
210 $discountCalc->expects($this->any())
211 ->method(
'fixQuantity')
212 ->with($this->equalTo($qty), $this->equalTo(
$rule))
213 ->will($this->returnValue($qty));
215 $discountCalc->expects($this->any())
216 ->method(
'calculate')
217 ->with($this->equalTo(
$rule), $this->equalTo(
$item), $this->equalTo($qty))
218 ->will($this->returnValue($discountData));
219 $this->calculatorFactory->expects($this->any())
221 ->with($this->anything())
222 ->will($this->returnValue($discountCalc));
$childrenValidationLocator