Skip to content

Commit

Permalink
Merge pull request magento#5761 from magento-tsg/2.4-develop-com-api-…
Browse files Browse the repository at this point in the history
…func-improve

[TSG-Commerce] Tests for 2.4.1 (api-func-improve)
  • Loading branch information
zakdma authored Jun 5, 2020
2 parents 082e3cc + d222581 commit d8ca81c
Show file tree
Hide file tree
Showing 59 changed files with 2,684 additions and 491 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
<?php
/**
*
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\TestModuleOverrideConfig\Model;

/**
* Class represent simple container to save data
*/
class FixtureCallStorage
{
/** @var array */
private $storage = [];

/**
* Add fixture to storage
*
* @param string $fixture
* @return void
*/
public function addFixtureToStorage(string $fixture): void
{
$this->storage[] = $fixture;
}

/**
* Get fixture position in storage
*
* @param string $fixture
* @return null|int
*/
public function getFixturePosition(string $fixture): ?int
{
return array_search($fixture, $this->storage) ?: null;
}

/**
* Get storage
*
* @return array
*/
public function getStorage(): array
{
return $this->storage;
}

/**
* Get fixtures count in storage
*
* @param string $fixture
* @return int
*/
public function getFixturesCount(string $fixture = ''): int
{
$count = count($this->storage);
if ($fixture) {
$result = array_filter($this->storage, function ($storedFixture) use ($fixture) {
return $storedFixture === $fixture;
});
$count = count($result);
}

return $count;
}

/**
* Clear storage
*
* @return void
*/
public function clearStorage(): void
{
$this->storage = [];
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"name": "magento/module-override-config-test",
"description": "module for override config check",
"config": {
"sort-packages": true
},
"require": {
"php": "~7.3.0||~7.4.0",
"magento/framework": "*",
"magento/module-integration": "*"
},
"type": "magento2-module",
"extra": {
"map": [
[
"*",
"Magento/TestModuleOverrideConfig"
]
]
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version="1.0"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Config:etc/system_file.xsd">
<system>
<section id="test_section" translate="label" type="text" sortOrder="10" showInDefault="1" showInWebsite="1" showInStore="1">
<group id="test_group" translate="label" type="text" sortOrder="100" showInDefault="1" showInWebsite="1" showInStore="1">
<field id="field_1" translate="label" type="text" sortOrder="10" showInDefault="1" showInWebsite="1" showInStore="1"/>
<field id="field_2" translate="label" type="text" sortOrder="10" showInDefault="1" showInWebsite="1" showInStore="1"/>
<field id="field_3" translate="label" type="text" sortOrder="10" showInDefault="1" showInWebsite="1" showInStore="1"/>
</group>
</section>
</system>
</config>
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?xml version="1.0"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Store:etc/config.xsd">
<default>
<test_section>
<test_group>
<field_1>1st field default value</field_1>
<field_2>2nd field default value</field_2>
<field_3>3rd field default value</field_3>
</test_group>
</test_section>
</default>
<websites>
<base>
<test_section>
<test_group>
<field_3>3rd field website scope default value</field_3>
</test_group>
</test_section>
</base>
</websites>
</config>
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="Magento_TestModuleOverrideConfig" />
</config>
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

use Magento\Framework\Component\ComponentRegistrar;

$registrar = new ComponentRegistrar();
if ($registrar->getPath(ComponentRegistrar::MODULE, 'Magento_TestModuleOverrideConfig') === null) {
ComponentRegistrar::register(ComponentRegistrar::MODULE, 'Magento_TestModuleOverrideConfig', __DIR__);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
<?xml version="1.0"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->
<overrides>
<!-- test node determine to which class config inside node should be applied -->
<test class="Magento\TestModuleOverrideConfig\MagentoApiConfigFixture\AddFixtureTest">
<!-- Node bellow will add magentoConfigFixture to fixtures list
'scopeType' required attribute and accept such values: store|website
'scopeCode' store|website code
skip 'scopeType' and 'scopeCode' attributes to set value in default scope
'path' required attribute determine config path, 'value' attribute determine which value will be set for provided path
to add fixture to fixtures list
-->
<magentoConfigFixture scopeType="store" scopeCode="default" path="test_section/test_group/field_1" value="overridden value for full class"/>
<!-- method node determine to which test method config inside node should be applied -->
<method name="testAddFixtureToMethod">
<magentoConfigFixture scopeType="store" scopeCode="default" path="test_section/test_group/field_1" value="overridden value for method"/>
<!-- dataSet node determine for which data set config inside should be applied -->
<dataSet name="second_data_set">
<magentoConfigFixture scopeType="store" scopeCode="default" path="test_section/test_group/field_1" value="overridden value for data set"/>
</dataSet>
</method>
<method name="testAddFixtureOnWebsiteScope">
<magentoConfigFixture scopeType="website" scopeCode="base" path="test_section/test_group/field_1" value="overridden value for method on website scope"/>
</method>
</test>
<test class="Magento\TestModuleOverrideConfig\MagentoApiConfigFixture\RemoveFixtureTest">
<!-- 'remove' attribute accept bool values, if value set to 'true' this node will remove matching fixture from fixtures list-->
<magentoConfigFixture scopeType="store" scopeCode="default" path="test_section/test_group/field_1" remove="true"/>
<method name="testRemoveFixtureForMethod">
<magentoConfigFixture scopeType="store" scopeCode="default" path="test_section/test_group/field_2" remove="true"/>
<dataSet name="second_data_set">
<magentoConfigFixture scopeType="store" scopeCode="default" path="test_section/test_group/field_3" remove="true"/>
</dataSet>
</method>
<method name="testRemoveWebsiteScopeFixture">
<magentoConfigFixture scopeType="website" scopeCode="base" path="test_section/test_group/field_3" remove="true"/>
</method>
<method name="testRemoveWebsiteScopeFixtureWithScopeCode">
<magentoConfigFixture scopeType="website" scopeCode="base" path="test_section/test_group/field_3" remove="true"/>
</method>
</test>
<test class="Magento\TestModuleOverrideConfig\MagentoApiConfigFixture\ReplaceFixtureTest">
<!-- Node bellow will replace value for matching fixture
'newValue' attribute determine to which value current value in matching fixture should be replaced -->
<magentoConfigFixture scopeType="store" scopeCode="default" path="test_section/test_group/field_1" newValue="Overridden fixture for class"/>
<method name="testReplaceFixtureForMethod">
<dataSet name="second_data_set">
<magentoConfigFixture scopeType="store" scopeCode="default" path="test_section/test_group/field_1" newValue="Overridden fixture for data set"/>
</dataSet>
<magentoConfigFixture scopeType="store" scopeCode="default" path="test_section/test_group/field_1" newValue="Overridden fixture for method"/>
</method>
<method name="testReplaceFixtureViaThirdModule" >
<dataSet name="second_data_set">
<magentoConfigFixture scopeType="store" scopeCode="default" path="test_section/test_group/field_1" newValue="Overridden fixture for data set from second module"/>
</dataSet>
<magentoConfigFixture scopeType="store" scopeCode="default" path="test_section/test_group/field_1" newValue="Overridden fixture for method from second module"/>
</method>
<method name="testReplaceWebsiteScopedFixture">
<magentoConfigFixture scopeType="website" scopeCode="base" path="test_section/test_group/field_1" newValue="Overridden value for website scope"/>
</method>
<method name="testReplaceDefaultConfig">
<magentoConfigFixture path="test_section/test_group/field_1" newValue="Overridden value for default scope"/>
</method>
</test>
<test class="Magento\TestModuleOverrideConfig\MagentoApiDataFixture\AddFixtureTest">
<!-- 'path' attribute determine path to fixture for which config should be applied
if only this attribute specified the fixture with such path will be applied -->
<magentoApiDataFixture path="Magento/TestModuleOverrideConfig2/_files/fixture1_second_module.php"/>
<method name="testAddFixtures">
<magentoApiDataFixture path="Magento/TestModuleOverrideConfig2/_files/fixture2_second_module.php"/>
<dataSet name="first_data_set">
<magentoApiDataFixture path="Magento/TestModuleOverrideConfig2/_files/fixture3_second_module.php"/>
</dataSet>
</method>
<method name="testAddSameFixtures">
<!-- Few same data fixtures can be applied for one test -->
<magentoApiDataFixture path="Magento/TestModuleOverrideConfig2/_files/fixture2_second_module.php"/>
<magentoApiDataFixture path="Magento/TestModuleOverrideConfig2/_files/fixture2_second_module.php"/>
</method>
<method name="testAddFixtureWithRequiredFixture">
<magentoApiDataFixture path="Magento/TestModuleOverrideConfig2/_files/fixture_with_required_fixture.php"/>
</method>
</test>
<test class="Magento\TestModuleOverrideConfig\MagentoApiDataFixture\RemoveFixtureTest">
<!-- 'remove' attribute support boolean values, to remove fixture with specified path you need to set this 'remove' attribute to 'true' -->
<magentoApiDataFixture path="Magento/TestModuleOverrideConfig/_files/fixture1_first_module.php" remove="true"/>
<method name="testRemoveFixtureForMethod">
<magentoApiDataFixture path="Magento/TestModuleOverrideConfig/_files/fixture2_first_module.php" remove="true"/>
<dataSet name="second_data_set">
<magentoApiDataFixture path="Magento/TestModuleOverrideConfig/_files/fixture3_first_module.php" remove="true"/>
</dataSet>
</method>
<method name="testRemoveSameFixtures">
<magentoApiDataFixture path="Magento/TestModuleOverrideConfig/_files/fixture2_first_module.php" remove="true"/>
<magentoApiDataFixture path="Magento/TestModuleOverrideConfig/_files/fixture2_first_module.php" remove="true"/>
</method>
</test>
<test class="Magento\TestModuleOverrideConfig\MagentoApiDataFixture\ReplaceFixtureTest">
<!-- Node bellow will call specified in 'newPath' attribute fixture instead of fixture specified in 'path' attribute
if such fixture exist in fixtures list -->
<magentoApiDataFixture path="Magento/TestModuleOverrideConfig/_files/fixture1_first_module.php" newPath="Magento/TestModuleOverrideConfig2/_files/fixture1_second_module.php" />
<!-- If you specify data fixture to replace you should also specify rollback fixture in the separate node-->
<magentoApiDataFixture path="Magento/TestModuleOverrideConfig/_files/fixture1_first_module_rollback.php" newPath="Magento/TestModuleOverrideConfig2/_files/fixture1_second_module_rollback.php" />

<method name="testReplaceFixturesForMethod">
<magentoApiDataFixture path="Magento/TestModuleOverrideConfig/_files/fixture1_first_module.php" newPath="Magento/TestModuleOverrideConfig2/_files/fixture2_second_module.php" />
<magentoApiDataFixture path="Magento/TestModuleOverrideConfig/_files/fixture1_first_module_rollback.php" newPath="Magento/TestModuleOverrideConfig2/_files/fixture2_second_module_rollback.php" />
<dataSet name="second_data_set">
<magentoApiDataFixture path="Magento/TestModuleOverrideConfig/_files/fixture1_first_module.php" newPath="Magento/TestModuleOverrideConfig2/_files/fixture3_second_module.php" />
<magentoApiDataFixture path="Magento/TestModuleOverrideConfig/_files/fixture1_first_module_rollback.php" newPath="Magento/TestModuleOverrideConfig2/_files/fixture3_second_module_rollback.php" />
</dataSet>
</method>
<method name="testReplaceFixtureViaThirdModule">
<magentoApiDataFixture path="Magento/TestModuleOverrideConfig/_files/fixture1_first_module.php" newPath="Magento/TestModuleOverrideConfig2/_files/fixture2_second_module.php" />
<magentoApiDataFixture path="Magento/TestModuleOverrideConfig/_files/fixture1_first_module_rollback.php" newPath="Magento/TestModuleOverrideConfig2/_files/fixture2_second_module_rollback.php" />
<dataSet name="first_data_set">
<magentoApiDataFixture path="Magento/TestModuleOverrideConfig/_files/fixture1_first_module.php" newPath="Magento/TestModuleOverrideConfig2/_files/fixture3_second_module.php" />
<magentoApiDataFixture path="Magento/TestModuleOverrideConfig/_files/fixture1_first_module_rollback.php" newPath="Magento/TestModuleOverrideConfig2/_files/fixture3_second_module_rollback.php" />
</dataSet>
</method>
<method name="testReplaceRequiredFixture">
<magentoApiDataFixture path="Magento/TestModuleOverrideConfig2/_files/fixture3_second_module.php" newPath="Magento/TestModuleOverrideConfig2/_files/fixture2_second_module.php" />
</method>
</test>
<test class="Magento\TestModuleOverrideConfig\MagentoApiDataFixture\SortFixturesTest">
<!-- 'after' attribute determine after which fixture current fixture should be placed, '-' value means that fixture shold be placed after all -->
<magentoApiDataFixture path="Magento/TestModuleOverrideConfig2/_files/fixture1_second_module.php" after="Magento/TestModuleOverrideConfig/_files/fixture1_first_module.php"/>
<method name="testSortFixtures">
<magentoApiDataFixture path="Magento/TestModuleOverrideConfig2/_files/fixture2_second_module.php" after="-"/>
<dataSet name="first_data_set">
<magentoApiDataFixture path="Magento/TestModuleOverrideConfig2/_files/fixture3_second_module.php" before="-"/>
</dataSet>
</method>
</test>
<!-- 'skip' attribute accept boolean values and will mark test as skipped test for which it specified if value set to 'true'-->
<test class="Magento\TestModuleOverrideConfig\Skip\SkipClassTest" skip="true"/>
<test class="Magento\TestModuleOverrideConfig\Skip\SkipMethodTest">
<method name="testMethodSkip" skip="true"/>
</test>
<test class="Magento\TestModuleOverrideConfig\Skip\SkipDataSetTest">
<method name="testSkipDataSet">
<dataSet name="first_data_set" skip="true"/>
</method>
</test>
</overrides>
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"name": "magento/module-override-config2-test",
"description": "module for override config check",
"config": {
"sort-packages": true
},
"require": {
"php": "~7.3.0||~7.4.0",
"magento/framework": "*",
"magento/module-integration": "*"
},
"type": "magento2-module",
"extra": {
"map": [
[
"*",
"Magento/TestModuleOverrideConfig2"
]
]
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="Magento_TestModuleOverrideConfig2">
<sequence>
<module name="Magento_TestModuleOverrideConfig"/>
</sequence>
</module>
</config>
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

use Magento\Framework\Component\ComponentRegistrar;

$registrar = new ComponentRegistrar();
if ($registrar->getPath(ComponentRegistrar::MODULE, 'Magento_TestModuleOverrideConfig2') === null) {
ComponentRegistrar::register(ComponentRegistrar::MODULE, 'Magento_TestModuleOverrideConfig2', __DIR__);
}
Loading

0 comments on commit d8ca81c

Please sign in to comment.