9
9
10
10
use Magento \TestFramework \Helper \Bootstrap ;
11
11
use Magento \TestFramework \TestCase \GraphQlAbstract ;
12
- use Magento \Quote \Model \Quote ;
12
+ use Magento \Quote \Model \QuoteFactory ;
13
13
use Magento \Quote \Model \QuoteIdToMaskedQuoteIdInterface ;
14
14
use Magento \Quote \Model \ResourceModel \Quote as QuoteResource ;
15
15
@@ -21,9 +21,9 @@ class AddSimpleProductToCartTest extends GraphQlAbstract
21
21
private $ quoteResource ;
22
22
23
23
/**
24
- * @var Quote
24
+ * @var QuoteFactory
25
25
*/
26
- private $ quote ;
26
+ private $ quoteFactory ;
27
27
28
28
/**
29
29
* @var QuoteIdToMaskedQuoteIdInterface
@@ -37,29 +37,48 @@ protected function setUp()
37
37
{
38
38
$ objectManager = Bootstrap::getObjectManager ();
39
39
$ this ->quoteResource = $ objectManager ->get (QuoteResource::class);
40
- $ this ->quote = $ objectManager ->create (Quote ::class);
40
+ $ this ->quoteFactory = $ objectManager ->get (QuoteFactory ::class);
41
41
$ this ->quoteIdToMaskedId = $ objectManager ->get (QuoteIdToMaskedQuoteIdInterface::class);
42
42
}
43
43
44
44
/**
45
45
* @magentoApiDataFixture Magento/Catalog/_files/products.php
46
46
* @magentoApiDataFixture Magento/Checkout/_files/active_quote.php
47
- * @expectedException \Exception
48
- * @expectedExceptionMessage The requested qty is not available
49
47
*/
50
- public function testAddProductIfQuantityIsNotAvailable ()
48
+ public function testAddSimpleProductToCart ()
51
49
{
52
50
$ sku = 'simple ' ;
53
- $ qty = 200 ;
51
+ $ qty = 2 ;
52
+ $ maskedQuoteId = $ this ->getMaskedQuoteId ();
54
53
55
- $ this ->quoteResource ->load (
56
- $ this ->quote ,
57
- 'test_order_1 ' ,
58
- 'reserved_order_id '
59
- );
60
- $ maskedQuoteId = $ this ->quoteIdToMaskedId ->execute ((int )$ this ->quote ->getId ());
54
+ $ query = $ this ->getAddSimpleProductQuery ($ maskedQuoteId , $ sku , $ qty );
55
+ $ response = $ this ->graphQlQuery ($ query );
56
+ self ::assertArrayHasKey ('cart ' , $ response ['addSimpleProductsToCart ' ]);
61
57
62
- $ query = <<<QUERY
58
+ self ::assertEquals ($ qty , $ response ['addSimpleProductsToCart ' ]['cart ' ]['items ' ][0 ]['qty ' ]);
59
+ self ::assertEquals ($ sku , $ response ['addSimpleProductsToCart ' ]['cart ' ]['items ' ][0 ]['product ' ]['sku ' ]);
60
+ }
61
+
62
+ /**
63
+ * @return string
64
+ */
65
+ public function getMaskedQuoteId () : string
66
+ {
67
+ $ quote = $ this ->quoteFactory ->create ();
68
+ $ this ->quoteResource ->load ($ quote , 'test_order_1 ' , 'reserved_order_id ' );
69
+
70
+ return $ this ->quoteIdToMaskedId ->execute ((int )$ quote ->getId ());
71
+ }
72
+
73
+ /**
74
+ * @param string $maskedQuoteId
75
+ * @param string $sku
76
+ * @param int $qty
77
+ * @return string
78
+ */
79
+ public function getAddSimpleProductQuery (string $ maskedQuoteId , string $ sku , int $ qty ): string
80
+ {
81
+ return <<<QUERY
63
82
mutation {
64
83
addSimpleProductsToCart(
65
84
input: {
@@ -77,12 +96,13 @@ public function testAddProductIfQuantityIsNotAvailable()
77
96
cart {
78
97
items {
79
98
qty
99
+ product {
100
+ sku
101
+ }
80
102
}
81
103
}
82
104
}
83
105
}
84
106
QUERY ;
85
-
86
- $ this ->graphQlQuery ($ query );
87
107
}
88
108
}
0 commit comments