ltsecurityinc安防产品在线商城代码
This commit is contained in:
@@ -0,0 +1,91 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
namespace Magento\PageCache\Model;
|
||||
|
||||
class ConfigTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* @var \Magento\PageCache\Model\Config
|
||||
*/
|
||||
private $config;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$readFactoryMock = $this->createMock(\Magento\Framework\Filesystem\Directory\ReadFactory::class);
|
||||
$modulesDirectoryMock = $this->createMock(\Magento\Framework\Filesystem\Directory\Write::class);
|
||||
$readFactoryMock->expects(
|
||||
$this->any()
|
||||
)->method(
|
||||
'create'
|
||||
)->willReturn(
|
||||
$modulesDirectoryMock
|
||||
);
|
||||
$modulesDirectoryMock->expects(
|
||||
$this->any()
|
||||
)->method(
|
||||
'readFile'
|
||||
)->willReturn(
|
||||
file_get_contents(__DIR__ . '/_files/test.vcl')
|
||||
);
|
||||
|
||||
/** @var \PHPUnit\Framework\MockObject\MockObject $vclTemplateLocator */
|
||||
$vclTemplateLocator = $this->getMockBuilder(\Magento\PageCache\Model\Varnish\VclTemplateLocator::class)
|
||||
->disableOriginalConstructor()
|
||||
->setMethods(['getTemplate'])
|
||||
->getMock();
|
||||
$vclTemplateLocator->expects($this->any())
|
||||
->method('getTemplate')
|
||||
->willReturn(file_get_contents(__DIR__ . '/_files/test.vcl'));
|
||||
|
||||
/** @var \PHPUnit\Framework\MockObject\MockObject $vclTemplateLocator */
|
||||
$vclGeneratorFactory = $this->getMockBuilder(\Magento\PageCache\Model\Varnish\VclGeneratorFactory::class)
|
||||
->disableOriginalConstructor()
|
||||
->setMethods(['create'])
|
||||
->getMock();
|
||||
$expectedParams = [
|
||||
'backendHost' => 'example.com',
|
||||
'backendPort' => '8080',
|
||||
'accessList' => explode(',', '127.0.0.1,192.168.0.1,127.0.0.2'),
|
||||
'designExceptions' => json_decode('{"_":{"regexp":"\/firefox\/i","value":"Magento\/blank"}}', true),
|
||||
'sslOffloadedHeader' => 'X-Forwarded-Proto',
|
||||
'gracePeriod' => 1234
|
||||
];
|
||||
$vclGeneratorFactory->expects($this->any())
|
||||
->method('create')
|
||||
->with($expectedParams)
|
||||
->willReturn(new \Magento\PageCache\Model\Varnish\VclGenerator(
|
||||
$vclTemplateLocator,
|
||||
'example.com',
|
||||
'8080',
|
||||
explode(',', '127.0.0.1,192.168.0.1,127.0.0.2'),
|
||||
1234,
|
||||
'X-Forwarded-Proto',
|
||||
json_decode('{"_":{"regexp":"\/firefox\/i","value":"Magento\/blank"}}', true)
|
||||
));
|
||||
$this->config = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
|
||||
\Magento\PageCache\Model\Config::class,
|
||||
[
|
||||
'vclGeneratorFactory' => $vclGeneratorFactory
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
// @codingStandardsIgnoreStart
|
||||
/**
|
||||
* @magentoConfigFixture default/system/full_page_cache/varnish/backend_host example.com
|
||||
* @magentoConfigFixture default/system/full_page_cache/varnish/backend_port 8080
|
||||
* @magentoConfigFixture default/system/full_page_cache/varnish/grace_period 1234
|
||||
* @magentoConfigFixture default/system/full_page_cache/varnish/access_list 127.0.0.1,192.168.0.1,127.0.0.2
|
||||
* @magentoConfigFixture current_store design/theme/ua_regexp {"_":{"regexp":"\/firefox\/i","value":"Magento\/blank"}}
|
||||
* @magentoAppIsolation enabled
|
||||
*/
|
||||
// @codingStandardsIgnoreEnd
|
||||
public function testGetVclFile()
|
||||
{
|
||||
$result = $this->config->getVclFile(Config::VARNISH_5_CONFIGURATION_PATH);
|
||||
$this->assertEquals(file_get_contents(__DIR__ . '/_files/result.vcl'), $result);
|
||||
}
|
||||
}
|
||||
+100
@@ -0,0 +1,100 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Magento\PageCache\Model\Layout;
|
||||
|
||||
use Magento\Framework\App\Cache\Type\Layout as LayoutCache;
|
||||
use Magento\Framework\Message\Session;
|
||||
use Magento\Framework\View\Layout;
|
||||
use Magento\Framework\View\LayoutFactory;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* Integration tests for \Magento\PageCache\Model\Layout\DepersonalizePlugin class.
|
||||
*
|
||||
* @magentoAppArea frontend
|
||||
*/
|
||||
class DepersonalizePluginTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @var Session
|
||||
*/
|
||||
private $messageSession;
|
||||
|
||||
/**
|
||||
* @var Layout
|
||||
*/
|
||||
private $layout;
|
||||
|
||||
/**
|
||||
* @var LayoutCache
|
||||
*/
|
||||
private $cache;
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->messageSession = Bootstrap::getObjectManager()->get(Session::class);
|
||||
$this->layout = Bootstrap::getObjectManager()->get(LayoutFactory::class)->create();
|
||||
$this->cache = Bootstrap::getObjectManager()->get(LayoutCache::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
protected function tearDown(): void
|
||||
{
|
||||
$this->messageSession->clearStorage();
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoCache full_page enabled
|
||||
* @dataProvider afterGenerateElementsDataProvider
|
||||
*
|
||||
* @param string $layout
|
||||
* @param array $expectedResult
|
||||
* @return void
|
||||
*/
|
||||
public function testAfterGenerateElements(string $layout, array $expectedResult): void
|
||||
{
|
||||
$this->cache->clean();
|
||||
$this->assertTrue($this->layout->loadFile($layout));
|
||||
$this->messageSession->setData(['some_data' => 1]);
|
||||
$this->layout->generateElements();
|
||||
$this->assertEquals($expectedResult, $this->messageSession->getData());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function afterGenerateElementsDataProvider(): array
|
||||
{
|
||||
return [
|
||||
'cacheable' => [
|
||||
'layout' => INTEGRATION_TESTS_DIR . '/testsuite/Magento/Framework/View/_files/layout/cacheable.xml',
|
||||
'expectedResult' => [],
|
||||
],
|
||||
'nonCacheable' => [
|
||||
'layout' => INTEGRATION_TESTS_DIR . '/testsuite/Magento/Framework/View/_files/layout/non_cacheable.xml',
|
||||
'expectedResult' => ['some_data' => 1],
|
||||
],
|
||||
'nonCacheableBlockWithoutReference' => [
|
||||
'layout' => INTEGRATION_TESTS_DIR
|
||||
. '/testsuite/Magento/Framework/View/_files/layout/non_cacheable_block_with_missing_refference.xml',
|
||||
'expectedResult' => [],
|
||||
],
|
||||
'nonCacheableBlockWithExistedReference' => [
|
||||
'layout' => INTEGRATION_TESTS_DIR
|
||||
. '/testsuite/Magento/Framework/View/_files/layout/non_cacheable_block_with_declared_reference.xml',
|
||||
'expectedResult' => ['some_data' => 1],
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
namespace Magento\PageCache\Model\Layout;
|
||||
|
||||
use Magento\Framework\View\EntitySpecificHandlesList;
|
||||
|
||||
class MergeTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* @magentoAppArea frontend
|
||||
*/
|
||||
public function testLoadEntitySpecificHandleWithEsiBlock()
|
||||
{
|
||||
$this->expectException(\LogicException::class);
|
||||
$this->expectExceptionMessage('Handle \'default\' must not contain blocks with \'ttl\' attribute specified');
|
||||
|
||||
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
|
||||
|
||||
// Mock cache to avoid layout being read from existing cache
|
||||
$cacheMock = $this->createMock(\Magento\Framework\Cache\FrontendInterface::class);
|
||||
/** @var \Magento\Framework\View\Model\Layout\Merge $layoutMerge */
|
||||
$layoutMerge = $objectManager->create(
|
||||
\Magento\Framework\View\Model\Layout\Merge::class,
|
||||
['cache' => $cacheMock]
|
||||
);
|
||||
|
||||
/** @var EntitySpecificHandlesList $entitySpecificHandleList */
|
||||
$entitySpecificHandleList = $objectManager->get(EntitySpecificHandlesList::class);
|
||||
// Add 'default' handle, which has declarations of blocks with ttl, to the list of entity specific handles.
|
||||
// This allows to simulate a situation, when block with ttl attribute
|
||||
// is declared e.g. in 'catalog_product_view_id_1' handle
|
||||
$entitySpecificHandleList->addHandle('default');
|
||||
$layoutMerge->load(['default']);
|
||||
}
|
||||
}
|
||||
+78
@@ -0,0 +1,78 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
namespace Magento\PageCache\Model\System\Config\Backend;
|
||||
|
||||
class TtlTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* @var \Magento\PageCache\Model\System\Config\Backend\Ttl
|
||||
*/
|
||||
protected $_model;
|
||||
|
||||
/**
|
||||
* @var \Magento\Framework\App\Config\ScopeConfigInterface
|
||||
*/
|
||||
protected $_config;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->_config = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()
|
||||
->create(\Magento\Framework\App\Config\ScopeConfigInterface::class);
|
||||
$this->_model = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()
|
||||
->create(\Magento\PageCache\Model\System\Config\Backend\Ttl::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider beforeSaveDataProvider
|
||||
*
|
||||
* @param $value
|
||||
* @param $path
|
||||
*/
|
||||
public function testBeforeSave($value, $path)
|
||||
{
|
||||
$this->_prepareData($value, $path);
|
||||
}
|
||||
|
||||
public function beforeSaveDataProvider()
|
||||
{
|
||||
return [
|
||||
[125, 'ttl_1'],
|
||||
[0, 'ttl_2'],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider beforeSaveDataProviderWithException
|
||||
*
|
||||
* @param $value
|
||||
* @param $path
|
||||
*/
|
||||
public function testBeforeSaveWithException($value, $path)
|
||||
{
|
||||
$this->expectException(\Magento\Framework\Exception\LocalizedException::class);
|
||||
$this->_prepareData($value, $path);
|
||||
}
|
||||
|
||||
public function beforeSaveDataProviderWithException()
|
||||
{
|
||||
return [
|
||||
['', 'ttl_3'],
|
||||
['sdfg', 'ttl_4']
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $value
|
||||
* @param $path
|
||||
*/
|
||||
protected function _prepareData($value, $path)
|
||||
{
|
||||
$this->_model->setValue($value);
|
||||
$this->_model->setPath($path);
|
||||
$this->_model->setField($path);
|
||||
$this->_model->save();
|
||||
}
|
||||
}
|
||||
+104
@@ -0,0 +1,104 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
namespace Magento\PageCache\Model\System\Config\Backend;
|
||||
|
||||
class VarnishTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* @var \Magento\PageCache\Model\System\Config\Backend\Varnish
|
||||
*/
|
||||
protected $_model;
|
||||
|
||||
/**
|
||||
* @var \Magento\Framework\App\Config\MutableScopeConfigInterface
|
||||
*/
|
||||
protected $_config;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->_config = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
|
||||
\Magento\Framework\App\Config\MutableScopeConfigInterface::class
|
||||
);
|
||||
$data = [
|
||||
'access_list' => 'localhost',
|
||||
'backend_host' => 'localhost',
|
||||
'backend_port' => 8080,
|
||||
'ttl' => 120,
|
||||
];
|
||||
$this->_config->setValue('system/full_page_cache/default', $data);
|
||||
$this->_model = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
|
||||
\Magento\PageCache\Model\System\Config\Backend\Varnish::class
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider beforeSaveDataProvider
|
||||
*
|
||||
* @param $value
|
||||
* @param $path
|
||||
* @param $expected
|
||||
* @param $needUpdate
|
||||
*/
|
||||
public function testBeforeSave($value, $path, $expected, $needUpdate)
|
||||
{
|
||||
if ($needUpdate) {
|
||||
$this->_model->load($path, 'path');
|
||||
}
|
||||
|
||||
$this->_model->setValue($value);
|
||||
$this->_model->setPath($path);
|
||||
$this->_model->setField($path);
|
||||
$this->_model->save();
|
||||
$value = $this->_model->getValue();
|
||||
|
||||
$this->assertEquals($value, $expected);
|
||||
}
|
||||
|
||||
public function beforeSaveDataProvider()
|
||||
{
|
||||
return [
|
||||
['localhost', 'access_list', 'localhost', false],
|
||||
['localhost', 'backend_host', 'localhost', false],
|
||||
[8081, 'backend_port', 8081, false],
|
||||
[125, 'ttl', 125, false],
|
||||
['localhost', 'access_list', 'localhost', true],
|
||||
['', 'backend_host', 'localhost', true],
|
||||
[0, 'backend_port', 8080, true],
|
||||
[0, 'ttl', 120, true]
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider afterLoadDataProvider
|
||||
*
|
||||
* @param $path
|
||||
* @param $expected
|
||||
* @param $needUpdate
|
||||
*/
|
||||
public function testAfterLoad($path, $expected, $needUpdate)
|
||||
{
|
||||
if ($needUpdate) {
|
||||
$this->_model->load($path, 'path');
|
||||
}
|
||||
$this->_model->setValue('');
|
||||
$this->_model->setPath($path);
|
||||
$this->_model->setField($path);
|
||||
$this->_model->save();
|
||||
$value = $this->_model->getValue();
|
||||
|
||||
$this->assertEquals($value, $expected);
|
||||
}
|
||||
|
||||
public function afterLoadDataProvider()
|
||||
{
|
||||
return [
|
||||
['access_list', 'localhost', true],
|
||||
['backend_host', 'localhost', true],
|
||||
['backend_port', 8080, true],
|
||||
['ttl', 120, true]
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
// Copyright © Magento, Inc. All rights reserved.
|
||||
// See COPYING.txt for license details.
|
||||
example.com:8080
|
||||
|
||||
by ips:
|
||||
"127.0.0.1";
|
||||
"192.168.0.1";
|
||||
"127.0.0.2";
|
||||
|
||||
if (req.http.user-agent ~ "(?i)firefox") {
|
||||
hash_data("Magento/blank");
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
// Copyright © Magento, Inc. All rights reserved.
|
||||
// See COPYING.txt for license details.
|
||||
/* {{ host }} */:/* {{ port }} */
|
||||
|
||||
by ips:
|
||||
/* {{ ips }} */
|
||||
|
||||
/* {{ design_exceptions_code }} */
|
||||
Reference in New Issue
Block a user