Skip to content

Commit 9400c1e

Browse files
🔃 [Magento Community Engineering] Community Contributions - 2.4-develop
Accepted Community Pull Requests: - #25940: Asynchronous operation validate (by @sedonik) - #25523: Contact form > Adding ViewModel (by @rafaelstz) - #25697: [New Relic] Making system configs dependent by Enabled field (by @eduard13) - #26067: [Msrp] Cover MsrpPriceCalculator by Unit Test (by @edenduong) - #24360: #24357 Eav sort order by attribute option_id (by @tnsezer) - #26069: [CMS] Improving the test coverage for UrlBuilder ViewModel (by @eduard13) - #26063: [Theme] Reverting removed container class (by @eduard13) - #26057: [Contact] covered Model Config by Unit Test (by @srsathish92) - #26050: [Catalog] covered product ViewModel AddToCompareAvailability by Unit Test (by @srsathish92) - #26037: Fixes phpcs errors and warnings for Magento\Framework\View\Element (by @krisdante) - #26045: [Downloadable] Cover Helper Data by Unit Test (by @edenduong) - #26043: [Persistent] Cover CustomerData by Unit Test (by @edenduong) - #26042: [Catalog] Cover Component/FilterFactory by Unit Test (by @edenduong) - #26044: Set empty value to color picker when input is reset to update preview (by @gperis) - #26034: MAGETWO-95866 Add horizontal scroll if elements extend menu's width (by @ptylek) - #26001: Fix caching Magento Metadata getVersion (by @luklewluk) - #26003: [Directory] Cover action directory/json/countryRegion by Integration Test (by @edenduong) Fixed GitHub Issues: - #100: Oracle and Other RDBMS Status? (reported by @dicgf8) has been fixed in #25940 by @sedonik in 2.4-develop branch Related commits: 1. dc8821d 2. f305a84 3. 345ece3 4. b1e518c - #24357: Eav sort order by attribute option_id (reported by @tnsezer) has been fixed in #24360 by @tnsezer in 2.4-develop branch Related commits: 1. 459c596 2. a047aca 3. 952d12e 4. 4000459 5. 49738bd 6. d0006b9 - #20379: calendar icon not aligned inside the textbox in Add Design Change page (reported by @irajneeshgupta) has been fixed in #26063 by @eduard13 in 2.4-develop branch Related commits: 1. 218c3ff - #18687: Left Side Back End Menu Design fix (reported by @jigar48) has been fixed in #26034 by @ptylek in 2.4-develop branch Related commits: 1. f59c1ca 2. 7a2bc8f 3. 6bf903f - #24025: Slow Performance of ProductMetadata::getVersion (reported by @beberlei) has been fixed in #26001 by @luklewluk in 2.4-develop branch Related commits: 1. 16ab63b 2. ab6cabd 3. 0b7c34e
2 parents 320ccf2 + 4ffea5b commit 9400c1e

File tree

46 files changed

+1651
-21
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+1651
-21
lines changed

Diff for: app/code/Magento/AsynchronousOperations/Model/Operation.php

+22-1
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,33 @@
66
namespace Magento\AsynchronousOperations\Model;
77

88
use Magento\AsynchronousOperations\Api\Data\OperationInterface;
9+
use Magento\AsynchronousOperations\Model\OperationStatusValidator;
910
use Magento\Framework\DataObject;
1011

