Skip to content

Commit 76e9e1c

Browse files
committed
PB-261: Add Missing Integration P0-P1 Tests For Products
- add more data to tests
1 parent 4e99a86 commit 76e9e1c

File tree

2 files changed

+87
-24
lines changed

2 files changed

+87
-24
lines changed

dev/tests/integration/testsuite/Magento/PageBuilder/Model/Catalog/SortingTest.php

Lines changed: 39 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@
66

77
namespace Magento\PageBuilder\Model\Catalog;
88

9+
use Magento\Catalog\Model\ResourceModel\Product\Collection;
10+
use Magento\Catalog\Model\ResourceModel\Product\CollectionFactory;
911
use Magento\Framework\Exception\NoSuchEntityException;
12+
use Magento\Indexer\Model\Indexer;
1013
use Magento\TestFramework\Helper\Bootstrap;
1114
use Magento\Catalog\Api\CategoryRepositoryInterface;
1215
use Magento\CatalogWidget\Block\Product\ProductsList;
@@ -17,12 +20,12 @@
1720
class SortingTest extends \PHPUnit\Framework\TestCase
1821
{
1922
/**
20-
* @var \Magento\Catalog\Model\ResourceModel\Product\CollectionFactory
23+
* @var CollectionFactory
2124
*/
2225
private $productCollectionFactory;
2326

2427
/**
25-
* @var \Magento\PageBuilder\Model\Catalog\Sorting
28+
* @var Sorting
2629
*/
2730
private $sortModel;
2831

@@ -32,7 +35,7 @@ class SortingTest extends \PHPUnit\Framework\TestCase
3235
private $categoryRepository;
3336

3437
/**
35-
* @var \Magento\Indexer\Model\Indexer
38+
* @var Indexer
3639
*/
3740
protected $indexer;
3841

@@ -53,7 +56,7 @@ protected function setUp()
5356
{
5457
$objectManager = Bootstrap::getObjectManager();
5558
$this->productCollectionFactory = $objectManager->create(
56-
\Magento\Catalog\Model\ResourceModel\Product\CollectionFactory::class
59+
CollectionFactory::class
5760
);
5861
$this->sortModel = $objectManager->create(Sorting::class);
5962
$this->categoryRepository = $objectManager->create(
@@ -99,7 +102,7 @@ public function testSortOptions(array $productSortData)
99102
'PB_VIRTUAL_PRODUCT,simple_second_website,simple1,simple2,simple3,bundle_product,' .
100103
'configurable,simple_11,simple_21,gift-card,grouped,simple_100000001,' .
101104
'simple_100000002,simple-with-fpt,downloadable-product-price-on-product,' .
102-
'downloadable-product-price-on-link'
105+
'downloadable-product-price-on-link,ZERO_QTY_IN_STOCK_PRODUCT,special_price_product'
103106
]
104107
]
105108
),
@@ -149,6 +152,8 @@ public function productSortDataProvider1() : array
149152
'bundle_product',
150153
'simple3',
151154
'simple1',
155+
'special_price_product',
156+
'ZERO_QTY_IN_STOCK_PRODUCT',
152157
'gift-card',
153158
'PB_VIRTUAL_PRODUCT',
154159
'PB_PRODUCT_CPR',
@@ -165,6 +170,8 @@ public function productSortDataProvider1() : array
165170
'PB_PRODUCT_CPR',
166171
'PB_VIRTUAL_PRODUCT',
167172
'gift-card',
173+
'ZERO_QTY_IN_STOCK_PRODUCT',
174+
'special_price_product',
168175
'simple1',
169176
'simple3',
170177
'bundle_product',
@@ -193,9 +200,13 @@ public function productSortDataProvider1() : array
193200
'simple_100000002',
194201
'simple1',
195202
'simple3',
196-
'simple-with-fpt'
203+
'simple-with-fpt',
204+
'special_price_product',
205+
'ZERO_QTY_IN_STOCK_PRODUCT'
197206
],
198207
'name_descending' => [
208+
'ZERO_QTY_IN_STOCK_PRODUCT',
209+
'special_price_product',
199210
'simple-with-fpt',
200211
'simple3',
201212
'simple1',
@@ -246,9 +257,13 @@ public function productSortDataProvider2() : array
246257
'simple1',
247258
'simple3',
248259
'simple_100000001',
249-
'simple_100000002'
260+
'simple_100000002',
261+
'special_price_product',
262+
'ZERO_QTY_IN_STOCK_PRODUCT'
250263
],
251264
'sku_descending' => [
265+
'ZERO_QTY_IN_STOCK_PRODUCT',
266+
'special_price_product',
252267
'simple_100000002',
253268
'simple_100000001',
254269
'simple3',
@@ -269,6 +284,7 @@ public function productSortDataProvider2() : array
269284
],
270285
'low_stock_first' => [
271286
'gift-card',
287+
'ZERO_QTY_IN_STOCK_PRODUCT',
272288
'bundle_product',
273289
'configurable',
274290
'grouped',
@@ -284,9 +300,11 @@ public function productSortDataProvider2() : array
284300
'PB_VIRTUAL_PRODUCT',
285301
'simple1',
286302
'simple3',
287-
'C_PB_PRODUCT'
303+
'C_PB_PRODUCT',
304+
'special_price_product'
288305
],
289306
'high_stock_first' => [
307+
'special_price_product',
290308
'C_PB_PRODUCT',
291309
'simple3',
292310
'simple1',
@@ -303,6 +321,7 @@ public function productSortDataProvider2() : array
303321
'grouped',
304322
'configurable',
305323
'bundle_product',
324+
'ZERO_QTY_IN_STOCK_PRODUCT',
306325
'gift-card'
307326
],
308327
],
@@ -323,6 +342,7 @@ public function productSortDataProvider3() : array
323342
'price_high_to_low' => [
324343
'bundle_product',
325344
'1_PB_PRODUCT',
345+
'ZERO_QTY_IN_STOCK_PRODUCT',
326346
'PB_VIRTUAL_PRODUCT',
327347
'simple_100000001',
328348
'simple-with-fpt',
@@ -335,6 +355,7 @@ public function productSortDataProvider3() : array
335355
'simple3',
336356
'simple1',
337357
'configurable',
358+
'special_price_product',
338359
'downloadable-product-price-on-link',
339360
'gift-card',
340361
'B_PB_PRODUCT'
@@ -343,6 +364,7 @@ public function productSortDataProvider3() : array
343364
'B_PB_PRODUCT',
344365
'gift-card',
345366
'downloadable-product-price-on-link',
367+
'special_price_product',
346368
'configurable',
347369
'simple1',
348370
'simple3',
@@ -355,6 +377,7 @@ public function productSortDataProvider3() : array
355377
'simple-with-fpt',
356378
'simple_100000001',
357379
'PB_VIRTUAL_PRODUCT',
380+
'ZERO_QTY_IN_STOCK_PRODUCT',
358381
'1_PB_PRODUCT',
359382
'bundle_product'
360383
],
@@ -365,7 +388,9 @@ public function productSortDataProvider3() : array
365388
'C_PB_PRODUCT',
366389
'PB_PRODUCT_CPR',
367390
'PB_VIRTUAL_PRODUCT',
368-
'gift-card'
391+
'gift-card',
392+
'ZERO_QTY_IN_STOCK_PRODUCT',
393+
'special_price_product'
369394
],
370395
'position_by_sku' => [
371396
'B_PB_PRODUCT',
@@ -384,7 +409,9 @@ public function productSortDataProvider3() : array
384409
'simple_100000002',
385410
'simple-with-fpt',
386411
'downloadable-product-price-on-product',
387-
'downloadable-product-price-on-link'
412+
'downloadable-product-price-on-link',
413+
'ZERO_QTY_IN_STOCK_PRODUCT',
414+
'special_price_product',
388415
]
389416
],
390417
]
@@ -394,10 +421,10 @@ public function productSortDataProvider3() : array
394421
/**
395422
* Retrieve SKUs from array
396423
*
397-
* @param \Magento\Catalog\Model\ResourceModel\Product\Collection $collection
424+
* @param Collection $collection
398425
* @return array
399426
*/
400-
private function getSkus(\Magento\Catalog\Model\ResourceModel\Product\Collection $collection): array
427+
private function getSkus(Collection $collection): array
401428
{
402429
$skus = [];
403430
foreach ($collection as $product) {

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

Lines changed: 48 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
*/
66

77
use Magento\Catalog\Api\CategoryLinkManagementInterface;
8+
use Magento\Catalog\Api\CategoryLinkRepositoryInterface;
89
use Magento\Catalog\Api\Data\CategoryProductLinkInterface;
910
use Magento\Catalog\Model\Category;
1011
use Magento\Catalog\Model\Product;
@@ -15,8 +16,9 @@
1516
use Magento\GiftCard\Model\Giftcard;
1617
use Magento\GiftCard\Model\Catalog\Product\Type\Giftcard as GiftcardType;
1718
use Magento\Store\Model\Website;
19+
use Magento\TestFramework\Helper\Bootstrap;
1820

19-
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
21+
$objectManager = Bootstrap::getObjectManager();
2022

2123
$category = $objectManager->create(Category::class);
2224
$category->isObjectNew(true);
@@ -34,7 +36,7 @@
3436
/* @var $productRepository ProductRepository */
3537
$productRepository = $objectManager->create(ProductRepository::class);
3638
$categoryLinkRepository = $objectManager->create(
37-
\Magento\Catalog\Api\CategoryLinkRepositoryInterface::class,
39+
CategoryLinkRepositoryInterface::class,
3840
[
3941
'productRepository' => $productRepository
4042
]
@@ -44,7 +46,6 @@
4446
/** @var $firstProduct Product */
4547
$firstProduct = $objectManager->create(Product::class);
4648
$firstProduct->setTypeId(Type::TYPE_SIMPLE)
47-
->setId(666)
4849
->setCreatedAt('2010-01-01 01:01:01')
4950
->setUpdatedAt('2010-01-01 01:01:01')
5051
->setAttributeSetId(4)
@@ -68,7 +69,6 @@
6869
/** @var $secondProduct Product */
6970
$secondProduct = $objectManager->create(Product::class);
7071
$secondProduct->setTypeId(Type::TYPE_SIMPLE)
71-
->setId(667)
7272
->setCreatedAt('2017-01-01 01:01:01')
7373
->setUpdatedAt('2017-01-01 01:01:01')
7474
->setAttributeSetId(4)
@@ -92,7 +92,6 @@
9292
/** @var $thirdProduct Product */
9393
$thirdProduct = $objectManager->create(Product::class);
9494
$thirdProduct->setTypeId(Type::TYPE_SIMPLE)
95-
->setId(668)
9695
->setCreatedAt('2000-01-01 01:01:01')
9796
->setUpdatedAt('2000-01-01 01:01:01')
9897
->setAttributeSetId(4)
@@ -116,7 +115,6 @@
116115
/** @var $fourthProduct Product */
117116
$fourthProduct = $objectManager->create(Product::class);
118117
$fourthProduct->setTypeId(Type::TYPE_SIMPLE)
119-
->setId(669)
120118
->setCreatedAt('2017-01-05 01:01:01')
121119
->setUpdatedAt('2017-01-05 01:01:01')
122120
->setAttributeSetId(4)
@@ -140,7 +138,6 @@
140138
/** @var Product $productWithCatalogPriceRule */
141139
$productWithCatalogPriceRule = $objectManager->create(Product::class);
142140
$productWithCatalogPriceRule->setTypeId(Type::TYPE_SIMPLE)
143-
->setId(670)
144141
->setCreatedAt('2018-01-05 01:01:01')
145142
->setUpdatedAt('2018-01-05 01:01:01')
146143
->setAttributeSetId(4)
@@ -162,7 +159,6 @@
162159
/** @var Product $productWithCatalogPriceRule */
163160
$virtualProduct = $objectManager->create(Product::class);
164161
$virtualProduct->setTypeId(Type::TYPE_VIRTUAL)
165-
->setId(671)
166162
->setCreatedAt('2018-01-06 01:01:01')
167163
->setUpdatedAt('2018-01-06 01:01:01')
168164
->setAttributeSetId(4)
@@ -189,7 +185,6 @@
189185
/** @var Product $productInSecondWebsite */
190186
$productInSecondWebsite = $objectManager->create(Product::class);
191187
$productInSecondWebsite->setTypeId(Type::TYPE_SIMPLE)
192-
->setId(672)
193188
->setCreatedAt('2018-01-07 01:01:01')
194189
->setUpdatedAt('2018-01-07 01:01:01')
195190
->setAttributeSetId(4)
@@ -213,7 +208,6 @@
213208
/** @var Product $giftCardProduct */
214209
$giftCardProduct = $objectManager->create(Product::class);
215210
$giftCardProduct->setTypeId(GiftcardType::TYPE_GIFTCARD)
216-
->setId(673)
217211
->setCreatedAt('2019-01-07 01:01:01')
218212
->setUpdatedAt('2019-01-07 01:01:01')
219213
->setAttributeSetId(4)
@@ -234,7 +228,6 @@
234228
/** @var Product $oosProduct */
235229
$oosProduct = $objectManager->create(Product::class);
236230
$oosProduct->setTypeId(Type::TYPE_SIMPLE)
237-
->setId(674)
238231
->setCreatedAt('2007-01-05 01:01:01')
239232
->setUpdatedAt('2007-01-05 01:01:01')
240233
->setAttributeSetId(4)
@@ -255,6 +248,47 @@
255248
->setStatus(Status::STATUS_ENABLED);
256249
$productRepository->save($oosProduct);
257250

251+
/** @var Product $zeroQuantityProduct */
252+
$zeroQuantityInStockProduct = $objectManager->create(Product::class);
253+
$zeroQuantityInStockProduct->setTypeId(Type::TYPE_SIMPLE)
254+
->setAttributeSetId(4)
255+
->setStoreId(1)
256+
->setWebsiteIds([1])
257+
->setName('Zero Quantity In Stock Product')
258+
->setSku('ZERO_QTY_IN_STOCK_PRODUCT')
259+
->setPrice(98)
260+
->setWeight(0)
261+
->setStockData(
262+
[
263+
'qty' => 0,
264+
'is_in_stock' => true
265+
]
266+
)
267+
->setVisibility(Visibility::VISIBILITY_BOTH)
268+
->setStatus(Status::STATUS_ENABLED);
269+
$productRepository->save($zeroQuantityInStockProduct);
270+
271+
/** @var Product $zeroQuantityProduct */
272+
$specialPriceProduct = $objectManager->create(Product::class);
273+
$specialPriceProduct->setTypeId(Type::TYPE_SIMPLE)
274+
->setAttributeSetId(4)
275+
->setStoreId(1)
276+
->setWebsiteIds([1])
277+
->setName('Special Price Product')
278+
->setSku('special_price_product')
279+
->setPrice(999)
280+
->setSpecialPrice('1.99')
281+
->setWeight(0)
282+
->setStockData(
283+
[
284+
'qty' => 1000,
285+
'is_in_stock' => true
286+
]
287+
)
288+
->setVisibility(Visibility::VISIBILITY_BOTH)
289+
->setStatus(Status::STATUS_ENABLED);
290+
$productRepository->save($specialPriceProduct);
291+
258292
// assign positions and categories
259293
$productPositions = [
260294
'1_PB_PRODUCT' => 3,
@@ -265,7 +299,9 @@
265299
'PB_VIRTUAL_PRODUCT' => 6,
266300
'simple_second_website' => 7,
267301
'gift-card' => 8,
268-
'OOS_PB_PRODUCT' => 9
302+
'OOS_PB_PRODUCT' => 9,
303+
'ZERO_QTY_IN_STOCK_PRODUCT' => 10,
304+
'special_price_product' => 11
269305
];
270306

271307
foreach ($productPositions as $sku => $position) {

0 commit comments

Comments
 (0)