Skip to content

Commit d4d685e

Browse files
committed
PB-107: Display total number of products matched into ProductsList
- Add more simple basic test coverage
1 parent 9a0aa2e commit d4d685e

File tree

3 files changed

+76
-10
lines changed

3 files changed

+76
-10
lines changed

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

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public function testProductTotals(
6565
public function productDataProvider()
6666
{
6767
return [
68-
[ // category with no products
68+
[ // #0 category with no products
6969
['1' => [
7070
'aggregator' => 'all',
7171
'new_child' => '',
@@ -80,7 +80,7 @@ public function productDataProvider()
8080
]
8181
], 0, 0, 0, 0
8282
],
83-
[ // category with 4 products, 1 disabled, 1 not visible
83+
[ // #1 category with 4 products, 3 disabled, 3 not visible
8484
['1' => [
8585
'aggregator' => 'all',
8686
'new_child' => '',
@@ -93,9 +93,9 @@ public function productDataProvider()
9393
'attribute' => 'category_ids',
9494
'value' => '3'
9595
]
96-
], 4, 1, 1, 0
96+
], 7, 3, 3, 1
9797
],
98-
[ // sku with no matches
98+
[ // #2 sku with no matches
9999
['1' => [
100100
'aggregator' => 'all',
101101
'new_child' => '',
@@ -110,7 +110,7 @@ public function productDataProvider()
110110
]
111111
], 0, 0, 0, 0
112112
],
113-
[ // sku with 2 matches, 1 disabled, 1 not visible
113+
[ // #3 sku with 2 matches, 1 disabled, 1 not visible, 1 out of stock
114114
['1' => [
115115
'aggregator' => 'all',
116116
'new_child' => '',
@@ -121,11 +121,11 @@ public function productDataProvider()
121121
'operator' => '()',
122122
'type' => \Magento\CatalogWidget\Model\Rule\Condition\Product::class,
123123
'attribute' => 'sku',
124-
'value' => 'not-visible-on-storefront, disabled-product'
124+
'value' => 'not-visible-on-storefront, disabled-product, out-of-stock'
125125
]
126-
], 2, 1, 1, 0
126+
], 3, 1, 1, 1
127127
],
128-
[ // condition with no matches
128+
[ // #4 condition with no matches
129129
['1' => [
130130
'aggregator' => 'all',
131131
'new_child' => '',
@@ -140,7 +140,7 @@ public function productDataProvider()
140140
]
141141
], 0, 0, 0, 0
142142
],
143-
[ // condition with 3 matches, 1 disabled, 1 not visible
143+
[ // #5 condition with 3 matches, 1 disabled, 1 not visible
144144
['1' => [
145145
'aggregator' => 'all',
146146
'new_child' => '',

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

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,3 +160,61 @@ function (\Magento\Catalog\Model\Product $product) {
160160
$defaultAttributeSet,
161161
$categoryLinkManagement
162162
);
163+
164+
// Create an out of stock product
165+
createTestProduct(
166+
'Out of Stock Product',
167+
'out-of-stock',
168+
function (\Magento\Catalog\Model\Product $product) {
169+
$product->setPrice(22.50);
170+
$product->setWeight(100);
171+
$product->setQuantityAndStockStatus(
172+
[
173+
'qty' => 0,
174+
'is_in_stock' => \Magento\CatalogInventory\Model\Stock\Status::STATUS_OUT_OF_STOCK
175+
]
176+
);
177+
return $product;
178+
},
179+
$objectManager,
180+
$defaultAttributeSet,
181+
$categoryLinkManagement
182+
);
183+
184+
// Create a disabled, not visible product
185+
createTestProduct(
186+
'Disabled & Not Visible Product',
187+
'disabled-not-visible-product',
188+
function (\Magento\Catalog\Model\Product $product) {
189+
$product->setPrice(45);
190+
$product->setWeight(2);
191+
$product->setVisibility(\Magento\Catalog\Model\Product\Visibility::VISIBILITY_NOT_VISIBLE);
192+
$product->setStatus(\Magento\Catalog\Model\Product\Attribute\Source\Status::STATUS_DISABLED);
193+
return $product;
194+
},
195+
$objectManager,
196+
$defaultAttributeSet,
197+
$categoryLinkManagement
198+
);
199+
200+
// Create a disabled, out of stock, not visible product
201+
createTestProduct(
202+
'Disabled OOS Not Visible',
203+
'disabled-out-of-stock-not-visible',
204+
function (\Magento\Catalog\Model\Product $product) {
205+
$product->setPrice(150);
206+
$product->setWeight(22);
207+
$product->setQuantityAndStockStatus(
208+
[
209+
'qty' => 0,
210+
'is_in_stock' => \Magento\CatalogInventory\Model\Stock\Status::STATUS_OUT_OF_STOCK
211+
]
212+
);
213+
$product->setVisibility(\Magento\Catalog\Model\Product\Visibility::VISIBILITY_NOT_VISIBLE);
214+
$product->setStatus(\Magento\Catalog\Model\Product\Attribute\Source\Status::STATUS_DISABLED);
215+
return $product;
216+
},
217+
$objectManager,
218+
$defaultAttributeSet,
219+
$categoryLinkManagement
220+
);

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,15 @@
1414
// Remove products
1515
/** @var \Magento\Catalog\Api\ProductRepositoryInterface $productRepository */
1616
$productRepository = $objectManager->create(\Magento\Catalog\Api\ProductRepositoryInterface::class);
17-
$productsToDelete = ['simple', '12345', 'simple-3', 'simple-4'];
17+
$productsToDelete = [
18+
'simple',
19+
'12345',
20+
'not-visible-on-storefront',
21+
'disabled-product',
22+
'out-of-stock',
23+
'disabled-not-visible-product',
24+
'disabled-out-of-stock-not-visible'
25+
];
1826

1927
foreach ($productsToDelete as $sku) {
2028
try {

0 commit comments

Comments
 (0)