1112
/**
12-
* Class Operation
13+
* Class Operation encapsulates methods for Operation Model Object
1314
*/
1415
class Operation extends DataObject implements OperationInterface
1516
{
17+
/**
18+
* @var OperationStatusValidator
19+
*/
20+
private $operationStatusValidator;
21+
22+
/**
23+
* Operation constructor.
24+
*
25+
* @param OperationStatusValidator $operationStatusValidator
26+
* @param array $data
27+
*/
28+
public function __construct(
29+
OperationStatusValidator $operationStatusValidator,
30+
array $data = []
31+
) {
32+
$this->operationStatusValidator = $operationStatusValidator;
33+
parent::__construct($data);
34+
}
35+
1636
/**
1737
* @inheritDoc
1838
*/
@@ -106,6 +126,7 @@ public function getStatus()
106126
*/
107127
public function setStatus($status)
108128
{
129+
$this->operationStatusValidator->validate($status);
109130
return $this->setData(self::STATUS, $status);
110131
}
111132

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\AsynchronousOperations\Model;
7+
8+
/**
9+
* Class OperationStatusPool
10+
*
11+
* Pool of statuses that require validate
12+
*/
13+
class OperationStatusPool
14+
{
15+
/**
16+
* @var array
17+
*/
18+
private $statuses;
19+
20+
/**
21+
* @param array $statuses
22+
*/
23+
public function __construct(array $statuses = [])
24+
{
25+
$this->statuses = $statuses;
26+
}
27+
28+
/**
29+
* Retrieve statuses that require validate
30+
*
31+
* @return array
32+
*/
33+
public function getStatuses()
34+
{
35+
return $this->statuses;
36+
}
37+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\AsynchronousOperations\Model;
7+
8+
use Magento\AsynchronousOperations\Model\OperationStatusPool;
9+
use Magento\Framework\Exception\NoSuchEntityException;
10+
use Doctrine\Instantiator\Exception\InvalidArgumentException;
11+
12+
/**
13+
* Class OperationStatusValidator to validate operation status
14+
*/
15+
class OperationStatusValidator
16+
{
17+
/**
18+
* @var OperationStatusPool
19+
*/
20+
private $operationStatusPool;
21+
22+
/**
23+
* OperationStatusValidator constructor.
24+
*
25+
* @param OperationStatusPool $operationStatusPool
26+
*/
27+
public function __construct(OperationStatusPool $operationStatusPool)
28+
{
29+
$this->operationStatusPool = $operationStatusPool;
30+
}
31+
32+
/**
33+
* Validate method
34+
*
35+
* @param int $status
36+
* @throws \InvalidArgumentException
37+
* @return void
38+
*/
39+
public function validate($status)
40+
{
41+
$statuses = $this->operationStatusPool->getStatuses();
42+
43+
if (!in_array($status, $statuses)) {
44+
throw new \InvalidArgumentException('Invalid Operation Status.');
45+
}
46+
}
47+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\AsynchronousOperations\Test\Unit\Model;
7+
8+
use Magento\AsynchronousOperations\Model\OperationStatusValidator;
9+
use Magento\AsynchronousOperations\Model\Operation;
10+
use Magento\AsynchronousOperations\Model\OperationStatusPool;
11+
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
12+
use PHPUnit\Framework\TestCase;
13+
14+
/**
15+
* Class OperationStatusValidatorTest implements logic for testing Operation::setStatus() method
16+
*/
17+
class OperationStatusValidatorTest extends TestCase
18+
{
19+
/**
20+
* @var OperationStatusPool
21+
*/
22+
private $operationStatusPool;
23+
24+
/**
25+
* @var OperationStatusValidator
26+
*/
27+
private $operationStatusValidator;
28+
29+
/**
30+
* @var Operation
31+
*/
32+
private $operation;
33+
34+
protected function setUp()
35+
{
36+
$this->operationStatusPool = $this->getMockBuilder(OperationStatusPool::class)
37+
->disableOriginalConstructor()
38+
->getMock();
39+
40+
$objectManager = new ObjectManager($this);
41+
42+
$this->operationStatusValidator = $objectManager->getObject(
43+
OperationStatusValidator::class,
44+
[
45+
'operationStatusPool' => $this->operationStatusPool
46+
]
47+
);
48+
49+
$this->operation = $objectManager->getObject(
50+
Operation::class,
51+
[
52+
'operationStatusValidator' => $this->operationStatusValidator
53+
]
54+
);
55+
}
56+
57+
/**
58+
* @param string $status
59+
* @param array $statusPool
60+
* @param string $expectedResult
61+
* @dataProvider dataProviderForTestSetStatus
62+
*/
63+
public function testSetStatus(
64+
string $status,
65+
array $statusPool,
66+
string $expectedResult
67+
) {
68+
$this->operationStatusPool
69+
->expects($this->any())
70+
->method('getStatuses')
71+
->willReturn($statusPool);
72+
73+
try {
74+
$this->operation->setStatus($status);
75+
$this->assertEquals($expectedResult, $this->operation->getStatus());
76+
} catch (\Exception $exception) {
77+
$this->assertEquals($expectedResult, $exception->getMessage());
78+
}
79+
}
80+
81+
/**
82+
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
83+
*/
84+
public function dataProviderForTestSetStatus()
85+
{
86+
return [
87+
[
88+
'status' => 0,
89+
'statusPool' => [
90+
'complete' => 1,
91+
'retriablyFailed' => 2,
92+
'notRetriablyFailed' => 3,
93+
'open' => 4,
94+
'rejected' => 5
95+
],
96+
'expectedResult' => 'Invalid Operation Status.'
97+
],
98+
[
99+
'status' => 1,
100+
'statusPool' => [
101+
'complete' => 1,
102+
'retriablyFailed' => 2,
103+
'notRetriablyFailed' => 3,
104+
'open' => 4,
105+
'rejected' => 5
106+
],
107+
'expectedResult' => 1
108+
],
109+
[
110+
'status' => 2,
111+
'statusPool' => [
112+
'complete' => 1,
113+
'retriablyFailed' => 2,
114+
'notRetriablyFailed' => 3,
115+
'open' => 4,
116+
'rejected' => 5
117+
],
118+
'expectedResult' => 2
119+
],
120+
[
121+
'status' => 3,
122+
'statusPool' => [
123+
'complete' => 1,
124+
'retriablyFailed' => 2,
125+
'notRetriablyFailed' => 3,
126+
'open' => 4,
127+
'rejected' => 5
128+
],
129+
'expectedResult' => 3
130+
],
131+
[
132+
'status' => 4,
133+
'statusPool' => [
134+
'complete' => 1,
135+
'retriablyFailed' => 2,
136+
'notRetriablyFailed' => 3,
137+
'open' => 4,
138+
'rejected' => 5
139+
],
140+
'expectedResult' => 4
141+
],
142+
[
143+
'status' => 5,
144+
'statusPool' => [
145+
'complete' => 1,
146+
'retriablyFailed' => 2,
147+
'notRetriablyFailed' => 3,
148+
'open' => 4,
149+
'rejected' => 5
150+
],
151+
'expectedResult' => 5
152+
]
153+
];
154+
}
155+
}

Diff for: app/code/Magento/AsynchronousOperations/etc/di.xml

+11
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,17 @@
8080
</argument>
8181
</arguments>
8282
</type>
83+
<type name="Magento\AsynchronousOperations\Model\OperationStatusPool">
84+
<arguments>
85+
<argument name="statuses" xsi:type="array">
86+
<item name="complete" xsi:type="string">1</item>
87+
<item name="retriablyFailed" xsi:type="string">2</item>
88+
<item name="notRetriablyFailed" xsi:type="string">3</item>
89+
<item name="open" xsi:type="string">4</item>
90+
<item name="rejected" xsi:type="string">5</item>
91+
</argument>
92+
</arguments>
93+
</type>
8394
<virtualType
8495
name="Magento\AsynchronousOperations\Ui\Component\DataProvider"
8596
type="Magento\Framework\View\Element\UiComponent\DataProvider\DataProvider"/>

0 commit comments

Comments
 (0)