8
8
namespace Magento \GraphQl \OfflineShipping ;
9
9
10
10
use Magento \Integration \Api \CustomerTokenServiceInterface ;
11
- use Magento \Quote \Model \Quote ;
11
+ use Magento \Quote \Model \QuoteFactory ;
12
12
use Magento \Quote \Model \QuoteIdToMaskedQuoteIdInterface ;
13
13
use Magento \Quote \Model \ResourceModel \Quote as QuoteResource ;
14
14
use Magento \TestFramework \Helper \Bootstrap ;
19
19
*/
20
20
class SetOfflineShippingOnCartTest extends GraphQlAbstract
21
21
{
22
+ /**
23
+ * @var QuoteFactory
24
+ */
25
+ private $ quoteFactory ;
26
+
22
27
/**
23
28
* @var CustomerTokenServiceInterface
24
29
*/
@@ -29,11 +34,6 @@ class SetOfflineShippingOnCartTest extends GraphQlAbstract
29
34
*/
30
35
private $ quoteResource ;
31
36
32
- /**
33
- * @var Quote
34
- */
35
- private $ quote ;
36
-
37
37
/**
38
38
* @var QuoteIdToMaskedQuoteIdInterface
39
39
*/
@@ -45,67 +45,44 @@ class SetOfflineShippingOnCartTest extends GraphQlAbstract
45
45
protected function setUp ()
46
46
{
47
47
$ objectManager = Bootstrap::getObjectManager ();
48
- $ this ->quoteResource = $ objectManager ->create (QuoteResource::class);
49
- $ this ->quote = $ objectManager ->create (Quote ::class);
50
- $ this ->quoteIdToMaskedId = $ objectManager ->create (QuoteIdToMaskedQuoteIdInterface::class);
48
+ $ this ->quoteResource = $ objectManager ->get (QuoteResource::class);
49
+ $ this ->quoteFactory = $ objectManager ->get (QuoteFactory ::class);
50
+ $ this ->quoteIdToMaskedId = $ objectManager ->get (QuoteIdToMaskedQuoteIdInterface::class);
51
51
$ this ->customerTokenService = $ objectManager ->get (CustomerTokenServiceInterface::class);
52
52
}
53
53
54
- /**
55
- * @magentoApiDataFixture Magento/Checkout/_files/quote_with_address_saved.php
56
- * @magentoApiDataFixture Magento/Checkout/_files/enable_all_shipping_methods.php
57
- */
58
- public function testSetFlatrateOnCart ()
59
- {
60
- $ this ->setShippingMethodAndCheckResponse (
61
- 'flatrate ' ,
62
- 'flatrate ' ,
63
- '10 ' ,
64
- 'Flat Rate - Fixed '
65
- );
66
- }
67
-
68
54
/**
69
55
* @magentoApiDataFixture Magento/Checkout/_files/quote_with_address_saved.php
70
56
* @magentoApiDataFixture Magento/OfflineShipping/_files/tablerates_weight.php
71
57
* @magentoApiDataFixture Magento/Checkout/_files/enable_all_shipping_methods.php
58
+ * @dataProvider offlineShippingMethodDataProvider()
59
+ * @param string $carrier
60
+ * @param string $method
61
+ * @param float $amount
62
+ * @param string $label
72
63
*/
73
- public function testSetTableRatesOnCart ( )
64
+ public function testSetOfflineShippingMethod ( string $ carrier , string $ method , float $ amount , string $ label )
74
65
{
75
66
$ this ->setShippingMethodAndCheckResponse (
76
- ' tablerate ' ,
77
- ' bestway ' ,
78
- ' 10 ' ,
79
- ' Best Way - Table Rate '
67
+ $ carrier ,
68
+ $ method ,
69
+ $ amount ,
70
+ $ label
80
71
);
81
72
}
82
73
83
74
/**
84
- * @magentoApiDataFixture Magento/Checkout/_files/quote_with_address_saved.php
85
- * @magentoApiDataFixture Magento/Checkout/_files/enable_all_shipping_methods.php
86
- */
87
- public function testSetFreeShippingOnCart ()
88
- {
89
- $ this ->setShippingMethodAndCheckResponse (
90
- 'freeshipping ' ,
91
- 'freeshipping ' ,
92
- '0 ' ,
93
- 'Free Shipping - Free '
94
- );
95
- }
96
-
97
- /**
98
- * @magentoApiDataFixture Magento/Checkout/_files/quote_with_address_saved.php
99
- * @magentoApiDataFixture Magento/Checkout/_files/enable_all_shipping_methods.php
75
+ * Data provider for base offline shipping methods
76
+ *
77
+ * @return array
100
78
*/
101
- public function testSetUpsOnCart ()
79
+ public function offlineShippingMethodDataProvider ()
102
80
{
103
- $ this ->setShippingMethodAndCheckResponse (
104
- 'ups ' ,
105
- 'GND ' ,
106
- '15.61 ' ,
107
- 'United Parcel Service - Ground '
108
- );
81
+ return [
82
+ ['flatrate ' , 'flatrate ' , 10 , 'Flat Rate - Fixed ' ],
83
+ ['tablerate ' , 'bestway ' , 10 , 'Best Way - Table Rate ' ],
84
+ ['freeshipping ' , 'freeshipping ' , 0 , 'Free Shipping - Free ' ]
85
+ ];
109
86
}
110
87
111
88
/**
@@ -121,17 +98,18 @@ public function testSetUpsOnCart()
121
98
private function setShippingMethodAndCheckResponse (
122
99
string $ shippingCarrierCode ,
123
100
string $ shippingMethodCode ,
124
- string $ shippingAmount ,
101
+ float $ shippingAmount ,
125
102
string $ shippingLabel
126
103
) {
104
+ $ quote = $ this ->quoteFactory ->create ();
127
105
$ this ->quoteResource ->load (
128
- $ this -> quote ,
106
+ $ quote ,
129
107
'test_order_1 ' ,
130
108
'reserved_order_id '
131
109
);
132
- $ shippingAddress = $ this -> quote ->getShippingAddress ();
110
+ $ shippingAddress = $ quote ->getShippingAddress ();
133
111
$ shippingAddressId = $ shippingAddress ->getId ();
134
- $ maskedQuoteId = $ this ->quoteIdToMaskedId ->execute ((int )$ this -> quote ->getId ());
112
+ $ maskedQuoteId = $ this ->quoteIdToMaskedId ->execute ((int )$ quote ->getId ());
135
113
136
114
$ query = $ this ->getQuery (
137
115
$ maskedQuoteId ,
0 commit comments