init
This commit is contained in:
+56
@@ -0,0 +1,56 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
namespace Magento\Analytics\Block\Adminhtml\System\Config;
|
||||
|
||||
use Magento\Framework\Data\FormFactory;
|
||||
use Magento\Framework\Data\Form\Element\TimeFactory;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* Provide tests for CollectionTimeLabel block.
|
||||
*/
|
||||
class CollectionTimeLabelTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* Test render will add comment considering config locale(default en_US).
|
||||
*
|
||||
* @magentoAppIsolation enabled
|
||||
*/
|
||||
public function testRenderWithDefaultLocale()
|
||||
{
|
||||
$result = $this->render();
|
||||
$this->assertMatchesRegularExpression('/<span>Pacific Standard Time/', $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test render will add comment considering config locale(non-default de_DE).
|
||||
*
|
||||
* @magentoConfigFixture default_store general/locale/code de_DE
|
||||
* @magentoAppIsolation enabled
|
||||
*/
|
||||
public function testRenderWithNonDefaultLocale()
|
||||
{
|
||||
$result = $this->render();
|
||||
$this->assertMatchesRegularExpression('/<span>Nordamerikanische Westküsten-Normalzeit/', $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* Render 'time' element.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function render()
|
||||
{
|
||||
$collectionTimeLabel = Bootstrap::getObjectManager()->get(CollectionTimeLabelFactory::class)->create();
|
||||
$form = Bootstrap::getObjectManager()->get(FormFactory::class)->create();
|
||||
$element = Bootstrap::getObjectManager()->get(TimeFactory::class)->create();
|
||||
$element->setForm($form);
|
||||
|
||||
return $collectionTimeLabel->render($element);
|
||||
}
|
||||
}
|
||||
+35
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Magento\Analytics\Controller\Adminhtml\Reports;
|
||||
|
||||
use Magento\TestFramework\TestCase\AbstractBackendController;
|
||||
|
||||
/**
|
||||
* @magentoAppArea adminhtml
|
||||
*/
|
||||
class ShowTest extends AbstractBackendController
|
||||
{
|
||||
private const REPORT_HOST = 'experienceleague.adobe.com';
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $resource = 'Magento_Analytics::advanced_reporting';
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $uri = 'backend/analytics/reports/show';
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function testAclHasAccess()
|
||||
{
|
||||
parent::testAclHasAccess();
|
||||
$this->assertSame(302, $this->getResponse()->getHttpResponseCode());
|
||||
$this->assertSame(self::REPORT_HOST, $this->getResponse()->getHeader('location')->uri()->getHost());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,91 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Magento\Analytics\Cron;
|
||||
|
||||
use Magento\Framework\App\Filesystem\DirectoryList;
|
||||
use Magento\Framework\Filesystem;
|
||||
use Magento\Framework\Filesystem\Directory\WriteInterface;
|
||||
use Magento\Framework\ObjectManagerInterface;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* Checks data collection process behaviour
|
||||
*
|
||||
* @see \Magento\Analytics\Cron\CollectData
|
||||
*
|
||||
* @magentoAppArea adminhtml
|
||||
*/
|
||||
class CollectDataTest extends TestCase
|
||||
{
|
||||
/** @var ObjectManagerInterface */
|
||||
private $objectManager;
|
||||
|
||||
/** @var CollectData */
|
||||
private $collectDataService;
|
||||
|
||||
/** @var WriteInterface */
|
||||
private $mediaDirectory;
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->objectManager = Bootstrap::getObjectManager();
|
||||
$this->collectDataService = $this->objectManager->get(CollectData::class);
|
||||
$this->mediaDirectory = $this->objectManager->get(Filesystem::class)->getDirectoryWrite(DirectoryList::MEDIA);
|
||||
$this->removeAnalyticsDirectory();
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
protected function tearDown(): void
|
||||
{
|
||||
$this->removeAnalyticsDirectory();
|
||||
|
||||
parent::tearDown();
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoConfigFixture current_store analytics/subscription/enabled 1
|
||||
* @magentoConfigFixture default/analytics/general/token 123
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testExecute(): void
|
||||
{
|
||||
$this->collectDataService->execute();
|
||||
$this->assertTrue(
|
||||
$this->mediaDirectory->isDirectory('analytics'),
|
||||
'Analytics was not created'
|
||||
);
|
||||
$files = $this->mediaDirectory->getDriver()
|
||||
->readDirectoryRecursively($this->mediaDirectory->getAbsolutePath('analytics'));
|
||||
$file = array_filter($files, function ($element) {
|
||||
return substr($element, -8) === 'data.tgz';
|
||||
});
|
||||
$this->assertNotEmpty($file, 'File was not created');
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove Analytics directory
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
private function removeAnalyticsDirectory(): void
|
||||
{
|
||||
$directoryToRemove = $this->mediaDirectory->getAbsolutePath('analytics');
|
||||
if ($this->mediaDirectory->isDirectory($directoryToRemove)) {
|
||||
$this->mediaDirectory->delete($directoryToRemove);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,235 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Magento\Analytics\Cron;
|
||||
|
||||
use Laminas\Http\Response;
|
||||
use Magento\Analytics\Model\Config\Backend\Baseurl\SubscriptionUpdateHandler;
|
||||
use Magento\Analytics\Model\Connector\Http\Client\Curl as CurlClient;
|
||||
use Magento\Analytics\Model\Connector\Http\ClientInterface;
|
||||
use Magento\Config\Model\PreparedValueFactory;
|
||||
use Magento\Config\Model\ResourceModel\Config\Data as ConfigDataResource;
|
||||
use Magento\Framework\App\Config\ScopeConfigInterface;
|
||||
use Magento\Framework\FlagManager;
|
||||
use Magento\Store\Model\Store;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use Magento\TestFramework\ObjectManager;
|
||||
|
||||
/**
|
||||
* @magentoAppArea adminhtml
|
||||
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
|
||||
*/
|
||||
class UpdateTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* @var ObjectManager
|
||||
*/
|
||||
private $objectManager;
|
||||
|
||||
/**
|
||||
* @var PreparedValueFactory
|
||||
*/
|
||||
private $preparedValueFactory;
|
||||
|
||||
/**
|
||||
* @var ConfigDataResource
|
||||
*/
|
||||
private $configValueResourceModel;
|
||||
|
||||
/**
|
||||
* @var Update
|
||||
*/
|
||||
private $updateCron;
|
||||
|
||||
/**
|
||||
* @var ClientInterface|\PHPUnit\Framework\MockObject\MockObject
|
||||
*/
|
||||
private $httpClient;
|
||||
|
||||
/**
|
||||
* @var FlagManager
|
||||
*/
|
||||
private $flagManager;
|
||||
|
||||
/**
|
||||
* @var ScopeConfigInterface
|
||||
*/
|
||||
private $scopeConfig;
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->objectManager = Bootstrap::getObjectManager();
|
||||
$this->httpClient = $this->getMockBuilder(ClientInterface::class)
|
||||
->getMockForAbstractClass();
|
||||
$this->objectManager->addSharedInstance($this->httpClient, CurlClient::class);
|
||||
$this->preparedValueFactory = $this->objectManager->get(PreparedValueFactory::class);
|
||||
$this->configValueResourceModel = $this->objectManager->get(ConfigDataResource::class);
|
||||
$this->updateCron = $this->objectManager->get(Update::class);
|
||||
$this->scopeConfig = $this->objectManager->get(ScopeConfigInterface::class);
|
||||
$this->flagManager = $this->objectManager->get(FlagManager::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoDbIsolation enabled
|
||||
* @magentoAppIsolation enabled
|
||||
* @magentoDataFixture Magento/Analytics/_files/enabled_subscription_with_invalid_token.php
|
||||
*
|
||||
*/
|
||||
public function testSuccessfulAttemptExecute()
|
||||
{
|
||||
$this->saveConfigValue(
|
||||
Store::XML_PATH_SECURE_BASE_URL,
|
||||
'http://store.com/'
|
||||
);
|
||||
|
||||
$this->mockRequestCall(201, 'URL has been changed');
|
||||
|
||||
$this->updateCron->execute();
|
||||
$this->assertEmpty($this->getUpdateCounterFlag());
|
||||
$this->assertEmpty($this->getPreviousBaseUrlFlag());
|
||||
$this->assertEmpty($this->getConfigValue(SubscriptionUpdateHandler::UPDATE_CRON_STRING_PATH));
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoDbIsolation enabled
|
||||
* @magentoAppIsolation enabled
|
||||
* @magentoDataFixture Magento/Analytics/_files/enabled_subscription_with_invalid_token.php
|
||||
*
|
||||
*/
|
||||
public function testUnsuccessfulAttemptExecute()
|
||||
{
|
||||
$this->saveConfigValue(
|
||||
Store::XML_PATH_SECURE_BASE_URL,
|
||||
'http://store.com/'
|
||||
);
|
||||
|
||||
$reverseCounter = $this->getUpdateCounterFlag();
|
||||
$this->mockRequestCall(500, 'Unauthorized access');
|
||||
|
||||
$this->updateCron->execute();
|
||||
$this->assertEquals($reverseCounter - 1, $this->getUpdateCounterFlag());
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoDbIsolation enabled
|
||||
* @magentoAppIsolation enabled
|
||||
* @magentoDataFixture Magento/Analytics/_files/enabled_subscription_with_invalid_token.php
|
||||
*
|
||||
*/
|
||||
public function testLastUnsuccessfulAttemptExecute()
|
||||
{
|
||||
$this->saveConfigValue(
|
||||
Store::XML_PATH_SECURE_BASE_URL,
|
||||
'http://store.com/'
|
||||
);
|
||||
|
||||
$this->setUpdateCounterValue(1);
|
||||
$this->mockRequestCall(500, 'Unauthorized access');
|
||||
|
||||
$this->updateCron->execute();
|
||||
$this->assertEmpty($this->getUpdateCounterFlag());
|
||||
$this->assertEmpty($this->getPreviousBaseUrlFlag());
|
||||
$this->assertEmpty($this->getConfigValue(SubscriptionUpdateHandler::UPDATE_CRON_STRING_PATH));
|
||||
}
|
||||
|
||||
/**
|
||||
* 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);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get update counter flag value
|
||||
*
|
||||
* @return int|null
|
||||
*/
|
||||
private function getUpdateCounterFlag(): ?int
|
||||
{
|
||||
return $this->flagManager
|
||||
->getFlagData(SubscriptionUpdateHandler::SUBSCRIPTION_UPDATE_REVERSE_COUNTER_FLAG_CODE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get previous URL flag value
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
private function getPreviousBaseUrlFlag(): ?string
|
||||
{
|
||||
return $this->flagManager
|
||||
->getFlagData(SubscriptionUpdateHandler::PREVIOUS_BASE_URL_FLAG_CODE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set response mock for the HTTP client
|
||||
*
|
||||
* @param int $responseCode
|
||||
* @param string $responseMessage
|
||||
*/
|
||||
private function mockRequestCall(int $responseCode, string $responseMessage): void
|
||||
{
|
||||
/** @var Response $response */
|
||||
$response = $this->objectManager->create(Response::class);
|
||||
$response->setStatusCode($responseCode);
|
||||
$response->getHeaders()->addHeaderLine('Content-Type', 'application/json');
|
||||
$response->setContent(json_encode(['message' => $responseMessage]));
|
||||
|
||||
$this->httpClient
|
||||
->expects($this->once())
|
||||
->method('request')
|
||||
->willReturn($response);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set value for update counter flag
|
||||
*
|
||||
* @param int $value
|
||||
*/
|
||||
private function setUpdateCounterValue(int $value): void
|
||||
{
|
||||
$this->flagManager
|
||||
->saveFlag(SubscriptionUpdateHandler::SUBSCRIPTION_UPDATE_REVERSE_COUNTER_FLAG_CODE, $value);
|
||||
}
|
||||
}
|
||||
+162
@@ -0,0 +1,162 @@
|
||||
<?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->saveConfigValue(Enabled::XML_ENABLED_CONFIG_STRUCTURE_PATH, (string)Enabledisable::ENABLE_VALUE);
|
||||
$this->reinitableConfig->reinit();
|
||||
$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));
|
||||
}
|
||||
}
|
||||
+193
@@ -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());
|
||||
}
|
||||
}
|
||||
+207
@@ -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();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
|
||||
|
||||
/**
|
||||
* @var $fileInfoManager \Magento\Analytics\Model\FileInfoManager
|
||||
*/
|
||||
$fileInfoManager = $objectManager->create(\Magento\Analytics\Model\FileInfoManager::class);
|
||||
|
||||
/**
|
||||
* @var $fileInfo \Magento\Analytics\Model\FileInfo
|
||||
*/
|
||||
$fileInfo = $objectManager->create(
|
||||
\Magento\Analytics\Model\FileInfo::class,
|
||||
['path' => 'analytics/jsldjsfdkldf/data.tgz', 'initializationVector' => 'binaryDataisdodssds8iui']
|
||||
);
|
||||
|
||||
$fileInfoManager->save($fileInfo);
|
||||
+30
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
use Magento\Analytics\Model\AnalyticsToken;
|
||||
use Magento\Analytics\Model\Config\Backend\Enabled\SubscriptionHandler;
|
||||
use Magento\Framework\App\Config\Storage\WriterInterface;
|
||||
use Magento\Framework\FlagManager;
|
||||
|
||||
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
|
||||
|
||||
/**
|
||||
* @var $configWriter WriterInterface
|
||||
*/
|
||||
$configWriter = $objectManager->get(WriterInterface::class);
|
||||
$configWriter->delete(SubscriptionHandler::CRON_STRING_PATH);
|
||||
|
||||
/**
|
||||
* @var $analyticsToken AnalyticsToken
|
||||
*/
|
||||
$analyticsToken = $objectManager->get(AnalyticsToken::class);
|
||||
$analyticsToken->storeToken('42');
|
||||
|
||||
/**
|
||||
* @var $flagManager FlagManager
|
||||
*/
|
||||
$flagManager = $objectManager->get(FlagManager::class);
|
||||
$flagManager->deleteFlag(SubscriptionHandler::ATTEMPTS_REVERSE_COUNTER_FLAG_CODE);
|
||||
+30
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
use Magento\Analytics\Model\AnalyticsToken;
|
||||
use Magento\Analytics\Model\Config\Backend\Enabled\SubscriptionHandler;
|
||||
use Magento\Framework\App\Config\Storage\WriterInterface;
|
||||
use Magento\Framework\FlagManager;
|
||||
|
||||
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
|
||||
|
||||
/**
|
||||
* @var $configWriter WriterInterface
|
||||
*/
|
||||
$configWriter = $objectManager->get(WriterInterface::class);
|
||||
$configWriter->save(SubscriptionHandler::CRON_STRING_PATH, join(' ', SubscriptionHandler::CRON_EXPR_ARRAY));
|
||||
|
||||
/**
|
||||
* @var $analyticsToken AnalyticsToken
|
||||
*/
|
||||
$analyticsToken = $objectManager->get(AnalyticsToken::class);
|
||||
$analyticsToken->storeToken(null);
|
||||
|
||||
/**
|
||||
* @var $flagManager FlagManager
|
||||
*/
|
||||
$flagManager = $objectManager->get(FlagManager::class);
|
||||
$flagManager->saveFlag(SubscriptionHandler::ATTEMPTS_REVERSE_COUNTER_FLAG_CODE, 24);
|
||||
Reference in New Issue
Block a user