From b31f618d87e3b7d4b70dc91bfe6248a4534ee26e Mon Sep 17 00:00:00 2001 From: Sergey Dovbenko Date: Fri, 5 Jul 2019 12:55:53 +0000 Subject: [PATCH 01/23] Added createCustomerGraphQl plugin --- .../Plugin/Customer/CreateCustomerAccount.php | 60 +++++++++++++++++++ .../CustomerGraphQl/etc/graphql/di.xml | 3 + 2 files changed, 63 insertions(+) create mode 100644 app/code/Magento/CustomerGraphQl/Model/Plugin/Customer/CreateCustomerAccount.php diff --git a/app/code/Magento/CustomerGraphQl/Model/Plugin/Customer/CreateCustomerAccount.php b/app/code/Magento/CustomerGraphQl/Model/Plugin/Customer/CreateCustomerAccount.php new file mode 100644 index 000000000000..d2aa00312577 --- /dev/null +++ b/app/code/Magento/CustomerGraphQl/Model/Plugin/Customer/CreateCustomerAccount.php @@ -0,0 +1,60 @@ +scopeConfig = $scopeConfig; + } + + /** + * Before Executing method. + * + * @param \Magento\CustomerGraphQl\Model\Customer\CreateCustomerAccount $subject + * @param $data + * @return array + */ + public function beforeExecute ( + \Magento\CustomerGraphQl\Model\Customer\CreateCustomerAccount $subject, $data + ) { + if (!$this->scopeConfig->getValue( + self::XML_PATH_NEWSLETTER_ACTIVE, + ScopeInterface::SCOPE_STORE + ) + ) { + $data['is_subscribed'] = false; + } + + return [$data]; + } +} diff --git a/app/code/Magento/CustomerGraphQl/etc/graphql/di.xml b/app/code/Magento/CustomerGraphQl/etc/graphql/di.xml index cb4ab0b7b27f..cafe1820b927 100644 --- a/app/code/Magento/CustomerGraphQl/etc/graphql/di.xml +++ b/app/code/Magento/CustomerGraphQl/etc/graphql/di.xml @@ -6,6 +6,9 @@ */ --> + + + From 51b433c519ad304225a8c952fbcc30c9c32a9720 Mon Sep 17 00:00:00 2001 From: Sergey Dovbenko Date: Thu, 11 Jul 2019 21:31:59 +0000 Subject: [PATCH 02/23] Moved logic from plugin to CreateCustomer --- .../Plugin/Customer/CreateCustomerAccount.php | 60 ------------------- .../Model/Resolver/CreateCustomer.php | 27 ++++++++- .../CustomerGraphQl/etc/graphql/di.xml | 3 - 3 files changed, 26 insertions(+), 64 deletions(-) delete mode 100644 app/code/Magento/CustomerGraphQl/Model/Plugin/Customer/CreateCustomerAccount.php diff --git a/app/code/Magento/CustomerGraphQl/Model/Plugin/Customer/CreateCustomerAccount.php b/app/code/Magento/CustomerGraphQl/Model/Plugin/Customer/CreateCustomerAccount.php deleted file mode 100644 index d2aa00312577..000000000000 --- a/app/code/Magento/CustomerGraphQl/Model/Plugin/Customer/CreateCustomerAccount.php +++ /dev/null @@ -1,60 +0,0 @@ -scopeConfig = $scopeConfig; - } - - /** - * Before Executing method. - * - * @param \Magento\CustomerGraphQl\Model\Customer\CreateCustomerAccount $subject - * @param $data - * @return array - */ - public function beforeExecute ( - \Magento\CustomerGraphQl\Model\Customer\CreateCustomerAccount $subject, $data - ) { - if (!$this->scopeConfig->getValue( - self::XML_PATH_NEWSLETTER_ACTIVE, - ScopeInterface::SCOPE_STORE - ) - ) { - $data['is_subscribed'] = false; - } - - return [$data]; - } -} diff --git a/app/code/Magento/CustomerGraphQl/Model/Resolver/CreateCustomer.php b/app/code/Magento/CustomerGraphQl/Model/Resolver/CreateCustomer.php index e12c636f0edf..848f418e8591 100644 --- a/app/code/Magento/CustomerGraphQl/Model/Resolver/CreateCustomer.php +++ b/app/code/Magento/CustomerGraphQl/Model/Resolver/CreateCustomer.php @@ -13,12 +13,24 @@ use Magento\Framework\GraphQl\Exception\GraphQlInputException; use Magento\Framework\GraphQl\Query\ResolverInterface; use Magento\Framework\GraphQl\Schema\Type\ResolveInfo; +use Magento\Store\Model\ScopeInterface; +use Magento\Framework\App\Config\ScopeConfigInterface; /** * Create customer account resolver */ class CreateCustomer implements ResolverInterface { + /** + * Configuration path to newsletter active setting + */ + const XML_PATH_NEWSLETTER_ACTIVE = 'newsletter/general/active'; + + /** + * @var ScopeConfigInterface + */ + private $scopeConfig; + /** * @var ExtractCustomerData */ @@ -30,13 +42,18 @@ class CreateCustomer implements ResolverInterface private $createCustomerAccount; /** + * CreateCustomer constructor. + * * @param ExtractCustomerData $extractCustomerData * @param CreateCustomerAccount $createCustomerAccount + * @param ScopeConfigInterface $scopeConfig */ public function __construct( ExtractCustomerData $extractCustomerData, - CreateCustomerAccount $createCustomerAccount + CreateCustomerAccount $createCustomerAccount, + ScopeConfigInterface $scopeConfig ) { + $this->scopeConfig = $scopeConfig; $this->extractCustomerData = $extractCustomerData; $this->createCustomerAccount = $createCustomerAccount; } @@ -55,6 +72,14 @@ public function resolve( throw new GraphQlInputException(__('"input" value should be specified')); } + if (!$this->scopeConfig->getValue( + self::XML_PATH_NEWSLETTER_ACTIVE, + ScopeInterface::SCOPE_STORE + ) + ) { + $args['input']['is_subscribed'] = false; + } + $customer = $this->createCustomerAccount->execute($args['input']); $data = $this->extractCustomerData->execute($customer); diff --git a/app/code/Magento/CustomerGraphQl/etc/graphql/di.xml b/app/code/Magento/CustomerGraphQl/etc/graphql/di.xml index cafe1820b927..cb4ab0b7b27f 100644 --- a/app/code/Magento/CustomerGraphQl/etc/graphql/di.xml +++ b/app/code/Magento/CustomerGraphQl/etc/graphql/di.xml @@ -6,9 +6,6 @@ */ --> - - - From dfa329ff5d9b2ac7f39f23e81e7be7e6b76d882a Mon Sep 17 00:00:00 2001 From: sdovbenko Date: Fri, 12 Jul 2019 01:19:29 +0300 Subject: [PATCH 03/23] Added test method testCreateCustomerSubscribed --- .../GraphQl/Customer/CreateCustomerTest.php | 33 +++++++++++++++++++ .../Customer/_files/customer_subscribe.php | 16 +++++++++ 2 files changed, 49 insertions(+) create mode 100644 dev/tests/integration/testsuite/Magento/Customer/_files/customer_subscribe.php diff --git a/dev/tests/api-functional/testsuite/Magento/GraphQl/Customer/CreateCustomerTest.php b/dev/tests/api-functional/testsuite/Magento/GraphQl/Customer/CreateCustomerTest.php index fc51f57a83a7..28f403078761 100644 --- a/dev/tests/api-functional/testsuite/Magento/GraphQl/Customer/CreateCustomerTest.php +++ b/dev/tests/api-functional/testsuite/Magento/GraphQl/Customer/CreateCustomerTest.php @@ -241,6 +241,39 @@ public function testCreateCustomerIfPassedAttributeDosNotExistsInCustomerInput() $this->graphQlMutation($query); } + /** + * @magentoApiDataFixture Magento/Customer/_files/customer_subscribe.php + * @throws \Exception + */ + public function testCreateCustomerSubscribed() + { + $newFirstname = 'Richard'; + $newLastname = 'Rowe'; + $newEmail = 'new_customer@example.com'; + + $query = <<graphQlMutation($query); + + $this->assertEquals(false, $response['createCustomer']['customer']['is_subscribed']); + } + public function tearDown() { $newEmail = 'new_customer@example.com'; diff --git a/dev/tests/integration/testsuite/Magento/Customer/_files/customer_subscribe.php b/dev/tests/integration/testsuite/Magento/Customer/_files/customer_subscribe.php new file mode 100644 index 000000000000..9585ad8b0274 --- /dev/null +++ b/dev/tests/integration/testsuite/Magento/Customer/_files/customer_subscribe.php @@ -0,0 +1,16 @@ +create(\Magento\Config\Model\ResourceModel\Config::class); + +$resourceConfig->saveConfig( + 'newsletter/general/active', + false, + 'default', + 0 +); \ No newline at end of file From 2ca787283282e1063de089d37c71bad28d5ba835 Mon Sep 17 00:00:00 2001 From: sdovbenko Date: Sat, 13 Jul 2019 01:27:10 +0300 Subject: [PATCH 04/23] Added rollback for newsletter/general/active --- .../_files/customer_subscribe_rollback.php | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 dev/tests/integration/testsuite/Magento/Customer/_files/customer_subscribe_rollback.php diff --git a/dev/tests/integration/testsuite/Magento/Customer/_files/customer_subscribe_rollback.php b/dev/tests/integration/testsuite/Magento/Customer/_files/customer_subscribe_rollback.php new file mode 100644 index 000000000000..43210e4cda69 --- /dev/null +++ b/dev/tests/integration/testsuite/Magento/Customer/_files/customer_subscribe_rollback.php @@ -0,0 +1,15 @@ +create(WriterInterface::class); +$configWriter->delete('newsletter/general/active'); From c37a7a41649fd68ca7f800082c5eff25fdec9cc0 Mon Sep 17 00:00:00 2001 From: sdovbenko Date: Sat, 13 Jul 2019 01:34:05 +0300 Subject: [PATCH 05/23] Added todo --- .../Magento/Customer/_files/customer_subscribe_rollback.php | 1 + 1 file changed, 1 insertion(+) diff --git a/dev/tests/integration/testsuite/Magento/Customer/_files/customer_subscribe_rollback.php b/dev/tests/integration/testsuite/Magento/Customer/_files/customer_subscribe_rollback.php index 43210e4cda69..d8773e97b5db 100644 --- a/dev/tests/integration/testsuite/Magento/Customer/_files/customer_subscribe_rollback.php +++ b/dev/tests/integration/testsuite/Magento/Customer/_files/customer_subscribe_rollback.php @@ -3,6 +3,7 @@ * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ +// TODO: Should be removed in scope of https://github.com/magento/graphql-ce/issues/167 declare(strict_types=1); use Magento\Framework\App\Config\Storage\WriterInterface; From c09c17e3b7c3d9a86cf650aa8b642cb632d29013 Mon Sep 17 00:00:00 2001 From: Sergey Dovbenko Date: Tue, 16 Jul 2019 22:25:15 +0000 Subject: [PATCH 06/23] Created Config Module for Newsletter --- .../Model/Resolver/CreateCustomer.php | 29 ++++------ app/code/Magento/Newsletter/Model/Config.php | 53 +++++++++++++++++++ 2 files changed, 63 insertions(+), 19 deletions(-) create mode 100644 app/code/Magento/Newsletter/Model/Config.php diff --git a/app/code/Magento/CustomerGraphQl/Model/Resolver/CreateCustomer.php b/app/code/Magento/CustomerGraphQl/Model/Resolver/CreateCustomer.php index 848f418e8591..daf37027f2d1 100644 --- a/app/code/Magento/CustomerGraphQl/Model/Resolver/CreateCustomer.php +++ b/app/code/Magento/CustomerGraphQl/Model/Resolver/CreateCustomer.php @@ -14,23 +14,13 @@ use Magento\Framework\GraphQl\Query\ResolverInterface; use Magento\Framework\GraphQl\Schema\Type\ResolveInfo; use Magento\Store\Model\ScopeInterface; -use Magento\Framework\App\Config\ScopeConfigInterface; +use Magento\Newsletter\Model\Config; /** * Create customer account resolver */ class CreateCustomer implements ResolverInterface { - /** - * Configuration path to newsletter active setting - */ - const XML_PATH_NEWSLETTER_ACTIVE = 'newsletter/general/active'; - - /** - * @var ScopeConfigInterface - */ - private $scopeConfig; - /** * @var ExtractCustomerData */ @@ -41,19 +31,24 @@ class CreateCustomer implements ResolverInterface */ private $createCustomerAccount; + /** + * @var Config + */ + private $config; + /** * CreateCustomer constructor. * * @param ExtractCustomerData $extractCustomerData * @param CreateCustomerAccount $createCustomerAccount - * @param ScopeConfigInterface $scopeConfig + * @param Config $config */ public function __construct( ExtractCustomerData $extractCustomerData, CreateCustomerAccount $createCustomerAccount, - ScopeConfigInterface $scopeConfig + Config $config ) { - $this->scopeConfig = $scopeConfig; + $this->config = $config; $this->extractCustomerData = $extractCustomerData; $this->createCustomerAccount = $createCustomerAccount; } @@ -72,11 +67,7 @@ public function resolve( throw new GraphQlInputException(__('"input" value should be specified')); } - if (!$this->scopeConfig->getValue( - self::XML_PATH_NEWSLETTER_ACTIVE, - ScopeInterface::SCOPE_STORE - ) - ) { + if (!$this->config->isActive()) { $args['input']['is_subscribed'] = false; } diff --git a/app/code/Magento/Newsletter/Model/Config.php b/app/code/Magento/Newsletter/Model/Config.php new file mode 100644 index 000000000000..0da18b661399 --- /dev/null +++ b/app/code/Magento/Newsletter/Model/Config.php @@ -0,0 +1,53 @@ +scopeConfig = $scopeConfig; + $this->resourceConfig = $resourceConfig; + } + + /** + * Returns newsletter's enabled status + * + * @return bool + */ + public function isActive() + { + return $this->scopeConfig->isSetFlag(self::XML_PATH_NEWSLETTER_ACTIVE); + } +} From c646296331120e3c20e5c73c702eb6093617eff0 Mon Sep 17 00:00:00 2001 From: Sergey Dovbenko Date: Tue, 6 Aug 2019 23:06:25 +0000 Subject: [PATCH 07/23] Deleted redundant dependency + set scopeType --- app/code/Magento/Newsletter/Model/Config.php | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/app/code/Magento/Newsletter/Model/Config.php b/app/code/Magento/Newsletter/Model/Config.php index 0da18b661399..c6e4ba36591f 100644 --- a/app/code/Magento/Newsletter/Model/Config.php +++ b/app/code/Magento/Newsletter/Model/Config.php @@ -7,6 +7,8 @@ namespace Magento\Newsletter\Model; +use Magento\Framework\App\Config\ScopeConfigInterface; + /** * Newsletter configuration model */ @@ -18,27 +20,19 @@ class Config const XML_PATH_NEWSLETTER_ACTIVE = 'newsletter/general/active'; /** - * @var \Magento\Framework\App\Config\ScopeConfigInterface + * @var ScopeConfigInterface */ protected $scopeConfig; - /** - * @var \Magento\Config\Model\ResourceModel\Config - */ - protected $resourceConfig; - /** * Config constructor. * - * @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig - * @param \Magento\Config\Model\ResourceModel\Config $resourceConfig + * @param ScopeConfigInterface $scopeConfig */ public function __construct( - \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig, - \Magento\Config\Model\ResourceModel\Config $resourceConfig + ScopeConfigInterface $scopeConfig ) { $this->scopeConfig = $scopeConfig; - $this->resourceConfig = $resourceConfig; } /** @@ -46,8 +40,8 @@ public function __construct( * * @return bool */ - public function isActive() + public function isActive($scopeType = ScopeConfigInterface::SCOPE_TYPE_DEFAULT) { - return $this->scopeConfig->isSetFlag(self::XML_PATH_NEWSLETTER_ACTIVE); + return $this->scopeConfig->isSetFlag(self::XML_PATH_NEWSLETTER_ACTIVE, $scopeType); } } From 02654a6baea7fd138a4dd731b9544a530dbafe58 Mon Sep 17 00:00:00 2001 From: Sergey Dovbenko Date: Fri, 16 Aug 2019 21:37:56 +0000 Subject: [PATCH 08/23] Added changes from PR #807 --- .../Magento/Customer/Block/Form/Register.php | 15 ++++-- .../Test/Unit/Block/Form/RegisterTest.php | 18 +++---- app/code/Magento/Newsletter/Model/Config.php | 3 +- .../PredispatchNewsletterObserver.php | 25 ++++++--- .../PredispatchNewsletterObserverTest.php | 52 ++++++++----------- 5 files changed, 61 insertions(+), 52 deletions(-) diff --git a/app/code/Magento/Customer/Block/Form/Register.php b/app/code/Magento/Customer/Block/Form/Register.php index a190ccde50b5..be16046d6907 100644 --- a/app/code/Magento/Customer/Block/Form/Register.php +++ b/app/code/Magento/Customer/Block/Form/Register.php @@ -6,7 +6,8 @@ namespace Magento\Customer\Block\Form; use Magento\Customer\Model\AccountManagement; -use Magento\Newsletter\Observer\PredispatchNewsletterObserver; +use Magento\Framework\App\ObjectManager; +use Magento\Newsletter\Model\Config; /** * Customer register form block @@ -32,6 +33,11 @@ class Register extends \Magento\Directory\Block\Data */ protected $_customerUrl; + /** + * @var Config + */ + private $newsLetterConfig; + /** * Constructor * @@ -45,6 +51,7 @@ class Register extends \Magento\Directory\Block\Data * @param \Magento\Customer\Model\Session $customerSession * @param \Magento\Customer\Model\Url $customerUrl * @param array $data + * @param Config $newsLetterConfig * * @SuppressWarnings(PHPMD.ExcessiveParameterList) */ @@ -58,11 +65,13 @@ public function __construct( \Magento\Framework\Module\ModuleManagerInterface $moduleManager, \Magento\Customer\Model\Session $customerSession, \Magento\Customer\Model\Url $customerUrl, - array $data = [] + array $data = [], + Config $newsLetterConfig = null ) { $this->_customerUrl = $customerUrl; $this->_moduleManager = $moduleManager; $this->_customerSession = $customerSession; + $this->newsLetterConfig = $newsLetterConfig ?: ObjectManager::getInstance()->get(Config::class); parent::__construct( $context, $directoryHelper, @@ -170,7 +179,7 @@ public function getRegion() public function isNewsletterEnabled() { return $this->_moduleManager->isOutputEnabled('Magento_Newsletter') - && $this->getConfig(PredispatchNewsletterObserver::XML_PATH_NEWSLETTER_ACTIVE); + && $this->newsLetterConfig->isActive(); } /** diff --git a/app/code/Magento/Customer/Test/Unit/Block/Form/RegisterTest.php b/app/code/Magento/Customer/Test/Unit/Block/Form/RegisterTest.php index b93b9f40d75b..e1adfdf4ed8f 100644 --- a/app/code/Magento/Customer/Test/Unit/Block/Form/RegisterTest.php +++ b/app/code/Magento/Customer/Test/Unit/Block/Form/RegisterTest.php @@ -7,7 +7,6 @@ use Magento\Customer\Block\Form\Register; use Magento\Customer\Model\AccountManagement; -use Magento\Newsletter\Observer\PredispatchNewsletterObserver; /** * Test class for \Magento\Customer\Block\Form\Register. @@ -49,6 +48,9 @@ class RegisterTest extends \PHPUnit\Framework\TestCase /** @var Register */ private $_block; + /** @var \PHPUnit_Framework_MockObject_MockObject | \Magento\Newsletter\Model\Config */ + private $newsletterConfig; + protected function setUp() { $this->_scopeConfig = $this->createMock(\Magento\Framework\App\Config\ScopeConfigInterface::class); @@ -59,9 +61,9 @@ protected function setUp() \Magento\Customer\Model\Session::class, ['getCustomerFormData'] ); + $this->newsletterConfig = $this->createMock(\Magento\Newsletter\Model\Config::class); $context = $this->createMock(\Magento\Framework\View\Element\Template\Context::class); $context->expects($this->any())->method('getScopeConfig')->will($this->returnValue($this->_scopeConfig)); - $this->_block = new \Magento\Customer\Block\Form\Register( $context, $this->directoryHelperMock, @@ -71,7 +73,9 @@ protected function setUp() $this->createMock(\Magento\Directory\Model\ResourceModel\Country\CollectionFactory::class), $this->_moduleManager, $this->_customerSession, - $this->_customerUrl + $this->_customerUrl, + [], + $this->newsletterConfig ); } @@ -292,17 +296,13 @@ public function testIsNewsletterEnabled($isNewsletterEnabled, $isNewsletterActiv )->will( $this->returnValue($isNewsletterEnabled) ); - - $this->_scopeConfig->expects( + $this->newsletterConfig->expects( $this->any() )->method( - 'getValue' - )->with( - PredispatchNewsletterObserver::XML_PATH_NEWSLETTER_ACTIVE + 'isActive' )->will( $this->returnValue($isNewsletterActive) ); - $this->assertEquals($expectedValue, $this->_block->isNewsletterEnabled()); } diff --git a/app/code/Magento/Newsletter/Model/Config.php b/app/code/Magento/Newsletter/Model/Config.php index c6e4ba36591f..be1ad759d650 100644 --- a/app/code/Magento/Newsletter/Model/Config.php +++ b/app/code/Magento/Newsletter/Model/Config.php @@ -38,9 +38,10 @@ public function __construct( /** * Returns newsletter's enabled status * + * @param string $scopeType * @return bool */ - public function isActive($scopeType = ScopeConfigInterface::SCOPE_TYPE_DEFAULT) + public function isActive(string $scopeType = ScopeConfigInterface::SCOPE_TYPE_DEFAULT): bool { return $this->scopeConfig->isSetFlag(self::XML_PATH_NEWSLETTER_ACTIVE, $scopeType); } diff --git a/app/code/Magento/Newsletter/Observer/PredispatchNewsletterObserver.php b/app/code/Magento/Newsletter/Observer/PredispatchNewsletterObserver.php index 9860798b2b9f..f63520e79496 100644 --- a/app/code/Magento/Newsletter/Observer/PredispatchNewsletterObserver.php +++ b/app/code/Magento/Newsletter/Observer/PredispatchNewsletterObserver.php @@ -12,6 +12,8 @@ use Magento\Framework\Event\ObserverInterface; use Magento\Framework\UrlInterface; use Magento\Store\Model\ScopeInterface; +use Magento\Newsletter\Model\Config; +use Magento\Framework\App\ObjectManager; /** * Class PredispatchNewsletterObserver @@ -19,10 +21,16 @@ class PredispatchNewsletterObserver implements ObserverInterface { /** - * Configuration path to newsletter active setting + * @deprecated + * @see \Magento\Newsletter\Model\Config::isActive() */ const XML_PATH_NEWSLETTER_ACTIVE = 'newsletter/general/active'; + /** + * @var Config + */ + private $newsletterConfig; + /** * @var ScopeConfigInterface */ @@ -38,11 +46,16 @@ class PredispatchNewsletterObserver implements ObserverInterface * * @param ScopeConfigInterface $scopeConfig * @param UrlInterface $url + * @param Config|null $newsletterConfig */ - public function __construct(ScopeConfigInterface $scopeConfig, UrlInterface $url) - { + public function __construct( + ScopeConfigInterface $scopeConfig, + UrlInterface $url, + Config $newsletterConfig = null + ) { $this->scopeConfig = $scopeConfig; $this->url = $url; + $this->newsletterConfig = $newsletterConfig ?: ObjectManager::getInstance()->get(Config::class); } /** @@ -52,11 +65,7 @@ public function __construct(ScopeConfigInterface $scopeConfig, UrlInterface $url */ public function execute(Observer $observer) : void { - if (!$this->scopeConfig->getValue( - self::XML_PATH_NEWSLETTER_ACTIVE, - ScopeInterface::SCOPE_STORE - ) - ) { + if (!$this->newsletterConfig->isActive(ScopeInterface::SCOPE_STORE)) { $defaultNoRouteUrl = $this->scopeConfig->getValue( 'web/default/no_route', ScopeInterface::SCOPE_STORE diff --git a/app/code/Magento/Newsletter/Test/Unit/Observer/PredispatchNewsletterObserverTest.php b/app/code/Magento/Newsletter/Test/Unit/Observer/PredispatchNewsletterObserverTest.php index 38d69e5128af..f88537397ae6 100644 --- a/app/code/Magento/Newsletter/Test/Unit/Observer/PredispatchNewsletterObserverTest.php +++ b/app/code/Magento/Newsletter/Test/Unit/Observer/PredispatchNewsletterObserverTest.php @@ -13,6 +13,7 @@ use Magento\Framework\Event\Observer; use Magento\Framework\TestFramework\Unit\Helper\ObjectManager; use Magento\Framework\UrlInterface; +use Magento\Newsletter\Model\Config; use Magento\Newsletter\Observer\PredispatchNewsletterObserver; use Magento\Store\Model\ScopeInterface; use PHPUnit\Framework\TestCase; @@ -52,30 +53,29 @@ class PredispatchNewsletterObserverTest extends TestCase */ private $objectManager; + /** + * @var Config + */ + private $newsletterConfig; + /** * @inheritdoc */ protected function setUp() : void { - $this->configMock = $this->getMockBuilder(ScopeConfigInterface::class) - ->disableOriginalConstructor() - ->getMock(); - $this->urlMock = $this->getMockBuilder(UrlInterface::class) - ->disableOriginalConstructor() - ->getMock(); + $this->configMock = $this->createMock(ScopeConfigInterface::class); + $this->urlMock = $this->createMock(UrlInterface::class); $this->responseMock = $this->getMockBuilder(ResponseInterface::class) ->disableOriginalConstructor() ->setMethods(['setRedirect']) ->getMockForAbstractClass(); - $this->redirectMock = $this->getMockBuilder(RedirectInterface::class) - ->getMock(); + $this->redirectMock = $this->createMock(RedirectInterface::class); + $this->newsletterConfig = $this->createMock(Config::class); $this->objectManager = new ObjectManager($this); - $this->mockObject = $this->objectManager->getObject( - PredispatchNewsletterObserver::class, - [ - 'scopeConfig' => $this->configMock, - 'url' => $this->urlMock - ] + $this->mockObject = new PredispatchNewsletterObserver( + $this->configMock, + $this->urlMock, + $this->newsletterConfig ); } @@ -88,19 +88,17 @@ public function testNewsletterEnabled() : void ->disableOriginalConstructor() ->setMethods(['getResponse', 'getData', 'setRedirect']) ->getMockForAbstractClass(); - - $this->configMock->method('getValue') - ->with(PredispatchNewsletterObserver::XML_PATH_NEWSLETTER_ACTIVE, ScopeInterface::SCOPE_STORE) + $this->newsletterConfig->expects($this->once()) + ->method('isActive') + ->with(ScopeInterface::SCOPE_STORE) ->willReturn(true); $observerMock->expects($this->never()) ->method('getData') ->with('controller_action') ->willReturnSelf(); - $observerMock->expects($this->never()) ->method('getResponse') ->willReturnSelf(); - $this->assertNull($this->mockObject->execute($observerMock)); } @@ -113,35 +111,27 @@ public function testNewsletterDisabled() : void ->disableOriginalConstructor() ->setMethods(['getControllerAction', 'getResponse']) ->getMockForAbstractClass(); - - $this->configMock->expects($this->at(0)) - ->method('getValue') - ->with(PredispatchNewsletterObserver::XML_PATH_NEWSLETTER_ACTIVE, ScopeInterface::SCOPE_STORE) + $this->newsletterConfig->expects($this->once()) + ->method('isActive') + ->with(ScopeInterface::SCOPE_STORE) ->willReturn(false); - $expectedRedirectUrl = 'https://test.com/index'; - - $this->configMock->expects($this->at(1)) + $this->configMock->expects($this->once()) ->method('getValue') ->with('web/default/no_route', ScopeInterface::SCOPE_STORE) ->willReturn($expectedRedirectUrl); - $this->urlMock->expects($this->once()) ->method('getUrl') ->willReturn($expectedRedirectUrl); - $observerMock->expects($this->once()) ->method('getControllerAction') ->willReturnSelf(); - $observerMock->expects($this->once()) ->method('getResponse') ->willReturn($this->responseMock); - $this->responseMock->expects($this->once()) ->method('setRedirect') ->with($expectedRedirectUrl); - $this->assertNull($this->mockObject->execute($observerMock)); } } From 8b1e739cbbbf5afa4b3d122a44d9a0c61c98f214 Mon Sep 17 00:00:00 2001 From: Sergey Dovbenko Date: Tue, 20 Aug 2019 19:44:04 +0000 Subject: [PATCH 09/23] Corrected Code Style --- .../testsuite/Magento/GraphQl/Customer/CreateCustomerTest.php | 2 +- .../testsuite/Magento/Customer/_files/customer_subscribe.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/dev/tests/api-functional/testsuite/Magento/GraphQl/Customer/CreateCustomerTest.php b/dev/tests/api-functional/testsuite/Magento/GraphQl/Customer/CreateCustomerTest.php index 2ff9026cb6a8..d6c7e590639f 100644 --- a/dev/tests/api-functional/testsuite/Magento/GraphQl/Customer/CreateCustomerTest.php +++ b/dev/tests/api-functional/testsuite/Magento/GraphQl/Customer/CreateCustomerTest.php @@ -241,7 +241,7 @@ public function testCreateCustomerIfPassedAttributeDosNotExistsInCustomerInput() $this->graphQlMutation($query); } - /** + /** * @expectedException \Exception * @expectedExceptionMessage Required parameters are missing: First Name */ diff --git a/dev/tests/integration/testsuite/Magento/Customer/_files/customer_subscribe.php b/dev/tests/integration/testsuite/Magento/Customer/_files/customer_subscribe.php index 9585ad8b0274..66ec54641d74 100644 --- a/dev/tests/integration/testsuite/Magento/Customer/_files/customer_subscribe.php +++ b/dev/tests/integration/testsuite/Magento/Customer/_files/customer_subscribe.php @@ -13,4 +13,4 @@ false, 'default', 0 -); \ No newline at end of file +); From 6a4ecbe6ea560da3ff1bdba7a70a5a3fd1607d8e Mon Sep 17 00:00:00 2001 From: Sergey Dovbenko Date: Wed, 21 Aug 2019 20:12:38 +0000 Subject: [PATCH 10/23] Added lines *Deleted unnecessary uses --- .../Customer/Test/Unit/Block/Form/RegisterTest.php | 3 +++ .../Observer/PredispatchNewsletterObserverTest.php | 11 +++++++++++ .../Magento/Customer/_files/customer_subscribe.php | 2 -- 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/app/code/Magento/Customer/Test/Unit/Block/Form/RegisterTest.php b/app/code/Magento/Customer/Test/Unit/Block/Form/RegisterTest.php index e1adfdf4ed8f..3022177ffb9e 100644 --- a/app/code/Magento/Customer/Test/Unit/Block/Form/RegisterTest.php +++ b/app/code/Magento/Customer/Test/Unit/Block/Form/RegisterTest.php @@ -64,6 +64,7 @@ protected function setUp() $this->newsletterConfig = $this->createMock(\Magento\Newsletter\Model\Config::class); $context = $this->createMock(\Magento\Framework\View\Element\Template\Context::class); $context->expects($this->any())->method('getScopeConfig')->will($this->returnValue($this->_scopeConfig)); + $this->_block = new \Magento\Customer\Block\Form\Register( $context, $this->directoryHelperMock, @@ -296,6 +297,7 @@ public function testIsNewsletterEnabled($isNewsletterEnabled, $isNewsletterActiv )->will( $this->returnValue($isNewsletterEnabled) ); + $this->newsletterConfig->expects( $this->any() )->method( @@ -303,6 +305,7 @@ public function testIsNewsletterEnabled($isNewsletterEnabled, $isNewsletterActiv )->will( $this->returnValue($isNewsletterActive) ); + $this->assertEquals($expectedValue, $this->_block->isNewsletterEnabled()); } diff --git a/app/code/Magento/Newsletter/Test/Unit/Observer/PredispatchNewsletterObserverTest.php b/app/code/Magento/Newsletter/Test/Unit/Observer/PredispatchNewsletterObserverTest.php index f88537397ae6..d0cfa507eb42 100644 --- a/app/code/Magento/Newsletter/Test/Unit/Observer/PredispatchNewsletterObserverTest.php +++ b/app/code/Magento/Newsletter/Test/Unit/Observer/PredispatchNewsletterObserverTest.php @@ -88,17 +88,21 @@ public function testNewsletterEnabled() : void ->disableOriginalConstructor() ->setMethods(['getResponse', 'getData', 'setRedirect']) ->getMockForAbstractClass(); + $this->newsletterConfig->expects($this->once()) ->method('isActive') ->with(ScopeInterface::SCOPE_STORE) ->willReturn(true); + $observerMock->expects($this->never()) ->method('getData') ->with('controller_action') ->willReturnSelf(); + $observerMock->expects($this->never()) ->method('getResponse') ->willReturnSelf(); + $this->assertNull($this->mockObject->execute($observerMock)); } @@ -111,27 +115,34 @@ public function testNewsletterDisabled() : void ->disableOriginalConstructor() ->setMethods(['getControllerAction', 'getResponse']) ->getMockForAbstractClass(); + $this->newsletterConfig->expects($this->once()) ->method('isActive') ->with(ScopeInterface::SCOPE_STORE) ->willReturn(false); + $expectedRedirectUrl = 'https://test.com/index'; $this->configMock->expects($this->once()) ->method('getValue') ->with('web/default/no_route', ScopeInterface::SCOPE_STORE) ->willReturn($expectedRedirectUrl); + $this->urlMock->expects($this->once()) ->method('getUrl') ->willReturn($expectedRedirectUrl); + $observerMock->expects($this->once()) ->method('getControllerAction') ->willReturnSelf(); + $observerMock->expects($this->once()) ->method('getResponse') ->willReturn($this->responseMock); + $this->responseMock->expects($this->once()) ->method('setRedirect') ->with($expectedRedirectUrl); + $this->assertNull($this->mockObject->execute($observerMock)); } } diff --git a/dev/tests/integration/testsuite/Magento/Customer/_files/customer_subscribe.php b/dev/tests/integration/testsuite/Magento/Customer/_files/customer_subscribe.php index 66ec54641d74..c776eeab48de 100644 --- a/dev/tests/integration/testsuite/Magento/Customer/_files/customer_subscribe.php +++ b/dev/tests/integration/testsuite/Magento/Customer/_files/customer_subscribe.php @@ -3,8 +3,6 @@ * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ -use Magento\Customer\Model\CustomerRegistry; - $resourceConfig = \Magento\TestFramework\Helper\Bootstrap::getObjectManager() ->create(\Magento\Config\Model\ResourceModel\Config::class); From b4bdc73fa35d865fdc460487ca217f8848930183 Mon Sep 17 00:00:00 2001 From: Sergey Dovbenko Date: Wed, 21 Aug 2019 21:17:51 +0000 Subject: [PATCH 11/23] Removed customer_subscribe.php and customer_subscribe_rollback.php --- .../GraphQl/Customer/CreateCustomerTest.php | 2 +- .../Customer/_files/customer_subscribe.php | 14 -------------- .../_files/customer_subscribe_rollback.php | 16 ---------------- 3 files changed, 1 insertion(+), 31 deletions(-) delete mode 100644 dev/tests/integration/testsuite/Magento/Customer/_files/customer_subscribe.php delete mode 100644 dev/tests/integration/testsuite/Magento/Customer/_files/customer_subscribe_rollback.php diff --git a/dev/tests/api-functional/testsuite/Magento/GraphQl/Customer/CreateCustomerTest.php b/dev/tests/api-functional/testsuite/Magento/GraphQl/Customer/CreateCustomerTest.php index d6c7e590639f..9654be4f5e3c 100644 --- a/dev/tests/api-functional/testsuite/Magento/GraphQl/Customer/CreateCustomerTest.php +++ b/dev/tests/api-functional/testsuite/Magento/GraphQl/Customer/CreateCustomerTest.php @@ -276,7 +276,7 @@ public function testCreateCustomerIfNameEmpty() } /** - * @magentoApiDataFixture Magento/Customer/_files/customer_subscribe.php + * @magentoConfigFixture default_store newsletter/general/active 0 * @throws \Exception */ public function testCreateCustomerSubscribed() diff --git a/dev/tests/integration/testsuite/Magento/Customer/_files/customer_subscribe.php b/dev/tests/integration/testsuite/Magento/Customer/_files/customer_subscribe.php deleted file mode 100644 index c776eeab48de..000000000000 --- a/dev/tests/integration/testsuite/Magento/Customer/_files/customer_subscribe.php +++ /dev/null @@ -1,14 +0,0 @@ -create(\Magento\Config\Model\ResourceModel\Config::class); - -$resourceConfig->saveConfig( - 'newsletter/general/active', - false, - 'default', - 0 -); diff --git a/dev/tests/integration/testsuite/Magento/Customer/_files/customer_subscribe_rollback.php b/dev/tests/integration/testsuite/Magento/Customer/_files/customer_subscribe_rollback.php deleted file mode 100644 index d8773e97b5db..000000000000 --- a/dev/tests/integration/testsuite/Magento/Customer/_files/customer_subscribe_rollback.php +++ /dev/null @@ -1,16 +0,0 @@ -create(WriterInterface::class); -$configWriter->delete('newsletter/general/active'); From 9cecea1826cd3eaf45b09cfd462bc8d013d47a71 Mon Sep 17 00:00:00 2001 From: Sergey Dovbenko Date: Wed, 28 Aug 2019 23:53:07 +0300 Subject: [PATCH 12/23] Update app/code/Magento/CustomerGraphQl/Model/Resolver/CreateCustomer.php Co-Authored-By: Lena Orobei --- .../Magento/CustomerGraphQl/Model/Resolver/CreateCustomer.php | 1 - 1 file changed, 1 deletion(-) diff --git a/app/code/Magento/CustomerGraphQl/Model/Resolver/CreateCustomer.php b/app/code/Magento/CustomerGraphQl/Model/Resolver/CreateCustomer.php index 8997ff06b5c6..86ba3df0eafe 100644 --- a/app/code/Magento/CustomerGraphQl/Model/Resolver/CreateCustomer.php +++ b/app/code/Magento/CustomerGraphQl/Model/Resolver/CreateCustomer.php @@ -13,7 +13,6 @@ use Magento\Framework\GraphQl\Exception\GraphQlInputException; use Magento\Framework\GraphQl\Query\ResolverInterface; use Magento\Framework\GraphQl\Schema\Type\ResolveInfo; -use Magento\Store\Model\ScopeInterface; use Magento\Newsletter\Model\Config; /** From 68940ec051915c416c89cccd0e57df857d6d0fee Mon Sep 17 00:00:00 2001 From: Sergey Dovbenko Date: Wed, 28 Aug 2019 23:55:20 +0300 Subject: [PATCH 13/23] Renamed $config to $newsletterConfig Co-Authored-By: Lena Orobei --- .../Magento/CustomerGraphQl/Model/Resolver/CreateCustomer.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/code/Magento/CustomerGraphQl/Model/Resolver/CreateCustomer.php b/app/code/Magento/CustomerGraphQl/Model/Resolver/CreateCustomer.php index 86ba3df0eafe..8133aae93f5a 100644 --- a/app/code/Magento/CustomerGraphQl/Model/Resolver/CreateCustomer.php +++ b/app/code/Magento/CustomerGraphQl/Model/Resolver/CreateCustomer.php @@ -33,7 +33,7 @@ class CreateCustomer implements ResolverInterface /** * @var Config */ - private $config; + private $newsletterConfig; /** * CreateCustomer constructor. From b88a3db488a1ea083da7e9db363550ff6363f444 Mon Sep 17 00:00:00 2001 From: Sergey Dovbenko Date: Wed, 28 Aug 2019 23:56:48 +0300 Subject: [PATCH 14/23] Renamed config to newsletterConfig Co-Authored-By: Lena Orobei --- .../Magento/CustomerGraphQl/Model/Resolver/CreateCustomer.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/code/Magento/CustomerGraphQl/Model/Resolver/CreateCustomer.php b/app/code/Magento/CustomerGraphQl/Model/Resolver/CreateCustomer.php index 8133aae93f5a..8a6163494d82 100644 --- a/app/code/Magento/CustomerGraphQl/Model/Resolver/CreateCustomer.php +++ b/app/code/Magento/CustomerGraphQl/Model/Resolver/CreateCustomer.php @@ -45,7 +45,7 @@ class CreateCustomer implements ResolverInterface public function __construct( ExtractCustomerData $extractCustomerData, CreateCustomerAccount $createCustomerAccount, - Config $config + Config $newsletterConfig ) { $this->config = $config; $this->extractCustomerData = $extractCustomerData; From 010536d6b152d8826e2c6c1b60e8c38e4f59f6a4 Mon Sep 17 00:00:00 2001 From: Sergey Dovbenko Date: Wed, 28 Aug 2019 23:57:31 +0300 Subject: [PATCH 15/23] Renamed config to newsletterConfig Co-Authored-By: Lena Orobei --- .../Magento/CustomerGraphQl/Model/Resolver/CreateCustomer.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/code/Magento/CustomerGraphQl/Model/Resolver/CreateCustomer.php b/app/code/Magento/CustomerGraphQl/Model/Resolver/CreateCustomer.php index 8a6163494d82..caf1436ae3ee 100644 --- a/app/code/Magento/CustomerGraphQl/Model/Resolver/CreateCustomer.php +++ b/app/code/Magento/CustomerGraphQl/Model/Resolver/CreateCustomer.php @@ -47,7 +47,7 @@ public function __construct( CreateCustomerAccount $createCustomerAccount, Config $newsletterConfig ) { - $this->config = $config; + $this->newsLetterConfig = $newsLetterConfig; $this->extractCustomerData = $extractCustomerData; $this->createCustomerAccount = $createCustomerAccount; } From bf5d62286f1c88b71f7837ca24315c0e032c3fd5 Mon Sep 17 00:00:00 2001 From: Sergey Dovbenko Date: Wed, 28 Aug 2019 23:57:48 +0300 Subject: [PATCH 16/23] Renamed config to newsletterConfig Co-Authored-By: Lena Orobei --- .../Magento/CustomerGraphQl/Model/Resolver/CreateCustomer.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/code/Magento/CustomerGraphQl/Model/Resolver/CreateCustomer.php b/app/code/Magento/CustomerGraphQl/Model/Resolver/CreateCustomer.php index caf1436ae3ee..b7ac4d5ea5fd 100644 --- a/app/code/Magento/CustomerGraphQl/Model/Resolver/CreateCustomer.php +++ b/app/code/Magento/CustomerGraphQl/Model/Resolver/CreateCustomer.php @@ -66,7 +66,7 @@ public function resolve( throw new GraphQlInputException(__('"input" value should be specified')); } - if (!$this->config->isActive()) { + if (!$this->newsLetterConfig->isActive()) { $args['input']['is_subscribed'] = false; } From 75e240865563979af8c9876e8530cb3818d51ed7 Mon Sep 17 00:00:00 2001 From: Sergey Dovbenko Date: Wed, 28 Aug 2019 23:58:21 +0300 Subject: [PATCH 17/23] Deleted empty line Co-Authored-By: Lena Orobei --- .../Test/Unit/Observer/PredispatchNewsletterObserverTest.php | 1 - 1 file changed, 1 deletion(-) diff --git a/app/code/Magento/Newsletter/Test/Unit/Observer/PredispatchNewsletterObserverTest.php b/app/code/Magento/Newsletter/Test/Unit/Observer/PredispatchNewsletterObserverTest.php index d0cfa507eb42..6846231319d6 100644 --- a/app/code/Magento/Newsletter/Test/Unit/Observer/PredispatchNewsletterObserverTest.php +++ b/app/code/Magento/Newsletter/Test/Unit/Observer/PredispatchNewsletterObserverTest.php @@ -93,7 +93,6 @@ public function testNewsletterEnabled() : void ->method('isActive') ->with(ScopeInterface::SCOPE_STORE) ->willReturn(true); - $observerMock->expects($this->never()) ->method('getData') ->with('controller_action') From c0caee9c5d36323979ec35aa46cc7ef36eccdbd6 Mon Sep 17 00:00:00 2001 From: Sergey Dovbenko Date: Wed, 28 Aug 2019 23:58:49 +0300 Subject: [PATCH 18/23] Removed Exception Co-Authored-By: Lena Orobei --- .../testsuite/Magento/GraphQl/Customer/CreateCustomerTest.php | 1 - 1 file changed, 1 deletion(-) diff --git a/dev/tests/api-functional/testsuite/Magento/GraphQl/Customer/CreateCustomerTest.php b/dev/tests/api-functional/testsuite/Magento/GraphQl/Customer/CreateCustomerTest.php index 9654be4f5e3c..c5714012f38c 100644 --- a/dev/tests/api-functional/testsuite/Magento/GraphQl/Customer/CreateCustomerTest.php +++ b/dev/tests/api-functional/testsuite/Magento/GraphQl/Customer/CreateCustomerTest.php @@ -277,7 +277,6 @@ public function testCreateCustomerIfNameEmpty() /** * @magentoConfigFixture default_store newsletter/general/active 0 - * @throws \Exception */ public function testCreateCustomerSubscribed() { From e99ddb823ac358249389693c7be0d66c295a507d Mon Sep 17 00:00:00 2001 From: Sergey Dovbenko Date: Wed, 28 Aug 2019 21:46:54 +0000 Subject: [PATCH 19/23] Set magentoApiDataFixture --- .../Magento/GraphQl/Customer/CreateCustomerTest.php | 2 +- .../Magento/Customer/_files/customer_subscribe.php | 13 +++++++++++++ .../Customer/_files/customer_subscribe_rollback.php | 13 +++++++++++++ 3 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 dev/tests/integration/testsuite/Magento/Customer/_files/customer_subscribe.php create mode 100644 dev/tests/integration/testsuite/Magento/Customer/_files/customer_subscribe_rollback.php diff --git a/dev/tests/api-functional/testsuite/Magento/GraphQl/Customer/CreateCustomerTest.php b/dev/tests/api-functional/testsuite/Magento/GraphQl/Customer/CreateCustomerTest.php index c5714012f38c..5ebf76f3b6cc 100644 --- a/dev/tests/api-functional/testsuite/Magento/GraphQl/Customer/CreateCustomerTest.php +++ b/dev/tests/api-functional/testsuite/Magento/GraphQl/Customer/CreateCustomerTest.php @@ -276,7 +276,7 @@ public function testCreateCustomerIfNameEmpty() } /** - * @magentoConfigFixture default_store newsletter/general/active 0 + * @magentoApiDataFixture Magento/Customer/_files/customer_subscribe.php */ public function testCreateCustomerSubscribed() { diff --git a/dev/tests/integration/testsuite/Magento/Customer/_files/customer_subscribe.php b/dev/tests/integration/testsuite/Magento/Customer/_files/customer_subscribe.php new file mode 100644 index 000000000000..ab45a28a795b --- /dev/null +++ b/dev/tests/integration/testsuite/Magento/Customer/_files/customer_subscribe.php @@ -0,0 +1,13 @@ +create(\Magento\Config\Model\ResourceModel\Config::class); +$resourceConfig->saveConfig( + 'newsletter/general/active', + false, + 'default', + 0 +); \ No newline at end of file diff --git a/dev/tests/integration/testsuite/Magento/Customer/_files/customer_subscribe_rollback.php b/dev/tests/integration/testsuite/Magento/Customer/_files/customer_subscribe_rollback.php new file mode 100644 index 000000000000..35e10e52b6e6 --- /dev/null +++ b/dev/tests/integration/testsuite/Magento/Customer/_files/customer_subscribe_rollback.php @@ -0,0 +1,13 @@ +create(WriterInterface::class); +$configWriter->delete('newsletter/general/active'); \ No newline at end of file From bfb57ec3bc426a9605682eab61dd12a8ae21da23 Mon Sep 17 00:00:00 2001 From: Sergey Dovbenko Date: Thu, 29 Aug 2019 14:34:41 +0000 Subject: [PATCH 20/23] Corrected newsLetterConfig --- .../CustomerGraphQl/Model/Resolver/CreateCustomer.php | 6 +++--- .../Magento/Customer/_files/customer_subscribe.php | 2 +- .../Magento/Customer/_files/customer_subscribe_rollback.php | 4 +++- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/app/code/Magento/CustomerGraphQl/Model/Resolver/CreateCustomer.php b/app/code/Magento/CustomerGraphQl/Model/Resolver/CreateCustomer.php index b7ac4d5ea5fd..18e417bb5edf 100644 --- a/app/code/Magento/CustomerGraphQl/Model/Resolver/CreateCustomer.php +++ b/app/code/Magento/CustomerGraphQl/Model/Resolver/CreateCustomer.php @@ -33,19 +33,19 @@ class CreateCustomer implements ResolverInterface /** * @var Config */ - private $newsletterConfig; + private $newsLetterConfig; /** * CreateCustomer constructor. * * @param ExtractCustomerData $extractCustomerData * @param CreateCustomerAccount $createCustomerAccount - * @param Config $config + * @param Config $newsLetterConfig */ public function __construct( ExtractCustomerData $extractCustomerData, CreateCustomerAccount $createCustomerAccount, - Config $newsletterConfig + Config $newsLetterConfig ) { $this->newsLetterConfig = $newsLetterConfig; $this->extractCustomerData = $extractCustomerData; diff --git a/dev/tests/integration/testsuite/Magento/Customer/_files/customer_subscribe.php b/dev/tests/integration/testsuite/Magento/Customer/_files/customer_subscribe.php index ab45a28a795b..58eb11fb00e8 100644 --- a/dev/tests/integration/testsuite/Magento/Customer/_files/customer_subscribe.php +++ b/dev/tests/integration/testsuite/Magento/Customer/_files/customer_subscribe.php @@ -10,4 +10,4 @@ false, 'default', 0 -); \ No newline at end of file +); diff --git a/dev/tests/integration/testsuite/Magento/Customer/_files/customer_subscribe_rollback.php b/dev/tests/integration/testsuite/Magento/Customer/_files/customer_subscribe_rollback.php index 35e10e52b6e6..2a84fd5556eb 100644 --- a/dev/tests/integration/testsuite/Magento/Customer/_files/customer_subscribe_rollback.php +++ b/dev/tests/integration/testsuite/Magento/Customer/_files/customer_subscribe_rollback.php @@ -5,9 +5,11 @@ */ // TODO: Should be removed in scope of https://github.com/magento/graphql-ce/issues/167 +declare(strict_types=1); + use Magento\Framework\App\Config\Storage\WriterInterface; use Magento\TestFramework\Helper\Bootstrap; $objectManager = Bootstrap::getObjectManager(); /** @var Writer $configWriter */ $configWriter = $objectManager->create(WriterInterface::class); -$configWriter->delete('newsletter/general/active'); \ No newline at end of file +$configWriter->delete('newsletter/general/active'); From c35ac36f888de3aba4c755c617d3c58a7cd9da4b Mon Sep 17 00:00:00 2001 From: Sergey Dovbenko Date: Thu, 29 Aug 2019 19:46:54 +0000 Subject: [PATCH 21/23] Corrected code styles --- .../Customer/_files/customer_subscribe_rollback.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/dev/tests/integration/testsuite/Magento/Customer/_files/customer_subscribe_rollback.php b/dev/tests/integration/testsuite/Magento/Customer/_files/customer_subscribe_rollback.php index 2a84fd5556eb..26823c7534b9 100644 --- a/dev/tests/integration/testsuite/Magento/Customer/_files/customer_subscribe_rollback.php +++ b/dev/tests/integration/testsuite/Magento/Customer/_files/customer_subscribe_rollback.php @@ -1,14 +1,15 @@ create(WriterInterface::class); From 1e0db4d659a4c5ac318db971db2fe666a72bd8a2 Mon Sep 17 00:00:00 2001 From: Sergey Dovbenko Date: Mon, 2 Sep 2019 19:39:14 +0000 Subject: [PATCH 22/23] Used @magentoConfigFixture + deleted customer_subscribe.php, customer_subscribe_rollback.php --- .../GraphQl/Customer/CreateCustomerTest.php | 2 +- .../Customer/_files/customer_subscribe.php | 13 ------------- .../_files/customer_subscribe_rollback.php | 16 ---------------- 3 files changed, 1 insertion(+), 30 deletions(-) delete mode 100644 dev/tests/integration/testsuite/Magento/Customer/_files/customer_subscribe.php delete mode 100644 dev/tests/integration/testsuite/Magento/Customer/_files/customer_subscribe_rollback.php diff --git a/dev/tests/api-functional/testsuite/Magento/GraphQl/Customer/CreateCustomerTest.php b/dev/tests/api-functional/testsuite/Magento/GraphQl/Customer/CreateCustomerTest.php index 5ebf76f3b6cc..c5714012f38c 100644 --- a/dev/tests/api-functional/testsuite/Magento/GraphQl/Customer/CreateCustomerTest.php +++ b/dev/tests/api-functional/testsuite/Magento/GraphQl/Customer/CreateCustomerTest.php @@ -276,7 +276,7 @@ public function testCreateCustomerIfNameEmpty() } /** - * @magentoApiDataFixture Magento/Customer/_files/customer_subscribe.php + * @magentoConfigFixture default_store newsletter/general/active 0 */ public function testCreateCustomerSubscribed() { diff --git a/dev/tests/integration/testsuite/Magento/Customer/_files/customer_subscribe.php b/dev/tests/integration/testsuite/Magento/Customer/_files/customer_subscribe.php deleted file mode 100644 index 58eb11fb00e8..000000000000 --- a/dev/tests/integration/testsuite/Magento/Customer/_files/customer_subscribe.php +++ /dev/null @@ -1,13 +0,0 @@ -create(\Magento\Config\Model\ResourceModel\Config::class); -$resourceConfig->saveConfig( - 'newsletter/general/active', - false, - 'default', - 0 -); diff --git a/dev/tests/integration/testsuite/Magento/Customer/_files/customer_subscribe_rollback.php b/dev/tests/integration/testsuite/Magento/Customer/_files/customer_subscribe_rollback.php deleted file mode 100644 index 26823c7534b9..000000000000 --- a/dev/tests/integration/testsuite/Magento/Customer/_files/customer_subscribe_rollback.php +++ /dev/null @@ -1,16 +0,0 @@ -create(WriterInterface::class); -$configWriter->delete('newsletter/general/active'); From 0768d89e8f2a81fb18539edaa889de94e6003818 Mon Sep 17 00:00:00 2001 From: Lena Orobei Date: Mon, 9 Sep 2019 10:10:30 -0500 Subject: [PATCH 23/23] magento/graphql-ce#762: Subscribe for newsletter even when not allowed --- .../Magento/CustomerGraphQl/Model/Resolver/CreateCustomer.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/code/Magento/CustomerGraphQl/Model/Resolver/CreateCustomer.php b/app/code/Magento/CustomerGraphQl/Model/Resolver/CreateCustomer.php index 18e417bb5edf..6d33dea35835 100644 --- a/app/code/Magento/CustomerGraphQl/Model/Resolver/CreateCustomer.php +++ b/app/code/Magento/CustomerGraphQl/Model/Resolver/CreateCustomer.php @@ -14,6 +14,7 @@ use Magento\Framework\GraphQl\Query\ResolverInterface; use Magento\Framework\GraphQl\Schema\Type\ResolveInfo; use Magento\Newsletter\Model\Config; +use Magento\Store\Model\ScopeInterface; /** * Create customer account resolver @@ -66,7 +67,7 @@ public function resolve( throw new GraphQlInputException(__('"input" value should be specified')); } - if (!$this->newsLetterConfig->isActive()) { + if (!$this->newsLetterConfig->isActive(ScopeInterface::SCOPE_STORE)) { $args['input']['is_subscribed'] = false; }