From 17b7c0a4b0c3f0732e51595fa9b53820e3b73f32 Mon Sep 17 00:00:00 2001 From: Vitaliy Boyko Date: Wed, 20 Mar 2019 17:00:47 +0200 Subject: [PATCH] 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']); + } +}