Skip to content

Commit e8db861

Browse files
committed
Merge remote-tracking branch 'origin/ACP2E-4136' into PR_2025_09_08_muntianu
2 parents 7e25e3c + 4402657 commit e8db861

File tree

3 files changed

+58
-74
lines changed

3 files changed

+58
-74
lines changed

app/code/Magento/CatalogWidget/Block/Product/ProductsList.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use Magento\Catalog\Block\Product\Context;
1212
use Magento\Catalog\Block\Product\Widget\Html\Pager;
1313
use Magento\Catalog\Model\Product;
14+
use Magento\Catalog\Model\Product\Attribute\Source\Status as ProductStatus;
1415
use Magento\Catalog\Model\Product\Visibility;
1516
use Magento\Catalog\Model\ResourceModel\Product\Collection;
1617
use Magento\Catalog\Model\ResourceModel\Product\CollectionFactory;
@@ -371,6 +372,7 @@ public function getBaseCollection(): Collection
371372
*/
372373
$collection = $this->_addProductAttributesAndPrices($collection)
373374
->addStoreFilter()
375+
->addAttributeToFilter(Product::STATUS, ProductStatus::STATUS_ENABLED)
374376
->addAttributeToSort('entity_id', 'desc')
375377
->setPageSize($this->getPageSize())
376378
->setCurPage($this->getRequest()->getParam($this->getData('page_var_name'), 1));

app/code/Magento/CatalogWidget/Test/Unit/Block/Product/ProductsListTest.php

Lines changed: 23 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
use Magento\Catalog\Block\Product\Widget\Html\Pager;
1111
use Magento\Catalog\Model\Product;
12+
use Magento\Catalog\Model\Product\Attribute\Source\Status as ProductStatus;
1213
use Magento\Catalog\Model\Product\Visibility;
1314
use Magento\Catalog\Model\ResourceModel\Product\Collection;
1415
use Magento\Catalog\Model\ResourceModel\Product\CollectionFactory;
@@ -41,57 +42,57 @@ class ProductsListTest extends TestCase
4142
/**
4243
* @var ProductsList
4344
*/
44-
protected $productsList;
45+
private $productsList;
4546

4647
/**
4748
* @var CollectionFactory|MockObject
4849
*/
49-
protected $collectionFactory;
50+
private $collectionFactory;
5051

5152
/**
5253
* @var Visibility|MockObject
5354
*/
54-
protected $visibility;
55+
private $visibility;
5556

5657
/**
5758
* @var Context|MockObject
5859
*/
59-
protected $httpContext;
60+
private $httpContext;
6061

6162
/**
6263
* @var Builder|MockObject
6364
*/
64-
protected $builder;
65+
private $builder;
6566

6667
/**
6768
* @var Rule|MockObject
6869
*/
69-
protected $rule;
70+
private $rule;
7071

7172
/**
7273
* @var Conditions|MockObject
7374
*/
74-
protected $widgetConditionsHelper;
75+
private $widgetConditionsHelper;
7576

7677
/**
7778
* @var StoreManagerInterface|MockObject
7879
*/
79-
protected $storeManager;
80+
private $storeManager;
8081

8182
/**
8283
* @var DesignInterface
8384
*/
84-
protected $design;
85+
private $design;
8586

8687
/**
8788
* @var RequestInterface
8889
*/
89-
protected $request;
90+
private $request;
9091

9192
/**
9293
* @var LayoutInterface
9394
*/
94-
protected $layout;
95+
private $layout;
9596

