Skip to content

Commit 5293fb8

Browse files
simsComputinghumeauantadisfballiano
authored
Fix integration tests for Magento_Backend and Magento_Bundle (#134)
* Fix Magento/Beckend/Block/Page/Footer integration test * Fix Magento/Bundle/Model/Product/IsSaleableTest * Fix all other bundle test * Integrate code review changes * Fix CatalogInventory test * Fix stockitem criteria * Fix test on price indexing because of confiurable out of stock * Fix ButtonLock dependency * Fix tests for Magento_Customer * Fix CustomerImportExport module test * Fix Mage-OS Product Name * Fix Magento_Downloadable integration tests * Backward compatibility * Fix customer adresses with empty line * Code review * PHPCS --------- Co-authored-by: s.humeau <humeau@antadis.com> Co-authored-by: simsComputing <simsComputing> Co-authored-by: Fabrizio Balliano <fabrizio.balliano@gmail.com>
1 parent afc98dc commit 5293fb8

File tree

23 files changed

+247
-198
lines changed

23 files changed

+247
-198
lines changed

app/code/Magento/Bundle/Model/ResourceModel/Option/AreBundleOptionsSalable.php

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,10 @@ public function execute(int $entityId, int $storeId): bool
7272
['child_products' => $this->resourceConnection->getTableName('catalog_product_entity')],
7373
'child_products.entity_id = bundle_selections.product_id',
7474
[]
75+
)->joinInner(
76+
['child_stock_item' => $this->resourceConnection->getTableName('cataloginventory_stock_item')],
77+
'child_stock_item.product_id = child_products.entity_id',
78+
[]
7579
)->group(
7680
['bundle_options.parent_id', 'bundle_options.option_id']
7781
)->where(
@@ -103,18 +107,36 @@ public function execute(int $entityId, int $storeId): bool
103107
'1',
104108
'0'
105109
);
110+
111+
$hasMinRequiredQuantity = $connection->getCheckSql(
112+
'required = 1 AND manage_stock = 1 AND selection_can_change_qty = 0',
113+
'(qty >= bundle_selections.selection_qty OR backorders > 0) AND is_in_stock = 1',
114+
'1'
115+
);
116+
117+
$requiredInStock = $connection->getCheckSql(
118+
'required = 1 AND manage_stock = 1 AND selection_can_change_qty = 1',
119+
'(qty >= 0 OR backorders > 0) AND is_in_stock = 1',
120+
'1'
121+
);
122+
106123
$optionsSaleabilitySelect->columns([
107124
'required' => 'bundle_options.required',
108125
'is_salable' => $isOptionSalableExpr,
109126
'is_required_and_unsalable' => $isRequiredOptionUnsalable,
127+
'has_min_required_quantity' => $hasMinRequiredQuantity,
128+
'required_in_stock' => $requiredInStock
110129
]);
111130

112131
$select = $connection->select()->from(
113132
$optionsSaleabilitySelect,
114-
[new \Zend_Db_Expr('(MAX(is_salable) = 1 AND MAX(is_required_and_unsalable) = 0)')]
133+
[new \Zend_Db_Expr(
134+
'(MAX(is_salable) = 1 AND MAX(is_required_and_unsalable) = 0)' .
135+
'AND MIN(required_in_stock) = 1 AND MIN(has_min_required_quantity) = 1'
136+
)]
115137
);
116-
$isSalable = $connection->fetchOne($select);
117138

139+
$isSalable = $connection->fetchOne($select);
118140
return (bool) $isSalable;
119141
}
120142
}

app/code/Magento/CatalogInventory/Model/ResourceModel/Stock/Item/StockItemCriteria.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
use Magento\CatalogInventory\Model\ResourceModel\Stock\Item\StockItemCriteriaMapper;
1111

