Skip to content

Commit 7664bb4

Browse files
author
Stanislav Idolov
authored
ENGCOM-2630: MSI-478: Unskip StockStatusFilterTest #15690
2 parents 21b5750 + de582aa commit 7664bb4

7 files changed

+350
-280
lines changed

dev/tests/integration/testsuite/Magento/Catalog/_files/multiselect_attribute.php

Lines changed: 43 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -12,45 +12,48 @@
1212
$attribute = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
1313
\Magento\Catalog\Model\ResourceModel\Eav\Attribute::class
1414
);
15-
$attribute->setData(
16-
[
17-
'attribute_code' => 'multiselect_attribute',
18-
'entity_type_id' => $installer->getEntityTypeId('catalog_product'),
19-
'is_global' => 1,
20-
'is_user_defined' => 1,
21-
'frontend_input' => 'multiselect',
22-
'is_unique' => 0,
23-
'is_required' => 0,
24-
'is_searchable' => 0,
25-
'is_visible_in_advanced_search' => 0,
26-
'is_comparable' => 0,
27-
'is_filterable' => 1,
28-
'is_filterable_in_search' => 0,
29-
'is_used_for_promo_rules' => 0,
30-
'is_html_allowed_on_front' => 1,
31-
'is_visible_on_front' => 0,
32-
'used_in_product_listing' => 0,
33-
'used_for_sort_by' => 0,
34-
'frontend_label' => ['Multiselect Attribute'],
35-
'backend_type' => 'varchar',
36-
'backend_model' => \Magento\Eav\Model\Entity\Attribute\Backend\ArrayBackend::class,
37-
'option' => [
38-
'value' => [
39-
'option_1' => ['Option 1'],
40-
'option_2' => ['Option 2'],
41-
'option_3' => ['Option 3'],
42-
'option_4' => ['Option 4 "!@#$%^&*']
15+
$entityType = $installer->getEntityTypeId('catalog_product');
16+
if (!$attribute->loadByCode($entityType, 'multiselect_attribute')->getAttributeId()) {
17+
$attribute->setData(
18+
[
19+
'attribute_code' => 'multiselect_attribute',
20+
'entity_type_id' => $entityType,
21+
'is_global' => 1,
22+
'is_user_defined' => 1,
23+
'frontend_input' => 'multiselect',
24+
'is_unique' => 0,
25+
'is_required' => 0,
26+
'is_searchable' => 0,
27+
'is_visible_in_advanced_search' => 0,
28+
'is_comparable' => 0,
29+
'is_filterable' => 1,
30+
'is_filterable_in_search' => 0,
31+
'is_used_for_promo_rules' => 0,
32+
'is_html_allowed_on_front' => 1,
33+
'is_visible_on_front' => 0,
34+
'used_in_product_listing' => 0,
35+
'used_for_sort_by' => 0,
36+
'frontend_label' => ['Multiselect Attribute'],
37+
'backend_type' => 'varchar',
38+
'backend_model' => \Magento\Eav\Model\Entity\Attribute\Backend\ArrayBackend::class,
39+
'option' => [
40+
'value' => [
41+
'option_1' => ['Option 1'],
42+
'option_2' => ['Option 2'],
43+
'option_3' => ['Option 3'],
44+
'option_4' => ['Option 4 "!@#$%^&*']
45+
],
46+
'order' => [
47+
'option_1' => 1,
48+
'option_2' => 2,
49+
'option_3' => 3,
50+
'option_4' => 4,
51+
],
4352
],
44-
'order' => [
45-
'option_1' => 1,
46-
'option_2' => 2,
47-
'option_3' => 3,
48-
'option_4' => 4,
49-
],
50-
],
51-
]
52-
);
53-
$attribute->save();
53+
]
54+
);
55+
$attribute->save();
5456

55-
/* Assign attribute to attribute set */
56-
$installer->addAttributeToGroup('catalog_product', 'Default', 'General', $attribute->getId());
57+
/* Assign attribute to attribute set */
58+
$installer->addAttributeToGroup('catalog_product', 'Default', 'General', $attribute->getId());
59+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
/**
9+
* Create multiselect attribute
10+
*/
11+
require __DIR__ . '/multiselect_attribute.php';
12+
13+
/** Create product with options out of stock and multiselect attribute */
14+
15+
/** @var $installer \Magento\Catalog\Setup\CategorySetup */
16+
$installer = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
17+
\Magento\Catalog\Setup\CategorySetup::class
18+
);
19+
20+
/** @var $options \Magento\Eav\Model\ResourceModel\Entity\Attribute\Option\Collection */
21+
$options = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
22+
\Magento\Eav\Model\ResourceModel\Entity\Attribute\Option\Collection::class
23+
);
24+
$options->setAttributeFilter($attribute->getId());
25+
$optionIds = $options->getAllIds();
26+
27+
$product = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(\Magento\Catalog\Model\Product::class);
28+
$product->setTypeId(\Magento\Catalog\Model\Product\Type::TYPE_SIMPLE)
29+
->setId($optionIds[1] * 20)
30+
->setAttributeSetId($installer->getAttributeSetId('catalog_product', 'Default'))
31+
->setWebsiteIds([1])
32+
->setName('Out of Stock With Multiselect')
33+
->setSku('simple_ms_out_of_stock')
34+
->setPrice(10)
35+
->setVisibility(\Magento\Catalog\Model\Product\Visibility::VISIBILITY_BOTH)
36+
->setMultiselectAttribute([$optionIds[1], $optionIds[2], $optionIds[3]])
37+
->setStatus(\Magento\Catalog\Model\Product\Attribute\Source\Status::STATUS_ENABLED)
38+
->setStockData(['use_config_manage_stock' => 1, 'qty' => 0,'is_in_stock' => 0])
39+
->save();
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
require __DIR__ . '/multiselect_attribute_rollback.php';
9+
10+
use Magento\Framework\Exception\NoSuchEntityException;
11+
use Magento\Framework\Indexer\IndexerRegistry;
12+
13+
/** @var \Magento\Framework\Registry $registry */
14+
$registry = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(\Magento\Framework\Registry::class);
15+
16+
$registry->unregister('isSecureArea');
17+
$registry->register('isSecureArea', true);
18+
19+
/** @var \Magento\Catalog\Api\ProductRepositoryInterface $productRepository */
20+
$productRepository = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()
21+
->get(\Magento\Catalog\Api\ProductRepositoryInterface::class);
22+
try {
23+
$product = $productRepository->get('simple_ms_out_of_stock', false, null, true);
24+
$productRepository->delete($product);
25+
} catch (NoSuchEntityException $e) {
26+
}
27+
28+
\Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(IndexerRegistry::class)
29+
->get(Magento\CatalogInventory\Model\Indexer\Stock\Processor::INDEXER_ID)
30+
->reindexAll();
31+
32+
$registry->unregister('isSecureArea');
33+
$registry->register('isSecureArea', false);

dev/tests/integration/testsuite/Magento/Catalog/_files/products_with_multiselect_attribute_rollback.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,11 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6+
67
require __DIR__ . '/multiselect_attribute_rollback.php';
8+
9+
use Magento\Framework\Indexer\IndexerRegistry;
10+
711
/**
812
* Remove all products as strategy of isolation process
913
*/
@@ -22,3 +26,7 @@
2226

2327
$registry->unregister('isSecureArea');
2428
$registry->register('isSecureArea', false);
29+
30+
\Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(IndexerRegistry::class)
31+
->get(Magento\CatalogInventory\Model\Indexer\Stock\Processor::INDEXER_ID)
32+
->reindexAll();

0 commit comments

Comments
 (0)