Skip to content

Commit cc3d7fc

Browse files
authored
Merge branch '2.4-develop' into bengals-mainline-deployment
2 parents c57c22f + cfaeeae commit cc3d7fc

File tree

4 files changed

+82
-9
lines changed

4 files changed

+82
-9
lines changed

app/code/Magento/CatalogSearch/Model/Autocomplete/DataProvider.php

+6-6
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,9 @@ class DataProvider implements DataProviderInterface
2121
/**
2222
* Autocomplete limit
2323
*/
24-
const CONFIG_AUTOCOMPLETE_LIMIT = 'catalog/search/autocomplete_limit';
24+
public const CONFIG_AUTOCOMPLETE_LIMIT = 'catalog/search/autocomplete_limit';
2525

2626
/**
27-
* Query factory
28-
*
2927
* @var QueryFactory
3028
*/
3129
protected $queryFactory;
@@ -38,8 +36,6 @@ class DataProvider implements DataProviderInterface
3836
protected $itemFactory;
3937

4038
/**
41-
* Limit
42-
*
4339
* @var int
4440
*/
4541
protected $limit;
@@ -68,8 +64,12 @@ public function __construct(
6864
*/
6965
public function getItems()
7066
{
71-
$collection = $this->getSuggestCollection();
7267
$query = $this->queryFactory->get()->getQueryText();
68+
if (!$query) {
69+
return [];
70+
}
71+
72+
$collection = $this->getSuggestCollection();
7373
$result = [];
7474
foreach ($collection as $item) {
7575
$resultItem = $this->itemFactory->create([

app/code/Magento/CatalogSearch/Test/Unit/Model/Autocomplete/DataProviderTest.php

+13
Original file line numberDiff line numberDiff line change
@@ -147,4 +147,17 @@ private function buildCollection(array $data)
147147
->method('getIterator')
148148
->willReturn(new \ArrayIterator($collectionData));
149149
}
150+
151+
public function testGetItemsWithEmptyQueryText()
152+
{
153+
$this->query->expects($this->once())
154+
->method('getQueryText')
155+
->willReturn('');
156+
$this->query->expects($this->never())
157+
->method('getSuggestCollection');
158+
$this->itemFactory->expects($this->never())
159+
->method('create');
160+
$result = $this->model->getItems();
161+
$this->assertEmpty($result);
162+
}
150163
}

setup/src/Magento/Setup/Fixtures/CouponCodesFixture.php

+15-2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66

77
namespace Magento\Setup\Fixtures;
88

9+
use Magento\SalesRule\Model\ResourceModel\Coupon\CollectionFactory as CouponCollectionFactory;
10+
911
/**
1012
* Fixture for generating coupon codes
1113
*
@@ -37,23 +39,32 @@ class CouponCodesFixture extends Fixture
3739
*/
3840
private $couponCodeFactory;
3941

42+
/**
43+
* @var CouponCollectionFactory
44+
*/
45+
private $couponCollectionFactory;
46+
4047
/**
4148
* Constructor
4249
*
4350
* @param FixtureModel $fixtureModel
4451
* @param \Magento\SalesRule\Model\RuleFactory|null $ruleFactory
4552
* @param \Magento\SalesRule\Model\CouponFactory|null $couponCodeFactory
53+
* @param CouponCollectionFactory|null $couponCollectionFactory
4654
*/
4755
public function __construct(
4856
FixtureModel $fixtureModel,
4957
\Magento\SalesRule\Model\RuleFactory $ruleFactory = null,
50-
\Magento\SalesRule\Model\CouponFactory $couponCodeFactory = null
58+
\Magento\SalesRule\Model\CouponFactory $couponCodeFactory = null,
59+
CouponCollectionFactory $couponCollectionFactory = null
5160
) {
5261
parent::__construct($fixtureModel);
5362
$this->ruleFactory = $ruleFactory ?: $this->fixtureModel->getObjectManager()
5463
->get(\Magento\SalesRule\Model\RuleFactory::class);
5564
$this->couponCodeFactory = $couponCodeFactory ?: $this->fixtureModel->getObjectManager()
5665
->get(\Magento\SalesRule\Model\CouponFactory::class);
66+
$this->couponCollectionFactory = $couponCollectionFactory ?: $this->fixtureModel->getObjectManager()
67+
->get(CouponCollectionFactory::class);
5768
}
5869

5970
/**
@@ -64,7 +75,9 @@ public function __construct(
6475
public function execute()
6576
{
6677
$this->fixtureModel->resetObjectManager();
67-
$this->couponCodesCount = $this->fixtureModel->getValue('coupon_codes', 0);
78+
$requestedCouponsCount = (int) $this->fixtureModel->getValue('coupon_codes', 0);
79+
$existedCouponsCount = $this->couponCollectionFactory->create()->getSize();
80+
$this->couponCodesCount = max(0, $requestedCouponsCount - $existedCouponsCount);
6881
if (!$this->couponCodesCount) {
6982
return;
7083
}

setup/src/Magento/Setup/Test/Unit/Fixtures/CouponCodesFixtureTest.php

+48-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99

1010
use Magento\Framework\ObjectManager\ObjectManager;
1111
use Magento\SalesRule\Model\Coupon;
12+
use Magento\SalesRule\Model\ResourceModel\Coupon\Collection as CouponCollection;
13+
use Magento\SalesRule\Model\ResourceModel\Coupon\CollectionFactory as CouponCollectionFactory;
1214
use Magento\SalesRule\Model\Rule;
1315
use Magento\Setup\Fixtures\CartPriceRulesFixture;
1416
use Magento\Setup\Fixtures\CouponCodesFixture;
@@ -43,6 +45,11 @@ class CouponCodesFixtureTest extends TestCase
4345
*/
4446
private $couponCodeFactoryMock;
4547

48+
/**
49+
* @var CouponCollectionFactory|MockObject
50+
*/
51+
private $couponCollectionFactoryMock;
52+
4653
/**
4754
* setUp
4855
*/
@@ -54,10 +61,12 @@ protected function setUp(): void
5461
\Magento\SalesRule\Model\CouponFactory::class,
5562
['create']
5663
);
64+
$this->couponCollectionFactoryMock = $this->createMock(CouponCollectionFactory::class);
5765
$this->model = new CouponCodesFixture(
5866
$this->fixtureModelMock,
5967
$this->ruleFactoryMock,
60-
$this->couponCodeFactoryMock
68+
$this->couponCodeFactoryMock,
69+
$this->couponCollectionFactoryMock
6170
);
6271
}
6372

@@ -66,6 +75,14 @@ protected function setUp(): void
6675
*/
6776
public function testExecute()
6877
{
78+
$couponCollectionMock = $this->createMock(CouponCollection::class);
79+
$this->couponCollectionFactoryMock->expects($this->once())
80+
->method('create')
81+
->willReturn($couponCollectionMock);
82+
$couponCollectionMock->expects($this->once())
83+
->method('getSize')
84+
->willReturn(0);
85+
6986
$websiteMock = $this->createMock(Website::class);
7087
$websiteMock->expects($this->once())
7188
->method('getId')
@@ -127,6 +144,14 @@ public function testExecute()
127144
*/
128145
public function testNoFixtureConfigValue()
129146
{
147+
$couponCollectionMock = $this->createMock(CouponCollection::class);
148+
$this->couponCollectionFactoryMock->expects($this->once())
149+
->method('create')
150+
->willReturn($couponCollectionMock);
151+
$couponCollectionMock->expects($this->once())
152+
->method('getSize')
153+
->willReturn(0);
154+
130155
$ruleMock = $this->createMock(Rule::class);
131156
$ruleMock->expects($this->never())->method('save');
132157

@@ -148,6 +173,28 @@ public function testNoFixtureConfigValue()
148173
$this->model->execute();
149174
}
150175

176+
public function testFixtureAlreadyCreated()
177+
{
178+
$couponCollectionMock = $this->createMock(CouponCollection::class);
179+
$this->couponCollectionFactoryMock->expects($this->once())
180+
->method('create')
181+
->willReturn($couponCollectionMock);
182+
$couponCollectionMock->expects($this->once())
183+
->method('getSize')
184+
->willReturn(1);
185+
186+
$this->fixtureModelMock
187+
->expects($this->once())
188+
->method('getValue')
189+
->willReturn(1);
190+
191+
$this->fixtureModelMock->expects($this->never())->method('getObjectManager');
192+
$this->ruleFactoryMock->expects($this->never())->method('create');
193+
$this->couponCodeFactoryMock->expects($this->never())->method('create');
194+
195+
$this->model->execute();
196+
}
197+
151198
/**
152199
* testGetActionTitle
153200
*/

0 commit comments

Comments
 (0)