1212
/**
13-
* Class StockItemCriteria
13+
* Build criteria to filter products on catalog_stockinventory table
1414
*/
1515
class StockItemCriteria extends AbstractCriteria implements \Magento\CatalogInventory\Api\StockItemCriteriaInterface
1616
{
@@ -55,7 +55,11 @@ public function setScopeFilter($scope)
5555
*/
5656
public function setProductsFilter($products)
5757
{
58-
$this->data['products_filter'] = [$products];
58+
if (is_array($products)) {
59+
$this->data['products_filter'] = $products;
60+
} else {
61+
$this->data['products_filter'] = [$products];
62+
}
5963
return true;
6064
}
6165

app/code/Magento/ConfigurableProduct/Model/Inventory/ChangeParentStockStatus.php

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public function __construct(
5959
/**
6060
* Update stock status of configurable products based on children products stock status
6161
*
62-
* @param array $childrenIds
62+
* @param array<string|int> $childrenIds
6363
* @return void
6464
*/
6565
public function execute(array $childrenIds): void
@@ -70,6 +70,17 @@ public function execute(array $childrenIds): void
7070
}
7171
}
7272

73+
/**
74+
* Updates the parent stock status based on children statuses
75+
*
76+
* @param int $parentId
77+
* @return void
78+
*/
79+
public function executeFromParent(int $parentId): void
80+
{
81+
$this->processStockForParent($parentId);
82+
}
83+
7384
/**
7485
* Update stock status of configurable product based on children products stock status
7586
*
@@ -106,6 +117,7 @@ private function processStockForParent(int $productId): void
106117
if ($this->isNeedToUpdateParent($parentStockItem, $childrenIsInStock)) {
107118
$parentStockItem->setIsInStock($childrenIsInStock);
108119
$parentStockItem->setStockStatusChangedAuto(1);
120+
// @phpstan-ignore method.notFound
109121
$parentStockItem->setStockStatusChangedAutomaticallyFlag(true);
110122
$this->stockItemRepository->save($parentStockItem);
111123
}

app/code/Magento/ConfigurableProduct/Model/Inventory/ParentItemProcessor.php

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

88
namespace Magento\ConfigurableProduct\Model\Inventory;
99

10+
use Magento\Catalog\Model\Product\Type;
1011
use Magento\ConfigurableProduct\Model\Product\Type\Configurable;
1112
use Magento\Catalog\Api\Data\ProductInterface as Product;
1213
use Magento\CatalogInventory\Api\StockItemCriteriaInterfaceFactory;
@@ -20,10 +21,7 @@
2021
*/
2122
class ParentItemProcessor implements ParentItemProcessorInterface
2223
{
23-
/**
24-
* @var ChangeParentStockStatus
25-
*/
26-
private $changeParentStockStatus;
24+
private ChangeParentStockStatus $changeParentStockStatus;
2725

2826
/**
2927
* @param Configurable $configurableType
@@ -50,8 +48,12 @@ public function __construct(
5048
* @param Product $product
5149
* @return void
5250
*/
53-
public function process(Product $product)
51+
public function process(Product $product): void
5452
{
55-
$this->changeParentStockStatus->execute([$product->getId()]);
53+
if ($product->getTypeId() === Type::TYPE_SIMPLE) {
54+
$this->changeParentStockStatus->execute([$product->getId()]);
55+
} elseif ($product->getTypeId() === Configurable::TYPE_CODE) {
56+
$this->changeParentStockStatus->executeFromParent((int)$product->getId());
57+
}
5658
}
5759
}

app/code/Magento/Customer/Helper/Address.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,7 @@ public function convertStreetLines($origStreets, $toCount)
330330
}
331331
}
332332

333-
return $lines;
333+
return array_filter($lines);
334334
}
335335

336336
/**

app/code/Magento/Customer/Model/Metadata/Form/Multiline.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ public function outputValue($format = ElementFactory::OUTPUT_FORMAT_TEXT)
116116
$output = implode("<br />", $values);
117117
break;
118118
case ElementFactory::OUTPUT_FORMAT_ONELINE:
119-
$output = implode(" ", $values);
119+
$output = trim(implode(" ", $values), ' ');
120120
break;
121121
default:
122122
$output = implode("\n", $values);

app/code/Magento/Customer/Model/ResourceModel/Grid/Collection.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,6 @@ protected function _initSelect()
7474
{
7575
parent::_initSelect();
7676
$this->joinRegionNameTable();
77-
7877
return $this;
7978
}
8079

app/code/Magento/Customer/Test/Unit/Helper/AddressTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,7 @@ public static function getConvertStreetLinesDataProvider()
242242
return [
243243
[['street1', 'street2', 'street3', 'street4'], 3, ['street1 street2', 'street3', 'street4']],
244244
[['street1', 'street2', 'street3', 'street4'], 2, ['street1 street2', 'street3 street4']],
245+
[['street1', ''], 2, ['street1']]
245246
];
246247
}
247248

dev/tests/integration/testsuite/Magento/Backend/Block/Page/FooterTest.php

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66

77
namespace Magento\Backend\Block\Page;
88

9+
use Magento\Framework\App\CacheInterface;
10+
use Magento\Framework\App\ProductMetadata;
11+
use Magento\TestFramework\Helper\Bootstrap;
12+
913
/**
1014
* Test \Magento\Backend\Block\Page\Footer
1115
*
@@ -16,7 +20,7 @@ class FooterTest extends \PHPUnit\Framework\TestCase
1620
/**
1721
* Test Product Version Value
1822
*/
19-
const TEST_PRODUCT_VERSION = '222.333.444';
23+
private const TEST_PRODUCT_VERSION = '222.333.444';
2024

