Skip to content

Commit

Permalink
magento/graphql-ce#480: [Test Coverage] 'GetBillingAddress' functiona…
Browse files Browse the repository at this point in the history
…lity
  • Loading branch information
atwixfirster committed Apr 1, 2019
1 parent bd91a20 commit 00cda03
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,11 @@ protected function setUp()

/**
* @magentoApiDataFixture Magento/Customer/_files/customer.php
* @magentoApiDataFixture Magento/Catalog/_files/product_simple.php
* @magentoApiDataFixture Magento/Catalog/_files/products.php
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/customer/create_empty_cart.php
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/add_simple_product.php
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/set_new_shipping_address.php
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/set_new_billing_address.php
*/
public function testGetCartWithBillingAddress()
{
Expand Down Expand Up @@ -91,7 +92,7 @@ public function testGetCartWithBillingAddress()

/**
* @magentoApiDataFixture Magento/Customer/_files/three_customers.php
* @magentoApiDataFixture Magento/Catalog/_files/product_simple.php
* @magentoApiDataFixture Magento/Catalog/_files/products.php
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/customer/create_empty_cart.php
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/add_simple_product.php
*/
Expand All @@ -111,7 +112,7 @@ public function testGetBillingAddressFromAnotherCustomerCart()

/**
* @magentoApiDataFixture Magento/Customer/_files/customer.php
* @magentoApiDataFixture Magento/Catalog/_files/product_simple.php
* @magentoApiDataFixture Magento/Catalog/_files/products.php
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/customer/create_empty_cart.php
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/add_simple_product.php
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,11 @@ protected function setUp()
}

/**
* @magentoApiDataFixture Magento/Catalog/_files/product_simple.php
* @magentoApiDataFixture Magento/Catalog/_files/products.php
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/guest/create_empty_cart.php
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/add_simple_product.php
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/set_new_shipping_address.php
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/set_new_billing_address.php
*/
public function testGetCartWithBillingAddress()
{
Expand All @@ -59,21 +60,21 @@ public function testGetCartWithBillingAddress()
$expectedBillingAddressData = [
'firstname' => 'John',
'lastname' => 'Smith',
'company' => null,
'company' => 'CompanyName',
'street' => [
'Black str, 48'
'Green str, 67'
],
'city' => 'CityX',
'city' => 'CityM',
'region' => [
'code' => 'AL',
'label' => 'Alabama',
],
'postcode' => '47676',
'postcode' => '75477',
'country' => [
'code' => 'US',
'label' => 'US',
],
'telephone' => '3234676',
'telephone' => '3468676',
'address_type' => 'BILLING',
];

Expand All @@ -82,10 +83,11 @@ public function testGetCartWithBillingAddress()

/**
* @magentoApiDataFixture Magento/Customer/_files/customer.php
* @magentoApiDataFixture Magento/Catalog/_files/product_simple.php
* @magentoApiDataFixture Magento/Catalog/_files/products.php
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/customer/create_empty_cart.php
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/add_simple_product.php
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/set_new_shipping_address.php
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/set_new_billing_address.php
*/
public function testGetBillingAddressFromAnotherCustomerCart()
{
Expand All @@ -100,9 +102,10 @@ public function testGetBillingAddressFromAnotherCustomerCart()
}

/**
* @magentoApiDataFixture Magento/Catalog/_files/product_simple.php
* @magentoApiDataFixture Magento/Catalog/_files/products.php
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/guest/create_empty_cart.php
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/add_simple_product.php
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/set_new_shipping_address.php
*/
public function testGetBillingAddressIfBillingAddressIsNotSet()
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

use Magento\Framework\Api\DataObjectHelper;
use Magento\Quote\Api\Data\AddressInterface;
use Magento\Quote\Api\Data\AddressInterfaceFactory;
use Magento\Quote\Api\BillingAddressManagementInterface;
use Magento\Quote\Model\QuoteFactory;
use Magento\Quote\Model\ResourceModel\Quote as QuoteResource;

use Magento\TestFramework\Helper\Bootstrap;

/** @var QuoteFactory $quoteFactory */
$quoteFactory = Bootstrap::getObjectManager()->get(QuoteFactory::class);
/** @var QuoteResource $quoteResource */
$quoteResource = Bootstrap::getObjectManager()->get(QuoteResource::class);
/** @var AddressInterfaceFactory $quoteAddressFactory */
$quoteAddressFactory = Bootstrap::getObjectManager()->get(AddressInterfaceFactory::class);
/** @var DataObjectHelper $dataObjectHelper */
$dataObjectHelper = Bootstrap::getObjectManager()->get(DataObjectHelper::class);
/** @var BillingAddressManagementInterface $billingAddressManagement */
$billingAddressManagement = Bootstrap::getObjectManager()->get(BillingAddressManagementInterface::class);

$quoteAddressData = [
AddressInterface::KEY_TELEPHONE => 3468676,
AddressInterface::KEY_POSTCODE => 75477,
AddressInterface::KEY_COUNTRY_ID => 'US',
AddressInterface::KEY_CITY => 'CityM',
AddressInterface::KEY_COMPANY => 'CompanyName',
AddressInterface::KEY_STREET => 'Green str, 67',
AddressInterface::KEY_LASTNAME => 'Smith',
AddressInterface::KEY_FIRSTNAME => 'John',
AddressInterface::KEY_REGION_ID => 1,
];
$quoteAddress = $quoteAddressFactory->create();
$dataObjectHelper->populateWithArray($quoteAddress, $quoteAddressData, AddressInterfaceFactory::class);

$quote = $quoteFactory->create();
$quoteResource->load($quote, 'test_quote', 'reserved_order_id');
$billingAddressManagement->assign($quote->getId(), $quoteAddress);
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,15 @@
*/
declare(strict_types=1);

use Magento\Catalog\Api\ProductRepositoryInterface;

require __DIR__ . '/address_list.php';

\Magento\TestFramework\Helper\Bootstrap::getInstance()->loadArea(\Magento\Framework\App\Area::AREA_FRONTEND);

$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
$productRepository = $objectManager->create(\Magento\Catalog\Api\ProductRepositoryInterface::class);
/** @var ProductRepositoryInterface $productRepository */
$productRepository = $objectManager->get(ProductRepositoryInterface::class);

/** @var \Magento\Catalog\Model\Product $product */
$product = $objectManager->create(\Magento\Catalog\Model\Product::class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
}

/** @var \Magento\Catalog\Api\ProductRepositoryInterface $productRepository */
$productRepository = $objectManager->create(\Magento\Catalog\Api\ProductRepositoryInterface::class);
$productRepository = $objectManager->get(\Magento\Catalog\Api\ProductRepositoryInterface::class);

try {
$product = $productRepository->get('simple-product-guest-quote', false, null, true);
Expand Down

0 comments on commit 00cda03

Please sign in to comment.