Skip to content

Commit b23231c

Browse files
committed
magento/graphql-ce#702: [Test coverage] Customer Downloadable Products
1 parent 70f40dc commit b23231c

File tree

6 files changed

+77
-198
lines changed

6 files changed

+77
-198
lines changed

dev/tests/api-functional/testsuite/Magento/GraphQl/Downloadable/CustomerDownloadableProductsTest.php

Lines changed: 10 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -8,52 +8,35 @@
88
namespace Magento\GraphQl\Downloadable;
99

1010
use Magento\Integration\Api\CustomerTokenServiceInterface;
11-
use Magento\Quote\Api\CartManagementInterface;
12-
use Magento\Quote\Model\ResourceModel\Quote as QuoteResource;
1311
use Magento\TestFramework\Helper\Bootstrap;
1412
use Magento\TestFramework\TestCase\GraphQlAbstract;
15-
use Magento\Quote\Model\QuoteFactory;
1613

1714
/**
18-
* Test retrieving of customer download products
15+
* Test retrieving of customer downloadable products.
1916
*/
2017
class CustomerDownloadableProductsTest extends GraphQlAbstract
2118
{
22-
/**
23-
* @var QuoteFactory
24-
*/
25-
protected $quoteFactory;
26-
27-
/**
28-
* @var QuoteResource
29-
*/
30-
protected $quoteResource;
31-
3219
/**
3320
* @var CustomerTokenServiceInterface
3421
*/
3522
private $customerTokenService;
3623

3724
/**
38-
* @var CartManagementInterface
25+
* @inheritdoc
3926
*/
40-
private $cartManagement;
27+
protected function setUp()
28+
{
29+
$objectManager = Bootstrap::getObjectManager();
30+
$this->customerTokenService = $objectManager->get(CustomerTokenServiceInterface::class);
31+
}
4132

4233
/**
4334
* @magentoApiDataFixture Magento/Customer/_files/customer.php
44-
* @magentoApiDataFixture Magento/GraphQl/Catalog/_files/downloadable_product.php
45-
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/customer/create_empty_cart.php
46-
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/add_downloadable_product.php
47-
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/enable_offline_payment_methods.php
48-
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/set_new_billing_address.php
49-
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/set_checkmo_payment_method.php
35+
* @magentoApiDataFixture Magento/Downloadable/_files/product_downloadable.php
36+
* @magentoApiDataFixture Magento/Downloadable/_files/customer_order_with_downloadable_product.php
5037
*/
5138
public function testCustomerDownloadableProducts()
5239
{
53-
$quote = $this->quoteFactory->create();
54-
$this->quoteResource->load($quote, 'test_quote', 'reserved_order_id');
55-
$this->cartManagement->placeOrder($quote->getId());
56-
5740
$query = $this->getQuery();
5841
$response = $this->graphQlQuery($query, [], '', $this->getHeaderMap());
5942

@@ -88,43 +71,6 @@ public function testCustomerHasNoOrders()
8871
self::assertCount(0, $response['customerDownloadableProducts']['items']);
8972
}
9073

91-
/**
92-
* @magentoApiDataFixture Magento/Customer/_files/customer.php
93-
* @magentoApiDataFixture Magento/GraphQl/Catalog/_files/simple_product.php
94-
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/enable_offline_shipping_methods.php
95-
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/enable_offline_payment_methods.php
96-
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/customer/create_empty_cart.php
97-
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/add_simple_product.php
98-
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/set_new_shipping_address.php
99-
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/set_new_billing_address.php
100-
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/set_flatrate_shipping_method.php
101-
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/set_checkmo_payment_method.php
102-
*/
103-
public function testCustomerHasNoDownloadableProducts()
104-
{
105-
$quote = $this->quoteFactory->create();
106-
$this->quoteResource->load($quote, 'test_quote', 'reserved_order_id');
107-
$this->cartManagement->placeOrder($quote->getId());
108-
109-
$query = $this->getQuery();
110-
$response = $this->graphQlQuery($query, [], '', $this->getHeaderMap());
111-
112-
self::assertArrayHasKey('items', $response['customerDownloadableProducts']);
113-
self::assertCount(0, $response['customerDownloadableProducts']['items']);
114-
}
115-
116-
/**
117-
* @inheritdoc
118-
*/
119-
protected function setUp()
120-
{
121-
$objectManager = Bootstrap::getObjectManager();
122-
$this->customerTokenService = $objectManager->get(CustomerTokenServiceInterface::class);
123-
$this->quoteFactory = $objectManager->get(QuoteFactory::class);
124-
$this->quoteResource = $objectManager->get(QuoteResource::class);
125-
$this->cartManagement = $objectManager->get(CartManagementInterface::class);
126-
}
127-
12874
/**
12975
* @return string
13076
*/
@@ -154,7 +100,6 @@ private function getQuery(): string
154100
private function getHeaderMap(string $username = '[email protected]', string $password = 'password'): array
155101
{
156102
$customerToken = $this->customerTokenService->createCustomerAccessToken($username, $password);
157-
$headerMap = ['Authorization' => 'Bearer ' . $customerToken];
158-
return $headerMap;
103+
return ['Authorization' => 'Bearer ' . $customerToken];
159104
}
160105
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
use Magento\Quote\Api\Data\AddressInterface;
9+
10+
$billingAddress = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
11+
\Magento\Sales\Model\Order\Address::class,
12+
[
13+
'data' => [
14+
AddressInterface::KEY_TELEPHONE => 3468676,
15+
AddressInterface::KEY_POSTCODE => 75477,
16+
AddressInterface::KEY_COUNTRY_ID => 'US',
17+
AddressInterface::KEY_CITY => 'CityM',
18+
AddressInterface::KEY_COMPANY => 'CompanyName',
19+
AddressInterface::KEY_STREET => 'Green str, 67',
20+
AddressInterface::KEY_LASTNAME => 'Smith',
21+
AddressInterface::KEY_FIRSTNAME => 'John',
22+
AddressInterface::KEY_REGION_ID => 1,
23+
]
24+
]
25+
);
26+
$billingAddress->setAddressType('billing');
27+
28+
$payment = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
29+
\Magento\Sales\Model\Order\Payment::class
30+
);
31+
$payment->setMethod('checkmo');
32+
33+
/** @var \Magento\Sales\Model\Order\Item $orderItem */
34+
$orderItem = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
35+
\Magento\Sales\Model\Order\Item::class
36+
);
37+
38+
/** @var \Magento\Catalog\Api\ProductRepositoryInterface $productRepository */
39+
$productRepository = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()
40+
->get(\Magento\Catalog\Api\ProductRepositoryInterface::class);
41+
$product = $productRepository->getById(1);
42+
$link = $product->getExtensionAttributes()->getDownloadableProductLinks()[0];
43+
44+
$orderItem->setProductId(1)
45+
->setProductType(\Magento\Downloadable\Model\Product\Type::TYPE_DOWNLOADABLE)
46+
->setProductOptions(['links' => [$link->getId()]])
47+
->setBasePrice(100)
48+
->setQtyOrdered(1);
49+
50+
$order = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(\Magento\Sales\Model\Order::class);
51+
$order->setCustomerEmail('[email protected]')
52+
->addItem($orderItem)
53+
->setIncrementId('100000001')
54+
->setCustomerId(1)
55+
->setStoreId(1)
56+
->setEmailSent(1)
57+
->setBillingAddress($billingAddress)
58+
->setPayment($payment);
59+
$order->save();
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
require __DIR__ . '/../../../Magento/Sales/_files/default_rollback.php';

dev/tests/integration/testsuite/Magento/GraphQl/Catalog/_files/downloadable_product.php

Lines changed: 0 additions & 74 deletions
This file was deleted.

dev/tests/integration/testsuite/Magento/GraphQl/Catalog/_files/downloadable_product_rollback.php

Lines changed: 0 additions & 31 deletions
This file was deleted.

dev/tests/integration/testsuite/Magento/GraphQl/Quote/_files/add_downloadable_product.php

Lines changed: 0 additions & 28 deletions
This file was deleted.

0 commit comments

Comments
 (0)