9697
/**
9798
* @var PriceCurrencyInterface|MockObject
@@ -105,24 +106,15 @@ class ProductsListTest extends TestCase
105106

106107
protected function setUp(): void
107108
{
108-
$this->collectionFactory =
109-
$this->getMockBuilder(CollectionFactory::class)
110-
->onlyMethods(['create'])
111-
->disableOriginalConstructor()
112-
->getMock();
113-
$this->visibility = $this->getMockBuilder(Visibility::class)
114-
->onlyMethods(['getVisibleInCatalogIds'])
115-
->disableOriginalConstructor()
116-
->getMock();
109+
$this->collectionFactory = $this->createMock(CollectionFactory::class);
110+
$this->visibility = $this->createMock(Visibility::class);
117111
$this->httpContext = $this->createMock(Context::class);
118112
$this->builder = $this->createMock(Builder::class);
119113
$this->rule = $this->createMock(Rule::class);
120114
$this->serializer = $this->createMock(Json::class);
121-
$this->widgetConditionsHelper = $this->getMockBuilder(Conditions::class)
122-
->disableOriginalConstructor()
123-
->getMock();
124-
$this->storeManager = $this->getMockForAbstractClass(StoreManagerInterface::class);
125-
$this->design = $this->getMockForAbstractClass(DesignInterface::class);
115+
$this->widgetConditionsHelper = $this->createMock(Conditions::class);
116+
$this->storeManager = $this->createMock(StoreManagerInterface::class);
117+
$this->design = $this->createMock(DesignInterface::class);
126118

127119
$objectManagerHelper = new ObjectManagerHelper($this);
128120
$arguments = $objectManagerHelper->getConstructArguments(
@@ -141,7 +133,7 @@ protected function setUp(): void
141133
);
142134
$this->request = $arguments['context']->getRequest();
143135
$this->layout = $arguments['context']->getLayout();
144-
$this->priceCurrency = $this->getMockForAbstractClass(PriceCurrencyInterface::class);
136+
$this->priceCurrency = $this->createMock(PriceCurrencyInterface::class);
145137

146138
$this->productsList = $objectManagerHelper->getObject(
147139
ProductsList::class,
@@ -297,21 +289,7 @@ public function testCreateCollection($pagerEnable, $productsCount, $productsPerP
297289
{
298290
$this->visibility->expects($this->once())->method('getVisibleInCatalogIds')
299291
->willReturn([Visibility::VISIBILITY_IN_CATALOG, Visibility::VISIBILITY_BOTH]);
300-
$collection = $this->getMockBuilder(Collection::class)
301-
->onlyMethods([
302-
'setVisibility',
303-
'addMinimalPrice',
304-
'addFinalPrice',
305-
'addTaxPercents',
306-
'addAttributeToSelect',
307-
'addUrlRewrite',
308-
'addStoreFilter',
309-
'addAttributeToSort',
310-
'setPageSize',
311-
'setCurPage',
312-
'distinct'
313-
])->disableOriginalConstructor()
314-
->getMock();
292+
$collection = $this->createMock(Collection::class);
315293
$collection->expects($this->once())->method('setVisibility')
316294
->with([Visibility::VISIBILITY_IN_CATALOG, Visibility::VISIBILITY_BOTH])
317295
->willReturnSelf();
@@ -321,6 +299,10 @@ public function testCreateCollection($pagerEnable, $productsCount, $productsPerP
321299
$collection->expects($this->once())->method('addAttributeToSelect')->willReturnSelf();
322300
$collection->expects($this->once())->method('addUrlRewrite')->willReturnSelf();
323301
$collection->expects($this->once())->method('addStoreFilter')->willReturnSelf();
302+
$collection->expects($this->once())
303+
->method('addAttributeToFilter')
304+
->with(Product::STATUS, ProductStatus::STATUS_ENABLED)
305+
->willReturnSelf();
324306
$collection->expects($this->once())->method('addAttributeToSort')->with('entity_id', 'desc')->willReturnSelf();
325307
$collection->expects($this->once())->method('setPageSize')->with($expectedPageSize)->willReturnSelf();
326308
$collection->expects($this->once())->method('setCurPage')->willReturnSelf();

dev/tests/integration/testsuite/Magento/CatalogWidget/Block/Product/ProductListTest.php renamed to dev/tests/integration/testsuite/Magento/CatalogWidget/Block/Product/ProductsListTest.php

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
use Magento\Bundle\Test\Fixture\Option as BundleOptionFixture;
1010
use Magento\Bundle\Test\Fixture\Product as BundleProductFixture;
11+
use Magento\Catalog\Model\Product\Attribute\Source\Status as ProductStatus;
1112
use Magento\Catalog\Test\Fixture\MultiselectAttribute as MultiselectAttributeFixture;
1213
use Magento\Catalog\Test\Fixture\Category as CategoryFixture;
1314
use Magento\Catalog\Test\Fixture\Product as ProductFixture;
@@ -20,31 +21,33 @@
2021
use Magento\TestFramework\Fixture\DataFixtureStorageManager;
2122
use Magento\TestFramework\Fixture\DbIsolation;
2223
use Magento\TestFramework\Helper\Bootstrap;
24+
use PHPUnit\Framework\Attributes\CoversClass;
2325
use PHPUnit\Framework\Attributes\DataProvider;
2426
use PHPUnit\Framework\TestCase;
2527

2628
/**
27-
* Tests for @see \Magento\CatalogWidget\Block\Product\ProductsList
28-
*
2929
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
3030
*/
31-
class ProductListTest extends TestCase
31+
#[
32+
CoversClass(ProductsList::class),
33+
DbIsolation(false),
34+
]
35+
class ProductsListTest extends TestCase
3236
{
3337
/**
3438
* @var ProductsList
3539
*/
36-
protected $block;
40+
private $block;
3741

3842
/**
3943
* @var CategoryCollection;
40-
4144
*/
4245
private $categoryCollection;
4346

4447
/**
4548
* @var ObjectManagerInterface
4649
*/
47-
protected $objectManager;
50+
private $objectManager;
4851

4952
/**
5053
* @var DataFixtureStorage
@@ -56,7 +59,7 @@ protected function setUp(): void
5659
$this->objectManager = Bootstrap::getObjectManager();
5760
$this->block = $this->objectManager->create(ProductsList::class);
5861
$this->categoryCollection = $this->objectManager->create(CategoryCollection::class);
59-
$this->fixtures = Bootstrap::getObjectManager()->get(DataFixtureStorageManager::class)->getStorage();
62+
$this->fixtures = $this->objectManager->get(DataFixtureStorageManager::class)->getStorage();
6063
}
6164

6265
/**
@@ -67,10 +70,10 @@ protected function setUp(): void
6770
* 3. Create product list widget condition based on the new multiselect attribute
6871
* 4. Set at least 2 options of multiselect attribute to match products for the product list widget
6972
* 5. Load collection for product list widget and make sure that number of loaded products is correct
70-
*
71-
* @magentoDbIsolation disabled
72-
* @magentoDataFixture Magento/Catalog/_files/products_with_multiselect_attribute.php
7373
*/
74+
#[
75+
DataFixture('Magento/Catalog/_files/products_with_multiselect_attribute.php'),
76+
]
7477
public function testCreateCollection()
7578
{
7679
// Reindex EAV attributes to enable products filtration by created multiselect attribute
@@ -111,10 +114,10 @@ public function testCreateCollection()
111114

112115
/**
113116
* Test product list widget can process condition with dropdown type of attribute
114-
*
115-
* @magentoDbIsolation disabled
116-
* @magentoDataFixture Magento/Catalog/_files/products_with_dropdown_attribute.php
117117
*/
118+
#[
119+
DataFixture('Magento/Catalog/_files/products_with_dropdown_attribute.php'),
120+
]
118121
public function testCreateCollectionWithDropdownAttribute()
119122
{
120123
/** @var $attribute Attribute */
@@ -166,15 +169,15 @@ private function performAssertions(int $count)
166169
/**
167170
* Check that collection returns correct result if use not contains operator for string attribute
168171
*
169-
* @magentoDbIsolation disabled
170-
* @magentoDataFixture Magento/Catalog/_files/product_simple_xss.php
171-
* @magentoDataFixture Magento/Catalog/_files/product_virtual.php
172-
* @dataProvider createCollectionForSkuDataProvider
173172
* @param string $encodedConditions
174173
* @param string $sku
175-
* @return void
176-
* @throws \Magento\Framework\Exception\LocalizedException
177174
*/
175+
#[
176+
DataFixture('Magento/Catalog/_files/product_simple_xss.php'),
177+
DataFixture('Magento/Catalog/_files/product_virtual.php'),
178+
DataFixture(ProductFixture::class, ['status' => ProductStatus::STATUS_DISABLED]),
179+
DataProvider('createCollectionForSkuDataProvider'),
180+
]
178181
public function testCreateCollectionForSku($encodedConditions, $sku)
179182
{
180183
$this->block->setData('conditions_encoded', $encodedConditions);
@@ -207,12 +210,10 @@ public static function createCollectionForSkuDataProvider()
207210

208211
/**
209212
* Check that collection returns correct result if use date attribute.
210-
*
211-
* @magentoDbIsolation disabled
212-
* @magentoDataFixture Magento/Catalog/_files/product_simple_with_date_attribute.php
213-
* @return void
214-
* @throws \Magento\Framework\Exception\LocalizedException
215213
*/
214+
#[
215+
DataFixture('Magento/Catalog/_files/product_simple_with_date_attribute.php'),
216+
]
216217
public function testProductListWithDateAttribute()
217218
{
218219
$encodedConditions = '^[`1`:^[`type`:`Magento||CatalogWidget||Model||Rule||Condition||Combine`,'
@@ -238,10 +239,10 @@ public function testProductListWithDateAttribute()
238239
* 2. Create 2 new products and assign them to the sub categories
239240
* 3. Create product list widget condition to display products from the anchor root category
240241
* 4. Load collection for product list widget and make sure that number of loaded products is correct
241-
*
242-
* @magentoDbIsolation disabled
243-
* @magentoDataFixture Magento/Catalog/_files/product_in_nested_anchor_categories.php
244242
*/
243+
#[
244+
DataFixture('Magento/Catalog/_files/product_in_nested_anchor_categories.php'),
245+
]
245246
public function testCreateAnchorCollection()
246247
{
247248
// Reindex EAV attributes to enable products filtration by created multiselect attribute
@@ -276,7 +277,6 @@ public function testCreateAnchorCollection()
276277
}
277278

