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
+145
View File
@@ -0,0 +1,145 @@
<?php
/**
* @author Amasty Team
* @copyright Copyright (c) Amasty (https://www.amasty.com)
* @package GeoIP Data for Magento 2 (System)
*/
// @codingStandardsIgnoreFile
namespace Amasty\Geoip\Test\Unit\Helper;
use Amasty\Geoip\Helper\Data;
use Amasty\Geoip\Test\Unit\Traits;
use PHPUnit_Framework_MockObject_MockObject as MockObject;
/**
* Class DataTest
*
* @see Data
*
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
*/
class DataTest extends \PHPUnit\Framework\TestCase
{
use Traits\ObjectManagerTrait;
use Traits\ReflectionTrait;
public const EXIST_FILE = BP . '/' . 'index.php';
public const NOT_EXIST_FILE = BP . '/' . 'missingIndexFile.php';
/**
* @covers Data::isDone
*
* @dataProvider isDoneDataProvider
*
* @throws \ReflectionException
*/
public function testIsDone($flushCache, $amount, $value, $expectedResult)
{
/** @var Data|MockObject $helper */
$helper = $this->getMockBuilder(Data::class)
->disableOriginalConstructor()
->setMethods(['flushConfigCache'])
->getMock();
$helper->expects($this->exactly($amount))->method('flushConfigCache');
/** @var \Magento\Framework\App\Config\ScopeConfigInterface|MockObject $scopeConfig */
$scopeConfig = $this->createMock(\Magento\Framework\App\Config\ScopeConfigInterface::class);
$scopeConfig->expects($this->any())->method('getValue')->willReturn($value);
$this->setProperty($helper, 'scopeConfig', $scopeConfig, Data::class);
$this->assertEquals($expectedResult, $helper->isDone($flushCache));
}
/**
* @covers Data::isFileExist
*
* @dataProvider isFileExistDataProvider
*
* @throws \ReflectionException
*/
public function testIsFileExist($file, $expectedResult)
{
$this->markTestSkipped();
/** @var \Magento\Framework\Filesystem\Driver\File $fileDriver */
$fileDriver = $this->getObjectManager()->getObject(\Magento\Framework\Filesystem\Driver\File::class);
/** @var Data $helper */
$helper = $this->getObjectManager()->getObject(Data::class,
[
'fileDriver' => $fileDriver
]
);
$this->assertEquals($expectedResult, $helper->isFileExist($file));
}
/**
* @covers Data::isCacheEnabled
*
* @dataProvider isCacheEnabledDataProvider
*
* @throws \ReflectionException
*/
public function testIsCacheEnabled($expectedResult, $value = null)
{
/** @var \Magento\Framework\App\Cache\StateInterface|MockObject $state */
$state = $this->createMock(\Magento\Framework\App\Cache\StateInterface::class);
$state->expects($this->any())->method('isEnabled')->willReturn(true);
/** @var Data $helper */
$helper = $this->getObjectManager()->getObject(Data::class,
[
'_cacheEnabled' => $value,
'_state' => $state
]
);
$this->assertEquals($expectedResult, $helper->isCacheEnabled('redis'));
}
/**
* Data provider for isCacheEnabled test
* @return array
*/
public function isCacheEnabledDataProvider()
{
return [
[true, true],
[false, false],
[true],
];
}
/**
* Data provider for isFileExist test
* @return array
*/
public function isFileExistDataProvider()
{
return [
[self::EXIST_FILE, true],
[self::NOT_EXIST_FILE, false],
];
}
/**
* Data provider for isDone test
* @return array
*/
public function isDoneDataProvider()
{
return [
[true, 1, true, true],
[false, 0, false, false],
[false, 0, true, true],
[true, 1, false, false],
[1, 1, false, false],
[0, 0, false, false],
['test', 1, false, false],
[-1, 1, false, false],
];
}
}
+158
View File
@@ -0,0 +1,158 @@
<?php
/**
* @author Amasty Team
* @copyright Copyright (c) Amasty (https://www.amasty.com)
* @package GeoIP Data for Magento 2 (System)
*/
// @codingStandardsIgnoreFile
namespace Amasty\Geoip\Test\Unit\Model;
use Amasty\Geoip\Model\Import;
use Amasty\Geoip\Test\Unit\Traits;
use Magento\Framework\Filesystem\Driver\File;
use Magento\Framework\App\Config\ConfigResource\ConfigInterface;
use PHPUnit_Framework_MockObject_MockObject as MockObject;
/**
* Class ImportTest
*
* @see ImportTest
*
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
*/
class ImportTest extends \PHPUnit\Framework\TestCase
{
use Traits\ObjectManagerTrait;
use Traits\ReflectionTrait;
public const TEST_FILE = BP . '/' . 'index.php';
/**
* @var \Magento\Framework\App\Config\ConfigResource\ConfigInterface|MockObject
*/
private $config;
/**
* @var \Magento\Framework\DB\Adapter\AdapterInterface|MockObject
*/
private $connection;
/**
* @var \Magento\Framework\App\ResourceConnection|MockObject
*/
private $resource;
/**
* @var Import
*/
private $model;
/**
* @var \Magento\Framework\Filesystem\Driver\File
*/
private $fileDriver;
public function setUp(): void
{
$this->markTestSkipped();
/** @var File $fileDriver */
$this->fileDriver = $this->getObjectManager()->getObject(File::class);
/** @var ConfigInterface|MockObject $config */
$this->config = $this->createMock(ConfigInterface::class);
$this->config->expects($this->any())->method('saveConfig')->willReturn($this->config);
/** @var \Magento\Framework\DB\Adapter\AdapterInterface|MockObject connection */
$this->connection = $this->createMock(\Magento\Framework\DB\Adapter\AdapterInterface::class);
/** @var \Magento\Framework\App\ResourceConnection|MockObject resource */
$this->resource = $this->createMock(\Magento\Framework\App\ResourceConnection::class);
$this->resource->expects($this->any())->method('getConnection')->willReturn($this->connection);
$this->resource->expects($this->any())->method('getTableName')->willReturn('amasty_geoip_search_test');
/** @var Import|MockObject $model */
$this->model = $this->getObjectManager()->getObject(Import::class,
[
'configInterface' => $this->config,
'resource' => $this->resource,
'driverFile' => $this->fileDriver
]
);
}
/**
* @covers Import::commitProcess
*
* @throws \ReflectionException
*/
public function testCommitProcess()
{
$this->connection->expects($this->any())->method('isTableExists')->willReturn(true);
$this->assertTrue($this->model->commitProcess('test_table'));
}
/**
* @covers Import::doProcess
*
* @dataProvider startProcessAndDoProccessDataProvider
*
* @throws \ReflectionException
*/
public function testDoProcess($key)
{
$result = $this->model->doProcess('test_table', self::TEST_FILE, 'import');
$this->assertArrayHasKey($key, $result);
}
/**
* @covers Import::startProcess
*
* @dataProvider startProcessAndDoProccessDataProvider
*
* @throws \ReflectionException
*/
public function testStartProcess($key, $expectedResult = null)
{
$this->connection->expects($this->any())->method('getTables')->willReturn(['table1, table2']);
/** @var Import|MockObject $model */
$model = $this->getMockBuilder(Import::class)
->disableOriginalConstructor()
->setMethods(['_prepareImport', '_getRowsCount', '_saveInDb'])
->getMock();
$helper = $this->createMock(\Amasty\Geoip\Helper\Data::class);
$helper->expects($this->any())->method('flushConfigCache');
$this->setProperty($model, 'driverFile', $this->fileDriver, Import::class);
$this->setProperty($model, 'resource', $this->resource, Import::class);
$this->setProperty($model, 'helper', $helper, Import::class);
$this->setProperty($model, 'configInterface', $this->config, Import::class);
$model->expects($this->any())->method('_prepareImport')->willReturn(true);
$model->expects($this->any())->method('_getRowsCount')->willReturn(10);
$model->expects($this->any())->method('_saveInDb')->willReturn(true);
$result = $model->startProcess('block', self::TEST_FILE, 'import');
$this->assertArrayHasKey($key, $result);
}
/**
* Data provider for startProcess and doProcess test
* @return array
*/
public function startProcessAndDoProccessDataProvider()
{
return [
['position'],
['tmp_table'],
['rows_count'],
['current_row']
];
}
}
@@ -0,0 +1,33 @@
<?php
/**
* @author Amasty Team
* @copyright Copyright (c) Amasty (https://www.amasty.com)
* @package GeoIP Data for Magento 2 (System)
*/
namespace Amasty\Geoip\Test\Unit\Traits;
/**
* Create Object Manager instance for test purposes.
*
* @codingStandardsIgnoreFile
*/
trait ObjectManagerTrait
{
/**
* @var \Magento\Framework\TestFramework\Unit\Helper\ObjectManager
*/
private $objectManager;
/**
* @return \Magento\Framework\TestFramework\Unit\Helper\ObjectManager
*/
private function getObjectManager()
{
if (!$this->objectManager) {
$this->objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
}
return $this->objectManager;
}
}
+69
View File
@@ -0,0 +1,69 @@
<?php
/**
* @author Amasty Team
* @copyright Copyright (c) Amasty (https://www.amasty.com)
* @package GeoIP Data for Magento 2 (System)
*/
namespace Amasty\Geoip\Test\Unit\Traits;
/**
* Provide useful methods with reflection.
*
* @codingStandardsIgnoreFile
*/
trait ReflectionTrait
{
/**
* @param object $object
* @param string $methodName
* @param array $parameters
*
* @return mixed
* @throws \ReflectionException
*/
private function invokeMethod($object, $methodName, array $parameters = [])
{
$reflection = new \ReflectionClass(get_class($object));
$method = $reflection->getMethod($methodName);
$method->setAccessible(true);
return $method->invokeArgs($object, $parameters);
}
/**
* @param object $object
* @param string $propertyName
* @param mixed $value
* @param string $originalClassName
*
* @return object
* @throws \ReflectionException
*/
private function setProperty($object, $propertyName, $value, $originalClassName = '')
{
$reflection = new \ReflectionClass($originalClassName ?: get_class($object));
$property = $reflection->getProperty($propertyName);
$property->setAccessible(true);
$property->setValue($object, $value);
return $object;
}
/**
* @param $object
* @param $propertyName
* @param string $originalClassName
*
* @return mixed
* @throws \ReflectionException
*/
private function getProperty($object, $propertyName, $originalClassName = '')
{
$reflection = new \ReflectionClass($originalClassName ?: get_class($object));
$property = $reflection->getProperty($propertyName);
$property->setAccessible(true);
return $property->getValue($object);
}
}