From 17b7c0a4b0c3f0732e51595fa9b53820e3b73f32 Mon Sep 17 00:00:00 2001 From: Vitaliy Boyko Date: Wed, 20 Mar 2019 17:00:47 +0200 Subject: [PATCH 01/10] graphQl-309: added agreement coverage --- .../Model/Resolver/CheckoutAgreements.php | 48 +++++++++++++ .../DataProvider/CheckoutAgreements.php | 68 +++++++++++++++++++ .../CheckoutAgreementsGraphQl/README.md | 4 ++ .../CheckoutAgreementsGraphQl/composer.json | 26 +++++++ .../CheckoutAgreementsGraphQl/etc/module.xml | 14 ++++ .../etc/schema.graphqls | 15 ++++ .../registration.php | 10 +++ composer.json | 1 + composer.lock | 3 +- .../Api/CheckoutAgreementsListTest.php | 43 ++++++++++++ 10 files changed, 230 insertions(+), 2 deletions(-) create mode 100644 app/code/Magento/CheckoutAgreementsGraphQl/Model/Resolver/CheckoutAgreements.php create mode 100644 app/code/Magento/CheckoutAgreementsGraphQl/Model/Resolver/DataProvider/CheckoutAgreements.php create mode 100644 app/code/Magento/CheckoutAgreementsGraphQl/README.md create mode 100644 app/code/Magento/CheckoutAgreementsGraphQl/composer.json create mode 100644 app/code/Magento/CheckoutAgreementsGraphQl/etc/module.xml create mode 100644 app/code/Magento/CheckoutAgreementsGraphQl/etc/schema.graphqls create mode 100644 app/code/Magento/CheckoutAgreementsGraphQl/registration.php create mode 100644 dev/tests/api-functional/testsuite/Magento/GraphQl/CheckoutAgreements/Api/CheckoutAgreementsListTest.php diff --git a/app/code/Magento/CheckoutAgreementsGraphQl/Model/Resolver/CheckoutAgreements.php b/app/code/Magento/CheckoutAgreementsGraphQl/Model/Resolver/CheckoutAgreements.php new file mode 100644 index 0000000000000..985c30182886a --- /dev/null +++ b/app/code/Magento/CheckoutAgreementsGraphQl/Model/Resolver/CheckoutAgreements.php @@ -0,0 +1,48 @@ +checkoutAgreementsDataProvider = $checkoutAgreementsDataProvider; + } + + /** + * @inheritdoc + */ + public function resolve( + Field $field, + $context, + ResolveInfo $info, + array $value = null, + array $args = null + ) { + $checkoutAgreementsData = $this->checkoutAgreementsDataProvider->getData(); + + return $checkoutAgreementsData; + } +} diff --git a/app/code/Magento/CheckoutAgreementsGraphQl/Model/Resolver/DataProvider/CheckoutAgreements.php b/app/code/Magento/CheckoutAgreementsGraphQl/Model/Resolver/DataProvider/CheckoutAgreements.php new file mode 100644 index 0000000000000..e8efde95ee380 --- /dev/null +++ b/app/code/Magento/CheckoutAgreementsGraphQl/Model/Resolver/DataProvider/CheckoutAgreements.php @@ -0,0 +1,68 @@ +checkoutAgreementsList = $checkoutAgreementsList; + $this->searchCriteriaBuilder = $searchCriteriaBuilder; + } + + /** + * Get All Active Checkout Agreements Data + * + * @return array + */ + public function getData(): array + { + $this->searchCriteriaBuilder->addFilter(AgreementInterface::IS_ACTIVE, true); + $searchCriteria = $this->searchCriteriaBuilder->create(); + $checkoutAgreements = $this->checkoutAgreementsList->getList($searchCriteria); + + $checkoutAgreementData = []; + foreach ($checkoutAgreements as $checkoutAgreement) { + $checkoutAgreementData[] = [ + AgreementInterface::AGREEMENT_ID => $checkoutAgreement->getAgreementId(), + AgreementInterface::CONTENT => $checkoutAgreement->getContent(), + AgreementInterface::NAME => $checkoutAgreement->getName(), + AgreementInterface::CONTENT_HEIGHT => $checkoutAgreement->getContentHeight(), + AgreementInterface::CHECKBOX_TEXT => $checkoutAgreement->getCheckboxText(), + AgreementInterface::IS_HTML => $checkoutAgreement->getIsHtml(), + ]; + } + + return $checkoutAgreementData; + } +} diff --git a/app/code/Magento/CheckoutAgreementsGraphQl/README.md b/app/code/Magento/CheckoutAgreementsGraphQl/README.md new file mode 100644 index 0000000000000..3ef735e3937f5 --- /dev/null +++ b/app/code/Magento/CheckoutAgreementsGraphQl/README.md @@ -0,0 +1,4 @@ +# CheckoutAgreementsGraphQl + +**CheckoutAgreementsGraphQl** provides type information for the GraphQl module +to generate Checkout Agreements fields for Checkout Agreements information endpoints. diff --git a/app/code/Magento/CheckoutAgreementsGraphQl/composer.json b/app/code/Magento/CheckoutAgreementsGraphQl/composer.json new file mode 100644 index 0000000000000..b4196a3008e54 --- /dev/null +++ b/app/code/Magento/CheckoutAgreementsGraphQl/composer.json @@ -0,0 +1,26 @@ +{ + "name": "magento/module-checkout-agreements-graph-ql", + "description": "N/A", + "type": "magento2-module", + "require": { + "php": "~7.1.3||~7.2.0", + "magento/framework": "*", + "magento/module-checkout-agreements": "*" + }, + "suggest": { + "magento/module-graph-ql": "*", + "magento/module-store-graph-ql": "*" + }, + "license": [ + "OSL-3.0", + "AFL-3.0" + ], + "autoload": { + "files": [ + "registration.php" + ], + "psr-4": { + "Magento\\CheckoutAgreementsGraphQl\\": "" + } + } +} diff --git a/app/code/Magento/CheckoutAgreementsGraphQl/etc/module.xml b/app/code/Magento/CheckoutAgreementsGraphQl/etc/module.xml new file mode 100644 index 0000000000000..55f09ccf7daee --- /dev/null +++ b/app/code/Magento/CheckoutAgreementsGraphQl/etc/module.xml @@ -0,0 +1,14 @@ + + + + + + + + + diff --git a/app/code/Magento/CheckoutAgreementsGraphQl/etc/schema.graphqls b/app/code/Magento/CheckoutAgreementsGraphQl/etc/schema.graphqls new file mode 100644 index 0000000000000..24bf75e2c379b --- /dev/null +++ b/app/code/Magento/CheckoutAgreementsGraphQl/etc/schema.graphqls @@ -0,0 +1,15 @@ +# Copyright © Magento, Inc. All rights reserved. +# See COPYING.txt for license details. + +type Query { + checkoutAgreements: [CheckoutAgreement] @resolver(class: "Magento\\CheckoutAgreementsGraphQl\\Model\\Resolver\\CheckoutAgreements") @doc(description: "The Checkout Agreements query returns information about a Checkout Agreements") +} + +type CheckoutAgreement @doc(description: "Defines all Checkout Agreement information") { + agreement_id: Int @doc(description: "Checkout Agreement identifier") + name: String @doc(description: "Checkout Agreement name") + content: String @doc(description: "Checkout Agreement content") + content_height: String @doc(description: "Checkout Agreement content height") + checkbox_text: String @doc(description: "Checkout Agreement checkbox tex") + is_html: Boolean @doc(description: "Is Checkout Agreement content in HTML format") +} diff --git a/app/code/Magento/CheckoutAgreementsGraphQl/registration.php b/app/code/Magento/CheckoutAgreementsGraphQl/registration.php new file mode 100644 index 0000000000000..b0b4839f33d1f --- /dev/null +++ b/app/code/Magento/CheckoutAgreementsGraphQl/registration.php @@ -0,0 +1,10 @@ +graphQlQuery($query); + $this->assertArrayHasKey('checkoutAgreements', $response); + $agreements = $response['checkoutAgreements']; + $this->assertEquals(1, count($agreements)); + $this->assertEquals('Checkout Agreement (active)', $agreements[0]['name']); + $this->assertEquals('Checkout agreement content: HTML', $agreements[0]['content']); + $this->assertEquals('200px', $agreements[0]['content_height']); + $this->assertEquals('Checkout agreement checkbox text.', $agreements[0]['checkbox_text']); + $this->assertEquals(true, $agreements[0]['is_html']); + } +} From d3190fe74f44646f5e01ca64a5b1df026e491026 Mon Sep 17 00:00:00 2001 From: Vitaliy Boyko Date: Thu, 21 Mar 2019 09:30:38 +0200 Subject: [PATCH 02/10] graphQl-309: static fixes --- .../Model/Resolver/DataProvider/CheckoutAgreements.php | 2 -- .../CheckoutAgreements/Api/CheckoutAgreementsListTest.php | 3 ++- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/app/code/Magento/CheckoutAgreementsGraphQl/Model/Resolver/DataProvider/CheckoutAgreements.php b/app/code/Magento/CheckoutAgreementsGraphQl/Model/Resolver/DataProvider/CheckoutAgreements.php index e8efde95ee380..2a8ac45ed65cc 100644 --- a/app/code/Magento/CheckoutAgreementsGraphQl/Model/Resolver/DataProvider/CheckoutAgreements.php +++ b/app/code/Magento/CheckoutAgreementsGraphQl/Model/Resolver/DataProvider/CheckoutAgreements.php @@ -9,9 +9,7 @@ use Magento\CheckoutAgreements\Api\CheckoutAgreementsListInterface; use Magento\CheckoutAgreements\Api\Data\AgreementInterface; -use Magento\Cms\Api\Data\PageInterface; use Magento\Framework\Api\SearchCriteriaBuilder; -use Magento\Framework\Exception\NoSuchEntityException; /** * Checkout Agreements data provider diff --git a/dev/tests/api-functional/testsuite/Magento/GraphQl/CheckoutAgreements/Api/CheckoutAgreementsListTest.php b/dev/tests/api-functional/testsuite/Magento/GraphQl/CheckoutAgreements/Api/CheckoutAgreementsListTest.php index 8e743674c38d1..4b419d939c183 100644 --- a/dev/tests/api-functional/testsuite/Magento/GraphQl/CheckoutAgreements/Api/CheckoutAgreementsListTest.php +++ b/dev/tests/api-functional/testsuite/Magento/GraphQl/CheckoutAgreements/Api/CheckoutAgreementsListTest.php @@ -3,8 +3,9 @@ * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ +declare(strict_types=1); -namespace Magento\GraphQL\CheckoutAgreements\Api; +namespace Magento\GraphQl\CheckoutAgreements\Api; use Magento\TestFramework\TestCase\GraphQlAbstract; From 6a8c89ba4a791bb32a82e77463ec0f4d1f7cfcf0 Mon Sep 17 00:00:00 2001 From: Vitaliy Boyko Date: Wed, 17 Apr 2019 16:27:07 +0300 Subject: [PATCH 03/10] graphQl-309: checkout agreements support multistore --- .../Model/Resolver/CheckoutAgreements.php | 2 +- .../DataProvider/CheckoutAgreements.php | 34 ++--- .../CheckoutAgreementsGraphQl/etc/module.xml | 6 +- .../etc/schema.graphqls | 2 +- .../Api/CheckoutAgreementsListTest.php | 124 ++++++++++++++++-- 5 files changed, 135 insertions(+), 33 deletions(-) diff --git a/app/code/Magento/CheckoutAgreementsGraphQl/Model/Resolver/CheckoutAgreements.php b/app/code/Magento/CheckoutAgreementsGraphQl/Model/Resolver/CheckoutAgreements.php index 985c30182886a..7009e1e2d85e6 100644 --- a/app/code/Magento/CheckoutAgreementsGraphQl/Model/Resolver/CheckoutAgreements.php +++ b/app/code/Magento/CheckoutAgreementsGraphQl/Model/Resolver/CheckoutAgreements.php @@ -13,7 +13,7 @@ use Magento\Framework\GraphQl\Schema\Type\ResolveInfo; /** - * CMS page field resolver, used for GraphQL request processing + * Checkout Agreements resolver, used for GraphQL request processing */ class CheckoutAgreements implements ResolverInterface { diff --git a/app/code/Magento/CheckoutAgreementsGraphQl/Model/Resolver/DataProvider/CheckoutAgreements.php b/app/code/Magento/CheckoutAgreementsGraphQl/Model/Resolver/DataProvider/CheckoutAgreements.php index 2a8ac45ed65cc..c235d348375c5 100644 --- a/app/code/Magento/CheckoutAgreementsGraphQl/Model/Resolver/DataProvider/CheckoutAgreements.php +++ b/app/code/Magento/CheckoutAgreementsGraphQl/Model/Resolver/DataProvider/CheckoutAgreements.php @@ -7,9 +7,10 @@ namespace Magento\CheckoutAgreementsGraphQl\Model\Resolver\DataProvider; -use Magento\CheckoutAgreements\Api\CheckoutAgreementsListInterface; use Magento\CheckoutAgreements\Api\Data\AgreementInterface; -use Magento\Framework\Api\SearchCriteriaBuilder; +use Magento\CheckoutAgreements\Model\Agreement; +use Magento\CheckoutAgreements\Model\ResourceModel\Agreement\CollectionFactory; +use Magento\Store\Model\StoreManagerInterface; /** * Checkout Agreements data provider @@ -17,25 +18,25 @@ class CheckoutAgreements { /** - * @var SearchCriteriaBuilder + * @var CollectionFactory */ - private $searchCriteriaBuilder; + private $agreementCollectionFactory; /** - * @var CheckoutAgreementsListInterface + * @var StoreManagerInterface */ - private $checkoutAgreementsList; + private $storeManager; /** - * @param CheckoutAgreementsListInterface $checkoutAgreementsList - * @param SearchCriteriaBuilder $searchCriteriaBuilder + * @param CollectionFactory $agreementCollectionFactory + * @param StoreManagerInterface $storeManager */ public function __construct( - CheckoutAgreementsListInterface $checkoutAgreementsList, - SearchCriteriaBuilder $searchCriteriaBuilder + CollectionFactory $agreementCollectionFactory, + StoreManagerInterface $storeManager ) { - $this->checkoutAgreementsList = $checkoutAgreementsList; - $this->searchCriteriaBuilder = $searchCriteriaBuilder; + $this->agreementCollectionFactory = $agreementCollectionFactory; + $this->storeManager = $storeManager; } /** @@ -45,12 +46,13 @@ public function __construct( */ public function getData(): array { - $this->searchCriteriaBuilder->addFilter(AgreementInterface::IS_ACTIVE, true); - $searchCriteria = $this->searchCriteriaBuilder->create(); - $checkoutAgreements = $this->checkoutAgreementsList->getList($searchCriteria); + $agreementsCollection = $this->agreementCollectionFactory->create(); + $agreementsCollection->addStoreFilter($this->storeManager->getStore()->getId()); // TODO: store should be get from query context + $agreementsCollection->addFieldToFilter('is_active', 1); $checkoutAgreementData = []; - foreach ($checkoutAgreements as $checkoutAgreement) { + /** @var Agreement $checkoutAgreement */ + foreach ($agreementsCollection->getItems() as $checkoutAgreement) { $checkoutAgreementData[] = [ AgreementInterface::AGREEMENT_ID => $checkoutAgreement->getAgreementId(), AgreementInterface::CONTENT => $checkoutAgreement->getContent(), diff --git a/app/code/Magento/CheckoutAgreementsGraphQl/etc/module.xml b/app/code/Magento/CheckoutAgreementsGraphQl/etc/module.xml index 55f09ccf7daee..d18e8ee17d097 100644 --- a/app/code/Magento/CheckoutAgreementsGraphQl/etc/module.xml +++ b/app/code/Magento/CheckoutAgreementsGraphQl/etc/module.xml @@ -6,9 +6,5 @@ */ --> - - - - - + diff --git a/app/code/Magento/CheckoutAgreementsGraphQl/etc/schema.graphqls b/app/code/Magento/CheckoutAgreementsGraphQl/etc/schema.graphqls index 24bf75e2c379b..e63368bb3c884 100644 --- a/app/code/Magento/CheckoutAgreementsGraphQl/etc/schema.graphqls +++ b/app/code/Magento/CheckoutAgreementsGraphQl/etc/schema.graphqls @@ -2,7 +2,7 @@ # See COPYING.txt for license details. type Query { - checkoutAgreements: [CheckoutAgreement] @resolver(class: "Magento\\CheckoutAgreementsGraphQl\\Model\\Resolver\\CheckoutAgreements") @doc(description: "The Checkout Agreements query returns information about a Checkout Agreements") + checkoutAgreements: [CheckoutAgreement] @resolver(class: "Magento\\CheckoutAgreementsGraphQl\\Model\\Resolver\\CheckoutAgreements") @doc(description: "The Checkout Agreements information") } type CheckoutAgreement @doc(description: "Defines all Checkout Agreement information") { diff --git a/dev/tests/api-functional/testsuite/Magento/GraphQl/CheckoutAgreements/Api/CheckoutAgreementsListTest.php b/dev/tests/api-functional/testsuite/Magento/GraphQl/CheckoutAgreements/Api/CheckoutAgreementsListTest.php index 4b419d939c183..38498fb016f3c 100644 --- a/dev/tests/api-functional/testsuite/Magento/GraphQl/CheckoutAgreements/Api/CheckoutAgreementsListTest.php +++ b/dev/tests/api-functional/testsuite/Magento/GraphQl/CheckoutAgreements/Api/CheckoutAgreementsListTest.php @@ -7,17 +7,111 @@ namespace Magento\GraphQl\CheckoutAgreements\Api; +use Magento\CheckoutAgreements\Api\Data\AgreementInterface; +use Magento\CheckoutAgreements\Model\Agreement as AgreementModel; +use Magento\CheckoutAgreements\Model\AgreementFactory; +use Magento\CheckoutAgreements\Model\ResourceModel\Agreement; +use Magento\Framework\ObjectManagerInterface; +use Magento\Store\Model\StoreManagerInterface; +use Magento\TestFramework\Helper\Bootstrap; use Magento\TestFramework\TestCase\GraphQlAbstract; class CheckoutAgreementsListTest extends GraphQlAbstract { + /** + * @var ObjectManagerInterface + */ + private $objectManager; + + protected function setUp() + { + parent::setUp(); + $this->objectManager = Bootstrap::getObjectManager(); + } + /** * @magentoApiDataFixture Magento/CheckoutAgreements/_files/agreement_active_with_html_content.php * @magentoApiDataFixture Magento/CheckoutAgreements/_files/agreement_inactive_with_text_content.php */ public function testGetActiveAgreement() { - $query = + $query = $this->getQuery(); + + $response = $this->graphQlQuery($query); + + $this->assertArrayHasKey('checkoutAgreements', $response); + $agreements = $response['checkoutAgreements']; + $this->assertCount(1, $agreements); + $this->assertEquals('Checkout Agreement (active)', $agreements[0]['name']); + $this->assertEquals('Checkout agreement content: HTML', $agreements[0]['content']); + $this->assertEquals('200px', $agreements[0]['content_height']); + $this->assertEquals('Checkout agreement checkbox text.', $agreements[0]['checkbox_text']); + $this->assertEquals(true, $agreements[0]['is_html']); + } + + /** + * @magentoApiDataFixture Magento/CheckoutAgreements/_files/agreement_active_with_html_content.php + * @magentoApiDataFixture Magento/CheckoutAgreements/_files/agreement_inactive_with_text_content.php + * @magentoApiDataFixture Magento/Store/_files/second_store.php + */ + public function testGetActiveAgreementOnSecondStore() + { + $secondStoreCode = 'fixture_second_store'; + $agreementsName = 'Checkout Agreement (active)'; + + $query = $this->getQuery(); + $this->assignAgreementsToStore($secondStoreCode, $agreementsName); + + $headerMap['Store'] = $secondStoreCode; + $response = $this->graphQlQuery($query, [], '', $headerMap); + + $this->assertArrayHasKey('checkoutAgreements', $response); + $agreements = $response['checkoutAgreements']; + $this->assertCount(1, $agreements); + $this->assertEquals($agreementsName, $agreements[0]['name']); + $this->assertEquals('Checkout agreement content: HTML', $agreements[0]['content']); + $this->assertEquals('200px', $agreements[0]['content_height']); + $this->assertEquals('Checkout agreement checkbox text.', $agreements[0]['checkbox_text']); + $this->assertEquals(true, $agreements[0]['is_html']); + } + + /** + * @magentoApiDataFixture Magento/CheckoutAgreements/_files/agreement_active_with_html_content.php + * @magentoApiDataFixture Magento/CheckoutAgreements/_files/agreement_inactive_with_text_content.php + * @magentoApiDataFixture Magento/Store/_files/second_store.php + */ + public function testGetActiveAgreementFromSecondStoreOnDefaultStore() + { + $secondStoreCode = 'fixture_second_store'; + $agreementsName = 'Checkout Agreement (active)'; + + $query = $this->getQuery(); + $this->assignAgreementsToStore($secondStoreCode, $agreementsName); + + $response = $this->graphQlQuery($query); + + $this->assertArrayHasKey('checkoutAgreements', $response); + $agreements = $response['checkoutAgreements']; + $this->assertCount(0, $agreements); + } + + public function testGetAgreementNotSet() + { + $query = $this->getQuery(); + + $response = $this->graphQlQuery($query); + + $this->assertArrayHasKey('checkoutAgreements', $response); + $agreements = $response['checkoutAgreements']; + $this->assertCount(0, $agreements); + } + + /** + * @return string + */ + private function getQuery(): string + { + return <<graphQlQuery($query); - $this->assertArrayHasKey('checkoutAgreements', $response); - $agreements = $response['checkoutAgreements']; - $this->assertEquals(1, count($agreements)); - $this->assertEquals('Checkout Agreement (active)', $agreements[0]['name']); - $this->assertEquals('Checkout agreement content: HTML', $agreements[0]['content']); - $this->assertEquals('200px', $agreements[0]['content_height']); - $this->assertEquals('Checkout agreement checkbox text.', $agreements[0]['checkbox_text']); - $this->assertEquals(true, $agreements[0]['is_html']); + /** + * @param string $storeCode + * @param string $agreementsName + * @return void + */ + private function assignAgreementsToStore(string $storeCode, string $agreementsName): void + { + $agreementsFactory = $this->objectManager->get(AgreementFactory::class); + /** @var Agreement $agreementsResource */ + $agreementsResource = $this->objectManager->get(Agreement::class); + /** @var StoreManagerInterface $storeManager */ + $storeManager = $this->objectManager->get(StoreManagerInterface::class); + $store = $storeManager->getStore($storeCode); + /** @var AgreementModel $agreements */ + $agreements = $agreementsFactory->create(); + $agreementsResource->load($agreements, $agreementsName, AgreementInterface::NAME); + $agreements->setData('stores', [$store->getId()]); + $agreementsResource->save($agreements); } } From f90a6201fa294844ac9a06daf3187bf0ae9c8224 Mon Sep 17 00:00:00 2001 From: Vitaliy Boyko Date: Wed, 17 Apr 2019 19:07:58 +0300 Subject: [PATCH 04/10] graphQl-309: checkout agreements support config --- .../DataProvider/CheckoutAgreements.php | 15 ++- .../Api/CheckoutAgreementsListTest.php | 91 +++++++++++++++++++ 2 files changed, 105 insertions(+), 1 deletion(-) diff --git a/app/code/Magento/CheckoutAgreementsGraphQl/Model/Resolver/DataProvider/CheckoutAgreements.php b/app/code/Magento/CheckoutAgreementsGraphQl/Model/Resolver/DataProvider/CheckoutAgreements.php index c235d348375c5..3dab845627261 100644 --- a/app/code/Magento/CheckoutAgreementsGraphQl/Model/Resolver/DataProvider/CheckoutAgreements.php +++ b/app/code/Magento/CheckoutAgreementsGraphQl/Model/Resolver/DataProvider/CheckoutAgreements.php @@ -10,6 +10,8 @@ use Magento\CheckoutAgreements\Api\Data\AgreementInterface; use Magento\CheckoutAgreements\Model\Agreement; use Magento\CheckoutAgreements\Model\ResourceModel\Agreement\CollectionFactory; +use Magento\Framework\App\Config\ScopeConfigInterface; +use Magento\Store\Model\ScopeInterface; use Magento\Store\Model\StoreManagerInterface; /** @@ -27,16 +29,24 @@ class CheckoutAgreements */ private $storeManager; + /** + * @var ScopeConfigInterface + */ + private $scopeConfig; + /** * @param CollectionFactory $agreementCollectionFactory * @param StoreManagerInterface $storeManager + * @param ScopeConfigInterface $scopeConfig */ public function __construct( CollectionFactory $agreementCollectionFactory, - StoreManagerInterface $storeManager + StoreManagerInterface $storeManager, + ScopeConfigInterface $scopeConfig ) { $this->agreementCollectionFactory = $agreementCollectionFactory; $this->storeManager = $storeManager; + $this->scopeConfig = $scopeConfig; } /** @@ -46,6 +56,9 @@ public function __construct( */ public function getData(): array { + if (!$this->scopeConfig->isSetFlag('checkout/options/enable_agreements', ScopeInterface::SCOPE_STORE)) { + return []; + } $agreementsCollection = $this->agreementCollectionFactory->create(); $agreementsCollection->addStoreFilter($this->storeManager->getStore()->getId()); // TODO: store should be get from query context $agreementsCollection->addFieldToFilter('is_active', 1); diff --git a/dev/tests/api-functional/testsuite/Magento/GraphQl/CheckoutAgreements/Api/CheckoutAgreementsListTest.php b/dev/tests/api-functional/testsuite/Magento/GraphQl/CheckoutAgreements/Api/CheckoutAgreementsListTest.php index 38498fb016f3c..17fa58be72fa2 100644 --- a/dev/tests/api-functional/testsuite/Magento/GraphQl/CheckoutAgreements/Api/CheckoutAgreementsListTest.php +++ b/dev/tests/api-functional/testsuite/Magento/GraphQl/CheckoutAgreements/Api/CheckoutAgreementsListTest.php @@ -11,22 +11,37 @@ use Magento\CheckoutAgreements\Model\Agreement as AgreementModel; use Magento\CheckoutAgreements\Model\AgreementFactory; use Magento\CheckoutAgreements\Model\ResourceModel\Agreement; +use Magento\Config\Model\ResourceModel\Config; +use Magento\Framework\App\Config\ReinitableConfigInterface; +use Magento\Framework\App\Config\ScopeConfigInterface; use Magento\Framework\ObjectManagerInterface; +use Magento\Store\Api\Data\StoreInterface; +use Magento\Store\Model\ScopeInterface; use Magento\Store\Model\StoreManagerInterface; use Magento\TestFramework\Helper\Bootstrap; use Magento\TestFramework\TestCase\GraphQlAbstract; class CheckoutAgreementsListTest extends GraphQlAbstract { + private $agreementsXmlConfigPath = 'checkout/options/enable_agreements'; + /** * @var ObjectManagerInterface */ private $objectManager; + /** + * @var Config + */ + private $config; + protected function setUp() { parent::setUp(); + $this->objectManager = Bootstrap::getObjectManager(); + $this->config = $this->objectManager->get(Config::class); + $this->saveAgreementConfig(1); } /** @@ -106,6 +121,34 @@ public function testGetAgreementNotSet() $this->assertCount(0, $agreements); } + /** + * @magentoApiDataFixture Magento/CheckoutAgreements/_files/agreement_active_with_html_content.php + * @magentoApiDataFixture Magento/CheckoutAgreements/_files/agreement_inactive_with_text_content.php + * @magentoApiDataFixture Magento/Store/_files/second_store.php + */ + public function testDisabledAgreements() + { + $secondStoreCode = 'fixture_second_store'; + $agreementsName = 'Checkout Agreement (active)'; + + $query = $this->getQuery(); + $this->assignAgreementsToStore($secondStoreCode, $agreementsName); + + /** @var StoreManagerInterface $storeManager */ + $storeManager = $this->objectManager->get(StoreManagerInterface::class); + $store = $storeManager->getStore($secondStoreCode); + $this->saveAgreementConfig(0, $store); + + $headerMap['Store'] = $secondStoreCode; + $response = $this->graphQlQuery($query, [], '', $headerMap); + + $this->assertArrayHasKey('checkoutAgreements', $response); + $agreements = $response['checkoutAgreements']; + $this->assertCount(0, $agreements); + + $this->deleteAgreementConfig($store); + } + /** * @return string */ @@ -145,4 +188,52 @@ private function assignAgreementsToStore(string $storeCode, string $agreementsNa $agreements->setData('stores', [$store->getId()]); $agreementsResource->save($agreements); } + + protected function tearDown() + { + parent::tearDown(); + + $this->deleteAgreementConfig(); + } + + /** + * @param int $value + * @param StoreInterface $store + */ + private function saveAgreementConfig(int $value, ?StoreInterface $store = null): void + { + $scopeId = $store ? $store->getId() : 0; + $scope = $store ? ScopeInterface::SCOPE_STORE : ScopeConfigInterface::SCOPE_TYPE_DEFAULT; + $this->config->saveConfig( + $this->agreementsXmlConfigPath, + $value, + $scope, + $scopeId + ); + + $this->reinitConfig(); + } + + /** + * @param StoreInterface $store + */ + private function deleteAgreementConfig(?StoreInterface $store = null): void + { + $scopeId = $store ? $store->getId() : 0; + $scope = $store ? ScopeInterface::SCOPE_STORE : ScopeConfigInterface::SCOPE_TYPE_DEFAULT; + $this->config->deleteConfig( + $this->agreementsXmlConfigPath, + $scope, + $scopeId + ); + + $this->reinitConfig(); + } + + private function reinitConfig(): void + { + /** @var ReinitableConfigInterface $config */ + $config = $this->objectManager->get(ReinitableConfigInterface::class); + $config->reinit(); + } } From 6b930331a8bc720d5e225f04a7aa25e5ed6ac01e Mon Sep 17 00:00:00 2001 From: Vitaliy Boyko Date: Wed, 17 Apr 2019 21:43:54 +0300 Subject: [PATCH 05/10] graphQl-309: fixed tests --- composer.lock | 33 +++++++++++++++- .../Api/CheckoutAgreementsListTest.php | 39 +++++++------------ 2 files changed, 45 insertions(+), 27 deletions(-) diff --git a/composer.lock b/composer.lock index 8747ecc6d8d28..db753d6de6cff 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "7d2484d86d4d31622f2427d46724ca6f", + "content-hash": "d5945e7c615def5bc906a9e876235934", "packages": [ { "name": "braintree/braintree_php", @@ -6618,6 +6618,36 @@ ], "time": "2018-02-14T22:37:14+00:00" }, + { + "name": "magento/magento-coding-standard", + "version": "1.0.2", + "source": { + "type": "git", + "url": "https://github.com/magento/magento-coding-standard.git", + "reference": "f7de26fb6add389d1b42286f67ee87424588a868" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/magento/magento-coding-standard/zipball/f7de26fb6add389d1b42286f67ee87424588a868", + "reference": "f7de26fb6add389d1b42286f67ee87424588a868", + "shasum": "" + }, + "require": { + "php": ">=5.6.0", + "squizlabs/php_codesniffer": "~3.3.0" + }, + "require-dev": { + "phpunit/phpunit": "^4.0 || ^5.0 || ^6.0 || ^7.0" + }, + "type": "phpcodesniffer-standard", + "notification-url": "https://packagist.org/downloads/", + "license": [ + "OSL-3.0", + "AFL-3.0" + ], + "description": "A set of Magento specific PHP CodeSniffer rules.", + "time": "2019-04-05T19:05:17+00:00" + }, { "name": "magento/magento2-functional-testing-framework", "version": "2.3.14", @@ -7842,6 +7872,7 @@ "mock", "xunit" ], + "abandoned": true, "time": "2018-08-09T05:50:03+00:00" }, { diff --git a/dev/tests/api-functional/testsuite/Magento/GraphQl/CheckoutAgreements/Api/CheckoutAgreementsListTest.php b/dev/tests/api-functional/testsuite/Magento/GraphQl/CheckoutAgreements/Api/CheckoutAgreementsListTest.php index 17fa58be72fa2..62491e5e8376b 100644 --- a/dev/tests/api-functional/testsuite/Magento/GraphQl/CheckoutAgreements/Api/CheckoutAgreementsListTest.php +++ b/dev/tests/api-functional/testsuite/Magento/GraphQl/CheckoutAgreements/Api/CheckoutAgreementsListTest.php @@ -16,7 +16,6 @@ use Magento\Framework\App\Config\ScopeConfigInterface; use Magento\Framework\ObjectManagerInterface; use Magento\Store\Api\Data\StoreInterface; -use Magento\Store\Model\ScopeInterface; use Magento\Store\Model\StoreManagerInterface; use Magento\TestFramework\Helper\Bootstrap; use Magento\TestFramework\TestCase\GraphQlAbstract; @@ -40,6 +39,8 @@ protected function setUp() parent::setUp(); $this->objectManager = Bootstrap::getObjectManager(); + + // TODO: remove usage of the Config, use ConfigFixture instead https://github.com/magento/graphql-ce/issues/167 $this->config = $this->objectManager->get(Config::class); $this->saveAgreementConfig(1); } @@ -124,29 +125,17 @@ public function testGetAgreementNotSet() /** * @magentoApiDataFixture Magento/CheckoutAgreements/_files/agreement_active_with_html_content.php * @magentoApiDataFixture Magento/CheckoutAgreements/_files/agreement_inactive_with_text_content.php - * @magentoApiDataFixture Magento/Store/_files/second_store.php */ public function testDisabledAgreements() { - $secondStoreCode = 'fixture_second_store'; - $agreementsName = 'Checkout Agreement (active)'; - $query = $this->getQuery(); - $this->assignAgreementsToStore($secondStoreCode, $agreementsName); + $this->saveAgreementConfig(0); - /** @var StoreManagerInterface $storeManager */ - $storeManager = $this->objectManager->get(StoreManagerInterface::class); - $store = $storeManager->getStore($secondStoreCode); - $this->saveAgreementConfig(0, $store); - - $headerMap['Store'] = $secondStoreCode; - $response = $this->graphQlQuery($query, [], '', $headerMap); + $response = $this->graphQlQuery($query); $this->assertArrayHasKey('checkoutAgreements', $response); $agreements = $response['checkoutAgreements']; $this->assertCount(0, $agreements); - - $this->deleteAgreementConfig($store); } /** @@ -200,31 +189,29 @@ protected function tearDown() * @param int $value * @param StoreInterface $store */ - private function saveAgreementConfig(int $value, ?StoreInterface $store = null): void + private function saveAgreementConfig(int $value): void { - $scopeId = $store ? $store->getId() : 0; - $scope = $store ? ScopeInterface::SCOPE_STORE : ScopeConfigInterface::SCOPE_TYPE_DEFAULT; $this->config->saveConfig( $this->agreementsXmlConfigPath, $value, - $scope, - $scopeId + ScopeConfigInterface::SCOPE_TYPE_DEFAULT, + 0 ); $this->reinitConfig(); } /** - * @param StoreInterface $store + * Delete config + * + * @return void */ - private function deleteAgreementConfig(?StoreInterface $store = null): void + private function deleteAgreementConfig(): void { - $scopeId = $store ? $store->getId() : 0; - $scope = $store ? ScopeInterface::SCOPE_STORE : ScopeConfigInterface::SCOPE_TYPE_DEFAULT; $this->config->deleteConfig( $this->agreementsXmlConfigPath, - $scope, - $scopeId + ScopeConfigInterface::SCOPE_TYPE_DEFAULT, + 0 ); $this->reinitConfig(); From cc5e2170467bb676e83e1fbad121f2ff51a7fb96 Mon Sep 17 00:00:00 2001 From: Vitaliy Boyko Date: Thu, 18 Apr 2019 08:38:20 +0300 Subject: [PATCH 06/10] graphQl-309: fixed dependency --- app/code/Magento/CheckoutAgreementsGraphQl/composer.json | 1 + 1 file changed, 1 insertion(+) diff --git a/app/code/Magento/CheckoutAgreementsGraphQl/composer.json b/app/code/Magento/CheckoutAgreementsGraphQl/composer.json index b4196a3008e54..064e8f7c2ec94 100644 --- a/app/code/Magento/CheckoutAgreementsGraphQl/composer.json +++ b/app/code/Magento/CheckoutAgreementsGraphQl/composer.json @@ -5,6 +5,7 @@ "require": { "php": "~7.1.3||~7.2.0", "magento/framework": "*", + "magento/module-store": "*", "magento/module-checkout-agreements": "*" }, "suggest": { From c94a655fe9a5829a2721b293869cda3ae1be430a Mon Sep 17 00:00:00 2001 From: Valerii Naida Date: Thu, 2 May 2019 17:42:33 -0500 Subject: [PATCH 07/10] GraphQl-309: [Checkout] Checkout Agreements --- .../Model/Resolver/CheckoutAgreements.php | 54 +++++++++++-- .../DataProvider/CheckoutAgreements.php | 81 ------------------- .../CheckoutAgreementsGraphQl/composer.json | 3 +- ...Test.php => GetCheckoutAgreementsTest.php} | 50 +++++++----- 4 files changed, 75 insertions(+), 113 deletions(-) delete mode 100644 app/code/Magento/CheckoutAgreementsGraphQl/Model/Resolver/DataProvider/CheckoutAgreements.php rename dev/tests/api-functional/testsuite/Magento/GraphQl/CheckoutAgreements/{Api/CheckoutAgreementsListTest.php => GetCheckoutAgreementsTest.php} (79%) diff --git a/app/code/Magento/CheckoutAgreementsGraphQl/Model/Resolver/CheckoutAgreements.php b/app/code/Magento/CheckoutAgreementsGraphQl/Model/Resolver/CheckoutAgreements.php index 7009e1e2d85e6..c312d8622a0a9 100644 --- a/app/code/Magento/CheckoutAgreementsGraphQl/Model/Resolver/CheckoutAgreements.php +++ b/app/code/Magento/CheckoutAgreementsGraphQl/Model/Resolver/CheckoutAgreements.php @@ -7,10 +7,14 @@ namespace Magento\CheckoutAgreementsGraphQl\Model\Resolver; -use Magento\CheckoutAgreementsGraphQl\Model\Resolver\DataProvider\CheckoutAgreements as CheckoutAgreementsDataProvider; use Magento\Framework\GraphQl\Config\Element\Field; use Magento\Framework\GraphQl\Query\ResolverInterface; use Magento\Framework\GraphQl\Schema\Type\ResolveInfo; +use Magento\CheckoutAgreements\Api\Data\AgreementInterface; +use Magento\CheckoutAgreements\Model\ResourceModel\Agreement\CollectionFactory; +use Magento\Framework\App\Config\ScopeConfigInterface; +use Magento\Store\Model\ScopeInterface; +use Magento\Store\Model\StoreManagerInterface; /** * Checkout Agreements resolver, used for GraphQL request processing @@ -18,17 +22,33 @@ class CheckoutAgreements implements ResolverInterface { /** - * @var CheckoutAgreementsDataProvider + * @var CollectionFactory */ - private $checkoutAgreementsDataProvider; + private $agreementCollectionFactory; /** - * @param CheckoutAgreementsDataProvider $checkoutAgreementsDataProvider + * @var StoreManagerInterface + */ + private $storeManager; + + /** + * @var ScopeConfigInterface + */ + private $scopeConfig; + + /** + * @param CollectionFactory $agreementCollectionFactory + * @param StoreManagerInterface $storeManager + * @param ScopeConfigInterface $scopeConfig */ public function __construct( - CheckoutAgreementsDataProvider $checkoutAgreementsDataProvider + CollectionFactory $agreementCollectionFactory, + StoreManagerInterface $storeManager, + ScopeConfigInterface $scopeConfig ) { - $this->checkoutAgreementsDataProvider = $checkoutAgreementsDataProvider; + $this->agreementCollectionFactory = $agreementCollectionFactory; + $this->storeManager = $storeManager; + $this->scopeConfig = $scopeConfig; } /** @@ -41,8 +61,26 @@ public function resolve( array $value = null, array $args = null ) { - $checkoutAgreementsData = $this->checkoutAgreementsDataProvider->getData(); + if (!$this->scopeConfig->isSetFlag('checkout/options/enable_agreements', ScopeInterface::SCOPE_STORE)) { + return []; + } + + $agreementsCollection = $this->agreementCollectionFactory->create(); + $agreementsCollection->addStoreFilter($this->storeManager->getStore()->getId()); + $agreementsCollection->addFieldToFilter('is_active', 1); - return $checkoutAgreementsData; + $checkoutAgreementData = []; + /** @var AgreementInterface $checkoutAgreement */ + foreach ($agreementsCollection->getItems() as $checkoutAgreement) { + $checkoutAgreementData[] = [ + AgreementInterface::AGREEMENT_ID => $checkoutAgreement->getAgreementId(), + AgreementInterface::CONTENT => $checkoutAgreement->getContent(), + AgreementInterface::NAME => $checkoutAgreement->getName(), + AgreementInterface::CONTENT_HEIGHT => $checkoutAgreement->getContentHeight(), + AgreementInterface::CHECKBOX_TEXT => $checkoutAgreement->getCheckboxText(), + AgreementInterface::IS_HTML => $checkoutAgreement->getIsHtml(), + ]; + } + return $checkoutAgreementData; } } diff --git a/app/code/Magento/CheckoutAgreementsGraphQl/Model/Resolver/DataProvider/CheckoutAgreements.php b/app/code/Magento/CheckoutAgreementsGraphQl/Model/Resolver/DataProvider/CheckoutAgreements.php deleted file mode 100644 index 3dab845627261..0000000000000 --- a/app/code/Magento/CheckoutAgreementsGraphQl/Model/Resolver/DataProvider/CheckoutAgreements.php +++ /dev/null @@ -1,81 +0,0 @@ -agreementCollectionFactory = $agreementCollectionFactory; - $this->storeManager = $storeManager; - $this->scopeConfig = $scopeConfig; - } - - /** - * Get All Active Checkout Agreements Data - * - * @return array - */ - public function getData(): array - { - if (!$this->scopeConfig->isSetFlag('checkout/options/enable_agreements', ScopeInterface::SCOPE_STORE)) { - return []; - } - $agreementsCollection = $this->agreementCollectionFactory->create(); - $agreementsCollection->addStoreFilter($this->storeManager->getStore()->getId()); // TODO: store should be get from query context - $agreementsCollection->addFieldToFilter('is_active', 1); - - $checkoutAgreementData = []; - /** @var Agreement $checkoutAgreement */ - foreach ($agreementsCollection->getItems() as $checkoutAgreement) { - $checkoutAgreementData[] = [ - AgreementInterface::AGREEMENT_ID => $checkoutAgreement->getAgreementId(), - AgreementInterface::CONTENT => $checkoutAgreement->getContent(), - AgreementInterface::NAME => $checkoutAgreement->getName(), - AgreementInterface::CONTENT_HEIGHT => $checkoutAgreement->getContentHeight(), - AgreementInterface::CHECKBOX_TEXT => $checkoutAgreement->getCheckboxText(), - AgreementInterface::IS_HTML => $checkoutAgreement->getIsHtml(), - ]; - } - - return $checkoutAgreementData; - } -} diff --git a/app/code/Magento/CheckoutAgreementsGraphQl/composer.json b/app/code/Magento/CheckoutAgreementsGraphQl/composer.json index 064e8f7c2ec94..5972d48b35ea9 100644 --- a/app/code/Magento/CheckoutAgreementsGraphQl/composer.json +++ b/app/code/Magento/CheckoutAgreementsGraphQl/composer.json @@ -9,8 +9,7 @@ "magento/module-checkout-agreements": "*" }, "suggest": { - "magento/module-graph-ql": "*", - "magento/module-store-graph-ql": "*" + "magento/module-graph-ql": "*" }, "license": [ "OSL-3.0", diff --git a/dev/tests/api-functional/testsuite/Magento/GraphQl/CheckoutAgreements/Api/CheckoutAgreementsListTest.php b/dev/tests/api-functional/testsuite/Magento/GraphQl/CheckoutAgreements/GetCheckoutAgreementsTest.php similarity index 79% rename from dev/tests/api-functional/testsuite/Magento/GraphQl/CheckoutAgreements/Api/CheckoutAgreementsListTest.php rename to dev/tests/api-functional/testsuite/Magento/GraphQl/CheckoutAgreements/GetCheckoutAgreementsTest.php index 62491e5e8376b..663b314ffdb57 100644 --- a/dev/tests/api-functional/testsuite/Magento/GraphQl/CheckoutAgreements/Api/CheckoutAgreementsListTest.php +++ b/dev/tests/api-functional/testsuite/Magento/GraphQl/CheckoutAgreements/GetCheckoutAgreementsTest.php @@ -5,7 +5,7 @@ */ declare(strict_types=1); -namespace Magento\GraphQl\CheckoutAgreements\Api; +namespace Magento\GraphQl\CheckoutAgreements; use Magento\CheckoutAgreements\Api\Data\AgreementInterface; use Magento\CheckoutAgreements\Model\Agreement as AgreementModel; @@ -20,8 +20,14 @@ use Magento\TestFramework\Helper\Bootstrap; use Magento\TestFramework\TestCase\GraphQlAbstract; -class CheckoutAgreementsListTest extends GraphQlAbstract +/** + * Get checkout agreements test + */ +class GetCheckoutAgreementsTest extends GraphQlAbstract { + /** + * @var string + */ private $agreementsXmlConfigPath = 'checkout/options/enable_agreements'; /** @@ -55,14 +61,14 @@ public function testGetActiveAgreement() $response = $this->graphQlQuery($query); - $this->assertArrayHasKey('checkoutAgreements', $response); + self::assertArrayHasKey('checkoutAgreements', $response); $agreements = $response['checkoutAgreements']; - $this->assertCount(1, $agreements); - $this->assertEquals('Checkout Agreement (active)', $agreements[0]['name']); - $this->assertEquals('Checkout agreement content: HTML', $agreements[0]['content']); - $this->assertEquals('200px', $agreements[0]['content_height']); - $this->assertEquals('Checkout agreement checkbox text.', $agreements[0]['checkbox_text']); - $this->assertEquals(true, $agreements[0]['is_html']); + self::assertCount(1, $agreements); + self::assertEquals('Checkout Agreement (active)', $agreements[0]['name']); + self::assertEquals('Checkout agreement content: HTML', $agreements[0]['content']); + self::assertEquals('200px', $agreements[0]['content_height']); + self::assertEquals('Checkout agreement checkbox text.', $agreements[0]['checkbox_text']); + self::assertEquals(true, $agreements[0]['is_html']); } /** @@ -81,14 +87,14 @@ public function testGetActiveAgreementOnSecondStore() $headerMap['Store'] = $secondStoreCode; $response = $this->graphQlQuery($query, [], '', $headerMap); - $this->assertArrayHasKey('checkoutAgreements', $response); + self::assertArrayHasKey('checkoutAgreements', $response); $agreements = $response['checkoutAgreements']; - $this->assertCount(1, $agreements); - $this->assertEquals($agreementsName, $agreements[0]['name']); - $this->assertEquals('Checkout agreement content: HTML', $agreements[0]['content']); - $this->assertEquals('200px', $agreements[0]['content_height']); - $this->assertEquals('Checkout agreement checkbox text.', $agreements[0]['checkbox_text']); - $this->assertEquals(true, $agreements[0]['is_html']); + self::assertCount(1, $agreements); + self::assertEquals($agreementsName, $agreements[0]['name']); + self::assertEquals('Checkout agreement content: HTML', $agreements[0]['content']); + self::assertEquals('200px', $agreements[0]['content_height']); + self::assertEquals('Checkout agreement checkbox text.', $agreements[0]['checkbox_text']); + self::assertEquals(true, $agreements[0]['is_html']); } /** @@ -106,9 +112,9 @@ public function testGetActiveAgreementFromSecondStoreOnDefaultStore() $response = $this->graphQlQuery($query); - $this->assertArrayHasKey('checkoutAgreements', $response); + self::assertArrayHasKey('checkoutAgreements', $response); $agreements = $response['checkoutAgreements']; - $this->assertCount(0, $agreements); + self::assertCount(0, $agreements); } public function testGetAgreementNotSet() @@ -117,9 +123,9 @@ public function testGetAgreementNotSet() $response = $this->graphQlQuery($query); - $this->assertArrayHasKey('checkoutAgreements', $response); + self::assertArrayHasKey('checkoutAgreements', $response); $agreements = $response['checkoutAgreements']; - $this->assertCount(0, $agreements); + self::assertCount(0, $agreements); } /** @@ -133,9 +139,9 @@ public function testDisabledAgreements() $response = $this->graphQlQuery($query); - $this->assertArrayHasKey('checkoutAgreements', $response); + self::assertArrayHasKey('checkoutAgreements', $response); $agreements = $response['checkoutAgreements']; - $this->assertCount(0, $agreements); + self::assertCount(0, $agreements); } /** From 7305a43ce2b0b96dbf17621ca3a238463773f6e7 Mon Sep 17 00:00:00 2001 From: Vitaliy Boyko Date: Wed, 8 May 2019 11:03:25 +0300 Subject: [PATCH 08/10] graphQl-309: added agreement mode --- .../Model/Resolver/DataProvider/CheckoutAgreements.php | 1 + app/code/Magento/CheckoutAgreementsGraphQl/etc/schema.graphqls | 1 + .../CheckoutAgreements/Api/CheckoutAgreementsListTest.php | 3 +++ 3 files changed, 5 insertions(+) diff --git a/app/code/Magento/CheckoutAgreementsGraphQl/Model/Resolver/DataProvider/CheckoutAgreements.php b/app/code/Magento/CheckoutAgreementsGraphQl/Model/Resolver/DataProvider/CheckoutAgreements.php index 3dab845627261..2fa3fe9d1284d 100644 --- a/app/code/Magento/CheckoutAgreementsGraphQl/Model/Resolver/DataProvider/CheckoutAgreements.php +++ b/app/code/Magento/CheckoutAgreementsGraphQl/Model/Resolver/DataProvider/CheckoutAgreements.php @@ -73,6 +73,7 @@ public function getData(): array AgreementInterface::CONTENT_HEIGHT => $checkoutAgreement->getContentHeight(), AgreementInterface::CHECKBOX_TEXT => $checkoutAgreement->getCheckboxText(), AgreementInterface::IS_HTML => $checkoutAgreement->getIsHtml(), + AgreementInterface::MODE => $checkoutAgreement->getMode(), ]; } diff --git a/app/code/Magento/CheckoutAgreementsGraphQl/etc/schema.graphqls b/app/code/Magento/CheckoutAgreementsGraphQl/etc/schema.graphqls index e63368bb3c884..3debdb2513c63 100644 --- a/app/code/Magento/CheckoutAgreementsGraphQl/etc/schema.graphqls +++ b/app/code/Magento/CheckoutAgreementsGraphQl/etc/schema.graphqls @@ -12,4 +12,5 @@ type CheckoutAgreement @doc(description: "Defines all Checkout Agreement informa content_height: String @doc(description: "Checkout Agreement content height") checkbox_text: String @doc(description: "Checkout Agreement checkbox tex") is_html: Boolean @doc(description: "Is Checkout Agreement content in HTML format") + mode: Int @doc(description: "Is Checkout Agreement content in HTML format") } diff --git a/dev/tests/api-functional/testsuite/Magento/GraphQl/CheckoutAgreements/Api/CheckoutAgreementsListTest.php b/dev/tests/api-functional/testsuite/Magento/GraphQl/CheckoutAgreements/Api/CheckoutAgreementsListTest.php index 62491e5e8376b..05f2afe0ed2cf 100644 --- a/dev/tests/api-functional/testsuite/Magento/GraphQl/CheckoutAgreements/Api/CheckoutAgreementsListTest.php +++ b/dev/tests/api-functional/testsuite/Magento/GraphQl/CheckoutAgreements/Api/CheckoutAgreementsListTest.php @@ -63,6 +63,7 @@ public function testGetActiveAgreement() $this->assertEquals('200px', $agreements[0]['content_height']); $this->assertEquals('Checkout agreement checkbox text.', $agreements[0]['checkbox_text']); $this->assertEquals(true, $agreements[0]['is_html']); + $this->assertEquals(0, $agreements[0]['mode']); } /** @@ -89,6 +90,7 @@ public function testGetActiveAgreementOnSecondStore() $this->assertEquals('200px', $agreements[0]['content_height']); $this->assertEquals('Checkout agreement checkbox text.', $agreements[0]['checkbox_text']); $this->assertEquals(true, $agreements[0]['is_html']); + $this->assertEquals(0, $agreements[0]['mode']); } /** @@ -153,6 +155,7 @@ private function getQuery(): string content_height checkbox_text is_html + mode } } QUERY; From c3040e682d56964b78c6e7a29388bea6c1a34c85 Mon Sep 17 00:00:00 2001 From: Valerii Naida Date: Wed, 8 May 2019 10:26:16 -0500 Subject: [PATCH 09/10] GraphQl-309: [Checkout] Checkout Agreements --- .../Model/Resolver/CheckoutAgreements.php | 8 ++++++-- .../etc/schema.graphqls | 17 +++++++++++------ .../GetCheckoutAgreementsTest.php | 14 +++++++------- 3 files changed, 24 insertions(+), 15 deletions(-) diff --git a/app/code/Magento/CheckoutAgreementsGraphQl/Model/Resolver/CheckoutAgreements.php b/app/code/Magento/CheckoutAgreementsGraphQl/Model/Resolver/CheckoutAgreements.php index 02345f71681f8..670107aef73f2 100644 --- a/app/code/Magento/CheckoutAgreementsGraphQl/Model/Resolver/CheckoutAgreements.php +++ b/app/code/Magento/CheckoutAgreementsGraphQl/Model/Resolver/CheckoutAgreements.php @@ -7,6 +7,8 @@ namespace Magento\CheckoutAgreementsGraphQl\Model\Resolver; +use Magento\CheckoutAgreements\Model\AgreementModeOptions; +use Magento\CheckoutAgreements\Model\ResourceModel\Agreement\Collection; use Magento\Framework\GraphQl\Config\Element\Field; use Magento\Framework\GraphQl\Query\ResolverInterface; use Magento\Framework\GraphQl\Schema\Type\ResolveInfo; @@ -65,9 +67,10 @@ public function resolve( return []; } + /** @var Collection $agreementsCollection */ $agreementsCollection = $this->agreementCollectionFactory->create(); $agreementsCollection->addStoreFilter($this->storeManager->getStore()->getId()); - $agreementsCollection->addFieldToFilter('is_active', 1); + $agreementsCollection->addFieldToFilter(AgreementInterface::IS_ACTIVE, 1); $checkoutAgreementData = []; /** @var AgreementInterface $checkoutAgreement */ @@ -79,7 +82,8 @@ public function resolve( AgreementInterface::CONTENT_HEIGHT => $checkoutAgreement->getContentHeight(), AgreementInterface::CHECKBOX_TEXT => $checkoutAgreement->getCheckboxText(), AgreementInterface::IS_HTML => $checkoutAgreement->getIsHtml(), - AgreementInterface::MODE => $checkoutAgreement->getMode(), + AgreementInterface::MODE => + AgreementModeOptions::MODE_AUTO === $checkoutAgreement->getMode() ? 'AUTO' : 'MANUAL', ]; } return $checkoutAgreementData; diff --git a/app/code/Magento/CheckoutAgreementsGraphQl/etc/schema.graphqls b/app/code/Magento/CheckoutAgreementsGraphQl/etc/schema.graphqls index 3debdb2513c63..64ef9411dfca6 100644 --- a/app/code/Magento/CheckoutAgreementsGraphQl/etc/schema.graphqls +++ b/app/code/Magento/CheckoutAgreementsGraphQl/etc/schema.graphqls @@ -6,11 +6,16 @@ type Query { } type CheckoutAgreement @doc(description: "Defines all Checkout Agreement information") { - agreement_id: Int @doc(description: "Checkout Agreement identifier") - name: String @doc(description: "Checkout Agreement name") - content: String @doc(description: "Checkout Agreement content") + agreement_id: Int! @doc(description: "Checkout Agreement identifier") + name: String! @doc(description: "Checkout Agreement name") + content: String! @doc(description: "Checkout Agreement content") content_height: String @doc(description: "Checkout Agreement content height") - checkbox_text: String @doc(description: "Checkout Agreement checkbox tex") - is_html: Boolean @doc(description: "Is Checkout Agreement content in HTML format") - mode: Int @doc(description: "Is Checkout Agreement content in HTML format") + checkbox_text: String! @doc(description: "Checkout Agreement checkbox text") + is_html: Boolean! @doc(description: "Is Checkout Agreement content in HTML format") + mode: CheckoutAgreementMode! +} + +enum CheckoutAgreementMode { + AUTO + MANUAL } diff --git a/dev/tests/api-functional/testsuite/Magento/GraphQl/CheckoutAgreements/GetCheckoutAgreementsTest.php b/dev/tests/api-functional/testsuite/Magento/GraphQl/CheckoutAgreements/GetCheckoutAgreementsTest.php index 8fdfd5cf0108d..3aa01d7994222 100644 --- a/dev/tests/api-functional/testsuite/Magento/GraphQl/CheckoutAgreements/GetCheckoutAgreementsTest.php +++ b/dev/tests/api-functional/testsuite/Magento/GraphQl/CheckoutAgreements/GetCheckoutAgreementsTest.php @@ -68,8 +68,8 @@ public function testGetActiveAgreement() self::assertEquals('Checkout agreement content: HTML', $agreements[0]['content']); self::assertEquals('200px', $agreements[0]['content_height']); self::assertEquals('Checkout agreement checkbox text.', $agreements[0]['checkbox_text']); - self::assertEquals(true, $agreements[0]['is_html']); - self::assertEquals(0, $agreements[0]['mode']); + self::assertTrue($agreements[0]['is_html']); + self::assertEquals('AUTO', $agreements[0]['mode']); } /** @@ -95,8 +95,8 @@ public function testGetActiveAgreementOnSecondStore() self::assertEquals('Checkout agreement content: HTML', $agreements[0]['content']); self::assertEquals('200px', $agreements[0]['content_height']); self::assertEquals('Checkout agreement checkbox text.', $agreements[0]['checkbox_text']); - self::assertEquals(true, $agreements[0]['is_html']); - self::assertEquals(0, $agreements[0]['mode']); + self::assertTrue($agreements[0]['is_html']); + self::assertEquals('AUTO', $agreements[0]['mode']); } /** @@ -116,7 +116,7 @@ public function testGetActiveAgreementFromSecondStoreOnDefaultStore() self::assertArrayHasKey('checkoutAgreements', $response); $agreements = $response['checkoutAgreements']; - self::assertCount(0, $agreements); + self::assertEmpty($agreements); } public function testGetAgreementNotSet() @@ -127,7 +127,7 @@ public function testGetAgreementNotSet() self::assertArrayHasKey('checkoutAgreements', $response); $agreements = $response['checkoutAgreements']; - self::assertCount(0, $agreements); + self::assertEmpty($agreements); } /** @@ -143,7 +143,7 @@ public function testDisabledAgreements() self::assertArrayHasKey('checkoutAgreements', $response); $agreements = $response['checkoutAgreements']; - self::assertCount(0, $agreements); + self::assertEmpty($agreements); } /** From 4d7be93e831db12cc1c10c41651f6c36c3bb122e Mon Sep 17 00:00:00 2001 From: Valerii Naida Date: Wed, 8 May 2019 10:54:54 -0500 Subject: [PATCH 10/10] GraphQl-309: [Checkout] Checkout Agreements --- .../Model/Resolver/CheckoutAgreements.php | 2 +- composer.lock | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/app/code/Magento/CheckoutAgreementsGraphQl/Model/Resolver/CheckoutAgreements.php b/app/code/Magento/CheckoutAgreementsGraphQl/Model/Resolver/CheckoutAgreements.php index 670107aef73f2..3daf88226d8e5 100644 --- a/app/code/Magento/CheckoutAgreementsGraphQl/Model/Resolver/CheckoutAgreements.php +++ b/app/code/Magento/CheckoutAgreementsGraphQl/Model/Resolver/CheckoutAgreements.php @@ -83,7 +83,7 @@ public function resolve( AgreementInterface::CHECKBOX_TEXT => $checkoutAgreement->getCheckboxText(), AgreementInterface::IS_HTML => $checkoutAgreement->getIsHtml(), AgreementInterface::MODE => - AgreementModeOptions::MODE_AUTO === $checkoutAgreement->getMode() ? 'AUTO' : 'MANUAL', + AgreementModeOptions::MODE_AUTO === (int)$checkoutAgreement->getMode() ? 'AUTO' : 'MANUAL', ]; } return $checkoutAgreementData; diff --git a/composer.lock b/composer.lock index 09ca8cd9f3f02..77783c00dd641 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "6b0350be54f49186c1c9f55ac29bf1cb", + "content-hash": "24c95683a202b83c7f182921c0c88328", "packages": [ { "name": "braintree/braintree_php", @@ -6775,12 +6775,12 @@ "version": "v1.6.5", "source": { "type": "git", - "url": "https://github.com/bovigo/vfsStream.git", + "url": "https://github.com/mikey179/vfsStream.git", "reference": "d5fec95f541d4d71c4823bb5e30cf9b9e5b96145" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/bovigo/vfsStream/zipball/d5fec95f541d4d71c4823bb5e30cf9b9e5b96145", + "url": "https://api.github.com/repos/mikey179/vfsStream/zipball/d5fec95f541d4d71c4823bb5e30cf9b9e5b96145", "reference": "d5fec95f541d4d71c4823bb5e30cf9b9e5b96145", "shasum": "" },