Skip to content

Commit 4285ac5

Browse files
committed
GraphQL-538: Api-functional tests fixture refactoring
1 parent ef61afe commit 4285ac5

26 files changed

+792
-547
lines changed

dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Customer/GetAvailablePaymentMethodsTest.php

Lines changed: 41 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -38,48 +38,56 @@ protected function setUp()
3838
}
3939

4040
/**
41-
* @magentoApiDataFixture Magento/Checkout/_files/quote_with_items_saved.php
41+
* @magentoApiDataFixture Magento/Customer/_files/customer.php
42+
* @magentoApiDataFixture Magento/Catalog/_files/product_simple.php
43+
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/customer/create_empty_cart.php
44+
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/add_simple_product.php
45+
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/set_new_shipping_address.php
4246
*/
43-
public function testGetCartWithPaymentMethods()
47+
public function testGetAvailablePaymentMethods()
4448
{
45-
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_order_item_with_items');
49+
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote');
4650
$query = $this->getQuery($maskedQuoteId);
4751
$response = $this->graphQlQuery($query, [], '', $this->getHeaderMap());
4852

4953
self::assertArrayHasKey('cart', $response);
54+
self::assertArrayHasKey('available_payment_methods', $response['cart']);
55+
self::assertCount(1, $response['cart']['available_payment_methods']);
56+
5057
self::assertEquals('checkmo', $response['cart']['available_payment_methods'][0]['code']);
5158
self::assertEquals('Check / Money order', $response['cart']['available_payment_methods'][0]['title']);
52-
self::assertGreaterThan(
53-
0,
54-
count($response['cart']['available_payment_methods']),
55-
'There are no available payment methods for customer cart!'
56-
);
5759
}
5860

5961
/**
62+
* @security
6063
* @magentoApiDataFixture Magento/Customer/_files/customer.php
61-
* @magentoApiDataFixture Magento/Checkout/_files/quote_with_virtual_product_saved.php
64+
* @magentoApiDataFixture Magento/Catalog/_files/product_simple.php
65+
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/guest/create_empty_cart.php
66+
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/add_simple_product.php
67+
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/set_new_shipping_address.php
6268
*/
63-
public function testGetPaymentMethodsFromGuestCart()
69+
public function testGetAvailablePaymentMethodsFromGuestCart()
6470
{
65-
$guestQuoteMaskedId = $this->getMaskedQuoteIdByReservedOrderId->execute(
66-
'test_order_with_virtual_product_without_address'
67-
);
68-
$query = $this->getQuery($guestQuoteMaskedId);
71+
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote');
72+
$query = $this->getQuery($maskedQuoteId);
6973

7074
$this->expectExceptionMessage(
71-
"The current user cannot perform operations on cart \"$guestQuoteMaskedId\""
75+
"The current user cannot perform operations on cart \"$maskedQuoteId\""
7276
);
7377
$this->graphQlQuery($query, [], '', $this->getHeaderMap());
7478
}
7579

