ltsecurityinc安防产品在线商城代码

This commit is contained in:
2026-09-14 17:47:10 +08:00
parent 57d8444c15
commit 6a3c9c5bd8
14539 changed files with 1775310 additions and 0 deletions
@@ -0,0 +1,81 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Setup\Console\Command;
use Symfony\Component\Console\Tester\CommandTester;
class DependenciesShowFrameworkCommandTest extends \PHPUnit\Framework\TestCase
{
/**
* @var DependenciesShowFrameworkCommand
*/
private $command;
/**
* @var CommandTester
*/
private $commandTester;
protected function setUp(): void
{
$modules = [
'Magento_A' => __DIR__ . '/_files/root/app/code/Magento/A',
'Magento_B' => __DIR__ . '/_files/root/app/code/Magento/B'
];
$objectManagerProvider = $this->createMock(\Magento\Setup\Model\ObjectManagerProvider::class);
$objectManager = $this->createMock(\Magento\Framework\App\ObjectManager::class);
$objectManagerProvider->expects($this->once())->method('get')->willReturn($objectManager);
$themePackageListMock = $this->createMock(\Magento\Framework\View\Design\Theme\ThemePackageList::class);
$componentRegistrarMock = $this->createMock(\Magento\Framework\Component\ComponentRegistrar::class);
$componentRegistrarMock->expects($this->any())->method('getPaths')->willReturn($modules);
$dirSearchMock = $this->createMock(\Magento\Framework\Component\DirSearch::class);
$dirSearchMock->expects($this->once())->method('collectFiles')->willReturn(
[
__DIR__ . '/_files/root/app/code/Magento/A/etc/module.xml',
__DIR__ . '/_files/root/app/code/Magento/B/etc/module.xml'
]
);
$objectManager->expects($this->any())->method('get')->willReturnMap([
[\Magento\Framework\View\Design\Theme\ThemePackageList::class, $themePackageListMock],
[\Magento\Framework\Component\ComponentRegistrar::class, $componentRegistrarMock],
[\Magento\Framework\Component\DirSearch::class, $dirSearchMock]
]);
$this->command = new DependenciesShowFrameworkCommand($componentRegistrarMock, $objectManagerProvider);
$this->commandTester = new CommandTester($this->command);
}
protected function tearDown(): void
{
if (file_exists(__DIR__ . '/_files/output/framework.csv')) {
unlink(__DIR__ . '/_files/output/framework.csv');
}
}
public function testExecute()
{
$this->commandTester->execute(
['--output' => __DIR__ . '/_files/output/framework.csv']
);
$this->assertEquals('Report successfully processed.' . PHP_EOL, $this->commandTester->getDisplay());
$fileContents = file_get_contents(__DIR__ . '/_files/output/framework.csv');
$this->assertStringContainsString(
'"Dependencies of framework:","Total number"' . PHP_EOL . ',2' . PHP_EOL,
$fileContents
);
$this->assertStringContainsString('"Dependencies for each module:",' . PHP_EOL, $fileContents);
$this->assertStringContainsString(
'Magento\A,1' . PHP_EOL . '" -- Magento\Framework",2' . PHP_EOL,
$fileContents
);
$this->assertStringContainsString(
'Magento\B,1' . PHP_EOL . '" -- Magento\Framework",2' . PHP_EOL,
$fileContents
);
}
}
@@ -0,0 +1,76 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Setup\Console\Command;
use Magento\Framework\Component\ComponentRegistrar;
use Symfony\Component\Console\Tester\CommandTester;
class DependenciesShowModulesCircularCommandTest extends \PHPUnit\Framework\TestCase
{
/**
* @var DependenciesShowModulesCircularCommand
*/
private $command;
/**
* @var CommandTester
*/
private $commandTester;
protected function setUp(): void
{
$modules = [
'Magento_A' => __DIR__ . '/_files/root/app/code/Magento/A',
'Magento_B' => __DIR__ . '/_files/root/app/code/Magento/B'
];
$objectManagerProvider = $this->createMock(\Magento\Setup\Model\ObjectManagerProvider::class);
$objectManager = $this->createMock(\Magento\Framework\App\ObjectManager::class);
$objectManagerProvider->expects($this->once())->method('get')->willReturn($objectManager);
$themePackageListMock = $this->createMock(\Magento\Framework\View\Design\Theme\ThemePackageList::class);
$componentRegistrarMock = $this->createMock(\Magento\Framework\Component\ComponentRegistrar::class);
$componentRegistrarMock->expects($this->any())->method('getPaths')->willReturn($modules);
$dirSearchMock = $this->createMock(\Magento\Framework\Component\DirSearch::class);
$objectManager->expects($this->any())->method('get')->willReturnMap([
[\Magento\Framework\View\Design\Theme\ThemePackageList::class, $themePackageListMock],
[\Magento\Framework\Component\ComponentRegistrar::class, $componentRegistrarMock],
[\Magento\Framework\Component\DirSearch::class, $dirSearchMock]
]);
$this->command = new DependenciesShowModulesCircularCommand($objectManagerProvider);
$this->commandTester = new CommandTester($this->command);
}
protected function tearDown(): void
{
if (file_exists(__DIR__ . '/_files/output/circular.csv')) {
unlink(__DIR__ . '/_files/output/circular.csv');
}
}
public function testExecute()
{
$this->commandTester->execute(
['--output' => __DIR__ . '/_files/output/circular.csv']
);
$this->assertEquals('Report successfully processed.' . PHP_EOL, $this->commandTester->getDisplay());
$fileContents = file_get_contents(__DIR__ . '/_files/output/circular.csv');
$this->assertStringContainsString(
'"Circular dependencies:","Total number of chains"' . PHP_EOL . ',2' . PHP_EOL,
$fileContents
);
$this->assertStringContainsString('"Circular dependencies for each module:",' . PHP_EOL, $fileContents);
$this->assertStringContainsString(
'magento/module-a,1' . PHP_EOL . 'magento/module-a->magento/module-b->magento/module-a' . PHP_EOL,
$fileContents
);
$this->assertStringContainsString(
'magento/module-b,1' . PHP_EOL . 'magento/module-b->magento/module-a->magento/module-b' . PHP_EOL,
$fileContents
);
}
}
@@ -0,0 +1,77 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Setup\Console\Command;
use Magento\Framework\Component\ComponentRegistrar;
use Symfony\Component\Console\Tester\CommandTester;
class DependenciesShowModulesCommandTest extends \PHPUnit\Framework\TestCase
{
/**
* @var DependenciesShowModulesCommand
*/
private $command;
/**
* @var CommandTester
*/
private $commandTester;
protected function setUp(): void
{
$modules = [
'Magento_A' => __DIR__ . '/_files/root/app/code/Magento/A',
'Magento_B' => __DIR__ . '/_files/root/app/code/Magento/B'
];
$objectManagerProvider = $this->createMock(\Magento\Setup\Model\ObjectManagerProvider::class);
$objectManager = $this->createMock(\Magento\Framework\App\ObjectManager::class);
$objectManagerProvider->expects($this->once())->method('get')->willReturn($objectManager);
$themePackageListMock = $this->createMock(\Magento\Framework\View\Design\Theme\ThemePackageList::class);
$componentRegistrarMock = $this->createMock(\Magento\Framework\Component\ComponentRegistrar::class);
$componentRegistrarMock->expects($this->any())->method('getPaths')->willReturn($modules);
$dirSearchMock = $this->createMock(\Magento\Framework\Component\DirSearch::class);
$objectManager->expects($this->any())->method('get')->willReturnMap([
[\Magento\Framework\View\Design\Theme\ThemePackageList::class, $themePackageListMock],
[\Magento\Framework\Component\ComponentRegistrar::class, $componentRegistrarMock],
[\Magento\Framework\Component\DirSearch::class, $dirSearchMock]
]);
$this->command = new DependenciesShowModulesCommand($objectManagerProvider);
$this->commandTester = new CommandTester($this->command);
}
protected function tearDown(): void
{
if (file_exists(__DIR__ . '/_files/output/modules.csv')) {
unlink(__DIR__ . '/_files/output/modules.csv');
}
}
public function testExecute()
{
$this->commandTester->execute(
['--output' => __DIR__ . '/_files/output/modules.csv']
);
$this->assertEquals('Report successfully processed.' . PHP_EOL, $this->commandTester->getDisplay());
$fileContents = file_get_contents(__DIR__ . '/_files/output/modules.csv');
$this->assertStringContainsString(
',All,Hard,Soft' . PHP_EOL . '"Total number of dependencies",2,2,0' . PHP_EOL,
$fileContents
);
$this->assertStringContainsString('"Dependencies for each module:",All,Hard,Soft'. PHP_EOL, $fileContents);
$this->assertStringContainsString(
'magento/module-a,1,1,0' . PHP_EOL . '" -- magento/module-b",,1,0' . PHP_EOL,
$fileContents
);
$this->assertStringContainsString(
'magento/module-b,1,1,0' . PHP_EOL . '" -- magento/module-a",,1,0' . PHP_EOL,
$fileContents
);
}
}
@@ -0,0 +1,210 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Setup\Console\Command;
use Magento\Deploy\Console\DeployStaticOptions;
use Magento\Framework\App\DeploymentConfig\FileReader;
use Magento\Framework\App\DeploymentConfig\Writer;
use Magento\Framework\App\DeploymentConfig\Writer\PhpFormatter;
use Magento\Framework\App\Filesystem\DirectoryList;
use Magento\Framework\Config\File\ConfigFilePool;
use Magento\Framework\Console\Cli;
use Magento\Framework\Filesystem;
use Magento\Framework\ObjectManagerInterface;
use Magento\Store\Model\StoreManagerInterface;
use Magento\TestFramework\Helper\Bootstrap;
use Symfony\Component\Console\Tester\CommandTester;
use Magento\Deploy\Console\ConsoleLoggerFactory;
use Magento\Setup\Model\ObjectManagerProvider;
use Magento\Deploy\Console\ConsoleLogger;
/**
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
*/
class DeployStaticContentCommandTest extends \PHPUnit\Framework\TestCase
{
/**
* @var ObjectManagerInterface
*/
private $objectManager;
/**
* @var CommandTester
*/
private $commandTester;
/**
* @var Filesystem
*/
private $filesystem;
/**
* @var ConfigFilePool
*/
private $configFilePool;
/**
* @var FileReader
*/
private $reader;
/**
* @var Writer
*/
private $writer;
/**
* @var array
*/
private $config;
/**
* @var array
*/
private $envConfig;
/**
* @var StoreManagerInterface
*/
private $storeManager;
/**
* @var PhpFormatter
*/
private $phpFormatter;
/**
* @inheritdoc
*/
protected function setUp(): void
{
$this->objectManager = Bootstrap::getObjectManager();
$this->reader = $this->objectManager->get(FileReader::class);
$this->writer = $this->objectManager->get(Writer::class);
$this->filesystem = $this->objectManager->get(Filesystem::class);
$this->configFilePool = $this->objectManager->get(ConfigFilePool::class);
$this->storeManager = $this->objectManager->get(StoreManagerInterface::class);
$this->phpFormatter = $this->objectManager->get(PhpFormatter::class);
$this->config = $this->loadConfig();
$this->envConfig = $this->loadEnvConfig();
$this->clearStaticFiles();
}
/**
* @inheritdoc
*/
protected function tearDown(): void
{
$this->filesystem->getDirectoryWrite(DirectoryList::CONFIG)->writeFile(
$this->configFilePool->getPath(ConfigFilePool::APP_CONFIG),
"<?php\n return [];\n"
);
$this->filesystem->getDirectoryWrite(DirectoryList::CONFIG)->writeFile(
$this->configFilePool->getPath(ConfigFilePool::APP_ENV),
"<?php\n return [];\n"
);
$this->writer->saveConfig([ConfigFilePool::APP_CONFIG => $this->config]);
$this->writer->saveConfig([ConfigFilePool::APP_ENV => $this->envConfig]);
$this->clearStaticFiles();
$this->storeManager->reinitStores();
}
/**
* Clear pub/static and var/view_preprocessed directories
*
* @return void
*/
private function clearStaticFiles()
{
$this->filesystem->getDirectoryWrite(DirectoryList::PUB)->delete(DirectoryList::STATIC_VIEW);
$this->filesystem->getDirectoryWrite(DirectoryList::VAR_DIR)->delete(DirectoryList::TMP_MATERIALIZATION_DIR);
}
public function testDeployStaticWithoutDbConnection()
{
// emulate app:config:dump command
$newData = array_replace_recursive(
$this->config,
require __DIR__ . '/_files/config/dump_config.php'
);
$this->writer->saveConfig([ConfigFilePool::APP_CONFIG => $newData], true);
// rewrite application environment config with only remote storage details to emulate work without db
$this->filesystem->getDirectoryWrite(DirectoryList::CONFIG)->writeFile(
$this->configFilePool->getPath(ConfigFilePool::APP_ENV),
$this->phpFormatter->format(['remote_storage' => $this->envConfig['remote_storage']])
);
$this->storeManager->reinitStores();
$this->commandTester = new CommandTester($this->getStaticContentDeployCommand());
$this->commandTester->execute(
['--force' => 1, '--' . DeployStaticOptions::THEME => ['Magento/blank']]
);
$commandOutput = $this->commandTester->getDisplay();
$this->assertEquals(Cli::RETURN_SUCCESS, $this->commandTester->getStatusCode());
$this->assertStringContainsString('Execution time:', $commandOutput);
$this->assertStringContainsString('frontend/Magento/blank/en_US', $commandOutput);
$this->assertStringNotContainsString('frontend/Magento/luma/en_US', $commandOutput);
$this->assertStringNotContainsString('adminhtml/Magento/backend', $commandOutput);
}
/**
* @return array
*/
private function loadConfig()
{
return $this->reader->load(ConfigFilePool::APP_CONFIG);
}
/**
* @return array
*/
private function loadEnvConfig()
{
return $this->reader->load(ConfigFilePool::APP_ENV);
}
/**
* Create DeployStaticContentCommand instance with mocked loggers
*
* @return DeployStaticContentCommand
*/
private function getStaticContentDeployCommand()
{
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
$consoleLoggerFactoryMock = $this->getMockBuilder(ConsoleLoggerFactory::class)
->setMethods(['getLogger'])
->disableOriginalConstructor()
->getMock();
$consoleLoggerFactoryMock
->method('getLogger')
->willReturnCallback(
function ($output) use ($objectManager) {
return $objectManager->create(ConsoleLogger::class, ['output' => $output]);
}
);
$objectManagerProviderMock = $this->getMockBuilder(ObjectManagerProvider::class)
->setMethods(['get'])
->disableOriginalConstructor()
->getMock();
$objectManagerProviderMock
->method('get')
->willReturn(\Magento\TestFramework\Helper\Bootstrap::getObjectManager());
$deployStaticContentCommand = $objectManager->create(
DeployStaticContentCommand::class,
[
'consoleLoggerFactory' => $consoleLoggerFactoryMock,
'objectManagerProvider' => $objectManagerProviderMock
]
);
return $deployStaticContentCommand;
}
}
@@ -0,0 +1,147 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Setup\Console\Command;
use Magento\Framework\App\ObjectManagerFactory;
use Magento\Framework\App\ResourceConnection;
use Magento\Framework\Console\Cli;
use Magento\Framework\ObjectManagerInterface;
use Magento\Indexer\Console\Command\IndexerReindexCommand;
use Magento\Setup\Fixtures\FixtureModel;
use Magento\TestFramework\Helper\Bootstrap;
use Symfony\Component\Console\Tester\CommandTester;
/**
* Class GenerateFixturesCommandCommandTest
*
* @magentoDbIsolation disabled
*/
class GenerateFixturesCommandTest extends \Magento\TestFramework\Indexer\TestCase
{
/** @var CommandTester */
private $indexerCommand;
/** @var FixtureModel */
private $fixtureModelMock;
/** @var ObjectManagerInterface */
private $objectManager;
/** @var GenerateFixturesCommand */
private $command;
/** @var CommandTester */
private $commandTester;
/**
* Setup
*/
protected function setUp(): void
{
$this->objectManager = Bootstrap::getObjectManager();
$this->objectManager->get(\Magento\TestFramework\App\Config::class)->clean();
$this->fixtureModelMock = $this->getMockBuilder(FixtureModel::class)
->setMethods(['getObjectManager'])
->setConstructorArgs([$this->objectManager->get(IndexerReindexCommand::class)])
->getMock();
$this->fixtureModelMock
->method('getObjectManager')
->willReturn($this->objectManager);
$this->command = $this->objectManager->create(
GenerateFixturesCommand::class,
[
'fixtureModel' => $this->fixtureModelMock
]
);
$objectFactoryMock = $this->getMockBuilder(ObjectManagerFactory::class)
->setMethods(['create'])
->disableOriginalConstructor()
->getMock();
$objectFactoryMock
->method('create')
->willReturn($this->objectManager);
$this->indexerCommand = new CommandTester($this->objectManager->create(
IndexerReindexCommand::class,
['objectManagerFactory' => $objectFactoryMock]
));
$this->commandTester = new CommandTester($this->command);
$this->setIncrement(3);
parent::setUp();
}
/**
* teardown
*/
protected function tearDown(): void
{
$this->setIncrement(1);
self::restoreFromDb();
self::$dbRestored = true;
parent::tearDown();
}
public static function setUpBeforeClass(): void
{
$db = Bootstrap::getInstance()->getBootstrap()
->getApplication()
->getDbInstance();
if (!$db->isDbDumpExists()) {
throw new \LogicException('DB dump does not exist.');
}
$db->restoreFromDbDump();
parent::setUpBeforeClass();
}
/**
* @magentoAppArea adminhtml
* @magentoAppIsolation enabled
*/
public function testExecute()
{
$profile = realpath(__DIR__ . "/_files/min_profile.xml");
$this->commandTester->execute(
[
GenerateFixturesCommand::PROFILE_ARGUMENT => $profile,
'--' . GenerateFixturesCommand::SKIP_REINDEX_OPTION => true
]
);
$this->indexerCommand->execute([]);
static::assertEquals(
Cli::RETURN_SUCCESS,
$this->indexerCommand->getStatusCode(),
$this->indexerCommand->getDisplay(true)
);
static::assertEquals(
Cli::RETURN_SUCCESS,
$this->commandTester->getStatusCode(),
$this->commandTester->getDisplay(true)
);
}
/**
* @param $value
*/
private function setIncrement($value)
{
/** @var \Magento\Framework\DB\Adapter\AdapterInterface $db */
$db = Bootstrap::getObjectManager()->get(ResourceConnection::class)->getConnection();
$db->query("SET @@session.auto_increment_increment=$value");
$db->query("SET @@session.auto_increment_offset=$value");
}
}
@@ -0,0 +1,99 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Setup\Console\Command;
use Symfony\Component\Console\Tester\CommandTester;
class I18nCollectPhrasesCommandTest extends \PHPUnit\Framework\TestCase
{
/**
* @var I18nCollectPhrasesCommand
*/
private $command;
/**
* @var CommandTester
*/
private $tester;
protected function setUp(): void
{
$this->command = new I18nCollectPhrasesCommand();
$this->tester = new CommandTester($this->command);
}
protected function tearDown(): void
{
$property = new \ReflectionProperty(\Magento\Setup\Module\I18n\ServiceLocator::class, '_dictionaryGenerator');
$property->setAccessible(true);
$property->setValue(null);
$property->setAccessible(false);
}
public function testExecuteConsoleOutput()
{
$this->tester->execute(
[
'directory' => BP . '/dev/tests/integration/testsuite/Magento/Setup/Console/Command/_files/',
]
);
$this->assertEquals('Dictionary successfully processed.' . PHP_EOL, $this->tester->getDisplay());
}
public function testExecuteCsvOutput()
{
$outputPath = BP . '/dev/tests/integration/testsuite/Magento/Setup/Console/Command/_files/output/phrases.csv';
$this->tester->execute(
[
'directory' => BP . '/dev/tests/integration/testsuite/Magento/Setup/Console/Command/_files/phrases/',
'--output' => $outputPath,
]
);
$handle = fopen($outputPath, 'r');
$output = fread($handle, filesize($outputPath));
$expected = file_get_contents(
BP . '/dev/tests/integration/testsuite/Magento/Setup/Console/Command/_files/expectedPhrases.csv'
);
$this->assertEquals($expected, $output);
unlink($outputPath);
}
/**
*/
public function testExecuteNonExistingPath()
{
$this->expectException(\InvalidArgumentException::class);
$this->expectExceptionMessage('Specified path doesn\'t exist');
$this->tester->execute(
[
'directory' => BP . '/dev/tests/integration/testsuite/Magento/Setup/Console/Command/_files/non_exist',
]
);
}
/**
*/
public function testExecuteMagentoFlagDirectoryPath()
{
$this->expectException(\InvalidArgumentException::class);
$this->expectExceptionMessage('Directory path is not needed when --magento flag is set.');
$this->tester->execute(['directory' => 'a', '--magento' => true]);
}
/**
*/
public function testExecuteNoMagentoFlagNoDirectoryPath()
{
$this->expectException(\InvalidArgumentException::class);
$this->expectExceptionMessage('Directory path is needed when --magento flag is not set.');
$this->tester->execute([]);
}
}
@@ -0,0 +1,98 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Setup\Console\Command;
use Symfony\Component\Console\Tester\CommandTester;
/**
* @magentoComponentsDir Magento/Setup/Console/Command/_files/root/app/code
*/
class I18nPackCommandTest extends \PHPUnit\Framework\TestCase
{
/**
* @var I18nCollectPhrasesCommand
*/
private $command;
/**
* @var CommandTester
*/
private $tester;
protected function setUp(): void
{
$this->command = new I18nPackCommand();
$this->tester = new CommandTester($this->command);
}
protected function tearDown(): void
{
$this->removeCsv('A');
$this->removeCsv('B');
$this->removeCsv('C');
$this->removeCsv('D');
}
private function removeCsv($module)
{
if (file_exists(__DIR__ . "/_files/root/app/code/Magento/{$module}/i18n")) {
$helper = new \Magento\Framework\Backup\Filesystem\Helper();
$helper->rm(__DIR__ . "/_files/root/app/code/Magento/{$module}/i18n", [], true);
}
}
public function testExecute()
{
$this->tester->execute(
[
'source' => BP . '/dev/tests/integration/testsuite/Magento/Setup/Console/Command/_files/i18n.csv',
'locale' => 'de_DE',
'--allow-duplicates' => true,
]
);
$this->assertEquals('Successfully saved de_DE language package.' . PHP_EOL, $this->tester->getDisplay());
$basePath = BP . '/dev/tests/integration/testsuite/Magento/Setup/Console/Command/_files/root/app/code';
$this->assertFileExists($basePath . '/Magento/A/i18n/de_DE.csv');
$this->assertFileExists($basePath . '/Magento/B/i18n/de_DE.csv');
$this->assertFileExists($basePath . '/Magento/C/i18n/de_DE.csv');
$this->assertFileExists($basePath . '/Magento/D/i18n/de_DE.csv');
}
/**
*/
public function testExecuteNonExistingPath()
{
$this->expectException(\InvalidArgumentException::class);
$this->expectExceptionMessage('Cannot open dictionary file:');
$nonExistPath = BP . '/dev/tests/integration/testsuite/Magento/Setup/Console/Command/_files/non_exist.csv';
$this->tester->execute(
[
'source' => $nonExistPath,
'locale' => 'de_DE',
'--allow-duplicates' => true,
]
);
}
/**
*/
public function testExecuteInvalidMode()
{
$this->expectException(\InvalidArgumentException::class);
$this->expectExceptionMessage('Possible values for \'mode\' option are \'replace\' and \'merge\'');
$this->tester->execute(
[
'source' => BP . '/dev/tests/integration/testsuite/Magento/Setup/Console/Command/_files/i18n.csv',
'locale' => 'de_DE',
'--allow-duplicates' => true,
'--mode' => 'invalid'
]
);
}
}
@@ -0,0 +1,164 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Setup\Console\Command;
use Magento\Catalog\Model\Indexer\Product\Price\DimensionModeConfiguration;
use Symfony\Component\Console\Tester\CommandTester;
use Magento\Framework\Console\Cli;
use Magento\Framework\ObjectManagerInterface;
use Magento\TestFramework\Helper\Bootstrap;
/**
* Test command that sets indexer mode for catalog_product_price indexer
*
* @magentoDbIsolation disabled
*/
class PriceIndexerDimensionsModeSetCommandTest extends \Magento\TestFramework\Indexer\TestCase
{
/** @var ObjectManagerInterface */
private $objectManager;
/** @var \Magento\Indexer\Console\Command\IndexerSetDimensionsModeCommand */
private $command;
/** @var CommandTester */
private $commandTester;
/**
* setUp
*/
protected function setUp(): void
{
$this->objectManager = Bootstrap::getObjectManager();
$this->objectManager->get(\Magento\TestFramework\App\Config::class)->clean();
$this->command = $this->objectManager->create(
\Magento\Indexer\Console\Command\IndexerSetDimensionsModeCommand::class
);
$this->commandTester = new CommandTester($this->command);
parent::setUp();
}
/**
* setUpBeforeClass
*/
public static function setUpBeforeClass(): void
{
$db = Bootstrap::getInstance()->getBootstrap()
->getApplication()
->getDbInstance();
if (!$db->isDbDumpExists()) {
throw new \LogicException('DB dump does not exist.');
}
$db->restoreFromDbDump();
parent::setUpBeforeClass();
}
/**
* @magentoAppArea adminhtml
* @magentoAppIsolation enabled
*
* @param string $previousMode
* @param string $currentMode
* @dataProvider modesDataProvider
*/
public function testSwitchMode($previousMode, $currentMode)
{
$this->commandTester->execute(
[
'indexer' => 'catalog_product_price',
'mode' => $currentMode,
]
);
$expectedOutput = 'Dimensions mode for indexer "Product Price" was changed from \''
. $previousMode . '\' to \'' . $currentMode . '\'' . PHP_EOL;
$actualOutput = $this->commandTester->getDisplay();
$this->assertStringContainsString($expectedOutput, $actualOutput);
static::assertEquals(
Cli::RETURN_SUCCESS,
$this->commandTester->getStatusCode(),
$this->commandTester->getDisplay(true)
);
}
/**
* Modes data provider
* @return array
*/
public function modesDataProvider()
{
return [
[DimensionModeConfiguration::DIMENSION_NONE, DimensionModeConfiguration::DIMENSION_WEBSITE],
[DimensionModeConfiguration::DIMENSION_WEBSITE, DimensionModeConfiguration::DIMENSION_CUSTOMER_GROUP],
[
DimensionModeConfiguration::DIMENSION_CUSTOMER_GROUP,
DimensionModeConfiguration::DIMENSION_WEBSITE_AND_CUSTOMER_GROUP
],
[
DimensionModeConfiguration::DIMENSION_WEBSITE_AND_CUSTOMER_GROUP,
DimensionModeConfiguration::DIMENSION_NONE
],
[
DimensionModeConfiguration::DIMENSION_NONE,
DimensionModeConfiguration::DIMENSION_WEBSITE_AND_CUSTOMER_GROUP
],
[
DimensionModeConfiguration::DIMENSION_WEBSITE_AND_CUSTOMER_GROUP,
DimensionModeConfiguration::DIMENSION_CUSTOMER_GROUP
],
[DimensionModeConfiguration::DIMENSION_CUSTOMER_GROUP, DimensionModeConfiguration::DIMENSION_WEBSITE],
[DimensionModeConfiguration::DIMENSION_WEBSITE, DimensionModeConfiguration::DIMENSION_NONE],
];
}
/**
* @magentoAppArea adminhtml
* @magentoAppIsolation enabled
*/
public function testSwitchModeForSameMode()
{
$this->commandTester->execute(
[
'indexer' => 'catalog_product_price',
'mode' => DimensionModeConfiguration::DIMENSION_NONE
]
);
$expectedOutput = 'Dimensions mode for indexer "Product Price" has not been changed' . PHP_EOL;
$actualOutput = $this->commandTester->getDisplay();
$this->assertStringContainsString($expectedOutput, $actualOutput);
static::assertEquals(
Cli::RETURN_SUCCESS,
$this->commandTester->getStatusCode(),
$this->commandTester->getDisplay(true)
);
}
/**
* @magentoAppArea adminhtml
* @magentoAppIsolation enabled
*
*/
public function testSwitchModeWithInvalidArgument()
{
$this->expectException(\InvalidArgumentException::class);
$this->commandTester->execute(
[
'indexer' => 'indexer_not_valid'
]
);
}
}
@@ -0,0 +1,94 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
return [
'scopes' => [
'websites' => [
'admin' => [
'website_id' => '0',
'code' => 'admin',
'name' => 'Admin',
'sort_order' => '0',
'default_group_id' => '0',
'is_default' => '0',
],
'base' => [
'website_id' => '1',
'code' => 'base',
'name' => 'Main Website',
'sort_order' => '0',
'default_group_id' => '1',
'is_default' => '1',
],
],
'groups' => [
0 => [
'group_id' => '0',
'website_id' => '0',
'code' => 'default',
'name' => 'Default',
'root_category_id' => '0',
'default_store_id' => '0',
],
1 => [
'group_id' => '1',
'website_id' => '1',
'code' => 'main_website_store',
'name' => 'Main Website Store',
'root_category_id' => '2',
'default_store_id' => '1',
],
],
'stores' => [
'admin' => [
'store_id' => '0',
'code' => 'admin',
'website_id' => '0',
'group_id' => '0',
'name' => 'Admin',
'sort_order' => '0',
'is_active' => '1',
],
'default' => [
'store_id' => '1',
'code' => 'default',
'website_id' => '1',
'group_id' => '1',
'name' => 'Default Store View',
'sort_order' => '0',
'is_active' => '1',
],
],
],
'themes' => [
'adminhtml/Magento/backend' => [
'parent_id' => null,
'theme_path' => 'Magento/backend',
'theme_title' => 'Magento 2 backend',
'is_featured' => '0',
'area' => 'adminhtml',
'type' => '0',
'code' => 'Magento/backend',
],
'frontend/Magento/blank' => [
'parent_id' => null,
'theme_path' => 'Magento/blank',
'theme_title' => 'Magento Blank',
'is_featured' => '0',
'area' => 'frontend',
'type' => '0',
'code' => 'Magento/blank',
],
'frontend/Magento/luma' => [
'parent_id' => 'Magento/blank',
'theme_path' => 'Magento/luma',
'theme_title' => 'Magento Luma',
'is_featured' => '0',
'area' => 'frontend',
'type' => '0',
'code' => 'Magento/luma',
],
],
];
@@ -0,0 +1,24 @@
"simple text","simple text"
"simple text with 1 string literal placeholder %1","simple text with 1 string literal placeholder %1"
"simple text with 1 variable placeholder %1","simple text with 1 variable placeholder %1"
"simple text with multiple placeholders %1 %2","simple text with multiple placeholders %1 %2"
"first part second part","first part second part"
"first part second part third part","first part second part third part"
"first part second part with one string literal placeholder %1","first part second part with one string literal placeholder %1"
"first part of concat second part with one variable placeholder %1","first part of concat second part with one variable placeholder %1"
"first part of concat second part with two placeholders %1, %2","first part of concat second part with two placeholders %1, %2"
"first part of concat second part third part with one placeholder %1","first part of concat second part third part with one placeholder %1"
"first part of concat second part third part with two placeholders %1, %2","first part of concat second part third part with two placeholders %1, %2"
"string with escaped 'single quotes'","string with escaped 'single quotes'"
"string with placeholder in escaped single quotes '%1'","string with placeholder in escaped single quotes '%1'"
"string with ""double quotes""","string with ""double quotes"""
"string with placeholder in double quotes ""%1""","string with placeholder in double quotes ""%1"""
"string with 'single quotes'","string with 'single quotes'"
"string with placeholder in single quotes '%1'","string with placeholder in single quotes '%1'"
"string with escaped ""double quotes""","string with escaped ""double quotes"""
"string with placeholder in escaped double quotes ""%1""","string with placeholder in escaped double quotes ""%1"""
"string that's got an unclosed single quote in it","string that's got an unclosed single quote in it"
"Thank you for your order from %store_name.","Thank you for your order from %store_name."
"Our hours are <span class=""no-link"">%store_hours</span>.","Our hours are <span class=""no-link"">%store_hours</span>."
"Translation inside if directive","Translation inside if directive"
"Test di text","Test di text"
1 simple text simple text
2 simple text with 1 string literal placeholder %1 simple text with 1 string literal placeholder %1
3 simple text with 1 variable placeholder %1 simple text with 1 variable placeholder %1
4 simple text with multiple placeholders %1 %2 simple text with multiple placeholders %1 %2
5 first part second part first part second part
6 first part second part third part first part second part third part
7 first part second part with one string literal placeholder %1 first part second part with one string literal placeholder %1
8 first part of concat second part with one variable placeholder %1 first part of concat second part with one variable placeholder %1
9 first part of concat second part with two placeholders %1, %2 first part of concat second part with two placeholders %1, %2
10 first part of concat second part third part with one placeholder %1 first part of concat second part third part with one placeholder %1
11 first part of concat second part third part with two placeholders %1, %2 first part of concat second part third part with two placeholders %1, %2
12 string with escaped 'single quotes' string with escaped 'single quotes'
13 string with placeholder in escaped single quotes '%1' string with placeholder in escaped single quotes '%1'
14 string with "double quotes" string with "double quotes"
15 string with placeholder in double quotes "%1" string with placeholder in double quotes "%1"
16 string with 'single quotes' string with 'single quotes'
17 string with placeholder in single quotes '%1' string with placeholder in single quotes '%1'
18 string with escaped "double quotes" string with escaped "double quotes"
19 string with placeholder in escaped double quotes "%1" string with placeholder in escaped double quotes "%1"
20 string that's got an unclosed single quote in it string that's got an unclosed single quote in it
21 Thank you for your order from %store_name. Thank you for your order from %store_name.
22 Our hours are <span class="no-link">%store_hours</span>. Our hours are <span class="no-link">%store_hours</span>.
23 Translation inside if directive Translation inside if directive
24 Test di text Test di text
@@ -0,0 +1,9 @@
"Read Details","Read Details",module,Magento_A
"Mark as Read","Mark as Read",module,Magento_A
"Are you sure?","Are you sure?",module,"Magento_A,Magento_B,Magento_C"
"Messages Inbox","Messages Inbox",module,Magento_D
"You have %1 new system messages","You have %1 new system messages",module,Magento_A
"You have %1 new system message","You have %1 new system message",module,Magento_B
"Incoming Message","Incoming Message",module,Magento_C
close,close,module,"Magento_B,Magento_C"
"Read details","Read details",module,Magento_D
1 Read Details Read Details module Magento_A
2 Mark as Read Mark as Read module Magento_A
3 Are you sure? Are you sure? module Magento_A,Magento_B,Magento_C
4 Messages Inbox Messages Inbox module Magento_D
5 You have %1 new system messages You have %1 new system messages module Magento_A
6 You have %1 new system message You have %1 new system message module Magento_B
7 Incoming Message Incoming Message module Magento_C
8 close close module Magento_B,Magento_C
9 Read details Read details module Magento_D
@@ -0,0 +1,122 @@
<?xml version="1.0"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->
<config xmlns:xi="http://www.w3.org/2001/XInclude">
<profile>
<admin_users>2</admin_users><!-- Number of admin users to generate -->
<websites>1</websites> <!-- Number of websites to generate -->
<store_groups>1</store_groups> <!--Number of stores-->
<store_views>1</store_views> <!-- Number of store views -->
<assign_entities_to_all_websites>0</assign_entities_to_all_websites> <!-- Whether to assign all products per each website -->
<simple_products>1</simple_products> <!-- Simple products count -->
<configurable_products> <!-- Configurable product -->
<config>
<attributes>
<attribute>
<options>3</options>
<swatches>image</swatches>
</attribute>
<attribute>
<options>8</options>
</attribute>
</attributes>
<sku>Configurable Product %s</sku>
<products>16</products>
</config>
</configurable_products>
<product-images>
<images-count>1</images-count>
<images-per-product>1</images-per-product>
</product-images>
<categories>1</categories> <!-- Number of categories to generate -->
<categories_nesting_level>1</categories_nesting_level> <!-- Nesting level for categories -->
<customers>1</customers> <!-- Number of customers to generate -->
<catalog_price_rules>1</catalog_price_rules> <!-- Number of catalog price rules -->
<cart_price_rules>1</cart_price_rules> <!-- Number of cart price rules -->
<cart_price_rules_floor>1</cart_price_rules_floor>
<coupon_codes>1</coupon_codes> <!-- Number of coupon codes -->
<product_attribute_sets>1</product_attribute_sets> <!-- Number of product attribute sets -->
<product_attribute_sets_attributes>1</product_attribute_sets_attributes> <!-- Number of attributes per set -->
<product_attribute_sets_attributes_values>1</product_attribute_sets_attributes_values> <!-- Number of values per attribute -->
<order_quotes_enable>true</order_quotes_enable>
<order_simple_product_count_from>1</order_simple_product_count_from>
<order_simple_product_count_to>1</order_simple_product_count_to>
<orders>1</orders> <!-- Orders count -->
<tax_rates_file>tax_rates_small.csv</tax_rates_file> <!-- Tax rates file in fixtures directory-->
<configs> <!-- Config variables and values for change -->
<config>
<path>admin/security/use_form_key</path>
<scope>default</scope>
<scopeId>0</scopeId>
<value>0</value>
</config>
<config>
<path>admin/security/session_lifetime</path>
<scope>default</scope>
<scopeId>0</scopeId>
<value>7200</value>
</config>
<config>
<path>admin/security/admin_account_sharing</path>
<scope>default</scope>
<scopeId>0</scopeId>
<value>1</value>
</config>
<config>
<path>carriers/flatrate/active</path>
<scope>default</scope>
<scopeId>0</scopeId>
<value>1</value>
</config>
</configs>
<indexers> <!-- Indexer mode value (true - Update by Schedule, false - Update on Save) -->
<indexer>
<id>catalog_category_product</id>
<set_scheduled>false</set_scheduled>
</indexer>
<indexer>
<id>catalog_product_category</id>
<set_scheduled>false</set_scheduled>
</indexer>
<indexer>
<id>catalog_product_price</id>
<set_scheduled>false</set_scheduled>
</indexer>
<indexer>
<id>catalog_product_attribute</id>
<set_scheduled>false</set_scheduled>
</indexer>
<indexer>
<id>cataloginventory_stock</id>
<set_scheduled>false</set_scheduled>
</indexer>
<indexer>
<id>catalogrule_rule</id>
<set_scheduled>false</set_scheduled>
</indexer>
<indexer>
<id>catalogrule_product</id>
<set_scheduled>false</set_scheduled>
</indexer>
<indexer>
<id>catalogsearch_fulltext</id>
<set_scheduled>false</set_scheduled>
</indexer>
</indexers>
<xi:include href="../../../../../../../../../setup/performance-toolkit/config/searchTermsLarge.xml" />
<xi:include href="../../../../../../../../../setup/performance-toolkit/config/attributeSets.xml" />
<xi:include href="../../../../../../../../../setup/performance-toolkit/config/searchConfig.xml" />
<xi:include href="../../../../../../../../../setup/performance-toolkit/config/customerConfig.xml" />
<xi:include href="../../../../../../../../../setup/performance-toolkit/config/description.xml" />
<xi:include href="../../../../../../../../../setup/performance-toolkit/config/shortDescription.xml" />
</profile>
</config>
@@ -0,0 +1,93 @@
<?php
/***
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
use Magento\Framework\Phrase;
/**
* @SuppressWarnings(PHPMD)
* @codingStandardsIgnoreStart
*/
class TestPhrases
{
public function awesomeFunction()
{
$str1 = 'str1';
$str2 = 'str2';
// Simple
$simpleCases = [
new Phrase('simple text'),
new Phrase('simple text with 1 string literal placeholder %1', 'arg'),
new Phrase('simple text with 1 variable placeholder %1', $str1),
new Phrase('simple text with multiple placeholders %1 %2', $str1, $str2),
];
// Phrase objects
$phraseObjects = [
// Single concatenation
new Phrase('first part'
. ' second part'),
new Phrase('first part' . ' second part' . ' third part'),
// Multiple concatenation
new Phrase('first part' . ' second part with one string literal placeholder %1', 'arg'),
new Phrase('first part of concat' . ' second part with one variable placeholder %1', $str1),
new Phrase('first part of concat' . ' second part with two placeholders %1, %2', $str1, $str2),
new Phrase('first part of concat' . ' second part' . ' third part with one placeholder %1', 'arg'),
new Phrase(
'first part of concat' . ' second part' . ' third part with two placeholders %1, %2',
$str1,
$str2
),
// Escaped quotes
new Phrase('string with escaped \'single quotes\''),
new Phrase('string with placeholder in escaped single quotes \'%1\'', 'arg'),
new Phrase('string with "double quotes"'),
new Phrase('string with placeholder in double quotes "%1"', 'arg'),
];
$singleQuoteTranslateFunctions = [
// Single concatenation
__('first part' . ' second part'),
__('first part' . ' second part' . ' third part'),
// Multiple concatenation
__('first part' . ' second part with one string literal placeholder %1', 'arg'),
__('first part of concat' . ' second part with one variable placeholder %1', $str1),
__('first part of concat' . ' second part with two placeholders %1, %2', $str1, $str2),
__('first part of concat' . ' second part' . ' third part with one placeholder %1', 'arg'),
__('first part of concat' . ' second part' . ' third part with two placeholders %1, %2', $str1, $str2),
// Escaped quotes
__('string with escaped \'single quotes\''),
__('string with placeholder in escaped single quotes \'%1\'', 'arg'),
__('string with "double quotes"'),
__('string with placeholder in double quotes "%1"', 'arg'),
];
$doubleQuoteTranslateFunctions = [
// Single concatenation
__("first part" . " second part"),
__("first part" . " second part" . " third part"),
// Multiple concatenation
__("first part" . " second part with one string literal placeholder %1", "arg"),
__("first part of concat" . " second part with one variable placeholder %1", $str1),
__("first part of concat" . " second part with two placeholders %1, %2", $str1, $str2),
__("first part of concat" . " second part" . " third part with one placeholder %1", "arg"),
__("first part of concat" . " second part" . " third part with two placeholders %1, %2", $str1, $str2),
// Escaped quotes
__("string with 'single quotes'"),
__("string with placeholder in single quotes '%1'", "arg"),
__("string with escaped \"double quotes\""),
__("string with placeholder in escaped double quotes \"%1\"", "arg"),
];
$unclosedApostrophePhrase = __('string that\'s got an unclosed single quote in it');
}
}
@@ -0,0 +1,16 @@
<?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:ObjectManager/etc/config.xsd">
<type name="TestName">
<arguments>
<argument name="test" xsi:type="array">
<item name="test" xsi:type="string" translatable="true">Test di text</item>
</argument>
</arguments>
</type>
</config>
@@ -0,0 +1,28 @@
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->
{{template config_path="design/email/header_template"}}
<table>
<tr class="email-intro">
<td>
<p>
{{trans "Thank you for your order from %store_name." store_name=$store.frontend_name}}
</p>
<p>
{{depend store_hours}}
{{trans 'Our hours are <span class="no-link">%store_hours</span>.' store_hours=$store_hours |raw}}
{{/depend}}
</p>
{{if something}}
<p>{{trans 'Translation inside if directive'}}</p>
{{/if}}
</td>
</tr>
</table>
{{template config_path="design/email/footer_template"}}
@@ -0,0 +1,17 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\A\Model;
class Foo
{
/**
* @SuppressWarnings(PHPMD.UnusedLocalVariable)
*/
public function foo()
{
$frameworkDependencies = new \Magento\Framework\A();
}
}
@@ -0,0 +1,12 @@
{
"name": "magento/module-a",
"config": {
"sort-packages": true
},
"require": {
"php": "~7.4.0||~8.0.0",
"magento/framework": "0.1",
"magento/module-b": "0.1"
},
"version": "0.1"
}
@@ -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_A" />
</config>
@@ -0,0 +1,9 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
use Magento\Framework\Component\ComponentRegistrar;
ComponentRegistrar::register(ComponentRegistrar::MODULE, 'Magento_A', __DIR__);
@@ -0,0 +1,17 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\B\Model;
class Foo
{
/**
* @SuppressWarnings(PHPMD.UnusedLocalVariable)
*/
public function foo()
{
$frameworkDependencies = new \Magento\Framework\B();
}
}
@@ -0,0 +1,12 @@
{
"name": "magento/module-b",
"config": {
"sort-packages": true
},
"require": {
"php": "~7.4.0||~8.0.0",
"magento/framework": "*",
"magento/module-a": "0.1"
},
"version": "0.1"
}
@@ -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_B" />
</config>
@@ -0,0 +1,9 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
use Magento\Framework\Component\ComponentRegistrar;
ComponentRegistrar::register(ComponentRegistrar::MODULE, 'Magento_B', __DIR__);
@@ -0,0 +1,9 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
use Magento\Framework\Component\ComponentRegistrar;
ComponentRegistrar::register(ComponentRegistrar::MODULE, 'Magento_C', __DIR__);
@@ -0,0 +1,9 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
use Magento\Framework\Component\ComponentRegistrar;
ComponentRegistrar::register(ComponentRegistrar::MODULE, 'Magento_D', __DIR__);
@@ -0,0 +1,141 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Framework\Test\Unit\View\Element;
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager as ObjectManagerHelper;
use Magento\Framework\View\Element\UiComponent\DataProvider\Sanitizer;
use PHPUnit\Framework\MockObject\MockObject;
class UiComponentFactoryTest extends \PHPUnit\Framework\TestCase
{
/** @var \Magento\Framework\View\Element\UiComponentFactory */
protected $model;
/** @var ObjectManagerHelper */
protected $objectManagerHelper;
/** @var \Magento\Framework\ObjectManagerInterface|MockObject */
protected $objectManagerMock;
/** @var \Magento\Framework\Data\Argument\InterpreterInterface|MockObject */
protected $interpreterMock;
/** @var \Magento\Framework\View\Element\UiComponent\ContextFactory|MockObject */
protected $contextFactoryMock;
/** @var \Magento\Framework\Config\DataInterfaceFactory|MockObject */
protected $dataInterfaceFactoryMock;
/** @var \Magento\Ui\Config\Reader\Definition\Data|MockObject */
protected $dataMock;
protected function setUp(): void
{
$this->objectManagerMock = $this->getMockBuilder(\Magento\Framework\ObjectManagerInterface::class)
->getMockForAbstractClass();
$this->interpreterMock = $this->getMockBuilder(\Magento\Framework\Data\Argument\InterpreterInterface::class)
->getMockForAbstractClass();
$this->contextFactoryMock = $this
->getMockBuilder(\Magento\Framework\View\Element\UiComponent\ContextFactory::class)
->setMethods(['create'])
->disableOriginalConstructor()
->getMock();
$this->dataInterfaceFactoryMock = $this->getMockBuilder(\Magento\Framework\Config\DataInterfaceFactory::class)
->setMethods(['create'])
->disableOriginalConstructor()
->getMock();
$this->dataMock = $this->createMock(\Magento\Framework\Config\DataInterface::class);
$sanitizerMock = $this->createMock(Sanitizer::class);
$sanitizerMock->method('sanitize')->willReturnArgument(0);
$sanitizerMock->method('sanitizeComponentMetadata')->willReturnArgument(0);
$this->objectManagerHelper = new ObjectManagerHelper($this);
$this->model = $this->objectManagerHelper->getObject(
\Magento\Framework\View\Element\UiComponentFactory::class,
[
'objectManager' => $this->objectManagerMock,
'argumentInterpreter' => $this->interpreterMock,
'contextFactory' => $this->contextFactoryMock,
'configFactory' => $this->dataInterfaceFactoryMock,
'data' => [],
'componentChildFactories' => [],
'definitionData' => $this->dataMock,
'sanitizer' => $sanitizerMock
]
);
}
public function testCreateRootComponent()
{
$identifier = "product_listing";
$context = $this->createMock(\Magento\Framework\View\Element\UiComponent\ContextInterface::class);
$bundleComponents = [
'attributes' => [
'class' => 'Some\Class\Component',
],
'arguments' => [
'config' => [
'class' => 'Some\Class\Component2'
]
],
'children' => []
];
$uiConfigMock = $this->createMock(\Magento\Framework\Config\DataInterface::class);
$this->dataInterfaceFactoryMock->expects($this->once())
->method('create')
->willReturn($uiConfigMock);
$uiConfigMock->expects($this->once())
->method('get')
->willReturn($bundleComponents);
$this->contextFactoryMock->expects($this->once())
->method('create')
->willReturn($context);
$expectedArguments = [
'config' => [
'class' => 'Some\Class\Component2'
],
'data' => [
'name' => $identifier
],
'context' => $context,
'components' => []
];
$this->objectManagerMock->expects($this->once())
->method('create')
->with('Some\Class\Component2', $expectedArguments);
$this->model->create($identifier);
}
public function testNonRootComponent()
{
$identifier = "custom_select";
$name = "fieldset";
$context = $this->createMock(\Magento\Framework\View\Element\UiComponent\ContextInterface::class);
$arguments = ['context' => $context];
$definitionArguments = [
'componentType' => 'select',
'attributes' => [
'class' => '\Some\Class',
],
'arguments' => []
];
$expectedArguments = [
'data' => [
'name' => $identifier
],
'context' => $context,
'components' => []
];
$this->dataMock->expects($this->once())
->method('get')
->with($name)
->willReturn($definitionArguments);
$this->objectManagerMock->expects($this->once())
->method('create')
->with('\Some\Class', $expectedArguments);
$this->model->create($identifier, $name, $arguments);
}
}