7
7
8
8
namespace Magento \Quote \Model ;
9
9
10
+ use Magento \Customer \Api \CustomerRepositoryInterface ;
10
11
use Magento \Framework \Api \FilterBuilder ;
11
12
use Magento \Framework \Api \SearchCriteria ;
12
13
use Magento \Framework \Api \SearchCriteriaBuilder ;
@@ -95,6 +96,11 @@ class QuoteRepositoryTest extends TestCase
95
96
*/
96
97
private $ store ;
97
98
99
+ /**
100
+ * @var CustomerRepositoryInterface
101
+ */
102
+ private $ customerRepository ;
103
+
98
104
/**
99
105
* @inheritdoc
100
106
*/
@@ -113,6 +119,7 @@ protected function setUp(): void
113
119
$ this ->itemFactory = $ this ->objectManager ->get (CartItemInterfaceFactory::class);
114
120
$ this ->quoteFactorys = $ this ->objectManager ->get (\Magento \Quote \Model \QuoteFactory::class);
115
121
$ this ->store = $ this ->objectManager ->get (\Magento \Store \Model \Store::class);
122
+ $ this ->customerRepository = $ this ->objectManager ->get (CustomerRepositoryInterface::class);
116
123
}
117
124
118
125
/**
@@ -298,7 +305,7 @@ private function performAssertions(CartSearchResultsInterface $searchResult): vo
298
305
* @return void
299
306
* @throws \Exception
300
307
*/
301
- public function testDeleteAllQuotesRelatedToCustomerIfWeDeleteStoreView (): void
308
+ public function testDeleteAllQuotesOnStoreViewDeletion (): void
302
309
{
303
310
$ storeData = [
304
311
[
@@ -329,22 +336,31 @@ public function testDeleteAllQuotesRelatedToCustomerIfWeDeleteStoreView(): void
329
336
$ firstStoreId = $ this ->store ->load ('store1 ' )->getId ();
330
337
$ secondStoreId = $ this ->store ->load ('store2 ' )->getId ();
331
338
332
- // Create a quote with store id 2
339
+ // Create a quote for guest user with store id 2
333
340
$ quote = $ this ->quoteFactorys ->create ();
334
341
$ quote ->setStoreId ($ firstStoreId );
335
342
$ quote ->save ();
336
343
337
344
// Assert that quote is created successfully.
338
345
$ this ->assertNotNull ($ quote ->getId ());
339
346
340
- // Create a quote with store id 3
347
+ // Create a quote for guest user with store id 3
341
348
$ secondQuote = $ this ->quoteFactorys ->create ();
342
349
$ secondQuote ->setStoreId ($ secondStoreId );
343
350
$ secondQuote ->save ();
344
351
345
352
// Assert that second quote is created successfully.
346
353
$ this ->assertNotNull ($ secondQuote ->getId ());
347
354
355
+ // load customer by id
356
+ $ customer = $ this ->customerRepository ->getById (1 );
357
+
358
+ // Create a quote for customer with store id 3
359
+ $ thirdQuote = $ this ->quoteFactorys ->create ();
360
+ $ thirdQuote ->setStoreId ($ secondStoreId );
361
+ $ thirdQuote ->setCustomer ($ customer );
362
+ $ thirdQuote ->save ();
363
+
348
364
// Loading the second store from the data fixture
349
365
$ this ->store ->load ('store2 ' , 'code ' );
350
366
/** @var \Magento\TestFramework\Helper\Bootstrap $registry */
@@ -357,8 +373,12 @@ public function testDeleteAllQuotesRelatedToCustomerIfWeDeleteStoreView(): void
357
373
// Deleting the second store.
358
374
$ this ->store ->delete ();
359
375
360
- // asserting that quote is also deleted when store is deleted
376
+ // asserting that quote associated with guest user is also deleted when store is deleted
361
377
$ afterDeletionQuote = $ this ->quoteFactorys ->create ()->load ($ secondQuote ->getId ());
362
378
$ this ->assertNull ($ afterDeletionQuote ->getId ());
379
+
380
+ // asserting that quote associated with customer is also deleted when store is deleted
381
+ $ afterDeletionQuote = $ this ->quoteFactorys ->create ()->load ($ thirdQuote ->getId ());
382
+ $ this ->assertNull ($ afterDeletionQuote ->getId ());
363
383
}
364
384
}
0 commit comments