Skip to content

Commit b368a0d

Browse files
committed
ACP2E-3432: usage_limit and uses_per_customer not updating in salesrule_coupon Table
1 parent a19dcf3 commit b368a0d

File tree

2 files changed

+63
-4
lines changed

2 files changed

+63
-4
lines changed

app/code/Magento/SalesRule/Model/ResourceModel/Rule.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22
/**
3-
* Copyright 2024 Adobe
3+
* Copyright 2011 Adobe
44
* All Rights Reserved.
55
*/
66

app/code/Magento/SalesRule/Test/Unit/Model/ResourceModel/RuleTest.php

Lines changed: 62 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
<?php
22
/**
3-
* Copyright © Magento, Inc. All rights reserved.
4-
* See COPYING.txt for license details.
3+
* Copyright 2015 Adobe
4+
* All Rights Reserved.
55
*/
6+
67
declare(strict_types=1);
78

89
namespace Magento\SalesRule\Test\Unit\Model\ResourceModel;
@@ -86,6 +87,11 @@ class RuleTest extends TestCase
8687
*/
8788
private $metadataPoolMock;
8889

90+
/**
91+
* @var \Magento\SalesRule\Model\ResourceModel\Coupon|MockObject
92+
*/
93+
private $resourceCoupon;
94+
8995
protected function setUp(): void
9096
{
9197
$this->objectManager = new ObjectManager($this);
@@ -169,6 +175,8 @@ protected function setUp(): void
169175
->disableOriginalConstructor()
170176
->getMock();
171177

178+
$this->resourceCoupon = $this->createMock(\Magento\SalesRule\Model\ResourceModel\Coupon::class);
179+
172180
$this->model = $this->objectManager->getObject(
173181
Rule::class,
174182
[
@@ -177,7 +185,8 @@ protected function setUp(): void
177185
'entityManager' => $this->entityManager,
178186
'associatedEntityMapInstance' => $associatedEntitiesMap,
179187
'serializer' => $serializerMock,
180-
'metadataPool' => $this->metadataPoolMock
188+
'metadataPool' => $this->metadataPoolMock,
189+
'resourceCoupon' => $this->resourceCoupon
181190
]
182191
);
183192
}
@@ -245,6 +254,56 @@ public function testSaveStoreLabels()
245254
$this->model->saveStoreLabels(1, ['test']);
246255
}
247256

257+
/**
258+
* @dataProvider afterSaveShouldUpdateExistingCouponsDataProvider
259+
* @param array $data
260+
* @param bool $update
261+
* @return void
262+
* @throws \PHPUnit\Framework\MockObject\Exception
263+
*/
264+
public function testAfterSaveShouldUpdateExistingCoupons(array $data, bool $update = true): void
265+
{
266+
/** @var AbstractModel|MockObject $abstractModel */
267+
$ruleMock = $this->getMockBuilder(\Magento\SalesRule\Model\Rule::class)
268+
->disableOriginalConstructor()
269+
->onlyMethods(['getConditions', 'getActions'])
270+
->getMock();
271+
$conditions = $this->createMock(\Magento\Rule\Model\Condition\Combine::class);
272+
$actions = $this->createMock(\Magento\Rule\Model\Action\Collection::class);
273+
$ruleMock->method('getConditions')->willReturn($conditions);
274+
$ruleMock->method('getActions')->willReturn($actions);
275+
$ruleMock->addData($data);
276+
$this->resourceCoupon->expects($update ? $this->once() : $this->never())
277+
->method('updateSpecificCoupons')
278+
->with($ruleMock);
279+
$this->model->afterSave($ruleMock);
280+
}
281+
282+
/**
283+
* @return array
284+
*/
285+
public static function afterSaveShouldUpdateExistingCouponsDataProvider(): array
286+
{
287+
return [
288+
[
289+
['use_auto_generation' => 0, 'coupon_type' => \Magento\SalesRule\Model\Rule::COUPON_TYPE_NO_COUPON],
290+
false
291+
],
292+
[
293+
['use_auto_generation' => 0, 'coupon_type' => \Magento\SalesRule\Model\Rule::COUPON_TYPE_SPECIFIC],
294+
false
295+
],
296+
[
297+
['use_auto_generation' => 1, 'coupon_type' => \Magento\SalesRule\Model\Rule::COUPON_TYPE_SPECIFIC],
298+
true
299+
],
300+
[
301+
['use_auto_generation' => 0, 'coupon_type' => \Magento\SalesRule\Model\Rule::COUPON_TYPE_AUTO],
302+
true
303+
]
304+
];
305+
}
306+
248307
/**
249308
* @return array
250309
*/

0 commit comments

Comments
 (0)