forked from magento/magento2
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
graphQl-309: added agreement coverage
- Loading branch information
Vitaliy Boyko
committed
Mar 20, 2019
1 parent
0e8428c
commit 17b7c0a
Showing
10 changed files
with
230 additions
and
2 deletions.
There are no files selected for viewing
48 changes: 48 additions & 0 deletions
48
app/code/Magento/CheckoutAgreementsGraphQl/Model/Resolver/CheckoutAgreements.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
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; | ||
|
||
/** | ||
* CMS page field resolver, used for GraphQL request processing | ||
*/ | ||
class CheckoutAgreements implements ResolverInterface | ||
{ | ||
/** | ||
* @var CheckoutAgreementsDataProvider | ||
*/ | ||
private $checkoutAgreementsDataProvider; | ||
|
||
/** | ||
* @param CheckoutAgreementsDataProvider $checkoutAgreementsDataProvider | ||
*/ | ||
public function __construct( | ||
CheckoutAgreementsDataProvider $checkoutAgreementsDataProvider | ||
) { | ||
$this->checkoutAgreementsDataProvider = $checkoutAgreementsDataProvider; | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
public function resolve( | ||
Field $field, | ||
$context, | ||
ResolveInfo $info, | ||
array $value = null, | ||
array $args = null | ||
) { | ||
$checkoutAgreementsData = $this->checkoutAgreementsDataProvider->getData(); | ||
|
||
return $checkoutAgreementsData; | ||
} | ||
} |
68 changes: 68 additions & 0 deletions
68
...code/Magento/CheckoutAgreementsGraphQl/Model/Resolver/DataProvider/CheckoutAgreements.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Magento\CheckoutAgreementsGraphQl\Model\Resolver\DataProvider; | ||
|
||
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 | ||
*/ | ||
class CheckoutAgreements | ||
{ | ||
/** | ||
* @var SearchCriteriaBuilder | ||
*/ | ||
private $searchCriteriaBuilder; | ||
|
||
/** | ||
* @var CheckoutAgreementsListInterface | ||
*/ | ||
private $checkoutAgreementsList; | ||
|
||
/** | ||
* @param CheckoutAgreementsListInterface $checkoutAgreementsList | ||
* @param SearchCriteriaBuilder $searchCriteriaBuilder | ||
*/ | ||
public function __construct( | ||
CheckoutAgreementsListInterface $checkoutAgreementsList, | ||
SearchCriteriaBuilder $searchCriteriaBuilder | ||
) { | ||
$this->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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# CheckoutAgreementsGraphQl | ||
|
||
**CheckoutAgreementsGraphQl** provides type information for the GraphQl module | ||
to generate Checkout Agreements fields for Checkout Agreements information endpoints. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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\\": "" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<?xml version="1.0"?> | ||
<!-- | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
--> | ||
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd"> | ||
<module name="Magento_CheckoutAgreementsGraphQl"> | ||
<sequence> | ||
<module name="Magento_GraphQl"/> | ||
</sequence> | ||
</module> | ||
</config> |
15 changes: 15 additions & 0 deletions
15
app/code/Magento/CheckoutAgreementsGraphQl/etc/schema.graphqls
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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") | ||
} |
10 changes: 10 additions & 0 deletions
10
app/code/Magento/CheckoutAgreementsGraphQl/registration.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
use Magento\Framework\Component\ComponentRegistrar; | ||
|
||
ComponentRegistrar::register(ComponentRegistrar::MODULE, 'Magento_CheckoutAgreementsGraphQl', __DIR__); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
43 changes: 43 additions & 0 deletions
43
...unctional/testsuite/Magento/GraphQl/CheckoutAgreements/Api/CheckoutAgreementsListTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
|
||
namespace Magento\GraphQL\CheckoutAgreements\Api; | ||
|
||
use Magento\TestFramework\TestCase\GraphQlAbstract; | ||
|
||
class CheckoutAgreementsListTest extends GraphQlAbstract | ||
{ | ||
/** | ||
* @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 | ||
{ | ||
checkoutAgreements { | ||
agreement_id | ||
name | ||
content | ||
content_height | ||
checkbox_text | ||
is_html | ||
} | ||
} | ||
QUERY; | ||
|
||
$response = $this->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: <b>HTML</b>', $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']); | ||
} | ||
} |