Skip to content

Commit

Permalink
graphQl-309: added agreement coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
Vitaliy Boyko committed Mar 20, 2019
1 parent 0e8428c commit 17b7c0a
Show file tree
Hide file tree
Showing 10 changed files with 230 additions and 2 deletions.
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;
}
}
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;
}
}
4 changes: 4 additions & 0 deletions app/code/Magento/CheckoutAgreementsGraphQl/README.md
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.
26 changes: 26 additions & 0 deletions app/code/Magento/CheckoutAgreementsGraphQl/composer.json
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\\": ""
}
}
}
14 changes: 14 additions & 0 deletions app/code/Magento/CheckoutAgreementsGraphQl/etc/module.xml
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 app/code/Magento/CheckoutAgreementsGraphQl/etc/schema.graphqls
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 app/code/Magento/CheckoutAgreementsGraphQl/registration.php
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__);
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@
"magento/module-catalog-widget": "*",
"magento/module-checkout": "*",
"magento/module-checkout-agreements": "*",
"magento/module-checkout-agreements-graph-ql": "*",
"magento/module-cms": "*",
"magento/module-cms-url-rewrite": "*",
"magento/module-config": "*",
Expand Down
3 changes: 1 addition & 2 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

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']);
}
}

0 comments on commit 17b7c0a

Please sign in to comment.