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,163 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);
namespace Magento\Analytics\Model\Config\Backend;
use Magento\Analytics\Model\SubscriptionStatusProvider;
use Magento\Config\Model\Config\Source\Enabledisable;
use Magento\Config\Model\PreparedValueFactory;
use Magento\Config\Model\ResourceModel\Config\Data as ConfigDataResource;
use Magento\Framework\App\Config\ReinitableConfigInterface;
use Magento\Framework\App\Config\ScopeConfigInterface;
use Magento\TestFramework\Helper\Bootstrap;
/**
* @magentoAppArea adminhtml
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
*/
class EnabledTest extends \PHPUnit\Framework\TestCase
{
/**
* @var \Magento\Framework\ObjectManagerInterface
*/
private $objectManager;
/**
* @var ScopeConfigInterface
*/
private $scopeConfig;
/**
* @var SubscriptionStatusProvider
*/
private $subscriptionStatusProvider;
/**
* @var PreparedValueFactory
*/
private $preparedValueFactory;
/**
* @var ConfigDataResource
*/
private $configValueResourceModel;
/**
* @var ReinitableConfigInterface
*/
private $reinitableConfig;
/**
* @inheritDoc
*/
protected function setUp(): void
{
$this->objectManager = Bootstrap::getObjectManager();
$this->scopeConfig = $this->objectManager->get(ScopeConfigInterface::class);
$this->subscriptionStatusProvider = $this->objectManager->get(SubscriptionStatusProvider::class);
$this->preparedValueFactory = $this->objectManager->get(PreparedValueFactory::class);
$this->configValueResourceModel = $this->objectManager->get(ConfigDataResource::class);
$this->reinitableConfig = $this->objectManager->get(ReinitableConfigInterface::class);
}
/**
* @magentoDbIsolation enabled
*/
public function testDisable()
{
$this->checkInitialStatus();
$this->saveConfigValue(Enabled::XML_ENABLED_CONFIG_STRUCTURE_PATH, (string)Enabledisable::DISABLE_VALUE);
$this->reinitableConfig->reinit();
$this->checkDisabledStatus();
}
/**
* @depends testDisable
* @magentoDbIsolation enabled
*/
public function testReEnable()
{
$this->checkDisabledStatus();
$this->saveConfigValue(Enabled::XML_ENABLED_CONFIG_STRUCTURE_PATH, (string)Enabledisable::ENABLE_VALUE);
$this->checkReEnabledStatus();
}
/**
* Get configuration value
*
* @param string $path
* @param string $scopeType
* @return mixed
*/
private function getConfigValue(
string $path,
string $scopeType = ScopeConfigInterface::SCOPE_TYPE_DEFAULT
) {
return $this->scopeConfig->getValue(
$path,
$scopeType
);
}
/**
* Save configuration value
*
* @param string $path The configuration path in format section/group/field_name
* @param string $value The configuration value
* @param string $scope The configuration scope (default, website, or store)
* @return void
* @throws \Magento\Framework\Exception\RuntimeException
* @throws \Magento\Framework\Exception\AlreadyExistsException
*/
private function saveConfigValue(
string $path,
string $value,
string $scope = ScopeConfigInterface::SCOPE_TYPE_DEFAULT
) {
$configValue = $this->preparedValueFactory->create(
$path,
$value,
$scope
);
$this->configValueResourceModel->save($configValue);
}
/**
* Check the instance status after installation
*/
private function checkInitialStatus()
{
$this->assertNotSame(SubscriptionStatusProvider::DISABLED, $this->subscriptionStatusProvider->getStatus());
$this->assertNotEmpty($this->getConfigValue(CollectionTime::CRON_SCHEDULE_PATH));
}
/**
* Check the instance status after disabling AR synchronisation
*/
private function checkDisabledStatus()
{
$this->assertSame(SubscriptionStatusProvider::DISABLED, $this->subscriptionStatusProvider->getStatus());
$this->assertEmpty($this->getConfigValue(CollectionTime::CRON_SCHEDULE_PATH));
}
/**
* Check the instance status after re-activation AR synchronisation
*/
private function checkReEnabledStatus()
{
$this->assertContains(
$this->subscriptionStatusProvider->getStatus(),
[
SubscriptionStatusProvider::ENABLED,
SubscriptionStatusProvider::PENDING,
]
);
$this->assertNotEmpty($this->getConfigValue(CollectionTime::CRON_SCHEDULE_PATH));
}
}
@@ -0,0 +1,193 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Analytics\Model\Connector\Http;
use Laminas\Http\Response;
use Magento\Analytics\Model\Config\Backend\Baseurl\SubscriptionUpdateHandler;
use Magento\Analytics\Model\Config\Backend\Enabled\SubscriptionHandler;
use Magento\Framework\App\Config\ScopeConfigInterface;
use Magento\Framework\FlagManager;
use Magento\TestFramework\Helper\Bootstrap;
/**
* Checks that cron job was set if error handler was set and appropriate http error code was returned.
*/
class ReSignUpResponseResolverTest extends \PHPUnit\Framework\TestCase
{
/**
* @var ResponseResolver
*/
private $otpResponseResolver;
/**
* @var ResponseResolver
*/
private $updateResponseResolver;
/**
* @var ConverterInterface
*/
private $converter;
/**
* @var ResponseResolver
*/
private $notifyDataChangedResponseResolver;
/**
* @var FlagManager
*/
private $flagManager;
/**
* @return void
*/
protected function setUp(): void
{
$objectManager = Bootstrap::getObjectManager();
$this->otpResponseResolver = $objectManager->get(
'OtpResponseResolver'
);
$this->updateResponseResolver = $objectManager->get(
'UpdateResponseResolver'
);
$this->notifyDataChangedResponseResolver = $objectManager->get(
'NotifyDataChangedResponseResolver'
);
$this->converter = $objectManager->get(ConverterInterface::class);
$this->flagManager = $objectManager->get(FlagManager::class);
}
/**
* @magentoDataFixture Magento/Analytics/_files/enabled_subscription_with_invalid_token.php
* @magentoDbIsolation enabled
*/
public function testReSignUpOnOtp()
{
$body = $this->converter->toBody(['test' => '42']);
$retryResponse = new Response();
$retryResponse->setStatusCode(Response::STATUS_CODE_401);
$retryResponse->getHeaders()->addHeaderLine($this->converter->getContentTypeHeader());
$retryResponse->setContent($body);
$this->otpResponseResolver->getResult($retryResponse);
$this->assertCronWasSet();
}
/**
* @magentoDataFixture Magento/Analytics/_files/enabled_subscription_with_invalid_token.php
* @magentoDbIsolation enabled
*/
public function testReSignOnOtpWasNotCalled()
{
$body = $this->converter->toBody(['test' => '42']);
$successResponse = new Response();
$successResponse->setStatusCode(Response::STATUS_CODE_201);
$successResponse->getHeaders()->addHeaderLine($this->converter->getContentTypeHeader());
$successResponse->setContent($body);
$this->otpResponseResolver->getResult($successResponse);
$this->assertCronWasNotSet();
}
/**
* @magentoDataFixture Magento/Analytics/_files/enabled_subscription_with_invalid_token.php
* @magentoDbIsolation enabled
*/
public function testReSignUpOnUpdateWasCalled()
{
$body = $this->converter->toBody(['test' => '42']);
$retryResponse = new Response();
$retryResponse->setStatusCode(Response::STATUS_CODE_401);
$retryResponse->getHeaders()->addHeaderLine($this->converter->getContentTypeHeader());
$retryResponse->setContent($body);
$this->updateResponseResolver->getResult($retryResponse);
$this->assertCronWasSet();
}
/**
* @magentoDataFixture Magento/Analytics/_files/enabled_subscription_with_invalid_token.php
* @magentoDbIsolation enabled
*/
public function testReSignUpOnUpdateWasNotCalled()
{
$body = $this->converter->toBody(['test' => '42']);
$successResponse = new Response();
$successResponse->setStatusCode(Response::STATUS_CODE_201);
$successResponse->getHeaders()->addHeaderLine($this->converter->getContentTypeHeader());
$successResponse->setContent($body);
$this->updateResponseResolver->getResult($successResponse);
$this->assertCronWasNotSet();
}
/**
* @magentoDataFixture Magento/Analytics/_files/enabled_subscription_with_invalid_token.php
* @magentoDbIsolation enabled
*/
public function testReSignUpOnNotifyDataChangedWasNotCalledWhenSubscriptionUpdateIsRunning()
{
$this->flagManager
->saveFlag(
SubscriptionUpdateHandler::PREVIOUS_BASE_URL_FLAG_CODE,
'https://previous.example.com/'
);
$body = $this->converter->toBody(['test' => '42']);
$retryResponse = new Response();
$retryResponse->setStatusCode(Response::STATUS_CODE_401);
$retryResponse->getHeaders()->addHeaderLine($this->converter->getContentTypeHeader());
$retryResponse->setContent($body);
$this->notifyDataChangedResponseResolver->getResult($retryResponse);
$this->assertCronWasNotSet();
}
/**
* @return string|null
*/
private function getSubscribeSchedule()
{
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
/**
* @var $scopeConfig ScopeConfigInterface
*/
$scopeConfig = $objectManager->get(ScopeConfigInterface::class);
return $scopeConfig->getValue(
SubscriptionHandler::CRON_STRING_PATH,
ScopeConfigInterface::SCOPE_TYPE_DEFAULT,
0
);
}
/**
* @return int|null
*/
private function getAttemptFlag()
{
$objectManager = Bootstrap::getObjectManager();
/**
* @var $flagManager FlagManager
*/
$flagManager = $objectManager->get(FlagManager::class);
return $flagManager->getFlagData(SubscriptionHandler::ATTEMPTS_REVERSE_COUNTER_FLAG_CODE);
}
/**
* @return void
*/
private function assertCronWasSet()
{
$this->assertEquals('0 * * * *', $this->getSubscribeSchedule());
$this->assertGreaterThan(1, $this->getAttemptFlag());
}
/**
* @return void
*/
private function assertCronWasNotSet()
{
$this->assertNull($this->getSubscribeSchedule());
$this->assertNull($this->getAttemptFlag());
}
}
@@ -0,0 +1,207 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Analytics\Model\Plugin;
use Magento\Analytics\Model\Config\Backend\Baseurl\SubscriptionUpdateHandler;
use Magento\Config\Model\PreparedValueFactory;
use Magento\Config\Model\ResourceModel\Config\Data as ConfigData;
use Magento\Framework\App\Config\ScopeConfigInterface;
use Magento\Framework\FlagManager;
use Magento\Framework\ObjectManagerInterface;
use Magento\Store\Model\ScopeInterface;
use Magento\Store\Model\Store;
use Magento\TestFramework\Helper\Bootstrap;
/**
* @magentoAppArea adminhtml
*/
class BaseUrlConfigPluginTest extends \PHPUnit\Framework\TestCase
{
/**
* @var PreparedValueFactory
*/
private $preparedValueFactory;
/**
* @var ConfigData
*/
private $configValueResourceModel;
/**
* @var ScopeConfigInterface
*/
private $scopeConfig;
/**
* @var FlagManager
*/
private $flagManager;
/**
* @var ObjectManagerInterface
*/
private $objectManager;
/**
* @return void
*/
protected function setUp(): void
{
$this->objectManager = Bootstrap::getObjectManager();
$this->preparedValueFactory = $this->objectManager->get(PreparedValueFactory::class);
$this->configValueResourceModel = $this->objectManager->get(ConfigData::class);
$this->scopeConfig = $this->objectManager->get(ScopeConfigInterface::class);
$this->flagManager = $this->objectManager->get(FlagManager::class);
}
/**
* @magentoDbIsolation enabled
*/
public function testAfterSaveNotSecureUrl()
{
$this->saveConfigValue(
Store::XML_PATH_UNSECURE_BASE_URL,
'http://store.com/',
ScopeConfigInterface::SCOPE_TYPE_DEFAULT
);
$this->assertCronWasNotSet();
}
/**
* @magentoDbIsolation enabled
*/
public function testAfterSaveSecureUrlNotInDefaultScope()
{
$this->saveConfigValue(
Store::XML_PATH_SECURE_BASE_URL,
'https://store.com/',
ScopeInterface::SCOPE_STORES
);
$this->assertCronWasNotSet();
}
/**
* @magentoDbIsolation enabled
* @magentoAdminConfigFixture web/secure/base_url https://previous.example.com/
*/
public function testAfterSaveSecureUrlInDefaultScopeOnDoesNotRegisteredInstance()
{
$this->saveConfigValue(
Store::XML_PATH_SECURE_BASE_URL,
'https://store.com/',
ScopeConfigInterface::SCOPE_TYPE_DEFAULT
);
$this->assertCronWasNotSet();
}
/**
* @magentoDbIsolation enabled
* @magentoAdminConfigFixture web/secure/base_url https://previous.example.com/
* @magentoAdminConfigFixture analytics/general/token MBI_token
*/
public function testAfterSaveSecureUrlInDefaultScopeOnRegisteredInstance()
{
$this->saveConfigValue(
Store::XML_PATH_SECURE_BASE_URL,
'https://store.com/',
ScopeConfigInterface::SCOPE_TYPE_DEFAULT
);
$this->assertCronWasSet();
}
/**
* @magentoDbIsolation enabled
* @magentoAdminConfigFixture web/secure/base_url https://previous.example.com/
* @magentoAdminConfigFixture analytics/general/token MBI_token
*/
public function testAfterSaveMultipleBaseUrlChanges()
{
$this->saveConfigValue(
Store::XML_PATH_SECURE_BASE_URL,
'https://store.com/',
ScopeConfigInterface::SCOPE_TYPE_DEFAULT
);
$this->saveConfigValue(
Store::XML_PATH_SECURE_BASE_URL,
'https://store10.com/',
ScopeConfigInterface::SCOPE_TYPE_DEFAULT
);
$this->assertCronWasSet();
}
/**
* @param string $path The configuration path in format section/group/field_name
* @param string $value The configuration value
* @param string $scope The configuration scope (default, website, or store)
* @return void
*/
private function saveConfigValue(string $path, string $value, string $scope)
{
$value = $this->preparedValueFactory->create(
$path,
$value,
$scope
);
$this->configValueResourceModel->save($value);
}
/**
* @return void
*/
private function assertCronWasNotSet()
{
$this->assertNull($this->getSubscriptionUpdateSchedule());
$this->assertNull($this->getPreviousUpdateUrl());
$this->assertNull($this->getUpdateReverseCounter());
}
/**
* @return void
*/
private function assertCronWasSet()
{
$this->assertSame(
'0 * * * *',
$this->getSubscriptionUpdateSchedule(),
'Subscription update schedule has not been set'
);
$this->assertSame(
'https://previous.example.com/',
$this->getPreviousUpdateUrl(),
'The previous URL stored for update is not correct'
);
$this->assertSame(48, $this->getUpdateReverseCounter());
}
/**
* @return mixed
*/
private function getSubscriptionUpdateSchedule()
{
return $this->scopeConfig->getValue(
SubscriptionUpdateHandler::UPDATE_CRON_STRING_PATH,
ScopeConfigInterface::SCOPE_TYPE_DEFAULT
);
}
/**
* @return mixed
*/
private function getPreviousUpdateUrl()
{
return $this->flagManager->getFlagData(SubscriptionUpdateHandler::PREVIOUS_BASE_URL_FLAG_CODE);
}
/**
* @return mixed
*/
private function getUpdateReverseCounter()
{
return $this->flagManager
->getFlagData(SubscriptionUpdateHandler::SUBSCRIPTION_UPDATE_REVERSE_COUNTER_FLAG_CODE);
}
}
@@ -0,0 +1,52 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Analytics\Model;
use Magento\Analytics\Model\Config\Backend\Baseurl\SubscriptionUpdateHandler;
use Magento\Analytics\Model\Exception\State\SubscriptionUpdateException;
use Magento\Framework\FlagManager;
use Magento\TestFramework\Helper\Bootstrap;
/**
* @magentoAppArea adminhtml
*/
class ReportUrlProviderTest extends \PHPUnit\Framework\TestCase
{
/**
* @var ReportUrlProvider
*/
private $reportUrlProvider;
/**
* @var FlagManager
*/
private $flagManager;
/**
* @return void
*/
protected function setUp(): void
{
$objectManager = Bootstrap::getObjectManager();
$this->reportUrlProvider = $objectManager->get(ReportUrlProvider::class);
$this->flagManager = $objectManager->get(FlagManager::class);
}
/**
* @magentoDbIsolation enabled
*/
public function testGetUrlWhenSubscriptionUpdateIsRunning()
{
$this->flagManager
->saveFlag(
SubscriptionUpdateHandler::PREVIOUS_BASE_URL_FLAG_CODE,
'https://previous.example.com/'
);
$this->expectException(SubscriptionUpdateException::class);
$this->reportUrlProvider->getUrl();
}
}