@@ -41,6 +41,23 @@ protected function setUp()
41
41
$ this ->quoteIdToMaskedId = $ objectManager ->get (QuoteIdToMaskedQuoteIdInterface::class);
42
42
}
43
43
44
+ /**
45
+ * @magentoApiDataFixture Magento/Catalog/_files/products.php
46
+ * @magentoApiDataFixture Magento/Checkout/_files/active_quote.php
47
+ */
48
+ public function testAddSimpleProductsToCart ()
49
+ {
50
+ $ sku = 'simple ' ;
51
+ $ qty = 2 ;
52
+ $ maskedQuoteId = $ this ->getMaskedQuoteId ();
53
+ $ query = $ this ->getQueryAddSimpleProduct ($ maskedQuoteId , $ sku , $ qty );
54
+ $ response = $ this ->graphQlQuery ($ query );
55
+ self ::assertArrayHasKey ('cart ' , $ response ['addSimpleProductsToCart ' ]);
56
+ $ cartQty = $ response ['addSimpleProductsToCart ' ]['cart ' ]['items ' ][0 ]['qty ' ];
57
+
58
+ $ this ->assertEquals ($ qty , $ cartQty );
59
+ }
60
+
44
61
/**
45
62
* @magentoApiDataFixture Magento/Catalog/_files/products.php
46
63
* @magentoApiDataFixture Magento/Checkout/_files/active_quote.php
@@ -52,14 +69,51 @@ public function testAddProductIfQuantityIsNotAvailable()
52
69
$ sku = 'simple ' ;
53
70
$ qty = 200 ;
54
71
72
+ $ maskedQuoteId = $ this ->getMaskedQuoteId ();
73
+ $ query = $ this ->getQueryAddSimpleProduct ($ maskedQuoteId , $ sku , $ qty );
74
+ $ this ->graphQlQuery ($ query );
75
+ }
76
+
77
+ /**
78
+ * @magentoApiDataFixture Magento/Catalog/_files/products.php
79
+ * @magentoApiDataFixture Magento/Checkout/_files/active_quote.php
80
+ * @expectedException \Exception
81
+ * @expectedExceptionMessage The most you may purchase is 10000.
82
+ */
83
+ public function testAddMoreProductsThatAllowed ()
84
+ {
85
+ $ sku = 'simple-product-with-huge-amount ' ;
86
+ $ qty = 20000 ;
87
+ $ maskedQuoteId = $ this ->getMaskedQuoteId ();
88
+ $ query = $ this ->getQueryAddSimpleProduct ($ maskedQuoteId , $ sku , $ qty );
89
+ $ this ->graphQlQuery ($ query );
90
+ }
91
+
92
+ /**
93
+ * @magentoApiDataFixture Magento/Checkout/_files/active_quote.php
94
+ * @return string
95
+ * @throws \Magento\Framework\Exception\NoSuchEntityException
96
+ */
97
+ public function getMaskedQuoteId ()
98
+ {
55
99
$ this ->quoteResource ->load (
56
100
$ this ->quote ,
57
101
'test_order_1 ' ,
58
102
'reserved_order_id '
59
103
);
60
- $ maskedQuoteId = $ this ->quoteIdToMaskedId ->execute ((int )$ this ->quote ->getId ());
104
+ return $ this ->quoteIdToMaskedId ->execute ((int )$ this ->quote ->getId ());
105
+ }
61
106
62
- $ query = <<<QUERY
107
+ /**
108
+ * @param string $maskedQuoteId
109
+ * @param string $sku
110
+ * @param int $qty
111
+ *
112
+ * @return string
113
+ */
114
+ public function getQueryAddSimpleProduct (string $ maskedQuoteId , string $ sku , int $ qty ) : string
115
+ {
116
+ return <<<QUERY
63
117
mutation {
64
118
addSimpleProductsToCart(
65
119
input: {
@@ -76,11 +130,12 @@ public function testAddProductIfQuantityIsNotAvailable()
76
130
) {
77
131
cart {
78
132
cart_id
133
+ items {
134
+ qty
135
+ }
79
136
}
80
137
}
81
138
}
82
139
QUERY ;
83
-
84
- $ this ->graphQlQuery ($ query );
85
140
}
86
141
}
0 commit comments