Skip to content

Commit fb14df6

Browse files
committed
Merge remote-tracking branch 'origin/MC-29686' into 2.4-develop-com-pr2
2 parents 934338c + 3751889 commit fb14df6

File tree

3 files changed

+96
-0
lines changed

3 files changed

+96
-0
lines changed

dev/tests/integration/testsuite/Magento/Catalog/Block/Product/ListProduct/ProductInCategoriesViewTest.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,19 @@ public function productDataProvider(): array
100100
];
101101
}
102102

103+
/**
104+
* @magentoConfigFixture default_store cataloginventory/options/show_out_of_stock 1
105+
* @magentoDataFixture Magento/Catalog/_files/out_of_stock_product_with_category.php
106+
* @return void
107+
*/
108+
public function testCategoryOutOfStockProductView(): void
109+
{
110+
$collection = $this->getCategoryProductCollection(333);
111+
112+
$this->assertEquals(1, $collection->getSize());
113+
$this->assertEquals('out-of-stock-product', $collection->getFirstItem()->getSku());
114+
}
115+
103116
/**
104117
* @magentoDataFixture Magento/Catalog/_files/category_product.php
105118
* @dataProvider productVisibilityProvider
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
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+
use Magento\Catalog\Api\CategoryLinkManagementInterface;
9+
use Magento\Catalog\Api\ProductRepositoryInterface;
10+
use Magento\Catalog\Model\Product\Attribute\Source\Status;
11+
use Magento\Catalog\Model\Product\Type;
12+
use Magento\Catalog\Model\Product\Visibility;
13+
use Magento\Catalog\Model\ProductFactory;
14+
use Magento\TestFramework\Helper\Bootstrap;
15+
16+
require __DIR__ . '/category.php';
17+
18+
$objectManager = Bootstrap::getObjectManager();
19+
/** @var ProductFactory $productFactory */
20+
$productFactory = $objectManager->get(ProductFactory::class);
21+
/** @var CategoryLinkManagementInterface $categoryLinkManagement */
22+
$categoryLinkManagement = $objectManager->get(CategoryLinkManagementInterface::class);
23+
$product = $productFactory->create();
24+
$product->isObjectNew(true);
25+
$product->setTypeId(Type::TYPE_SIMPLE)
26+
->setAttributeSetId($product->getDefaultAttributeSetId())
27+
->setWebsiteIds([1])
28+
->setName('Simple Product Out Of Stock')
29+
->setSku('out-of-stock-product')
30+
->setPrice(10)
31+
->setWeight(1)
32+
->setShortDescription("Short description")
33+
->setTaxClassId(0)
34+
->setDescription('Description with <b>html tag</b>')
35+
->setMetaTitle('meta title')
36+
->setMetaKeyword('meta keyword')
37+
->setMetaDescription('meta description')
38+
->setVisibility(Visibility::VISIBILITY_BOTH)
39+
->setStatus(Status::STATUS_ENABLED)
40+
->setCategoryIds([333])
41+
->setStockData(
42+
[
43+
'use_config_manage_stock' => 1,
44+
'qty' => 0,
45+
'is_qty_decimal' => 0,
46+
'is_in_stock' => 0,
47+
]
48+
)
49+
->setCanSaveCustomOptions(true)
50+
->setHasOptions(true);
51+
/** @var ProductRepositoryInterface $productRepositoryFactory */
52+
$productRepository = $objectManager->create(ProductRepositoryInterface::class);
53+
$productRepository->save($product);
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
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+
use Magento\Catalog\Api\ProductRepositoryInterface;
9+
use Magento\Framework\Exception\NoSuchEntityException;
10+
use Magento\Framework\Registry;
11+
use Magento\TestFramework\Helper\Bootstrap;
12+
13+
require __DIR__ . '/category_rollback.php';
14+
15+
$objectManager = Bootstrap::getObjectManager();
16+
/** @var Registry $registry */
17+
$registry = $objectManager->get(Registry::class);
18+
19+
$registry->unregister('isSecureArea');
20+
$registry->register('isSecureArea', true);
21+
/** @var ProductRepositoryInterface $productRepository */
22+
$productRepository = $objectManager->create(ProductRepositoryInterface::class);
23+
24+
try {
25+
$productRepository->deleteById('out-of-stock-product');
26+
} catch (NoSuchEntityException $e) {
27+
//already removed
28+
}
29+
$registry->unregister('isSecureArea');
30+
$registry->register('isSecureArea', false);

0 commit comments

Comments
 (0)