2125
/**
2226
* @var \Magento\Backend\Block\Page\Footer
@@ -26,13 +30,14 @@ class FooterTest extends \PHPUnit\Framework\TestCase
2630
protected function setUp(): void
2731
{
2832
parent::setUp();
29-
$productMetadataMock = $this->getMockBuilder(\Magento\Framework\App\ProductMetadata::class)
30-
->onlyMethods(['getVersion'])
33+
$productMetadataMock = $this->getMockBuilder(ProductMetadata::class)
3134
->disableOriginalConstructor()
3235
->getMock();
36+
3337
$productMetadataMock->expects($this->once())
34-
->method('getVersion')
38+
->method('getDistributionVersion')
3539
->willReturn($this::TEST_PRODUCT_VERSION);
40+
3641
$this->block = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(
3742
\Magento\Framework\View\LayoutInterface::class
3843
)->createBlock(
@@ -44,6 +49,8 @@ protected function setUp(): void
4449

4550
public function testToHtml()
4651
{
52+
/** @var \Magento\Framework\App\CacheInterface $cacheManager */
53+
Bootstrap::getObjectManager()->create(CacheInterface::class);
4754
$footerContent = $this->block->toHtml();
4855
$this->assertStringContainsString(
4956
'ver. ' . $this::TEST_PRODUCT_VERSION,

dev/tests/integration/testsuite/Magento/Bundle/Model/Product/IsSaleableTest.php

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66

77
namespace Magento\Bundle\Model\Product;
88

9+
use Magento\Framework\Exception\NoSuchEntityException;
10+
911
/**
1012
* Test class for \Magento\Bundle\Model\Product\Type (bundle product type)
1113
*
@@ -216,6 +218,7 @@ public function testIsSaleableOnBundleWithoutSaleableSelectionsOnRequiredOption(
216218
/**
217219
* Check bundle product is NOT saleable if
218220
* there are not enough qty of selection on required option
221+
* when user cannot define own quantities
219222
*
220223
* @magentoAppIsolation enabled
221224
* @covers \Magento\Bundle\Model\Product\Type::isSalable
@@ -224,9 +227,7 @@ public function testIsSaleableOnBundleWithoutSaleableSelectionsOnRequiredOption(
224227
public function testIsSaleableOnBundleWithNotEnoughQtyOfSelection()
225228
{
226229
$this->setQtyForSelections(['simple1', 'simple2', 'simple3'], 1);
227-
228230
$bundleProduct = $this->productRepository->get('bundle-product');
229-
230231
$this->assertFalse(
231232
$bundleProduct->isSalable(),
232233
'Bundle product supposed to be non saleable'
@@ -354,4 +355,22 @@ private function setQtyForSelections($productsSku, $qty)
354355
$this->productRepository->save($product);
355356
}
356357
}
358+
359+
/**
360+
* Check bundle product is not salable if required option where user can
361+
* set own quantity is not in stock
362+
*
363+
* @return void
364+
* @magentoAppIsolation enabled
365+
* @throws NoSuchEntityException
366+
*/
367+
public function testIsSalableOnBundleWithRequiredOptionUserCanChangeQtyWithoutStock()
368+
{
369+
$product = $this->productRepository->get('bundle-product-checkbox-required-option');
370+
$this->setQtyForSelections(['simple1'], 0);
371+
$this->assertFalse(
372+
$product->isSalable(),
373+
'Bundle product with required option that has 0 stock should not be salable'
374+
);
375+
}
357376
}

0 commit comments

Comments
 (0)