Skip to content

Commit d8ca81c

Browse files
authored
Merge pull request #5761 from magento-tsg/2.4-develop-com-api-func-improve
[TSG-Commerce] Tests for 2.4.1 (api-func-improve)
2 parents 082e3cc + d222581 commit d8ca81c

File tree

59 files changed

+2684
-491
lines changed

Some content is hidden

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

59 files changed

+2684
-491
lines changed
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
<?php
2+
/**
3+
*
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
declare(strict_types=1);
8+
9+
namespace Magento\TestModuleOverrideConfig\Model;
10+
11+
/**
12+
* Class represent simple container to save data
13+
*/
14+
class FixtureCallStorage
15+
{
16+
/** @var array */
17+
private $storage = [];
18+
19+
/**
20+
* Add fixture to storage
21+
*
22+
* @param string $fixture
23+
* @return void
24+
*/
25+
public function addFixtureToStorage(string $fixture): void
26+
{
27+
$this->storage[] = $fixture;
28+
}
29+
30+
/**
31+
* Get fixture position in storage
32+
*
33+
* @param string $fixture
34+
* @return null|int
35+
*/
36+
public function getFixturePosition(string $fixture): ?int
37+
{
38+
return array_search($fixture, $this->storage) ?: null;
39+
}
40+
41+
/**
42+
* Get storage
43+
*
44+
* @return array
45+
*/
46+
public function getStorage(): array
47+
{
48+
return $this->storage;
49+
}
50+
51+
/**
52+
* Get fixtures count in storage
53+
*
54+
* @param string $fixture
55+
* @return int
56+
*/
57+
public function getFixturesCount(string $fixture = ''): int
58+
{
59+
$count = count($this->storage);
60+
if ($fixture) {
61+
$result = array_filter($this->storage, function ($storedFixture) use ($fixture) {
62+
return $storedFixture === $fixture;
63+
});
64+
$count = count($result);
65+
}
66+
67+
return $count;
68+
}
69+
70+
/**
71+
* Clear storage
72+
*
73+
* @return void
74+
*/
75+
public function clearStorage(): void
76+
{
77+
$this->storage = [];
78+
}
79+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"name": "magento/module-override-config-test",
3+
"description": "module for override config check",
4+
"config": {
5+
"sort-packages": true
6+
},
7+
"require": {
8+
"php": "~7.3.0||~7.4.0",
9+
"magento/framework": "*",
10+
"magento/module-integration": "*"
11+
},
12+
"type": "magento2-module",
13+
"extra": {
14+
"map": [
15+
[
16+
"*",
17+
"Magento/TestModuleOverrideConfig"
18+
]
19+
]
20+
}
21+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?xml version="1.0"?>
2+
<!--
3+
/**
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Config:etc/system_file.xsd">
9+
<system>
10+
<section id="test_section" translate="label" type="text" sortOrder="10" showInDefault="1" showInWebsite="1" showInStore="1">
11+
<group id="test_group" translate="label" type="text" sortOrder="100" showInDefault="1" showInWebsite="1" showInStore="1">
12+
<field id="field_1" translate="label" type="text" sortOrder="10" showInDefault="1" showInWebsite="1" showInStore="1"/>
13+
<field id="field_2" translate="label" type="text" sortOrder="10" showInDefault="1" showInWebsite="1" showInStore="1"/>
14+
<field id="field_3" translate="label" type="text" sortOrder="10" showInDefault="1" showInWebsite="1" showInStore="1"/>
15+
</group>
16+
</section>
17+
</system>
18+
</config>
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?xml version="1.0"?>
2+
<!--
3+
/**
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Store:etc/config.xsd">
9+
<default>
10+
<test_section>
11+
<test_group>
12+
<field_1>1st field default value</field_1>
13+
<field_2>2nd field default value</field_2>
14+
<field_3>3rd field default value</field_3>
15+
</test_group>
16+
</test_section>
17+
</default>
18+
<websites>
19+
<base>
20+
<test_section>
21+
<test_group>
22+
<field_3>3rd field website scope default value</field_3>
23+
</test_group>
24+
</test_section>
25+
</base>
26+
</websites>
27+
</config>
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?xml version="1.0"?>
2+
<!--
3+
/**
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
9+
<module name="Magento_TestModuleOverrideConfig" />
10+
</config>
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
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\Framework\Component\ComponentRegistrar;
9+
10+
$registrar = new ComponentRegistrar();
11+
if ($registrar->getPath(ComponentRegistrar::MODULE, 'Magento_TestModuleOverrideConfig') === null) {
12+
ComponentRegistrar::register(ComponentRegistrar::MODULE, 'Magento_TestModuleOverrideConfig', __DIR__);
13+
}
Lines changed: 150 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
1+
<?xml version="1.0"?>
2+
<!--
3+
/**
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
<overrides>
9+
<!-- test node determine to which class config inside node should be applied -->
10+
<test class="Magento\TestModuleOverrideConfig\MagentoApiConfigFixture\AddFixtureTest">
11+
<!-- Node bellow will add magentoConfigFixture to fixtures list
12+
'scopeType' required attribute and accept such values: store|website
13+
'scopeCode' store|website code
14+
skip 'scopeType' and 'scopeCode' attributes to set value in default scope
15+
'path' required attribute determine config path, 'value' attribute determine which value will be set for provided path
16+
to add fixture to fixtures list
17+
-->
18+
<magentoConfigFixture scopeType="store" scopeCode="default" path="test_section/test_group/field_1" value="overridden value for full class"/>
19+
<!-- method node determine to which test method config inside node should be applied -->
20+
<method name="testAddFixtureToMethod">
21+
<magentoConfigFixture scopeType="store" scopeCode="default" path="test_section/test_group/field_1" value="overridden value for method"/>
22+
<!-- dataSet node determine for which data set config inside should be applied -->
23+
<dataSet name="second_data_set">
24+
<magentoConfigFixture scopeType="store" scopeCode="default" path="test_section/test_group/field_1" value="overridden value for data set"/>
25+
</dataSet>
26+
</method>
27+
<method name="testAddFixtureOnWebsiteScope">
28+
<magentoConfigFixture scopeType="website" scopeCode="base" path="test_section/test_group/field_1" value="overridden value for method on website scope"/>
29+
</method>
30+
</test>
31+
<test class="Magento\TestModuleOverrideConfig\MagentoApiConfigFixture\RemoveFixtureTest">
32+
<!-- 'remove' attribute accept bool values, if value set to 'true' this node will remove matching fixture from fixtures list-->
33+
<magentoConfigFixture scopeType="store" scopeCode="default" path="test_section/test_group/field_1" remove="true"/>
34+
<method name="testRemoveFixtureForMethod">
35+
<magentoConfigFixture scopeType="store" scopeCode="default" path="test_section/test_group/field_2" remove="true"/>
36+
<dataSet name="second_data_set">
37+
<magentoConfigFixture scopeType="store" scopeCode="default" path="test_section/test_group/field_3" remove="true"/>
38+
</dataSet>
39+
</method>
40+
<method name="testRemoveWebsiteScopeFixture">
41+
<magentoConfigFixture scopeType="website" scopeCode="base" path="test_section/test_group/field_3" remove="true"/>
42+
</method>
43+
<method name="testRemoveWebsiteScopeFixtureWithScopeCode">
44+
<magentoConfigFixture scopeType="website" scopeCode="base" path="test_section/test_group/field_3" remove="true"/>
45+
</method>
46+
</test>
47+
<test class="Magento\TestModuleOverrideConfig\MagentoApiConfigFixture\ReplaceFixtureTest">
48+
<!-- Node bellow will replace value for matching fixture
49+
'newValue' attribute determine to which value current value in matching fixture should be replaced -->
50+
<magentoConfigFixture scopeType="store" scopeCode="default" path="test_section/test_group/field_1" newValue="Overridden fixture for class"/>
51+
<method name="testReplaceFixtureForMethod">
52+
<dataSet name="second_data_set">
53+
<magentoConfigFixture scopeType="store" scopeCode="default" path="test_section/test_group/field_1" newValue="Overridden fixture for data set"/>
54+
</dataSet>
55+
<magentoConfigFixture scopeType="store" scopeCode="default" path="test_section/test_group/field_1" newValue="Overridden fixture for method"/>
56+
</method>
57+
<method name="testReplaceFixtureViaThirdModule" >
58+
<dataSet name="second_data_set">
59+
<magentoConfigFixture scopeType="store" scopeCode="default" path="test_section/test_group/field_1" newValue="Overridden fixture for data set from second module"/>
60+
</dataSet>
61+
<magentoConfigFixture scopeType="store" scopeCode="default" path="test_section/test_group/field_1" newValue="Overridden fixture for method from second module"/>
62+
</method>
63+
<method name="testReplaceWebsiteScopedFixture">
64+
<magentoConfigFixture scopeType="website" scopeCode="base" path="test_section/test_group/field_1" newValue="Overridden value for website scope"/>
65+
</method>
66+
<method name="testReplaceDefaultConfig">
67+
<magentoConfigFixture path="test_section/test_group/field_1" newValue="Overridden value for default scope"/>
68+
</method>
69+
</test>
70+
<test class="Magento\TestModuleOverrideConfig\MagentoApiDataFixture\AddFixtureTest">
71+
<!-- 'path' attribute determine path to fixture for which config should be applied
72+
if only this attribute specified the fixture with such path will be applied -->
73+
<magentoApiDataFixture path="Magento/TestModuleOverrideConfig2/_files/fixture1_second_module.php"/>
74+
<method name="testAddFixtures">
75+
<magentoApiDataFixture path="Magento/TestModuleOverrideConfig2/_files/fixture2_second_module.php"/>
76+
<dataSet name="first_data_set">
77+
<magentoApiDataFixture path="Magento/TestModuleOverrideConfig2/_files/fixture3_second_module.php"/>
78+
</dataSet>
79+
</method>
80+
<method name="testAddSameFixtures">
81+
<!-- Few same data fixtures can be applied for one test -->
82+
<magentoApiDataFixture path="Magento/TestModuleOverrideConfig2/_files/fixture2_second_module.php"/>
83+
<magentoApiDataFixture path="Magento/TestModuleOverrideConfig2/_files/fixture2_second_module.php"/>
84+
</method>
85+
<method name="testAddFixtureWithRequiredFixture">
86+
<magentoApiDataFixture path="Magento/TestModuleOverrideConfig2/_files/fixture_with_required_fixture.php"/>
87+
</method>
88+
</test>
89+
<test class="Magento\TestModuleOverrideConfig\MagentoApiDataFixture\RemoveFixtureTest">
90+
<!-- 'remove' attribute support boolean values, to remove fixture with specified path you need to set this 'remove' attribute to 'true' -->
91+
<magentoApiDataFixture path="Magento/TestModuleOverrideConfig/_files/fixture1_first_module.php" remove="true"/>
92+
<method name="testRemoveFixtureForMethod">
93+
<magentoApiDataFixture path="Magento/TestModuleOverrideConfig/_files/fixture2_first_module.php" remove="true"/>
94+
<dataSet name="second_data_set">
95+
<magentoApiDataFixture path="Magento/TestModuleOverrideConfig/_files/fixture3_first_module.php" remove="true"/>
96+
</dataSet>
97+
</method>
98+
<method name="testRemoveSameFixtures">
99+
<magentoApiDataFixture path="Magento/TestModuleOverrideConfig/_files/fixture2_first_module.php" remove="true"/>
100+
<magentoApiDataFixture path="Magento/TestModuleOverrideConfig/_files/fixture2_first_module.php" remove="true"/>
101+
</method>
102+
</test>
103+
<test class="Magento\TestModuleOverrideConfig\MagentoApiDataFixture\ReplaceFixtureTest">
104+
<!-- Node bellow will call specified in 'newPath' attribute fixture instead of fixture specified in 'path' attribute
105+
if such fixture exist in fixtures list -->
106+
<magentoApiDataFixture path="Magento/TestModuleOverrideConfig/_files/fixture1_first_module.php" newPath="Magento/TestModuleOverrideConfig2/_files/fixture1_second_module.php" />
107+
<!-- If you specify data fixture to replace you should also specify rollback fixture in the separate node-->
108+
<magentoApiDataFixture path="Magento/TestModuleOverrideConfig/_files/fixture1_first_module_rollback.php" newPath="Magento/TestModuleOverrideConfig2/_files/fixture1_second_module_rollback.php" />
109+
110+
<method name="testReplaceFixturesForMethod">
111+
<magentoApiDataFixture path="Magento/TestModuleOverrideConfig/_files/fixture1_first_module.php" newPath="Magento/TestModuleOverrideConfig2/_files/fixture2_second_module.php" />
112+
<magentoApiDataFixture path="Magento/TestModuleOverrideConfig/_files/fixture1_first_module_rollback.php" newPath="Magento/TestModuleOverrideConfig2/_files/fixture2_second_module_rollback.php" />
113+
<dataSet name="second_data_set">
114+
<magentoApiDataFixture path="Magento/TestModuleOverrideConfig/_files/fixture1_first_module.php" newPath="Magento/TestModuleOverrideConfig2/_files/fixture3_second_module.php" />
115+
<magentoApiDataFixture path="Magento/TestModuleOverrideConfig/_files/fixture1_first_module_rollback.php" newPath="Magento/TestModuleOverrideConfig2/_files/fixture3_second_module_rollback.php" />
116+
</dataSet>
117+
</method>
118+
<method name="testReplaceFixtureViaThirdModule">
119+
<magentoApiDataFixture path="Magento/TestModuleOverrideConfig/_files/fixture1_first_module.php" newPath="Magento/TestModuleOverrideConfig2/_files/fixture2_second_module.php" />
120+
<magentoApiDataFixture path="Magento/TestModuleOverrideConfig/_files/fixture1_first_module_rollback.php" newPath="Magento/TestModuleOverrideConfig2/_files/fixture2_second_module_rollback.php" />
121+
<dataSet name="first_data_set">
122+
<magentoApiDataFixture path="Magento/TestModuleOverrideConfig/_files/fixture1_first_module.php" newPath="Magento/TestModuleOverrideConfig2/_files/fixture3_second_module.php" />
123+
<magentoApiDataFixture path="Magento/TestModuleOverrideConfig/_files/fixture1_first_module_rollback.php" newPath="Magento/TestModuleOverrideConfig2/_files/fixture3_second_module_rollback.php" />
124+
</dataSet>
125+
</method>
126+
<method name="testReplaceRequiredFixture">
127+
<magentoApiDataFixture path="Magento/TestModuleOverrideConfig2/_files/fixture3_second_module.php" newPath="Magento/TestModuleOverrideConfig2/_files/fixture2_second_module.php" />
128+
</method>
129+
</test>
130+
<test class="Magento\TestModuleOverrideConfig\MagentoApiDataFixture\SortFixturesTest">
131+
<!-- 'after' attribute determine after which fixture current fixture should be placed, '-' value means that fixture shold be placed after all -->
132+
<magentoApiDataFixture path="Magento/TestModuleOverrideConfig2/_files/fixture1_second_module.php" after="Magento/TestModuleOverrideConfig/_files/fixture1_first_module.php"/>
133+
<method name="testSortFixtures">
134+
<magentoApiDataFixture path="Magento/TestModuleOverrideConfig2/_files/fixture2_second_module.php" after="-"/>
135+
<dataSet name="first_data_set">
136+
<magentoApiDataFixture path="Magento/TestModuleOverrideConfig2/_files/fixture3_second_module.php" before="-"/>
137+
</dataSet>
138+
</method>
139+
</test>
140+
<!-- 'skip' attribute accept boolean values and will mark test as skipped test for which it specified if value set to 'true'-->
141+
<test class="Magento\TestModuleOverrideConfig\Skip\SkipClassTest" skip="true"/>
142+
<test class="Magento\TestModuleOverrideConfig\Skip\SkipMethodTest">
143+
<method name="testMethodSkip" skip="true"/>
144+
</test>
145+
<test class="Magento\TestModuleOverrideConfig\Skip\SkipDataSetTest">
146+
<method name="testSkipDataSet">
147+
<dataSet name="first_data_set" skip="true"/>
148+
</method>
149+
</test>
150+
</overrides>
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"name": "magento/module-override-config2-test",
3+
"description": "module for override config check",
4+
"config": {
5+
"sort-packages": true
6+
},
7+
"require": {
8+
"php": "~7.3.0||~7.4.0",
9+
"magento/framework": "*",
10+
"magento/module-integration": "*"
11+
},
12+
"type": "magento2-module",
13+
"extra": {
14+
"map": [
15+
[
16+
"*",
17+
"Magento/TestModuleOverrideConfig2"
18+
]
19+
]
20+
}
21+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?xml version="1.0"?>
2+
<!--
3+
/**
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
9+
<module name="Magento_TestModuleOverrideConfig2">
10+
<sequence>
11+
<module name="Magento_TestModuleOverrideConfig"/>
12+
</sequence>
13+
</module>
14+
</config>
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
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\Framework\Component\ComponentRegistrar;
9+
10+
$registrar = new ComponentRegistrar();
11+
if ($registrar->getPath(ComponentRegistrar::MODULE, 'Magento_TestModuleOverrideConfig2') === null) {
12+
ComponentRegistrar::register(ComponentRegistrar::MODULE, 'Magento_TestModuleOverrideConfig2', __DIR__);
13+
}

0 commit comments

Comments
 (0)