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,114 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\DownloadableImportExport\Model;
use Magento\CatalogImportExport\Model\AbstractProductExportImportTestCase;
use Magento\Catalog\Model\Product;
/**
* Test export and import downloadable products
*/
class DownloadableTest extends AbstractProductExportImportTestCase
{
/**
* @return array
*/
public function exportImportDataProvider(): array
{
return [
'downloadable-product' => [
[
'Magento/Downloadable/_files/product_downloadable_with_link_url_and_sample_url.php'
],
[
'downloadable-product',
],
],
];
}
/**
* Run import/export tests.
*
* @magentoAppArea adminhtml
* @magentoDbIsolation disabled
* @magentoAppIsolation enabled
*
* @param array $fixtures
* @param string[] $skus
* @param string[] $skippedAttributes
* @return void
* @dataProvider exportImportDataProvider
*/
public function testImportExport(array $fixtures, array $skus, array $skippedAttributes = []): void
{
$skippedAttributes = array_merge(self::$skippedAttributes, ['downloadable_links']);
parent::testImportExport($fixtures, $skus, $skippedAttributes);
}
/**
* Run import/export test with pagination.
*
* @magentoAppArea adminhtml
* @magentoDbIsolation disabled
* @magentoAppIsolation enabled
*
* @param array $fixtures
* @param string[] $skus
* @param string[] $skippedAttributes
* @dataProvider exportImportDataProvider
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
public function testImportExportWithPagination(array $fixtures, array $skus, array $skippedAttributes = [])
{
$skippedAttributes = array_merge(self::$skippedAttributes, ['downloadable_links']);
parent::testImportExportWithPagination($fixtures, $skus, $skippedAttributes);
}
/**
* @inheritdoc
*/
protected function assertEqualsSpecificAttributes(
Product $expectedProduct,
Product $actualProduct
): void {
$expectedProductLinks = $expectedProduct->getExtensionAttributes()->getDownloadableProductLinks();
$expectedProductSamples = $expectedProduct->getExtensionAttributes()->getDownloadableProductSamples();
$actualProductLinks = $actualProduct->getExtensionAttributes()->getDownloadableProductLinks();
$actualProductSamples = $actualProduct->getExtensionAttributes()->getDownloadableProductSamples();
$this->assertEquals(count($expectedProductLinks), count($actualProductLinks));
$this->assertEquals(count($expectedProductSamples), count($actualProductSamples));
$actualLinks = $this->getDataWithSortingById($actualProductLinks);
$expectedLinks = $this->getDataWithSortingById($actualProductLinks);
foreach ($actualLinks as $key => $actualLink) {
$this->assertEquals($expectedLinks[$key], $actualLink);
}
$actualSamples = $this->getDataWithSortingById($actualProductSamples);
$expectedSamples = $this->getDataWithSortingById($expectedProductSamples);
foreach ($actualSamples as $key => $actualSample) {
$this->assertEquals($expectedSamples[$key], $actualSample);
}
}
/**
* Get data with sorting by id
*
* @param array $objects
*
* @return array
*/
private function getDataWithSortingById(array $objects)
{
$result = [];
foreach ($objects as $object) {
$result[$object->getId()] = $object->getData();
}
return $result;
}
}
@@ -0,0 +1,210 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\DownloadableImportExport\Model\Import\Product\Type;
use Magento\Downloadable\Api\DomainManagerInterface;
use Magento\Framework\App\Filesystem\DirectoryList;
/**
* @magentoAppArea adminhtml
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
*/
class DownloadableTest extends \PHPUnit\Framework\TestCase
{
/**
* Downloadable product test Name
*/
const TEST_PRODUCT_NAME = 'Downloadable 1';
/**
* Downloadable product test Type
*/
const TEST_PRODUCT_TYPE = 'downloadable';
/**
* Downloadable product Links Group Name
*/
const TEST_PRODUCT_LINKS_GROUP_NAME = 'TEST Import Links';
/**
* Downloadable product Samples Group Name
*/
const TEST_PRODUCT_SAMPLES_GROUP_NAME = 'TEST Import Samples';
/**
* @var DomainManagerInterface
*/
private $domainManager;
/**
* @var \Magento\CatalogImportExport\Model\Import\Product
*/
protected $model;
/**
* @var \Magento\Framework\ObjectManagerInterface
*/
protected $objectManager;
/**
* @var \Magento\Framework\EntityManager\EntityMetadata
*/
protected $productMetadata;
/**
* @inheritDoc
*/
protected function setUp(): void
{
$this->objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
$this->model = $this->objectManager->create(
\Magento\CatalogImportExport\Model\Import\Product::class
);
/** @var \Magento\Framework\EntityManager\MetadataPool $metadataPool */
$metadataPool = $this->objectManager->get(\Magento\Framework\EntityManager\MetadataPool::class);
$this->productMetadata = $metadataPool->getMetadata(\Magento\Catalog\Api\Data\ProductInterface::class);
$this->domainManager = $this->objectManager->get(DomainManagerInterface::class);
$this->domainManager->addDomains(['www.bing.com', 'www.google.com', 'www.yahoo.com']);
}
/**
* @inheritDoc
*/
protected function tearDown(): void
{
$this->domainManager->removeDomains(['www.bing.com', 'www.google.com', 'www.yahoo.com']);
}
/**
* @magentoAppArea adminhtml
* @magentoDbIsolation enabled
* @magentoAppIsolation enabled
*
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
*/
public function testDownloadableImport()
{
// import data from CSV file
$pathToFile = __DIR__ . '/../../_files/import_downloadable.csv';
$filesystem = $this->objectManager->create(
\Magento\Framework\Filesystem::class
);
$directory = $filesystem->getDirectoryWrite(DirectoryList::ROOT);
$source = $this->objectManager->create(
\Magento\ImportExport\Model\Import\Source\Csv::class,
[
'file' => $pathToFile,
'directory' => $directory
]
);
$errors = $this->model->setSource(
$source
)->setParameters(
[
'behavior' => \Magento\ImportExport\Model\Import::BEHAVIOR_APPEND,
'entity' => 'catalog_product'
]
)->validateData();
$this->assertTrue($errors->getErrorsCount() == 0);
$this->model->importData();
$resource = $this->objectManager->get(\Magento\Catalog\Model\ResourceModel\Product::class);
$productId = $resource->getIdBySku(self::TEST_PRODUCT_NAME);
$this->assertIsNumeric($productId);
/** @var \Magento\Catalog\Model\Product $product */
$product = $this->objectManager->create(
\Magento\Catalog\Model\Product::class
);
$product->load($productId);
$this->assertFalse($product->isObjectNew());
$this->assertEquals(self::TEST_PRODUCT_NAME, $product->getName());
$this->assertEquals(self::TEST_PRODUCT_TYPE, $product->getTypeId());
$downloadableProductLinks = $product->getExtensionAttributes()->getDownloadableProductLinks();
$downloadableLinks = $product->getDownloadableLinks();
$downloadableProductSamples = $product->getExtensionAttributes()->getDownloadableProductSamples();
$downloadableSamples = $product->getDownloadableSamples();
//TODO: Track Fields: id, link_id, link_file and sample_file)
$expectedLinks = [
'file' => [
'title' => 'TEST Import Link Title File',
'sort_order' => '78',
'sample_type' => 'file',
'price' => 123,
'number_of_downloads' => '123',
'is_shareable' => '0',
'link_type' => 'file'
],
'url' => [
'title' => 'TEST Import Link Title URL',
'sort_order' => '42',
'sample_type' => 'url',
'sample_url' => 'http://www.bing.com',
'price' => 1,
'number_of_downloads' => '0',
'is_shareable' => '1',
'link_type' => 'url',
'link_url' => 'http://www.google.com'
]
];
foreach ($downloadableProductLinks as $link) {
$actualLink = $link->getData();
$this->assertArrayHasKey('link_type', $actualLink);
foreach ($expectedLinks[$actualLink['link_type']] as $expectedKey => $expectedValue) {
$this->assertArrayHasKey($expectedKey, $actualLink);
$this->assertEquals($actualLink[$expectedKey], $expectedValue);
}
}
foreach ($downloadableLinks as $link) {
$actualLink = $link->getData();
$this->assertArrayHasKey('link_type', $actualLink);
$this->assertArrayHasKey('product_id', $actualLink);
$this->assertEquals($actualLink['product_id'], $product->getData($this->productMetadata->getLinkField()));
foreach ($expectedLinks[$actualLink['link_type']] as $expectedKey => $expectedValue) {
$this->assertArrayHasKey($expectedKey, $actualLink);
$this->assertEquals($actualLink[$expectedKey], $expectedValue);
}
}
//TODO: Track Fields: id, sample_id and sample_file)
$expectedSamples = [
'file' => [
'title' => 'TEST Import Sample File',
'sort_order' => '178',
'sample_type' => 'file'
],
'url' => [
'title' => 'TEST Import Sample URL',
'sort_order' => '178',
'sample_type' => 'url',
'sample_url' => 'http://www.yahoo.com'
]
];
foreach ($downloadableProductSamples as $sample) {
$actualSample = $sample->getData();
$this->assertArrayHasKey('sample_type', $actualSample);
foreach ($expectedSamples[$actualSample['sample_type']] as $expectedKey => $expectedValue) {
$this->assertArrayHasKey($expectedKey, $actualSample);
$this->assertEquals($actualSample[$expectedKey], $expectedValue);
}
}
foreach ($downloadableSamples as $sample) {
$actualSample = $sample->getData();
$this->assertArrayHasKey('sample_type', $actualSample);
$this->assertArrayHasKey('product_id', $actualSample);
$this->assertEquals($actualSample['product_id'], $product->getData($this->productMetadata->getLinkField()));
foreach ($expectedSamples[$actualSample['sample_type']] as $expectedKey => $expectedValue) {
$this->assertArrayHasKey($expectedKey, $actualSample);
$this->assertEquals($actualSample[$expectedKey], $expectedValue);
}
}
}
}
@@ -0,0 +1,2 @@
sku,attribute_set_code,product_type,product_websites,name,product_online,tax_class_name,visibility,price,url_key,out_of_stock_qty,use_config_min_qty,is_qty_decimal,allow_backorders,use_config_backorders,min_cart_qty,use_config_min_sale_qty,max_cart_qty,use_config_max_sale_qty,is_in_stock,notify_on_stock_below,use_config_notify_stock_qty,manage_stock,use_config_manage_stock,use_config_qty_increments,qty_increments,use_config_enable_qty_inc,enable_qty_increments,is_decimal_divided,website_id,downloadable_links,downloadable_samples
Downloadable 1,Default,downloadable,base,Downloadable 1,1,Taxable Goods,"Catalog, Search",100,downloadable-1,0,1,0,0,1,1,1,10000,1,0,1,1,1,1,1,1,0,0,0,1,"group_title=TEST Import Links,sample=/i/m/p/o/r/t/sample1.jpg,downloads=123,sortorder=78,shareable=0,file=/i/m/p/o/r/t/file.jpg,price=123,title=TEST Import Link Title File|group_title=TEST Import Links,sample=http://www.bing.com,downloads=unlimited,sortorder=42,shareable=1,url=http://www.google.com,price=1,title=TEST Import Link Title URL","group_title=TEST Import Samples,sortorder=178,file=/i/m/p/o/r/t/sample2.jpg,title=TEST Import Sample File|group_title=TEST Import Samples,sortorder=178,url=http://www.yahoo.com,title=TEST Import Sample URL"
1 sku attribute_set_code product_type product_websites name product_online tax_class_name visibility price url_key out_of_stock_qty use_config_min_qty is_qty_decimal allow_backorders use_config_backorders min_cart_qty use_config_min_sale_qty max_cart_qty use_config_max_sale_qty is_in_stock notify_on_stock_below use_config_notify_stock_qty manage_stock use_config_manage_stock use_config_qty_increments qty_increments use_config_enable_qty_inc enable_qty_increments is_decimal_divided website_id downloadable_links downloadable_samples
2 Downloadable 1 Default downloadable base Downloadable 1 1 Taxable Goods Catalog, Search 100 downloadable-1 0 1 0 0 1 1 1 10000 1 0 1 1 1 1 1 1 0 0 0 1 group_title=TEST Import Links,sample=/i/m/p/o/r/t/sample1.jpg,downloads=123,sortorder=78,shareable=0,file=/i/m/p/o/r/t/file.jpg,price=123,title=TEST Import Link Title File|group_title=TEST Import Links,sample=http://www.bing.com,downloads=unlimited,sortorder=42,shareable=1,url=http://www.google.com,price=1,title=TEST Import Link Title URL group_title=TEST Import Samples,sortorder=178,file=/i/m/p/o/r/t/sample2.jpg,title=TEST Import Sample File|group_title=TEST Import Samples,sortorder=178,url=http://www.yahoo.com,title=TEST Import Sample URL