Skip to content

Commit 565382e

Browse files
[Magento Community Engineering] Community Contributions - 2.4-develop-fast-lane-prs
- merged with '2.4-develop-expedited-prs' branch
2 parents 9a8658f + 05d7d0f commit 565382e

File tree

23 files changed

+1852
-279
lines changed

23 files changed

+1852
-279
lines changed

app/code/Magento/Catalog/Model/Product/Type.php

Lines changed: 25 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -6,43 +6,37 @@
66
namespace Magento\Catalog\Model\Product;
77

88
use Magento\Catalog\Model\Product;
9+
use Magento\Catalog\Model\Product\Type\Pool;
10+
use Magento\Catalog\Model\Product\Type\Price;
11+
use Magento\Catalog\Model\Product\Type\Price\Factory as PriceFactory;
12+
use Magento\Catalog\Model\Product\Type\Simple;
13+
use Magento\Catalog\Model\ProductTypes\ConfigInterface;
914
use Magento\Framework\Data\OptionSourceInterface;
15+
use Magento\Framework\Pricing\PriceInfo\Factory as PriceInfoFactory;
1016

1117
/**
1218
* Product type model
1319
*
20+
*
1421
* @api
1522
* @since 100.0.2
1623
*/
1724
class Type implements OptionSourceInterface
1825
{
19-
/**#@+
20-
* Available product types
21-
*/
2226
const TYPE_SIMPLE = 'simple';
2327

2428
const TYPE_BUNDLE = 'bundle';
2529

2630
const TYPE_VIRTUAL = 'virtual';
27-
/**#@-*/
2831

29-
/**
30-
* Default product type
31-
*/
3232
const DEFAULT_TYPE = 'simple';
3333

34-
/**
35-
* Default product type model
36-
*/
37-
const DEFAULT_TYPE_MODEL = \Magento\Catalog\Model\Product\Type\Simple::class;
34+
const DEFAULT_TYPE_MODEL = Simple::class;
3835

39-
/**
40-
* Default price model
41-
*/
42-
const DEFAULT_PRICE_MODEL = \Magento\Catalog\Model\Product\Type\Price::class;
36+
const DEFAULT_PRICE_MODEL = Price::class;
4337

4438
/**
45-
* @var \Magento\Catalog\Model\ProductTypes\ConfigInterface
39+
* @var ConfigInterface
4640
*/
4741
protected $_config;
4842

@@ -77,35 +71,35 @@ class Type implements OptionSourceInterface
7771
/**
7872
* Product type factory
7973
*
80-
* @var \Magento\Catalog\Model\Product\Type\Pool
74+
* @var Pool
8175
*/
8276
protected $_productTypePool;
8377

8478
/**
8579
* Price model factory
8680
*
87-
* @var \Magento\Catalog\Model\Product\Type\Price\Factory
81+
* @var PriceFactory
8882
*/
8983
protected $_priceFactory;
9084

9185
/**
92-
* @var \Magento\Framework\Pricing\PriceInfo\Factory
86+
* @var PriceInfoFactory
9387
*/
9488
protected $_priceInfoFactory;
9589

9690
/**
9791
* Construct
9892
*
99-
* @param \Magento\Catalog\Model\ProductTypes\ConfigInterface $config
100-
* @param \Magento\Catalog\Model\Product\Type\Pool $productTypePool
101-
* @param \Magento\Catalog\Model\Product\Type\Price\Factory $priceFactory
102-
* @param \Magento\Framework\Pricing\PriceInfo\Factory $priceInfoFactory
93+
* @param ConfigInterface $config
94+
* @param Pool $productTypePool
95+
* @param PriceFactory $priceFactory
96+
* @param PriceInfoFactory $priceInfoFactory
10397
*/
10498
public function __construct(
105-
\Magento\Catalog\Model\ProductTypes\ConfigInterface $config,
106-
\Magento\Catalog\Model\Product\Type\Pool $productTypePool,
107-
\Magento\Catalog\Model\Product\Type\Price\Factory $priceFactory,
108-
\Magento\Framework\Pricing\PriceInfo\Factory $priceInfoFactory
99+
ConfigInterface $config,
100+
Pool $productTypePool,
101+
PriceFactory $priceFactory,
102+
PriceInfoFactory $priceInfoFactory
109103
) {
110104
$this->_config = $config;
111105
$this->_productTypePool = $productTypePool;
@@ -116,8 +110,8 @@ public function __construct(
116110
/**
117111
* Factory to product singleton product type instances
118112
*
119-
* @param \Magento\Catalog\Model\Product $product
120-
* @return \Magento\Catalog\Model\Product\Type\AbstractType
113+
* @param \Magento\Catalog\Api\Data\ProductInterface $product
114+
* @return \Magento\Catalog\Model\Product\Type\AbstractType
121115
*/
122116
public function factory($product)
123117
{
@@ -139,8 +133,8 @@ public function factory($product)
139133
/**
140134
* Product type price model factory
141135
*
142-
* @param string $productType
143-
* @return \Magento\Catalog\Model\Product\Type\Price
136+
* @param string $productType
137+
* @return \Magento\Catalog\Model\Product\Type\Price
144138
*/
145139
public function priceFactory($productType)
146140
{

app/code/Magento/Catalog/Test/Mftf/Data/ProductData.xml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,17 @@
212212
<data key="quantity">1001</data>
213213
<requiredEntity type="product_extension_attribute">EavStockItem</requiredEntity>
214214
</entity>
215+
<entity name="SimpleProductDisabledStockQuantityZero" type="product">
216+
<data key="sku" unique="suffix">testSku</data>
217+
<data key="type_id">simple</data>
218+
<data key="attribute_set_id">4</data>
219+
<data key="name" unique="suffix">Simple Product Disabled Quantity Zero</data>
220+
<data key="price">123.00</data>
221+
<data key="visibility">4</data>
222+
<data key="status">2</data>
223+
<data key="quantity">0</data>
224+
<requiredEntity type="product_extension_attribute">EavStock0</requiredEntity>
225+
</entity>
215226
<entity name="SimpleProductNotVisibleIndividually" type="product">
216227
<data key="name" unique="suffix">Simple Product Not Visible Individually</data>
217228
<data key="sku" unique="suffix">simple_product_not_visible_individually</data>
Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
declare(strict_types=1);
8+
9+
namespace Magento\CatalogUrlRewrite\Test\Unit\Observer;
10+
11+
use Magento\Catalog\Model\Product;
12+
use Magento\CatalogUrlRewrite\Model\ProductUrlRewriteGenerator;
13+
use Magento\CatalogUrlRewrite\Observer\ProductProcessUrlRewriteRemovingObserver;
14+
use Magento\Framework\Event;
15+
use Magento\Framework\Event\Observer;
16+
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
17+
use Magento\UrlRewrite\Model\UrlPersistInterface;
18+
use Magento\UrlRewrite\Service\V1\Data\UrlRewrite;
19+
use PHPUnit\Framework\MockObject\MockObject;
20+
use PHPUnit\Framework\TestCase;
21+
22+
/**
23+
* Unit test for Magento\CatalogUrlRewrite\Observer\ProductProcessUrlRewriteRemovingObserver
24+
*/
25+
class ProductProcessUrlRewriteRemovingObserverTest extends TestCase
26+
{
27+
/*
28+
* Stub product ID
29+
*/
30+
private const STUB_PRODUCT_ID = 333;
31+
32+
/**
33+
* Testable Object
34+
*
35+
* @var ProductProcessUrlRewriteRemovingObserver
36+
*/
37+
private $observer;
38+
39+
/**
40+
* @var ObjectManager
41+
*/
42+
private $objectManager;
43+
44+
/**
45+
* @var Observer|MockObject
46+
*/
47+
private $observerMock;
48+
49+
/**
50+
* @var Event|MockObject
51+
*/
52+
private $eventMock;
53+
54+
/**
55+
* @var Product|MockObject
56+
*/
57+
private $productMock;
58+
59+
/**
60+
* @var UrlPersistInterface|MockObject
61+
*/
62+
private $urlPersistMock;
63+
64+
/**
65+
* @inheritdoc
66+
*/
67+
protected function setUp(): void
68+
{
69+
$this->objectManager = new ObjectManager($this);
70+
$this->observerMock = $this->createMock(Observer::class);
71+
72+
$this->eventMock = $this->getMockBuilder(Event::class)
73+
->disableOriginalConstructor()
74+
->setMethods(['getProduct'])
75+
->getMock();
76+
77+
$this->productMock = $this->getMockBuilder(Product::class)
78+
->disableOriginalConstructor()
79+
->setMethods(['getId'])
80+
->getMock();
81+
82+
$this->urlPersistMock = $this->getMockBuilder(UrlPersistInterface::class)
83+
->disableOriginalConstructor()
84+
->getMock();
85+
86+
$this->observer = $this->objectManager->getObject(
87+
ProductProcessUrlRewriteRemovingObserver::class,
88+
[
89+
'urlPersist' => $this->urlPersistMock
90+
]
91+
);
92+
}
93+
94+
/**
95+
* Test for execute(), covers test case for removing product URLs from storage
96+
*/
97+
public function testRemoveProductUrlsFromStorage(): void
98+
{
99+
$this->observerMock
100+
->expects($this->once())
101+
->method('getEvent')
102+
->willReturn($this->eventMock);
103+
104+
$this->eventMock
105+
->expects($this->once())
106+
->method('getProduct')
107+
->willReturn($this->productMock);
108+
109+
$this->productMock
110+
->expects($this->exactly(2))
111+
->method('getId')
112+
->willReturn(self::STUB_PRODUCT_ID);
113+
114+
$this->urlPersistMock->expects($this->once())
115+
->method('deleteByData')
116+
->with([
117+
UrlRewrite::ENTITY_ID => self::STUB_PRODUCT_ID,
118+
UrlRewrite::ENTITY_TYPE => ProductUrlRewriteGenerator::ENTITY_TYPE,
119+
]);
120+
121+
$this->observer->execute($this->observerMock);
122+
}
123+
124+
/**
125+
* Test for execute(), covers test case for removing product URLs when the product doesn't have an ID
126+
*/
127+
public function testRemoveProductUrlsWithEmptyProductId()
128+
{
129+
$this->observerMock
130+
->expects($this->once())
131+
->method('getEvent')
132+
->willReturn($this->eventMock);
133+
134+
$this->eventMock
135+
->expects($this->once())
136+
->method('getProduct')
137+
->willReturn($this->productMock);
138+
139+
$this->productMock
140+
->expects($this->once())
141+
->method('getId')
142+
->willReturn(null);
143+
144+
$this->urlPersistMock->expects($this->never())->method('deleteByData');
145+
146+
$this->observer->execute($this->observerMock);
147+
}
148+
}

0 commit comments

Comments
 (0)