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
- use Magento \Config \Model \ResourceModel \Config ;
16
15
17
16
class AddSimpleProductToCartTest extends GraphQlAbstract
18
17
{
@@ -22,30 +21,24 @@ class AddSimpleProductToCartTest extends GraphQlAbstract
22
21
private $ quoteResource ;
23
22
24
23
/**
25
- * @var Quote
24
+ * @var QuoteFactory
26
25
*/
27
- private $ quote ;
26
+ private $ quoteFactory ;
28
27
29
28
/**
30
29
* @var QuoteIdToMaskedQuoteIdInterface
31
30
*/
32
31
private $ quoteIdToMaskedId ;
33
32
34
- /**
35
- * @var Config
36
- */
37
- private $ config ;
38
-
39
33
/**
40
34
* @inheritdoc
41
35
*/
42
36
protected function setUp ()
43
37
{
44
38
$ objectManager = Bootstrap::getObjectManager ();
45
39
$ this ->quoteResource = $ objectManager ->get (QuoteResource::class);
46
- $ this ->quote = $ objectManager ->create (Quote ::class);
40
+ $ this ->quoteFactory = $ objectManager ->get (QuoteFactory ::class);
47
41
$ this ->quoteIdToMaskedId = $ objectManager ->get (QuoteIdToMaskedQuoteIdInterface::class);
48
- $ this ->config = $ objectManager ->get (Config::class);
49
42
}
50
43
51
44
/**
@@ -57,68 +50,33 @@ public function testAddSimpleProductsToCart()
57
50
$ sku = 'simple ' ;
58
51
$ qty = 2 ;
59
52
$ maskedQuoteId = $ this ->getMaskedQuoteId ();
60
- $ query = $ this ->getQueryAddSimpleProduct ($ maskedQuoteId , $ sku , $ qty );
53
+
54
+ $ query = $ this ->geAddSimpleProducttQuery ($ maskedQuoteId , $ sku , $ qty );
61
55
$ response = $ this ->graphQlQuery ($ query );
62
56
self ::assertArrayHasKey ('cart ' , $ response ['addSimpleProductsToCart ' ]);
63
- $ cartQty = $ response ['addSimpleProductsToCart ' ]['cart ' ]['items ' ][0 ]['qty ' ];
64
-
65
- $ this ->assertEquals ($ qty , $ cartQty );
66
- }
67
-
68
- /**
69
- * @magentoApiDataFixture Magento/Catalog/_files/products.php
70
- * @magentoApiDataFixture Magento/Checkout/_files/active_quote.php
71
- * @expectedException \Exception
72
- * @expectedExceptionMessage The requested qty is not available
73
- */
74
- public function testAddProductIfQuantityIsNotAvailable ()
75
- {
76
- $ sku = 'simple ' ;
77
- $ qty = 200 ;
78
-
79
- $ maskedQuoteId = $ this ->getMaskedQuoteId ();
80
- $ query = $ this ->getQueryAddSimpleProduct ($ maskedQuoteId , $ sku , $ qty );
81
- $ this ->graphQlQuery ($ query );
82
- }
83
57
84
- /**
85
- * @magentoApiDataFixture Magento/Catalog/_files/products.php
86
- * @magentoApiDataFixture Magento/Checkout/_files/active_quote.php
87
- * @expectedExceptionMessage The most you may purchase is 5.
88
- */
89
- public function testAddMoreProductsThatAllowed ()
90
- {
91
- $ sku = 'custom-design-simple-product ' ;
92
- $ qty = 7 ;
93
- $ maxQty = 5 ;
94
-
95
- $ this ->config ->saveConfig ('cataloginventory/item_options/max_sale_qty ' , $ maxQty , 'default ' , 0 );
96
- $ maskedQuoteId = $ this ->getMaskedQuoteId ();
97
- $ query = $ this ->getQueryAddSimpleProduct ($ maskedQuoteId , $ sku , $ qty );
98
- $ this ->graphQlQuery ($ query );
58
+ $ cartQty = $ response ['addSimpleProductsToCart ' ]['cart ' ]['items ' ][0 ]['qty ' ];
59
+ self ::assertEquals ($ qty , $ cartQty );
99
60
}
100
61
101
62
/**
102
63
* @return string
103
64
*/
104
65
public function getMaskedQuoteId () : string
105
66
{
106
- $ this ->quoteResource ->load (
107
- $ this ->quote ,
108
- 'test_order_1 ' ,
109
- 'reserved_order_id '
110
- );
111
- return $ this ->quoteIdToMaskedId ->execute ((int )$ this ->quote ->getId ());
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 ());
112
71
}
113
72
114
73
/**
115
74
* @param string $maskedQuoteId
116
75
* @param string $sku
117
76
* @param int $qty
118
- *
119
77
* @return string
120
78
*/
121
- public function getQueryAddSimpleProduct (string $ maskedQuoteId , string $ sku , int $ qty ) : string
79
+ public function geAddSimpleProducttQuery (string $ maskedQuoteId , string $ sku , int $ qty ) : string
122
80
{
123
81
return <<<QUERY
124
82
mutation {
0 commit comments