Skip to content

Commit 7f7d1e9

Browse files
committed
PB-107: Display total number of products matched into ProductsList
- Improve integration test
1 parent d4d685e commit 7f7d1e9

File tree

3 files changed

+93
-33
lines changed

3 files changed

+93
-33
lines changed

dev/tests/integration/testsuite/Magento/PageBuilder/Controller/Adminhtml/Form/Element/ProductTotalsTest.php

Lines changed: 32 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -30,32 +30,22 @@ protected function setUp()
3030

3131
/**
3232
* @param string condition
33-
* @param int $expectedTotal
34-
* @param int $expectedDisabled
35-
* @param int $expectedNotVisible
36-
* @param int $expectedOutOfStock
33+
* @param int $expectedTotals
3734
* @dataProvider productDataProvider
3835
*/
3936
public function testProductTotals(
4037
$condition,
41-
$expectedTotal,
42-
$expectedDisabled,
43-
$expectedNotVisible,
44-
$expectedOutOfStock
38+
$expectedTotals
4539
) {
4640
$this->getRequest()->setMethod(\Magento\Framework\App\Request\Http::METHOD_POST);
4741
$this->getRequest()->setPostValue(['conditionValue' => json_encode($condition)]);
4842

4943
$this->dispatch('backend/pagebuilder/form/element_producttotals');
5044
$decoded = $this->serializer->unserialize($this->getResponse()->getBody());
5145

52-
$this->assertEquals($expectedTotal, $decoded['total'], 'Failed asserting total count matches.');
53-
$this->assertEquals($expectedDisabled, $decoded['disabled'], 'Failed asserting disabled count matches.');
54-
$this->assertEquals($expectedNotVisible, $decoded['notVisible'], 'Failed asserting not visible count matches.');
5546
$this->assertEquals(
56-
$expectedOutOfStock,
57-
$decoded['outOfStock'],
58-
'Failed asserting out of stock count matches.'
47+
[$decoded['total'], $decoded['disabled'], $decoded['notVisible'], $decoded['outOfStock']],
48+
$expectedTotals
5949
);
6050
}
6151

@@ -78,7 +68,8 @@ public function productDataProvider()
7868
'attribute' => 'category_ids',
7969
'value' => '4'
8070
]
81-
], 0, 0, 0, 0
71+
],
72+
[0, 0, 0, 0]
8273
],
8374
[ // #1 category with 4 products, 3 disabled, 3 not visible
8475
['1' => [
@@ -93,7 +84,8 @@ public function productDataProvider()
9384
'attribute' => 'category_ids',
9485
'value' => '3'
9586
]
96-
], 7, 3, 3, 1
87+
],
88+
[8, 3, 3, 1]
9789
],
9890
[ // #2 sku with no matches
9991
['1' => [
@@ -108,7 +100,8 @@ public function productDataProvider()
108100
'attribute' => 'sku',
109101
'value' => 'shoes'
110102
]
111-
], 0, 0, 0, 0
103+
],
104+
[0, 0, 0, 0]
112105
],
113106
[ // #3 sku with 2 matches, 1 disabled, 1 not visible, 1 out of stock
114107
['1' => [
@@ -123,7 +116,8 @@ public function productDataProvider()
123116
'attribute' => 'sku',
124117
'value' => 'not-visible-on-storefront, disabled-product, out-of-stock'
125118
]
126-
], 3, 1, 1, 1
119+
],
120+
[3, 1, 1, 1]
127121
],
128122
[ // #4 condition with no matches
129123
['1' => [
@@ -138,7 +132,8 @@ public function productDataProvider()
138132
'attribute' => 'price',
139133
'value' => '10000'
140134
]
141-
], 0, 0, 0, 0
135+
],
136+
[0, 0, 0, 0]
142137
],
143138
[ // #5 condition with 3 matches, 1 disabled, 1 not visible
144139
['1' => [
@@ -153,7 +148,24 @@ public function productDataProvider()
153148
'attribute' => 'price',
154149
'value' => '20'
155150
]
156-
], 3, 1, 1, 0
151+
],
152+
[3, 1, 1, 0]
153+
],
154+
[ // #6 2 configurable products with multiple children, 1 disabled
155+
['1' => [
156+
'aggregator' => 'all',
157+
'new_child' => '',
158+
'type' => \Magento\CatalogWidget\Model\Rule\Condition\Combine::class,
159+
'value' => '1',
160+
],
161+
'1--1' => [
162+
'operator' => '==',
163+
'type' => \Magento\CatalogWidget\Model\Rule\Condition\Product::class,
164+
'attribute' => 'category_ids',
165+
'value' => '5'
166+
]
167+
],
168+
[2, 1, 0, 0]
157169
],
158170
];
159171
}

dev/tests/integration/testsuite/Magento/PageBuilder/_files/product_totals/products.php

Lines changed: 58 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,12 @@
99
->getEntityType('catalog_product')
1010
->getDefaultAttributeSetId();
1111

12+
/* @var \Magento\Catalog\Api\ProductRepositoryInterface $productRepository */
1213
$productRepository = $objectManager->create(
1314
\Magento\Catalog\Api\ProductRepositoryInterface::class
1415
);
1516

