From cf51d98466e3ab423c78f2a45cc0e49ef098fd59 Mon Sep 17 00:00:00 2001 From: Max Lesechko Date: Mon, 16 Mar 2020 14:16:30 -0500 Subject: [PATCH] MC-32086: [AR] Report account is unavailable after URL change --- app/code/Magento/Analytics/Cron/SignUp.php | 11 +- app/code/Magento/Analytics/Cron/Update.php | 28 +- .../Patch/Data/ActivateDataCollection.php | 95 +++++++ .../Setup/Patch/Data/PrepareInitialConfig.php | 58 ++--- .../Analytics/Test/Unit/Cron/UpdateTest.php | 15 +- .../Analytics/etc/adminhtml/system.xml | 9 +- app/code/Magento/Analytics/etc/di.xml | 2 +- .../Magento/Analytics/Cron/UpdateTest.php | 239 ++++++++++++++++++ .../Model/Config/Backend/EnabledTest.php | 163 ++++++++++++ ...nabled_subscription_with_invalid_token.php | 19 +- ...bscription_with_invalid_token_rollback.php | 23 +- 11 files changed, 594 insertions(+), 68 deletions(-) create mode 100644 app/code/Magento/Analytics/Setup/Patch/Data/ActivateDataCollection.php create mode 100644 dev/tests/integration/testsuite/Magento/Analytics/Cron/UpdateTest.php create mode 100644 dev/tests/integration/testsuite/Magento/Analytics/Model/Config/Backend/EnabledTest.php diff --git a/app/code/Magento/Analytics/Cron/SignUp.php b/app/code/Magento/Analytics/Cron/SignUp.php index 8f97b839ec8ee..2588b87e84c1c 100644 --- a/app/code/Magento/Analytics/Cron/SignUp.php +++ b/app/code/Magento/Analytics/Cron/SignUp.php @@ -7,6 +7,7 @@ use Magento\Analytics\Model\Config\Backend\Enabled\SubscriptionHandler; use Magento\Analytics\Model\Connector; +use Magento\Framework\Exception\NotFoundException; use Magento\Framework\FlagManager; use Magento\Framework\App\Config\ReinitableConfigInterface; use Magento\Framework\App\Config\Storage\WriterInterface; @@ -57,22 +58,24 @@ public function __construct( } /** - * Execute scheduled subscription operation + * Execute scheduled subscription operation. + * * In case of failure writes message to notifications inbox * * @return bool + * @throws NotFoundException */ public function execute() { - $attemptsCount = $this->flagManager->getFlagData(SubscriptionHandler::ATTEMPTS_REVERSE_COUNTER_FLAG_CODE); + $attemptsCount = (int)$this->flagManager->getFlagData(SubscriptionHandler::ATTEMPTS_REVERSE_COUNTER_FLAG_CODE); - if (($attemptsCount === null) || ($attemptsCount <= 0)) { + if ($attemptsCount <= 0) { $this->deleteAnalyticsCronExpr(); $this->flagManager->deleteFlag(SubscriptionHandler::ATTEMPTS_REVERSE_COUNTER_FLAG_CODE); return false; } - $attemptsCount -= 1; + $attemptsCount--; $this->flagManager->saveFlag(SubscriptionHandler::ATTEMPTS_REVERSE_COUNTER_FLAG_CODE, $attemptsCount); $signUpResult = $this->connector->execute('signUp'); if ($signUpResult === false) { diff --git a/app/code/Magento/Analytics/Cron/Update.php b/app/code/Magento/Analytics/Cron/Update.php index 9062a7bac7551..b5e4b82a0777e 100644 --- a/app/code/Magento/Analytics/Cron/Update.php +++ b/app/code/Magento/Analytics/Cron/Update.php @@ -8,6 +8,7 @@ use Magento\Analytics\Model\AnalyticsToken; use Magento\Analytics\Model\Config\Backend\Baseurl\SubscriptionUpdateHandler; use Magento\Analytics\Model\Connector; +use Magento\Framework\Exception\NotFoundException; use Magento\Framework\FlagManager; use Magento\Framework\App\Config\ReinitableConfigInterface; use Magento\Framework\App\Config\Storage\WriterInterface; @@ -67,26 +68,37 @@ public function __construct( * Execute scheduled update operation * * @return bool + * @throws NotFoundException */ public function execute() { $result = false; - $attemptsCount = $this->flagManager + $attemptsCount = (int)$this->flagManager ->getFlagData(SubscriptionUpdateHandler::SUBSCRIPTION_UPDATE_REVERSE_COUNTER_FLAG_CODE); - if ($attemptsCount) { - $attemptsCount -= 1; + if (($attemptsCount > 0) && $this->analyticsToken->isTokenExist()) { + $attemptsCount--; + $this->flagManager + ->saveFlag(SubscriptionUpdateHandler::SUBSCRIPTION_UPDATE_REVERSE_COUNTER_FLAG_CODE, $attemptsCount); $result = $this->connector->execute('update'); } if ($result || ($attemptsCount <= 0) || (!$this->analyticsToken->isTokenExist())) { - $this->flagManager - ->deleteFlag(SubscriptionUpdateHandler::SUBSCRIPTION_UPDATE_REVERSE_COUNTER_FLAG_CODE); - $this->flagManager->deleteFlag(SubscriptionUpdateHandler::PREVIOUS_BASE_URL_FLAG_CODE); - $this->configWriter->delete(SubscriptionUpdateHandler::UPDATE_CRON_STRING_PATH); - $this->reinitableConfig->reinit(); + $this->exitFromUpdateProcess(); } return $result; } + + /** + * Clean-up flags and refresh configuration + */ + private function exitFromUpdateProcess(): void + { + $this->flagManager + ->deleteFlag(SubscriptionUpdateHandler::SUBSCRIPTION_UPDATE_REVERSE_COUNTER_FLAG_CODE); + $this->flagManager->deleteFlag(SubscriptionUpdateHandler::PREVIOUS_BASE_URL_FLAG_CODE); + $this->configWriter->delete(SubscriptionUpdateHandler::UPDATE_CRON_STRING_PATH); + $this->reinitableConfig->reinit(); + } } diff --git a/app/code/Magento/Analytics/Setup/Patch/Data/ActivateDataCollection.php b/app/code/Magento/Analytics/Setup/Patch/Data/ActivateDataCollection.php new file mode 100644 index 0000000000000..dd60d74b53d09 --- /dev/null +++ b/app/code/Magento/Analytics/Setup/Patch/Data/ActivateDataCollection.php @@ -0,0 +1,95 @@ +scopeConfig = $scopeConfig; + $this->subscriptionStatusProvider = $subscriptionStatusProvider; + $this->collectionTimeBackendModel = $collectionTimeBackendModel; + } + + /** + * @inheritDoc + * + * @throws LocalizedException + */ + public function apply() + { + $subscriptionStatus = $this->subscriptionStatusProvider->getStatus(); + $isCollectionProcessActivated = $this->scopeConfig->getValue(CollectionTime::CRON_SCHEDULE_PATH); + if ($subscriptionStatus !== $this->subscriptionStatusProvider->getStatusForDisabledSubscription() + && !$isCollectionProcessActivated + ) { + $this->collectionTimeBackendModel + ->setValue($this->scopeConfig->getValue($this->analyticsCollectionTimeConfigPath)); + $this->collectionTimeBackendModel->setPath($this->analyticsCollectionTimeConfigPath); + $this->collectionTimeBackendModel->afterSave(); + } + + return $this; + } + + /** + * @inheritDoc + */ + public function getAliases() + { + return []; + } + + /** + * @inheritDoc + */ + public static function getDependencies() + { + return [ + PrepareInitialConfig::class, + ]; + } +} diff --git a/app/code/Magento/Analytics/Setup/Patch/Data/PrepareInitialConfig.php b/app/code/Magento/Analytics/Setup/Patch/Data/PrepareInitialConfig.php index a352854a8b77b..97ac340f9d491 100644 --- a/app/code/Magento/Analytics/Setup/Patch/Data/PrepareInitialConfig.php +++ b/app/code/Magento/Analytics/Setup/Patch/Data/PrepareInitialConfig.php @@ -4,17 +4,18 @@ * See COPYING.txt for license details. */ +declare(strict_types=1); + namespace Magento\Analytics\Setup\Patch\Data; use Magento\Analytics\Model\Config\Backend\Enabled\SubscriptionHandler; +use Magento\Config\Model\Config\Source\Enabledisable; use Magento\Framework\Setup\ModuleDataSetupInterface; use Magento\Framework\Setup\Patch\DataPatchInterface; use Magento\Framework\Setup\Patch\PatchVersionInterface; /** - * Initial patch. - * - * @package Magento\Analytics\Setup\Patch + * Active subscription process for Advanced Reporting */ class PrepareInitialConfig implements DataPatchInterface, PatchVersionInterface { @@ -24,50 +25,47 @@ class PrepareInitialConfig implements DataPatchInterface, PatchVersionInterface private $moduleDataSetup; /** - * PrepareInitialConfig constructor. + * @var SubscriptionHandler + */ + private $subscriptionHandler; + + /** + * @var string + */ + private $subscriptionEnabledConfigPath = 'analytics/subscription/enabled'; + + /** * @param ModuleDataSetupInterface $moduleDataSetup + * @param SubscriptionHandler $subscriptionHandler */ public function __construct( - ModuleDataSetupInterface $moduleDataSetup + ModuleDataSetupInterface $moduleDataSetup, + SubscriptionHandler $subscriptionHandler ) { $this->moduleDataSetup = $moduleDataSetup; + $this->subscriptionHandler = $subscriptionHandler; } /** - * {@inheritdoc} + * @inheritDoc */ public function apply() { - $this->moduleDataSetup->getConnection()->insertMultiple( + $this->moduleDataSetup->getConnection()->insert( $this->moduleDataSetup->getTable('core_config_data'), [ - [ - 'scope' => 'default', - 'scope_id' => 0, - 'path' => 'analytics/subscription/enabled', - 'value' => 1 - ], - [ - 'scope' => 'default', - 'scope_id' => 0, - 'path' => SubscriptionHandler::CRON_STRING_PATH, - 'value' => join(' ', SubscriptionHandler::CRON_EXPR_ARRAY) - ] + 'path' => $this->subscriptionEnabledConfigPath, + 'value' => Enabledisable::ENABLE_VALUE, ] ); - $this->moduleDataSetup->getConnection()->insert( - $this->moduleDataSetup->getTable('flag'), - [ - 'flag_code' => SubscriptionHandler::ATTEMPTS_REVERSE_COUNTER_FLAG_CODE, - 'state' => 0, - 'flag_data' => 24, - ] - ); + $this->subscriptionHandler->processEnabled(); + + return $this; } /** - * {@inheritdoc} + * @inheritDoc */ public static function getDependencies() { @@ -75,7 +73,7 @@ public static function getDependencies() } /** - * {@inheritdoc} + * @inheritDoc */ public static function getVersion() { @@ -83,7 +81,7 @@ public static function getVersion() } /** - * {@inheritdoc} + * @inheritDoc */ public function getAliases() { diff --git a/app/code/Magento/Analytics/Test/Unit/Cron/UpdateTest.php b/app/code/Magento/Analytics/Test/Unit/Cron/UpdateTest.php index aa3011ffc94f6..fa007268474c4 100644 --- a/app/code/Magento/Analytics/Test/Unit/Cron/UpdateTest.php +++ b/app/code/Magento/Analytics/Test/Unit/Cron/UpdateTest.php @@ -11,6 +11,7 @@ use Magento\Analytics\Model\Connector; use Magento\Framework\App\Config\ReinitableConfigInterface; use Magento\Framework\App\Config\Storage\WriterInterface; +use Magento\Framework\Exception\NotFoundException; use Magento\Framework\FlagManager; class UpdateTest extends \PHPUnit\Framework\TestCase @@ -45,6 +46,9 @@ class UpdateTest extends \PHPUnit\Framework\TestCase */ private $update; + /** + * @inheritDoc + */ protected function setUp() { $this->connectorMock = $this->getMockBuilder(Connector::class) @@ -74,6 +78,7 @@ protected function setUp() /** * @return void + * @throws NotFoundException */ public function testExecuteWithoutToken() { @@ -82,12 +87,12 @@ public function testExecuteWithoutToken() ->with(SubscriptionUpdateHandler::SUBSCRIPTION_UPDATE_REVERSE_COUNTER_FLAG_CODE) ->willReturn(10); $this->connectorMock - ->expects($this->once()) + ->expects($this->never()) ->method('execute') ->with('update') ->willReturn(false); $this->analyticsTokenMock - ->expects($this->once()) + ->expects($this->any()) ->method('isTokenExist') ->willReturn(false); $this->addFinalOutputAsserts(); @@ -120,6 +125,7 @@ private function addFinalOutputAsserts(bool $isExecuted = true) * @param $counterData * @return void * @dataProvider executeWithEmptyReverseCounterDataProvider + * @throws NotFoundException */ public function testExecuteWithEmptyReverseCounter($counterData) { @@ -159,6 +165,7 @@ public function executeWithEmptyReverseCounterDataProvider() * @param bool $functionResult * @return void * @dataProvider executeRegularScenarioDataProvider + * @throws NotFoundException */ public function testExecuteRegularScenario( int $reverseCount, @@ -170,6 +177,10 @@ public function testExecuteRegularScenario( ->method('getFlagData') ->with(SubscriptionUpdateHandler::SUBSCRIPTION_UPDATE_REVERSE_COUNTER_FLAG_CODE) ->willReturn($reverseCount); + $this->flagManagerMock + ->expects($this->once()) + ->method('saveFlag') + ->with(SubscriptionUpdateHandler::SUBSCRIPTION_UPDATE_REVERSE_COUNTER_FLAG_CODE, $reverseCount - 1); $this->connectorMock ->expects($this->once()) ->method('execute') diff --git a/app/code/Magento/Analytics/etc/adminhtml/system.xml b/app/code/Magento/Analytics/etc/adminhtml/system.xml index 999d565353329..0aba6e4dd00ed 100644 --- a/app/code/Magento/Analytics/etc/adminhtml/system.xml +++ b/app/code/Magento/Analytics/etc/adminhtml/system.xml @@ -28,6 +28,9 @@ Magento\Analytics\Block\Adminhtml\System\Config\CollectionTimeLabel Magento\Analytics\Model\Config\Backend\CollectionTime + + 1 + Industry Data @@ -36,9 +39,9 @@ Magento\Analytics\Model\Config\Source\Vertical Magento\Analytics\Model\Config\Backend\Vertical Magento\Analytics\Block\Adminhtml\System\Config\Vertical - - 1 - + + 1 + diff --git a/app/code/Magento/Analytics/etc/di.xml b/app/code/Magento/Analytics/etc/di.xml index b9bb9cc9ff00c..cdb42f18718b7 100644 --- a/app/code/Magento/Analytics/etc/di.xml +++ b/app/code/Magento/Analytics/etc/di.xml @@ -6,7 +6,7 @@ */ --> - + diff --git a/dev/tests/integration/testsuite/Magento/Analytics/Cron/UpdateTest.php b/dev/tests/integration/testsuite/Magento/Analytics/Cron/UpdateTest.php new file mode 100644 index 0000000000000..c8ce98d34074b --- /dev/null +++ b/dev/tests/integration/testsuite/Magento/Analytics/Cron/UpdateTest.php @@ -0,0 +1,239 @@ +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 + { + $response = $this->objectManager->create( + \Zend_Http_Response::class, + [ + 'code' => $responseCode, + 'headers' => [ + 'Content-Type' => 'application/json' + ], + 'body' => 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); + } +} diff --git a/dev/tests/integration/testsuite/Magento/Analytics/Model/Config/Backend/EnabledTest.php b/dev/tests/integration/testsuite/Magento/Analytics/Model/Config/Backend/EnabledTest.php new file mode 100644 index 0000000000000..61cc8b56af949 --- /dev/null +++ b/dev/tests/integration/testsuite/Magento/Analytics/Model/Config/Backend/EnabledTest.php @@ -0,0 +1,163 @@ +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)); + } +} diff --git a/dev/tests/integration/testsuite/Magento/Analytics/_files/enabled_subscription_with_invalid_token.php b/dev/tests/integration/testsuite/Magento/Analytics/_files/enabled_subscription_with_invalid_token.php index 0106bf6f1bdac..c52de227deae8 100644 --- a/dev/tests/integration/testsuite/Magento/Analytics/_files/enabled_subscription_with_invalid_token.php +++ b/dev/tests/integration/testsuite/Magento/Analytics/_files/enabled_subscription_with_invalid_token.php @@ -3,27 +3,28 @@ * 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 \Magento\Framework\App\Config\Storage\WriterInterface + * @var $configWriter WriterInterface */ -$configWriter = $objectManager->get(\Magento\Framework\App\Config\Storage\WriterInterface::class); - +$configWriter = $objectManager->get(WriterInterface::class); $configWriter->delete(SubscriptionHandler::CRON_STRING_PATH); -$configWriter->save('analytics/subscription/enabled', 1); /** - * @var $analyticsToken \Magento\Analytics\Model\AnalyticsToken + * @var $analyticsToken AnalyticsToken */ -$analyticsToken = $objectManager->get(\Magento\Analytics\Model\AnalyticsToken::class); +$analyticsToken = $objectManager->get(AnalyticsToken::class); $analyticsToken->storeToken('42'); /** - * @var $flagManager \Magento\Framework\FlagManager + * @var $flagManager FlagManager */ -$flagManager = $objectManager->get(\Magento\Framework\FlagManager::class); - +$flagManager = $objectManager->get(FlagManager::class); $flagManager->deleteFlag(SubscriptionHandler::ATTEMPTS_REVERSE_COUNTER_FLAG_CODE); diff --git a/dev/tests/integration/testsuite/Magento/Analytics/_files/enabled_subscription_with_invalid_token_rollback.php b/dev/tests/integration/testsuite/Magento/Analytics/_files/enabled_subscription_with_invalid_token_rollback.php index 3fd3e21e282e0..a47a4b3475c9d 100644 --- a/dev/tests/integration/testsuite/Magento/Analytics/_files/enabled_subscription_with_invalid_token_rollback.php +++ b/dev/tests/integration/testsuite/Magento/Analytics/_files/enabled_subscription_with_invalid_token_rollback.php @@ -3,27 +3,28 @@ * 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 \Magento\Framework\App\Config\Storage\WriterInterface + * @var $configWriter WriterInterface */ -$configWriter = $objectManager->get(\Magento\Framework\App\Config\Storage\WriterInterface::class); - -$configWriter->delete(SubscriptionHandler::CRON_STRING_PATH); -$configWriter->save('analytics/subscription/enabled', 0); +$configWriter = $objectManager->get(WriterInterface::class); +$configWriter->save(SubscriptionHandler::CRON_STRING_PATH, join(' ', SubscriptionHandler::CRON_EXPR_ARRAY)); /** - * @var $analyticsToken \Magento\Analytics\Model\AnalyticsToken + * @var $analyticsToken AnalyticsToken */ -$analyticsToken = $objectManager->get(\Magento\Analytics\Model\AnalyticsToken::class); +$analyticsToken = $objectManager->get(AnalyticsToken::class); $analyticsToken->storeToken(null); /** - * @var $flagManager \Magento\Framework\FlagManager + * @var $flagManager FlagManager */ -$flagManager = $objectManager->get(\Magento\Framework\FlagManager::class); - -$flagManager->deleteFlag(SubscriptionHandler::ATTEMPTS_REVERSE_COUNTER_FLAG_CODE); +$flagManager = $objectManager->get(FlagManager::class); +$flagManager->saveFlag(SubscriptionHandler::ATTEMPTS_REVERSE_COUNTER_FLAG_CODE, 24);