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,263 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);
namespace Magento\Customer\Model\Metadata\Form;
use Magento\Framework\App\Filesystem\DirectoryList;
use Magento\Framework\Exception\FileSystemException;
use Magento\Framework\Filesystem;
use Magento\Framework\Filesystem\Directory\WriteInterface;
use Magento\Framework\ObjectManagerInterface;
use Magento\TestFramework\Helper\Bootstrap;
class ImageTest extends \PHPUnit\Framework\TestCase
{
/**
* @var ObjectManagerInterface
*/
private $objectManager;
/**
* @var Filesystem
*/
private $filesystem;
/**
* @var string
*/
private $fileName = 'magento.jpg';
/**
* @var string
*/
private $invalidFileName = '../../invalidFile.xyz';
/**
* @var string
*/
private $imageFixtureDir;
/**
* @var string
*/
private $expectedFileName;
/**
* @var WriteInterface
*/
private $mediaDirectory;
/**
* @inheritDoc
*/
public function setUp(): void
{
$this->objectManager = Bootstrap::getObjectManager();
$this->filesystem = $this->objectManager->get(Filesystem::class);
$this->mediaDirectory = $this->filesystem->getDirectoryWrite(DirectoryList::MEDIA);
$this->imageFixtureDir = realpath(__DIR__ . '/../../../_files/image');
$this->expectedFileName = '/m/a/' . $this->fileName;
}
/**
* Test for processCustomerAddressValue method
*
* @magentoAppIsolation enabled
* @throws FileSystemException
* @throws \ReflectionException
*/
public function testProcessCustomerAddressValue()
{
$entityTypeCode = 'customer_address';
$tmpFilePath = $this->prepareImageForTest($entityTypeCode);
$imageFile = $this->getImageValues();
$params = [
'entityTypeCode' => 'customer_address',
'formCode' => 'customer_address_edit',
'isAjax' => false,
'value' => $imageFile
];
$expectedPath = $this->mediaDirectory->getAbsolutePath('customer_address' . $this->expectedFileName);
/** @var Image $image */
$image = $this->objectManager->create(\Magento\Customer\Model\Metadata\Form\Image::class, $params);
$processCustomerAddressValueMethod = new \ReflectionMethod(
\Magento\Customer\Model\Metadata\Form\Image::class,
'processCustomerAddressValue'
);
$processCustomerAddressValueMethod->setAccessible(true);
$actual = $processCustomerAddressValueMethod->invoke($image, $imageFile);
$this->assertEquals($this->expectedFileName, $actual);
$this->assertTrue($this->mediaDirectory->isExist($expectedPath));
$this->assertFileDoesNotExist($tmpFilePath);
}
/**
* Test for processCustomerValue method
*
* @magentoAppIsolation enabled
* @throws FileSystemException
* @throws \ReflectionException
*/
public function testProcessCustomerValue()
{
$entityTypeCode = 'customer';
$tmpFilePath = $this->prepareImageForTest($entityTypeCode);
$imageFile = $this->getImageValues();
$params = [
'entityTypeCode' => $entityTypeCode,
'formCode' => 'customer_edit',
'isAjax' => false,
'value' => $imageFile
];
/** @var Image $image */
$image = $this->objectManager->create(\Magento\Customer\Model\Metadata\Form\Image::class, $params);
$processCustomerAddressValueMethod = new \ReflectionMethod(
\Magento\Customer\Model\Metadata\Form\Image::class,
'processCustomerValue'
);
$processCustomerAddressValueMethod->setAccessible(true);
$result = $processCustomerAddressValueMethod->invoke($image, $imageFile);
$this->assertInstanceOf('Magento\Framework\Api\ImageContent', $result);
$this->assertFileDoesNotExist($tmpFilePath);
}
/**
* Test for processCustomerValue method with invalid value
*
* @magentoAppIsolation enabled
*
* @throws FileSystemException
* @throws \ReflectionException
*/
public function testProcessCustomerInvalidValue()
{
$this->expectException(
\Magento\Framework\Exception\ValidatorException::class
);
$entityTypeCode = 'customer';
$this->prepareImageForTest($entityTypeCode);
$imageFile = $this->getImageValues();
$imageFile['file'] = $this->invalidFileName;
$params = [
'entityTypeCode' => $entityTypeCode,
'formCode' => 'customer_edit',
'isAjax' => false,
'value' => $imageFile
];
/** @var Image $image */
$image = $this->objectManager->create(\Magento\Customer\Model\Metadata\Form\Image::class, $params);
$processCustomerAddressValueMethod = new \ReflectionMethod(
\Magento\Customer\Model\Metadata\Form\Image::class,
'processCustomerValue'
);
$processCustomerAddressValueMethod->setAccessible(true);
$processCustomerAddressValueMethod->invoke($image, $imageFile);
}
/**
* Test for _validateByRules method with not existed file
*
* @magentoAppIsolation enabled
*
* @throws FileSystemException
* @throws \ReflectionException
*/
public function testValidateByRulesWithNotValidFile()
{
$entityTypeCode = 'customer';
$this->mediaDirectory->delete($entityTypeCode);
$imageFile = $this->getImageValues();
$params = [
'entityTypeCode' => $entityTypeCode,
'formCode' => 'customer_edit',
'isAjax' => false,
'value' => $imageFile
];
$image = $this->objectManager->create(\Magento\Customer\Model\Metadata\Form\Image::class, $params);
$processValidateMethod = new \ReflectionMethod(
\Magento\Customer\Model\Metadata\Form\Image::class,
'_validateByRules'
);
$processValidateMethod->setAccessible(true);
$validationResult = $processValidateMethod->invoke($image, $imageFile);
$this->assertEquals('"' . $this->fileName .'" is not a valid file.', $validationResult[0]->__toString());
}
/**
* @inheritdoc
* @throws FileSystemException
*/
public static function tearDownAfterClass(): void
{
parent::tearDownAfterClass();
$filesystem = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(
Filesystem::class
);
/** @var WriteInterface $mediaDirectory */
$mediaDirectory = $filesystem->getDirectoryWrite(DirectoryList::MEDIA);
$mediaDirectory->delete('customer');
$mediaDirectory->delete('customer_address');
}
/**
* @param string $source
* @param string $destination
* @throws FileSystemException
*/
private function copyFile(string $source, string $destination)
{
$driver = $this->mediaDirectory->getDriver();
$driver->createDirectory(dirname($destination));
$driver->filePutContents($destination, file_get_contents($source));
}
/**
* Returns image values
*
* @return array
*/
private function getImageValues(): array
{
return [
'name' => $this->fileName,
'type' => 'image/jpeg',
'tmp_name' => $this->fileName,
'file' => $this->fileName,
'error' => 0,
'size' => 12500,
'previewType' => 'image',
];
}
/**
* Copies image from fixture to necessary for test dir
*
* @param string $entityTypeCode
* @return string
* @throws FileSystemException
*/
private function prepareImageForTest(string $entityTypeCode): string
{
$this->mediaDirectory->delete($entityTypeCode);
$this->mediaDirectory->create($this->mediaDirectory->getRelativePath($entityTypeCode . '/tmp/'));
$tmpFilePath = $this->mediaDirectory->getAbsolutePath($entityTypeCode . '/tmp/' . $this->fileName);
$this->copyFile($this->imageFixtureDir . DIRECTORY_SEPARATOR . $this->fileName, $tmpFilePath);
return $tmpFilePath;
}
}
@@ -0,0 +1,65 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Customer\Model\Metadata;
use Magento\TestFramework\Helper\Bootstrap;
class FormFactoryTest extends \PHPUnit\Framework\TestCase
{
/** @var array */
private $_requestData;
/** @var array */
private $_expectedData;
protected function setUp(): void
{
$this->_requestData = [
'id' => 13,
'default_shipping' => true,
'default_billing' => false,
'company' => 'Magento Commerce Inc.',
'middlename' => 'MiddleName',
'prefix' => 'Mr.',
'suffix' => 'Esq.',
'vat_id' => 'S46',
'firstname' => 'John',
'lastname' => 'Doe',
'street' => ['2211 North First Street'],
'city' => 'San Jose',
'country_id' => 'US',
'postcode' => '95131',
'telephone' => '5135135135',
'region_id' => 12,
'region' => 'California',
];
$this->_expectedData = $this->_requestData;
unset($this->_expectedData['id']);
unset($this->_expectedData['default_shipping']);
unset($this->_expectedData['default_billing']);
unset($this->_expectedData['middlename']);
unset($this->_expectedData['prefix']);
unset($this->_expectedData['suffix']);
}
public function testCreate()
{
/** @var FormFactory $formFactory */
$formFactory = Bootstrap::getObjectManager()->create(\Magento\Customer\Model\Metadata\FormFactory::class);
$form = $formFactory->create('customer_address', 'customer_address_edit');
$this->assertInstanceOf(\Magento\Customer\Model\Metadata\Form::class, $form);
$this->assertNotEmpty($form->getAttributes());
/** @var \Magento\Framework\App\RequestInterface $request */
$request = Bootstrap::getObjectManager()->get(\Magento\Framework\App\RequestInterface::class);
$request->setParams($this->_requestData);
$this->assertEquals($this->_expectedData, $form->restoreData($form->extractData($request)));
}
}
@@ -0,0 +1,148 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Customer\Model\Metadata;
use Magento\Framework\App\RequestInterface;
use Magento\TestFramework\Helper\Bootstrap;
use PHPUnit\Framework\TestCase;
class FormTest extends TestCase
{
/**
* @var Form
*/
protected $_form;
/** @var array */
protected $_attributes;
/** @var RequestInterface */
protected $_request;
/** @var array */
protected $_expected;
/** @var array */
protected $_requestData = [];
protected function setUp(): void
{
$objectManager = Bootstrap::getObjectManager();
/** @var FormFactory $formFactory */
$formFactory = $objectManager->create(FormFactory::class);
$this->_form = $formFactory->create('customer_address', 'customer_address_edit');
$this->_attributes = [
'id' => 14,
'default_shipping' => 1,
'default_billing' => 0,
'company' => 'Company Name',
'middlename' => 'Mid',
'prefix' => 'Mr.',
'suffix' => 'Esq.',
'vat_id' => '',
'firstname' => 'Jane',
'lastname' => 'Doe',
'street' => ['2211 North First Street'],
'city' => 'San Jose',
'country_id' => 'US',
'postcode' => '95131',
'telephone' => '5125125125',
'region_id' => 12,
'region' => 'California',
];
$requestData = [
'company' => 'Company Name',
'middlename' => 'Mid',
'prefix' => 'Mr.',
'suffix' => 'Esq.',
'vat_id' => '',
'firstname' => 'New Name',
'lastname' => 'Doe',
'street' => ['2211 New Street'],
'city' => 'San Jose',
'country_id' => 'US',
'postcode' => '95131',
'telephone' => '5125125125',
'region_id' => 12,
'region' => 'California',
];
$this->_request = $objectManager->get(RequestInterface::class);
$this->_request->setParams($requestData);
$this->_expected = array_merge($this->_attributes, $requestData);
unset($this->_expected['id']);
unset($this->_expected['default_shipping']);
unset($this->_expected['default_billing']);
unset($this->_expected['middlename']);
unset($this->_expected['prefix']);
unset($this->_expected['suffix']);
}
/**
* @magentoAppIsolation enabled
*/
public function testCompactData()
{
$attributeValues = $this->_form->compactData($this->_form->extractData($this->_request));
$this->assertEquals($this->_expected, $attributeValues);
}
/**
* @magentoAppIsolation enabled
*/
public function testGetAttributes()
{
$expectedAttributes = [
'prefix',
'firstname',
'middlename',
'lastname',
'suffix',
'company',
'street',
'country_id',
'region',
'region_id',
'city',
'postcode',
'telephone',
'fax',
'vat_id',
];
$this->assertEquals($expectedAttributes, array_keys($this->_form->getAttributes()));
}
/**
* @magentoAppIsolation enabled
*/
public function testGetSystemAttributes()
{
$this->assertCount(15, $this->_form->getSystemAttributes());
}
/**
* @magentoAppIsolation enabled
* @magentoDataFixture Magento/Customer/_files/attribute_user_defined_address.php
*/
public function testGetUserAttributes()
{
$expectedAttributes = ['address_user_attribute'];
$this->assertEquals($expectedAttributes, array_keys($this->_form->getUserAttributes()));
}
/**
* @magentoAppIsolation enabled
*/
public function testRestoreData()
{
$attributeValues = $this->_form->restoreData($this->_form->extractData($this->_request));
$this->assertEquals($this->_expected, $attributeValues);
}
}