15
15
use Magento \Wishlist \Model \Item ;
16
16
use Magento \Wishlist \Model \ResourceModel \Wishlist \CollectionFactory ;
17
17
use Magento \Wishlist \Model \Wishlist ;
18
+ use Magento \Customer \Api \CustomerRepositoryInterface ;
19
+ use Magento \Framework \Registry ;
18
20
19
21
/**
20
22
* Test coverage for customer wishlists
@@ -68,6 +70,80 @@ public function testCustomerWishlist(): void
68
70
$ this ->assertEquals ('simple ' , $ wishlistItemResponse ['product ' ]['sku ' ]);
69
71
}
70
72
73
+ /**
74
+ * @magentoConfigFixture default_store wishlist/general/active 1
75
+ * @magentoApiDataFixture Magento/Catalog/_files/product_simple_duplicated.php
76
+ * @throws Exception
77
+ */
78
+ public function testWishlistCreationScenario (): void
79
+ {
80
+ try {
81
+ $ customerEmail = 'customer@wishlist.com ' ;
82
+ $ this ->graphQlMutation (
83
+ $ this ->getCreateCustomerQuery ($ customerEmail ),
84
+ [],
85
+ ''
86
+ );
87
+ $ response = $ this ->graphQlQuery (
88
+ $ this ->getQuery (),
89
+ [],
90
+ '' ,
91
+ $ this ->getCustomerAuthHeaders ($ customerEmail , '123123^q ' )
92
+ );
93
+ $ this ->assertArrayHasKey ('wishlists ' , $ response ['customer ' ]);
94
+ $ wishlists = $ response ['customer ' ]['wishlists ' ];
95
+ $ this ->assertNotEmpty ($ wishlists );
96
+ $ wishlist = $ wishlists [0 ];
97
+ $ this ->assertEquals (0 , $ wishlist ['items_count ' ]);
98
+ $ sku = 'simple-1 ' ;
99
+ $ qty = 1 ;
100
+ $ addProductToWishlistQuery =
101
+ <<<QUERY
102
+ mutation{
103
+ addProductsToWishlist(
104
+ wishlistId: {$ wishlist ['id ' ]}
105
+ wishlistItems:[
106
+ {
107
+ sku:" {$ sku }"
108
+ quantity: {$ qty }
109
+ }
110
+ ])
111
+ {
112
+ wishlist{
113
+ id
114
+ items_count
115
+ items{product{name sku} description qty}
116
+ }
117
+ user_errors{code message}
118
+ }
119
+ }
120
+
121
+ QUERY ;
122
+ $ addToWishlistResponse = $ this ->graphQlMutation (
123
+ $ addProductToWishlistQuery ,
124
+ [],
125
+ '' ,
126
+ $ this ->getCustomerAuthHeaders ($ customerEmail , '123123^q ' )
127
+ );
128
+ $ this ->assertArrayHasKey ('user_errors ' , $ addToWishlistResponse ['addProductsToWishlist ' ]);
129
+ $ this ->assertCount (0 , $ addToWishlistResponse ['addProductsToWishlist ' ]['user_errors ' ]);
130
+ } finally {
131
+ /** @var Registry $registry */
132
+ $ registry = Bootstrap::getObjectManager ()
133
+ ->get (Registry::class);
134
+ $ registry ->unregister ('isSecureArea ' );
135
+ $ registry ->register ('isSecureArea ' , true );
136
+
137
+ $ objectManager = Bootstrap::getObjectManager ();
138
+ $ customerRepository = $ objectManager ->create (CustomerRepositoryInterface::class);
139
+ $ customer = $ customerRepository ->get ($ customerEmail );
140
+ $ customerRepository ->delete ($ customer );
141
+
142
+ $ registry ->unregister ('isSecureArea ' );
143
+ $ registry ->register ('isSecureArea ' , false );
144
+ }
145
+ }
146
+
71
147
/**
72
148
* Testing fetching the wishlist when wishlist is disabled
73
149
*
@@ -109,11 +185,13 @@ private function getQuery(): string
109
185
query {
110
186
customer {
111
187
wishlists {
188
+ id
112
189
items_count
113
190
sharing_code
114
191
updated_at
115
192
items_v2 {
116
- items {product {name sku}
193
+ items {
194
+ product {name sku}
117
195
}
118
196
}
119
197
}
@@ -122,6 +200,25 @@ private function getQuery(): string
122
200
QUERY ;
123
201
}
124
202
203
+ private function getCreateCustomerQuery ($ customerEmail ): string
204
+ {
205
+ return <<<QUERY
206
+ mutation {
207
+ createCustomer(input: {
208
+ firstname: "test"
209
+ lastname: "test"
210
+ email: " $ customerEmail"
211
+ password: "123123^q"
212
+ })
213
+ {
214
+ customer {
215
+ email
216
+ }
217
+ }
218
+ }
219
+ QUERY ;
220
+ }
221
+
125
222
/**
126
223
* Getting customer auth headers
127
224
*
0 commit comments