278279
#[
279-
DbIsolation(false),
280280
DataFixture(ProductFixture::class, ['price' => 10], 'p1'),
281281
DataFixture(ProductFixture::class, ['price' => 20], 'p2'),
282282
DataFixture(BundleOptionFixture::class, ['product_links' => ['$p1$', '$p2$']], 'opt1'),
@@ -301,14 +301,15 @@ public function testBundleProductList()
301301
/**
302302
* Test that price rule condition works correctly
303303
*
304-
* @magentoDbIsolation disabled
305-
* @magentoDataFixture Magento/Catalog/_files/category_with_different_price_products.php
306-
* @magentoDataFixture Magento/ConfigurableProduct/_files/product_configurable.php
307304
* @param string $operator
308305
* @param int $value
309306
* @param array $matches
310-
* @dataProvider priceFilterDataProvider
311307
*/
308+
#[
309+
DataFixture('Magento/Catalog/_files/category_with_different_price_products.php'),
310+
DataFixture('Magento/ConfigurableProduct/_files/product_configurable.php'),
311+
DataProvider('priceFilterDataProvider'),
312+
]
312313
public function testPriceFilter(string $operator, int $value, array $matches)
313314
{
314315
$encodedConditions = '^[`1`:^[`type`:`Magento||CatalogWidget||Model||Rule||Condition||Combine`,
@@ -375,7 +376,6 @@ public static function priceFilterDataProvider(): array
375376
}
376377

377378
#[
378-
DbIsolation(false),
379379
DataProvider('collectionResultWithMultiselectAttributeDataProvider'),
380380
DataFixture(
381381
MultiselectAttributeFixture::class,

0 commit comments

Comments
 (0)