15
15
use Magento \TestFramework \Fixture \DataFixture ;
16
16
use Magento \TestFramework \TestCase \WebapiAbstract ;
17
17
use Magento \TestFramework \Helper \Bootstrap ;
18
- use Magento \Quote \Model \Quote ;
19
18
use Magento \Quote \Model \QuoteIdMaskFactory ;
20
19
use Magento \Checkout \Api \Data \ShippingInformationInterface ;
21
20
use Magento \Checkout \Api \Data \ShippingInformationInterfaceFactory ;
22
21
use Magento \Quote \Api \Data \AddressInterface ;
23
22
use Magento \Quote \Api \Data \AddressInterfaceFactory ;
23
+ use Magento \TestFramework \Fixture \DataFixtureStorageManager ;
24
24
25
25
/**
26
26
* Test GuestShippingInformationManagement API validation.
@@ -46,13 +46,19 @@ class GuestShippingInformationManagementValidationTest extends WebapiAbstract
46
46
*/
47
47
private $ quoteIdMaskFactory ;
48
48
49
+ /**
50
+ * @var DataFixtureStorageManager
51
+ */
52
+ private $ fixtures ;
53
+
49
54
protected function setUp (): void
50
55
{
51
56
parent ::setUp ();
52
57
$ this ->shippingInformationFactory = Bootstrap::getObjectManager ()
53
58
->get (ShippingInformationInterfaceFactory::class);
54
59
$ this ->addressFactory = Bootstrap::getObjectManager ()->get (AddressInterfaceFactory::class);
55
60
$ this ->quoteIdMaskFactory = Bootstrap::getObjectManager ()->get (QuoteIdMaskFactory::class);
61
+ $ this ->fixtures = DataFixtureStorageManager::getStorage ();
56
62
}
57
63
58
64
#[
@@ -66,9 +72,9 @@ protected function setUp(): void
66
72
*/
67
73
public function testSaveAddressInformationWithValidData ()
68
74
{
69
- $ quote = Bootstrap:: getObjectManager ()-> create (Quote::class );
70
- $ quote -> load ( ' test_order_1 ' , ' reserved_order_id ' );
71
- $ cartId = $ quote -> getId ( );
75
+ $ cart = $ this -> fixtures -> get ( ' cart ' );
76
+ $ cartId = $ cart -> getId ( );
77
+ $ maskedCartId = $ this -> getMaskedCartId ( $ cartId );
72
78
$ shippingAddress = $ this ->addressFactory ->create ();
73
79
$ shippingAddress ->setData ([
74
80
'firstname ' => 'John ' ,
@@ -102,12 +108,32 @@ public function testSaveAddressInformationWithValidData()
102
108
$ shippingInformation ->setBillingAddress ($ billingAddress );
103
109
$ shippingInformation ->setShippingMethodCode ('flatrate ' );
104
110
$ shippingInformation ->setShippingCarrierCode ('flatrate ' );
105
- $ result = $ this ->callSaveAddressInformation ($ cartId , $ shippingInformation );
111
+ $ result = $ this ->callSaveAddressInformation ($ maskedCartId , $ shippingInformation );
106
112
$ this ->assertNotEmpty ($ result );
107
113
$ this ->assertArrayHasKey ('payment_methods ' , $ result );
108
114
$ this ->assertArrayHasKey ('totals ' , $ result );
109
115
}
110
116
117
+ /**
118
+ * Get masked cart ID for the given quote
119
+ *
120
+ * @param string $cartId
121
+ * @return string
122
+ */
123
+ private function getMaskedCartId (string $ cartId ): string
124
+ {
125
+ $ quoteIdMask = $ this ->quoteIdMaskFactory ->create ();
126
+ $ quoteIdMask ->load ($ cartId , 'quote_id ' );
127
+
128
+ if (!$ quoteIdMask ->getMaskedId ()) {
129
+ $ quoteIdMask ->setQuoteId ($ cartId );
130
+ $ quoteIdMask ->setMaskedId (uniqid ('masked_ ' , true ));
131
+ $ quoteIdMask ->save ();
132
+ }
133
+
134
+ return $ quoteIdMask ->getMaskedId ();
135
+ }
136
+
111
137
/**
112
138
* Call the saveAddressInformation API
113
139
*
0 commit comments