17+
/* @var \Magento\Catalog\Api\CategoryLinkRepositoryInterface $categoryLinkRepository */
1618
$categoryLinkRepository = $objectManager->create(
1719
\Magento\Catalog\Api\CategoryLinkRepositoryInterface::class,
1820
[
@@ -67,6 +69,21 @@
6769
->setDescription('Category 1.1 description.')
6870
->save();
6971

72+
$category = $objectManager->create(\Magento\Catalog\Model\Category::class);
73+
$category->isObjectNew(true);
74+
$category->setId(5)
75+
->setName('Configurable Product Category')
76+
->setParentId(3)
77+
->setPath('1/2/3/5')
78+
->setLevel(3)
79+
->setAvailableSortBy('name')
80+
->setDefaultSortBy('name')
81+
->setIsActive(true)
82+
->setIsAnchor(true)
83+
->setPosition(1)
84+
->setDescription('Configurable Product Category')
85+
->save();
86+
7087
if (!function_exists('createTestProduct')) {
7188
/**
7289
* Create a test product
@@ -79,8 +96,15 @@
7996
* @param $categoryLinkManagement
8097
* @throws Exception
8198
*/
82-
function createTestProduct($name, $sku, $modifier, $objectManager, $defaultAttributeSet, $categoryLinkManagement)
83-
{
99+
function createTestProduct(
100+
$name,
101+
$sku,
102+
$modifier,
103+
$objectManager,
104+
$defaultAttributeSet,
105+
$categoryLinkManagement,
106+
$productRepository
107+
) {
84108
/** @var $product \Magento\Catalog\Model\Product */
85109
$product = $objectManager->create(\Magento\Catalog\Model\Product::class);
86110
$product->isObjectNew(true);
@@ -100,7 +124,7 @@ function createTestProduct($name, $sku, $modifier, $objectManager, $defaultAttri
100124
$product = $modifier($product);
101125
}
102126

103-
$product->save();
127+
$productRepository->save($product);
104128

105129
$categoryLinkManagement->assignProductToCategories(
106130
$product->getSku(),
@@ -116,7 +140,8 @@ function createTestProduct($name, $sku, $modifier, $objectManager, $defaultAttri
116140
false,
117141
$objectManager,
118142
$defaultAttributeSet,
119-
$categoryLinkManagement
143+
$categoryLinkManagement,
144+
$productRepository
120145
);
121146

122147
// Create same product as above with SKU as numbers
@@ -130,7 +155,8 @@ function (\Magento\Catalog\Model\Product $product) {
130155
},
131156
$objectManager,
132157
$defaultAttributeSet,
133-
$categoryLinkManagement
158+
$categoryLinkManagement,
159+
$productRepository
134160
);
135161

136162
// Create a product not visible on store front
@@ -145,7 +171,8 @@ function (\Magento\Catalog\Model\Product $product) {
145171
},
146172
$objectManager,
147173
$defaultAttributeSet,
148-
$categoryLinkManagement
174+
$categoryLinkManagement,
175+
$productRepository
149176
);
150177

151178
// Create disabled product
@@ -158,7 +185,8 @@ function (\Magento\Catalog\Model\Product $product) {
158185
},
159186
$objectManager,
160187
$defaultAttributeSet,
161-
$categoryLinkManagement
188+
$categoryLinkManagement,
189+
$productRepository
162190
);
163191

164192
// Create an out of stock product
@@ -178,7 +206,8 @@ function (\Magento\Catalog\Model\Product $product) {
178206
},
179207
$objectManager,
180208
$defaultAttributeSet,
181-
$categoryLinkManagement
209+
$categoryLinkManagement,
210+
$productRepository
182211
);
183212

184213
// Create a disabled, not visible product
@@ -194,7 +223,8 @@ function (\Magento\Catalog\Model\Product $product) {
194223
},
195224
$objectManager,
196225
$defaultAttributeSet,
197-
$categoryLinkManagement
226+
$categoryLinkManagement,
227+
$productRepository
198228
);
199229

200230
// Create a disabled, out of stock, not visible product
@@ -216,5 +246,22 @@ function (\Magento\Catalog\Model\Product $product) {
216246
},
217247
$objectManager,
218248
$defaultAttributeSet,
219-
$categoryLinkManagement
220-
);
249+
$categoryLinkManagement,
250+
$productRepository
251+
);
252+
253+
// Create a standard virtual product
254+
createTestProduct(
255+
'Virtual Product',
256+
'virtual-product',
257+
function (\Magento\Catalog\Model\Product $product) {
258+
$product->setPrice(150);
259+
$product->setWeight(22);
260+
$product->setTypeId(\Magento\Catalog\Model\Product\Type::TYPE_VIRTUAL);
261+
return $product;
262+
},
263+
$objectManager,
264+
$defaultAttributeSet,
265+
$categoryLinkManagement,
266+
$productRepository
267+
);

dev/tests/integration/testsuite/Magento/PageBuilder/_files/product_totals/products_rollback.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@
2121
'disabled-product',
2222
'out-of-stock',
2323
'disabled-not-visible-product',
24-
'disabled-out-of-stock-not-visible'
24+
'disabled-out-of-stock-not-visible',
25+
'virtual-product'
2526
];
2627

2728
foreach ($productsToDelete as $sku) {
@@ -36,7 +37,7 @@
3637
//Remove categories
3738
/** @var Magento\Catalog\Model\ResourceModel\Category\Collection $collection */
3839
$collection = $objectManager->create(\Magento\Catalog\Model\ResourceModel\Category\Collection::class);
39-
foreach ($collection->addAttributeToFilter('level', ['in' => [2, 3, 4]]) as $category) {
40+
foreach ($collection->addAttributeToFilter('level', ['in' => [2, 3, 4, 5]]) as $category) {
4041
/** @var \Magento\Catalog\Model\Category $category */
4142
$category->delete();
4243
}

0 commit comments

Comments
 (0)