This commit is contained in:
2026-09-15 10:26:34 +08:00
commit ecf36afa56
10493 changed files with 1404888 additions and 0 deletions
@@ -0,0 +1,109 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);
namespace Magento\TestModuleOverrideConfig\MagentoApiConfigFixture;
use Magento\Framework\App\Config\ScopeConfigInterface;
use Magento\Store\Model\ScopeInterface;
use Magento\TestFramework\Config\Model\ConfigStorage;
use Magento\TestModuleOverrideConfig\AbstractOverridesTest;
/**
* Class checks that magentoConfigFixtures can be added via override config
*
* @magentoAppIsolation enabled
*/
class AddFixtureTest extends AbstractOverridesTest
{
/** @var ScopeConfigInterface */
private $config;
/** @var ConfigStorage */
private $configStorage;
/**
* @inheritdoc
*/
protected function setUp(): void
{
parent::setUp();
$this->config = $this->objectManager->get(ScopeConfigInterface::class);
$this->configStorage = $this->objectManager->get(ConfigStorage::class);
}
/**
* Checks that fixture added in test class node successfully applied
*
* @return void
*/
public function testAddFixtureToClass(): void
{
$value = $this->config->getValue('test_section/test_group/field_1', ScopeInterface::SCOPE_STORES, 'default');
$this->assertEquals('overridden value for full class', $value);
$this->assertEquals(
'overridden value for full class',
$this->configStorage->getValueFromDb(
'test_section/test_group/field_1',
ScopeInterface::SCOPE_STORES,
'default'
)
);
}
/**
* Checks that fixtures added in method and data set nodes successfully applied
*
* @dataProvider testDataProvider
*
* @param string $expectedConfigValue
* @return void
*/
public function testAddFixtureToMethod(string $expectedConfigValue): void
{
$value = $this->config->getValue('test_section/test_group/field_1', ScopeInterface::SCOPE_STORES, 'default');
$this->assertEquals($expectedConfigValue, $value);
$this->assertEquals(
$expectedConfigValue,
$this->configStorage->getValueFromDb(
'test_section/test_group/field_1',
ScopeInterface::SCOPE_STORES,
'default'
)
);
}
/**
* @return array
*/
public function testDataProvider(): array
{
return [
'first_data_set' => ['expected_config_value' => 'overridden value for method'],
'second_data_set' => ['expected_config_value' => 'overridden value for data set']
];
}
/**
* Checks that fixtures can be added on website scope
*
* @return void
*/
public function testAddFixtureOnWebsiteScope(): void
{
$value = $this->config->getValue('test_section/test_group/field_1', ScopeInterface::SCOPE_WEBSITES, 'base');
$this->assertEquals('overridden value for method on website scope', $value);
$this->assertEquals(
'overridden value for method on website scope',
$this->configStorage->getValueFromDb(
'test_section/test_group/field_1',
ScopeInterface::SCOPE_WEBSITES,
'base'
)
);
}
}
@@ -0,0 +1,178 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);
namespace Magento\TestModuleOverrideConfig\MagentoApiConfigFixture;
use Magento\Framework\App\Config\ScopeConfigInterface;
use Magento\Store\Model\ScopeInterface;
use Magento\TestFramework\Config\Model\ConfigStorage;
use Magento\TestModuleOverrideConfig\AbstractOverridesTest;
/**
* Class checks that magentoConfigFixtures can be removed using override config
*
* @magentoAppIsolation enabled
*/
class RemoveFixtureTest extends AbstractOverridesTest
{
/** @var ScopeConfigInterface */
private $config;
/** @var ConfigStorage */
private $configStorage;
/**
* @inheritdoc
*/
protected function setUp(): void
{
parent::setUp();
$this->config = $this->objectManager->get(ScopeConfigInterface::class);
$this->configStorage = $this->objectManager->get(ConfigStorage::class);
}
/**
* Checks that fixture can be removed in test class node
*
* @magentoConfigFixture default_store test_section/test_group/field_1 new_value
*
* @return void
*/
public function testRemoveFixtureForClass(): void
{
$value = $this->config->getValue(
'test_section/test_group/field_1',
ScopeInterface::SCOPE_STORES,
'default'
);
$this->assertEquals('1st field default value', $value);
$this->assertFalse(
$this->configStorage->checkIsRecordExist(
'test_section/test_group/field_1',
ScopeInterface::SCOPE_STORES,
'default'
)
);
}
/**
* Checks that fixtures can be removed in method and data set nodes
*
* @magentoConfigFixture default_store test_section/test_group/field_2 new_value
* @magentoConfigFixture default_store test_section/test_group/field_3 new_value
*
* @dataProvider testDataProvider
*
* @param string $expectedFirstValue
* @param string $expectedSecondValue
* @param bool $firstvalueExist
* @param bool $secondvalueExist
* @return void
*/
public function testRemoveFixtureForMethod(
string $expectedFirstValue,
string $expectedSecondValue,
bool $firstvalueExist,
bool $secondvalueExist
): void {
$fistValue = $this->config->getValue(
'test_section/test_group/field_2',
ScopeInterface::SCOPE_STORES,
'default'
);
$secondValue = $this->config->getValue(
'test_section/test_group/field_3',
ScopeInterface::SCOPE_STORES,
'default'
);
$this->assertEquals($expectedFirstValue, $fistValue);
if ($firstvalueExist) {
$this->assertEquals(
$expectedFirstValue,
$this->configStorage->getValueFromDb(
'test_section/test_group/field_2',
ScopeInterface::SCOPE_STORES,
'default'
)
);
}
$this->assertEquals(
$firstvalueExist,
$this->configStorage->checkIsRecordExist(
'test_section/test_group/field_2',
ScopeInterface::SCOPE_STORES,
'default'
)
);
$this->assertEquals($expectedSecondValue, $secondValue);
if ($secondvalueExist) {
$this->assertEquals(
$expectedSecondValue,
$this->configStorage->getValueFromDb(
'test_section/test_group/field_3',
ScopeInterface::SCOPE_STORES,
'default'
)
);
}
$this->assertEquals(
$secondvalueExist,
$this->configStorage->checkIsRecordExist(
'test_section/test_group/field_3',
ScopeInterface::SCOPE_STORES,
'default'
)
);
}
/**
* @return array
*/
public function testDataProvider(): array
{
return [
'first_data_set' => [
'expected_first_config_value' => '2nd field default value',
'expected_second_config_value' => 'new_value',
'first_value_exist' => false,
'second_value_exist' => true,
],
'second_data_set' => [
'expected_first_config_value' => '2nd field default value',
'expected_second_config_value' => '3rd field website scope default value',
'first_value_exist' => false,
'second_value_exist' => false,
],
];
}
/**
* Checks that website scope fixture can be removed
*
* @magentoConfigFixture base_website test_section/test_group/field_3 new_value
*
* @return void
*/
public function testRemoveWebsiteScopeFixture(): void
{
$value = $this->config->getValue(
'test_section/test_group/field_3',
ScopeInterface::SCOPE_WEBSITES,
'base'
);
$this->assertEquals('3rd field website scope default value', $value);
$this->assertFalse(
$this->configStorage->checkIsRecordExist(
'test_section/test_group/field_3',
ScopeInterface::SCOPE_WEBSITES,
'base'
)
);
}
}
@@ -0,0 +1,178 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);
namespace Magento\TestModuleOverrideConfig\MagentoApiConfigFixture;
use Magento\Framework\App\Config\ScopeConfigInterface;
use Magento\Store\Model\ScopeInterface;
use Magento\TestFramework\Config\Model\ConfigStorage;
use Magento\TestModuleOverrideConfig\AbstractOverridesTest;
/**
* Class check that fixtures can be replaced using override config
*
* @magentoAppIsolation enabled
*/
class ReplaceFixtureTest extends AbstractOverridesTest
{
/** @var ScopeConfigInterface */
private $config;
/** @var ConfigStorage */
private $configStorage;
/**
* @inheritdoc
*/
protected function setUp(): void
{
parent::setUp();
$this->config = $this->objectManager->get(ScopeConfigInterface::class);
$this->configStorage = $this->objectManager->get(ConfigStorage::class);
}
/**
* Checks that fixture can be replaced in test class node
*
* @magentoConfigFixture default_store test_section/test_group/field_1 new_value
*
* @return void
*/
public function testReplaceFixtureForClass(): void
{
$expectedValue = 'Overridden fixture for class';
$value = $this->config->getValue('test_section/test_group/field_1', ScopeInterface::SCOPE_STORES, 'default');
$this->assertEquals($expectedValue, $value);
$this->assertEquals(
$expectedValue,
$this->configStorage->getValueFromDb(
'test_section/test_group/field_1',
ScopeInterface::SCOPE_STORES,
'default'
)
);
}
/**
* Checks that fixture can be replaced in method and data set nodes
*
* @magentoConfigFixture default_store test_section/test_group/field_1 new_value
*
* @dataProvider testDataProvider
*
* @param string $expectedConfigValue
* @return void
*/
public function testReplaceFixtureForMethod(string $expectedConfigValue): void
{
$value = $this->config->getValue('test_section/test_group/field_1', ScopeInterface::SCOPE_STORES, 'default');
$this->assertEquals($expectedConfigValue, $value);
$this->assertEquals(
$expectedConfigValue,
$this->configStorage->getValueFromDb(
'test_section/test_group/field_1',
ScopeInterface::SCOPE_STORES,
'default'
)
);
}
/**
* @return array
*/
public function testDataProvider(): array
{
return [
'first_data_set' => [
'expected_config_value' => 'Overridden fixture for method',
],
'second_data_set' => [
'expected_config_value' => 'Overridden fixture for data set',
],
];
}
/**
* Checks that website scope fixture can be replaced
*
* @magentoConfigFixture base_website test_section/test_group/field_1 new_value
*
* @return void
*/
public function testReplaceWebsiteScopedFixture(): void
{
$expectedConfigValue = 'Overridden value for website scope';
$value = $this->config->getValue('test_section/test_group/field_1', ScopeInterface::SCOPE_WEBSITES, 'base');
$this->assertEquals($expectedConfigValue, $value);
$this->assertEquals(
$expectedConfigValue,
$this->configStorage->getValueFromDb(
'test_section/test_group/field_1',
ScopeInterface::SCOPE_WEBSITE,
'base'
)
);
}
/**
* Checks that replace config from last loaded file will be applied
*
* @magentoConfigFixture default_store test_section/test_group/field_1 new_value
*
* @dataProvider configValuesProvider
*
* @param string $expectedConfigValue
* @return void
*/
public function testReplaceFixtureViaThirdModule(string $expectedConfigValue): void
{
$value = $this->config->getValue('test_section/test_group/field_1', ScopeInterface::SCOPE_STORES, 'default');
$this->assertEquals($expectedConfigValue, $value);
$this->assertEquals(
$expectedConfigValue,
$this->configStorage->getValueFromDb(
'test_section/test_group/field_1',
ScopeInterface::SCOPE_STORES,
'default'
)
);
}
/**
* @return array
*/
public function configValuesProvider(): array
{
return [
'first_data_set' => [
'expected_config_value' => 'Overridden fixture for method from third module',
],
'second_data_set' => [
'expected_config_value' => 'Overridden fixture for data set from third module',
],
];
}
/**
* Checks that fixture for global scope can be replaced
*
* @magentoConfigFixture test_section/test_group/field_1 new_value
*
* @return void
*/
public function testReplaceDefaultConfig(): void
{
$expectedConfigValue = 'Overridden value for default scope';
$value = $this->config->getValue('test_section/test_group/field_1');
$this->assertEquals('Overridden value for default scope', $value);
$this->assertEquals(
$expectedConfigValue,
$this->configStorage->getValueFromDb('test_section/test_group/field_1')
);
}
}