ltsecurityinc安防产品在线商城代码
This commit is contained in:
@@ -0,0 +1,161 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
namespace Magento\Ui\Config;
|
||||
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use Magento\Framework\Config\FileIterator;
|
||||
use Magento\Framework\Filesystem\DriverPool;
|
||||
use Magento\Framework\Filesystem\File\ReadFactory;
|
||||
|
||||
class ConverterTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* @var Converter
|
||||
*/
|
||||
private $converter;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $fixturePath;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$objectManager = Bootstrap::getObjectManager();
|
||||
$this->converter = $objectManager->create(Converter::class);
|
||||
$this->fixturePath = realpath(__DIR__ . '/../_files/view/ui_component');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $componentName
|
||||
* @return void
|
||||
* @dataProvider getComponentNameDataProvider
|
||||
*/
|
||||
public function testConvert($componentName)
|
||||
{
|
||||
$expectedResult = $this->getExpectedResult($componentName);
|
||||
|
||||
$fixtureFiles = $this->getFixtureFiles($componentName);
|
||||
foreach ($fixtureFiles as $filePath => $fileContent) {
|
||||
$dom = new \DOMDocument();
|
||||
$dom->loadXML($fileContent);
|
||||
$actualResult = $this->converter->convert($dom);
|
||||
|
||||
if (isset($actualResult[Converter::DATA_ATTRIBUTES_KEY])) {
|
||||
unset($actualResult[Converter::DATA_ATTRIBUTES_KEY]);
|
||||
}
|
||||
|
||||
$this->assertEquals(
|
||||
$expectedResult,
|
||||
$actualResult,
|
||||
"Wrong '{$this->getTypeByPath($filePath)}' configuration for '{$componentName}' Ui Component" . PHP_EOL
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
public function getComponentNameDataProvider()
|
||||
{
|
||||
return [
|
||||
['action'],
|
||||
['actionDelete'],
|
||||
['actions'],
|
||||
['actionsColumn'],
|
||||
['bookmark'],
|
||||
['boolean'],
|
||||
['button'],
|
||||
['checkbox'],
|
||||
['checkboxset'],
|
||||
['column'],
|
||||
['columns'],
|
||||
['columnsControls'],
|
||||
['component'],
|
||||
['dataSource'],
|
||||
['date'],
|
||||
['dynamicRows'],
|
||||
['email'],
|
||||
['exportButton'],
|
||||
['field'],
|
||||
['fieldset'],
|
||||
['file'],
|
||||
['fileUploader'],
|
||||
['filterDate'],
|
||||
['filterInput'],
|
||||
['filterRange'],
|
||||
['filters'],
|
||||
['form'],
|
||||
['hidden'],
|
||||
['htmlContent'],
|
||||
['imageUploader'],
|
||||
['input'],
|
||||
['insertForm'],
|
||||
['insertListing'],
|
||||
['listing'],
|
||||
['listingToolbar'],
|
||||
['massaction'],
|
||||
['modal'],
|
||||
['multiline'],
|
||||
['multiselect'],
|
||||
['paging'],
|
||||
['radioset'],
|
||||
['range'],
|
||||
['select'],
|
||||
['selectionsColumn'],
|
||||
['tab'],
|
||||
['text'],
|
||||
['textarea'],
|
||||
['wysiwyg'],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve fixture files by $componentName
|
||||
*
|
||||
* @param string $componentName
|
||||
* @return FileIterator
|
||||
*/
|
||||
private function getFixtureFiles($componentName)
|
||||
{
|
||||
$realPaths = [];
|
||||
foreach (['semantic', 'mixed', 'arbitrary'] as $filePath) {
|
||||
$realPaths[] = $this->fixturePath . '/' . $filePath . '/' . $componentName . '.xml';
|
||||
}
|
||||
return new FileIterator(new ReadFactory(new DriverPool), $realPaths);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve expected result by $componentName
|
||||
*
|
||||
* @param string $componentName
|
||||
* @return array
|
||||
*/
|
||||
private function getExpectedResult($componentName)
|
||||
{
|
||||
$filename = $this->fixturePath . '/expected/' . $componentName . '.php';
|
||||
if (is_file($filename)) {
|
||||
return include($filename);
|
||||
}
|
||||
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve fixture type by file path
|
||||
*
|
||||
* @param string $path
|
||||
* @return string
|
||||
*/
|
||||
private function getTypeByPath($path)
|
||||
{
|
||||
$result = '';
|
||||
$pos = strpos($path, $this->fixturePath);
|
||||
if ($pos !== false) {
|
||||
$restParts = explode('/', substr($path, strlen($this->fixturePath) + 1));
|
||||
$result = array_shift($restParts);
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
namespace Magento\Ui\Config;
|
||||
|
||||
use Magento\Framework\Config\FileIterator;
|
||||
use Magento\Framework\Filesystem\DriverPool;
|
||||
use Magento\Framework\Filesystem\File\ReadFactory;
|
||||
use Magento\Framework\Module\Dir;
|
||||
|
||||
class FileResolverStub implements \Magento\Framework\Config\FileResolverInterface
|
||||
{
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private $files = [
|
||||
'etc/definition.xml' => [
|
||||
'module_one/ui_component/etc/test_definition.xml',
|
||||
'module_two/ui_component/etc/test_definition.xml'
|
||||
],
|
||||
'etc/definition.map.xml' => [
|
||||
'ui_component/etc/definition.map.xml'
|
||||
],
|
||||
'etc/test_definition.xml' => [
|
||||
'module_one/ui_component/etc/test_definition.xml',
|
||||
'module_two/ui_component/etc/test_definition.xml'
|
||||
],
|
||||
'test_component.xml' => [
|
||||
'module_one/ui_component/test_component.xml',
|
||||
'module_two/ui_component/test_component.xml'
|
||||
],
|
||||
'parent_component.xml' => [
|
||||
'module_one/ui_component/parent_component.xml',
|
||||
'module_two/ui_component/parent_component.xml'
|
||||
]
|
||||
];
|
||||
|
||||
/**
|
||||
* @var Dir\Reader
|
||||
*/
|
||||
private $moduleReader;
|
||||
|
||||
/**
|
||||
* FileResolverStub constructor.
|
||||
*
|
||||
* @param \Magento\Framework\Module\Dir\Reader $moduleReader
|
||||
* @param array $files
|
||||
*/
|
||||
public function __construct(\Magento\Framework\Module\Dir\Reader $moduleReader, array $files = [])
|
||||
{
|
||||
$this->files = array_replace($this->files, $files);
|
||||
$this->moduleReader = $moduleReader;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function get($filename, $scope)
|
||||
{
|
||||
if ($filename == 'etc/definition.map.xml') {
|
||||
$path = $this->moduleReader->getModuleDir(Dir::MODULE_VIEW_DIR, 'Magento_Ui') . '/base';
|
||||
} else {
|
||||
$path = realpath(__DIR__ . '/../_files/view');
|
||||
}
|
||||
$files = isset($this->files[$filename]) ? $this->files[$filename] : [];
|
||||
$realPaths = [];
|
||||
foreach ($files as $filePath) {
|
||||
$realPaths[] = $path . '/' . $filePath;
|
||||
}
|
||||
return new FileIterator(new ReadFactory(new DriverPool), $realPaths);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,91 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
namespace Magento\Ui\Config\Reader;
|
||||
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use Magento\Framework\Config\FileIterator;
|
||||
use Magento\Framework\Filesystem\DriverPool;
|
||||
use Magento\Framework\Filesystem\File\ReadFactory;
|
||||
|
||||
class DomTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* @var Dom
|
||||
*/
|
||||
private $dom;
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function testConfigurationDom()
|
||||
{
|
||||
$filename = 'test_component.xml';
|
||||
foreach ($this->getComponentFiles($filename) as $content) {
|
||||
if (!$this->dom) {
|
||||
$objectManager = Bootstrap::getObjectManager();
|
||||
|
||||
$this->dom = $objectManager->create(Dom::class, ['xml' => $content]);
|
||||
} else {
|
||||
$this->dom->merge($content);
|
||||
}
|
||||
}
|
||||
$this->assertXmlStringEqualsXmlFile(
|
||||
$this->getMergedFilePath('test_component_merged.xml'),
|
||||
$this->dom->getDom()->saveXML()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function testDefinitionDom()
|
||||
{
|
||||
$filename = 'etc/test_definition.xml';
|
||||
foreach ($this->getComponentFiles($filename) as $content) {
|
||||
if (!$this->dom) {
|
||||
$objectManager = Bootstrap::getObjectManager();
|
||||
|
||||
$this->dom = $objectManager->create(
|
||||
Dom::class,
|
||||
[
|
||||
'xml' => $content,
|
||||
'idAttributes' => ['/' => 'name'],
|
||||
'schemaLocator' => $objectManager->create(Definition\SchemaLocator::class)
|
||||
]
|
||||
);
|
||||
} else {
|
||||
$this->dom->merge($content);
|
||||
}
|
||||
}
|
||||
$this->assertXmlStringEqualsXmlFile(
|
||||
$this->getMergedFilePath('etc/test_definition_merged.xml'),
|
||||
$this->dom->getDom()->saveXML()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $filename
|
||||
* @return \Magento\Framework\Config\FileIterator
|
||||
*/
|
||||
private function getComponentFiles($filename)
|
||||
{
|
||||
$path = realpath(__DIR__ . '/../../_files/view');
|
||||
$paths = [
|
||||
$path . '/module_one/ui_component/' . $filename,
|
||||
$path . '/module_two/ui_component/' . $filename
|
||||
];
|
||||
return new FileIterator(new ReadFactory(new DriverPool), $paths);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $filename
|
||||
* @return string
|
||||
*/
|
||||
private function getMergedFilePath($filename)
|
||||
{
|
||||
return realpath(__DIR__ . '/../../_files/view/ui_component') . DIRECTORY_SEPARATOR. $filename;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
namespace Magento\Ui\Config;
|
||||
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use Magento\Ui\Config\FileResolverStub;
|
||||
|
||||
class ReaderTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* @var Reader
|
||||
*/
|
||||
private $reader;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$objectManager = Bootstrap::getObjectManager();
|
||||
|
||||
$objectManager->configure(
|
||||
[
|
||||
'preferences' => [
|
||||
\Magento\Ui\Config\Reader\FileResolver::class => FileResolverStub::class
|
||||
]
|
||||
]
|
||||
);
|
||||
|
||||
$this->reader = $objectManager->create(
|
||||
Reader::class,
|
||||
[
|
||||
'fileName' => 'test_component.xml'
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
protected function tearDown(): void
|
||||
{
|
||||
$objectManager = Bootstrap::getObjectManager();
|
||||
|
||||
$objectManager->configure(
|
||||
[
|
||||
'preferences' => [
|
||||
\Magento\Ui\Config\Reader\FileResolver::class => \Magento\Ui\Config\Reader\FileResolver::class
|
||||
]
|
||||
]
|
||||
);
|
||||
|
||||
parent::tearDown();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function testReader()
|
||||
{
|
||||
$mergedConfiguration = include __DIR__ . '/../_files/expected_result_configuration.php';
|
||||
$readConfiguration = $this->reader->read();
|
||||
|
||||
$this->assertEquals($mergedConfiguration, $readConfiguration);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user