7680
/**
81+
* @security
7782
* @magentoApiDataFixture Magento/Customer/_files/three_customers.php
78-
* @magentoApiDataFixture Magento/Checkout/_files/quote_with_items_saved.php
83+
* @magentoApiDataFixture Magento/Catalog/_files/product_simple.php
84+
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/customer/create_empty_cart.php
85+
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/add_simple_product.php
86+
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/set_new_shipping_address.php
7987
*/
80-
public function testGetPaymentMethodsFromAnotherCustomerCart()
88+
public function testGetAvailablePaymentMethodsFromAnotherCustomerCart()
8189
{
82-
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_order_item_with_items');
90+
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote');
8391
$query = $this->getQuery($maskedQuoteId);
8492

8593
$this->expectExceptionMessage(
@@ -89,24 +97,31 @@ public function testGetPaymentMethodsFromAnotherCustomerCart()
8997
}
9098

9199
/**
92-
* @magentoApiDataFixture Magento/Checkout/_files/quote_with_items_saved.php
93-
* @magentoApiDataFixture Magento/Payment/_files/disable_all_active_payment_methods.php
100+
* @magentoApiDataFixture Magento/Customer/_files/customer.php
101+
* @magentoApiDataFixture Magento/Catalog/_files/product_simple.php
102+
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/customer/create_empty_cart.php
103+
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/add_simple_product.php
104+
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/set_new_shipping_address.php
105+
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/disable_all_active_payment_methods.php
94106
*/
95-
public function testGetPaymentMethodsIfPaymentsAreNotSet()
107+
public function testGetAvailablePaymentMethodsIfPaymentsAreNotPresent()
96108
{
97-
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_order_item_with_items');
109+
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote');
98110
$query = $this->getQuery($maskedQuoteId);
99111
$response = $this->graphQlQuery($query, [], '', $this->getHeaderMap());
100112

101-
self::assertEquals(0, count($response['cart']['available_payment_methods']));
113+
self::assertArrayHasKey('cart', $response);
114+
self::assertArrayHasKey('available_payment_methods', $response['cart']);
115+
self::assertEmpty($response['cart']['available_payment_methods']);
102116
}
103117

104118
/**
105119
* @magentoApiDataFixture Magento/Customer/_files/customer.php
120+
*
106121
* @expectedException \Exception
107122
* @expectedExceptionMessage Could not find a cart with ID "non_existent_masked_id"
108123
*/
109-
public function testGetPaymentMethodsOfNonExistentCart()
124+
public function testGetAvailablePaymentMethodsOfNonExistentCart()
110125
{
111126
$maskedQuoteId = 'non_existent_masked_id';
112127
$query = $this->getQuery($maskedQuoteId);
@@ -118,9 +133,8 @@ public function testGetPaymentMethodsOfNonExistentCart()
118133
* @param string $maskedQuoteId
119134
* @return string
120135
*/
121-
private function getQuery(
122-
string $maskedQuoteId
123-
): string {
136+
private function getQuery(string $maskedQuoteId): string
137+
{
124138
return <<<QUERY
125139
{
126140
cart(cart_id: "$maskedQuoteId") {

dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Customer/GetCartTest.php

Lines changed: 30 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,6 @@
99

1010
use Magento\GraphQl\Quote\GetMaskedQuoteIdByReservedOrderId;
1111
use Magento\Integration\Api\CustomerTokenServiceInterface;
12-
use Magento\Quote\Model\QuoteFactory;
13-
use Magento\Quote\Model\QuoteIdToMaskedQuoteIdInterface;
14-
use Magento\Quote\Model\ResourceModel\Quote as QuoteResource;
1512
use Magento\TestFramework\Helper\Bootstrap;
1613
use Magento\TestFramework\TestCase\GraphQlAbstract;
1714

@@ -25,21 +22,6 @@ class GetCartTest extends GraphQlAbstract
2522
*/
2623
private $getMaskedQuoteIdByReservedOrderId;
2724

28-
/**
29-
* @var QuoteResource
30-
*/
31-
private $quoteResource;
32-
33-
/**
34-
* @var QuoteFactory
35-
*/
36-
private $quoteFactory;
37-
38-
/**
39-
* @var QuoteIdToMaskedQuoteIdInterface
40-
*/
41-
private $quoteIdToMaskedId;
42-
4325
/**
4426
* @var CustomerTokenServiceInterface
4527
*/
@@ -49,19 +31,21 @@ protected function setUp()
4931
{
5032
$objectManager = Bootstrap::getObjectManager();
5133
$this->getMaskedQuoteIdByReservedOrderId = $objectManager->get(GetMaskedQuoteIdByReservedOrderId::class);
52-
$this->quoteResource = $objectManager->get(QuoteResource::class);
53-
$this->quoteFactory = $objectManager->get(QuoteFactory::class);
54-
$this->quoteIdToMaskedId = $objectManager->get(QuoteIdToMaskedQuoteIdInterface::class);
5534
$this->customerTokenService = $objectManager->get(CustomerTokenServiceInterface::class);
5635
}
5736

5837
/**
59-
* @magentoApiDataFixture Magento/Checkout/_files/quote_with_items_saved.php
38+
* @magentoApiDataFixture Magento/Customer/_files/customer.php
39+
* @magentoApiDataFixture Magento/Catalog/_files/product_simple.php
40+
* @magentoApiDataFixture Magento/Catalog/_files/product_virtual.php
41+
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/customer/create_empty_cart.php
42+
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/add_simple_product.php
43+
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/add_virtual_product.php
6044
*/
6145
public function testGetCart()
6246
{
63-
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_order_item_with_items');
64-
$query = $this->getCartQuery($maskedQuoteId);
47+
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote');
48+
$query = $this->getQuery($maskedQuoteId);
6549

6650
$response = $this->graphQlQuery($query, [], '', $this->getHeaderMap());
6751

@@ -70,24 +54,23 @@ public function testGetCart()
7054
self::assertCount(2, $response['cart']['items']);
7155

7256
self::assertNotEmpty($response['cart']['items'][0]['id']);
73-
self::assertEquals($response['cart']['items'][0]['qty'], 2);
74-
self::assertEquals($response['cart']['items'][0]['product']['sku'], 'simple');
57+
self::assertEquals(2, $response['cart']['items'][0]['qty']);
58+
self::assertEquals('simple', $response['cart']['items'][0]['product']['sku']);
7559

7660
self::assertNotEmpty($response['cart']['items'][1]['id']);
77-
self::assertEquals($response['cart']['items'][1]['qty'], 1);
78-
self::assertEquals($response['cart']['items'][1]['product']['sku'], 'simple_one');
61+
self::assertEquals(2, $response['cart']['items'][1]['qty']);
62+
self::assertEquals('virtual-product', $response['cart']['items'][1]['product']['sku']);
7963
}
8064

8165
/**
66+
* @security
8267
* @magentoApiDataFixture Magento/Customer/_files/customer.php
83-
* @magentoApiDataFixture Magento/Checkout/_files/quote_with_simple_product_saved.php
68+
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/guest/create_empty_cart.php
8469
*/
8570
public function testGetGuestCart()
8671
{
87-
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute(
88-
'test_order_with_simple_product_without_address'
89-
);
90-
$query = $this->getCartQuery($maskedQuoteId);
72+
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote');
73+
$query = $this->getQuery($maskedQuoteId);
9174

9275
$this->expectExceptionMessage(
9376
"The current user cannot perform operations on cart \"{$maskedQuoteId}\""
@@ -96,13 +79,14 @@ public function testGetGuestCart()
9679
}
9780

9881
/**
82+
* @security
9983
* @magentoApiDataFixture Magento/Customer/_files/three_customers.php
100-
* @magentoApiDataFixture Magento/Checkout/_files/quote_with_items_saved.php
84+
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/customer/create_empty_cart.php
10185
*/
10286
public function testGetAnotherCustomerCart()
10387
{
104-
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_order_item_with_items');
105-
$query = $this->getCartQuery($maskedQuoteId);
88+
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote');
89+
$query = $this->getQuery($maskedQuoteId);
10690

10791
$this->expectExceptionMessage(
10892
"The current user cannot perform operations on cart \"{$maskedQuoteId}\""
@@ -112,33 +96,30 @@ public function testGetAnotherCustomerCart()
11296

11397
/**
11498
* @magentoApiDataFixture Magento/Customer/_files/customer.php
99+
*
115100
* @expectedException \Exception
116101
* @expectedExceptionMessage Could not find a cart with ID "non_existent_masked_id"
117102
*/
118103
public function testGetNonExistentCart()
119104
{
120105
$maskedQuoteId = 'non_existent_masked_id';
121-
$query = $this->getCartQuery($maskedQuoteId);
106+
$query = $this->getQuery($maskedQuoteId);
122107

123108
$this->graphQlQuery($query, [], '', $this->getHeaderMap());
124109
}
125110

126111
/**
127-
* @magentoApiDataFixture Magento/Checkout/_files/quote_with_simple_product_saved.php
128112
* @magentoApiDataFixture Magento/Customer/_files/customer.php
113+
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/customer/create_empty_cart.php
114+
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/make_cart_inactive.php
115+
*
129116
* @expectedException \Exception
130117
* @expectedExceptionMessage Current user does not have an active cart.
131118
*/
132119
public function testGetInactiveCart()
133120
{
134-
$quote = $this->quoteFactory->create();
135-
$this->quoteResource->load($quote, 'test_order_with_simple_product_without_address', 'reserved_order_id');
136-
$quote->setCustomerId(1);
137-
$quote->setIsActive(false);
138-
$this->quoteResource->save($quote);
139-
$maskedQuoteId = $this->quoteIdToMaskedId->execute((int)$quote->getId());
140-
141-
$query = $this->getCartQuery($maskedQuoteId);
121+
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote');
122+
$query = $this->getQuery($maskedQuoteId);
142123

143124
$this->graphQlQuery($query, [], '', $this->getHeaderMap());
144125
}
@@ -147,12 +128,11 @@ public function testGetInactiveCart()
147128
* @param string $maskedQuoteId
148129
* @return string
149130
*/
150-
private function getCartQuery(
151-
string $maskedQuoteId
152-
) : string {
131+
private function getQuery(string $maskedQuoteId): string
132+
{
153133
return <<<QUERY
154134
{
155-
cart(cart_id: "$maskedQuoteId") {
135+
cart(cart_id: "{$maskedQuoteId}") {
156136
items {
157137
id
158138
qty

0 commit comments

Comments
 (0)