7
7
8
8
use Magento \Customer \Api \Data \CustomerInterfaceFactory ;
9
9
use Magento \TestFramework \Helper \Bootstrap ;
10
+ use Magento \Framework \Exception \LocalizedException ;
11
+ use Magento \Catalog \Model \ProductRepository ;
10
12
11
13
/**
12
14
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
@@ -32,7 +34,7 @@ public function testCollectTotalsWithVirtual()
32
34
$ productRepository = Bootstrap::getObjectManager ()->create (
33
35
\Magento \Catalog \Api \ProductRepositoryInterface::class
34
36
);
35
- $ product = $ productRepository ->get ('virtual-product ' );
37
+ $ product = $ productRepository ->get ('virtual-product ' , false , null , true );
36
38
$ quote ->addProduct ($ product );
37
39
$ quote ->collectTotals ();
38
40
@@ -46,9 +48,9 @@ public function testSetCustomerData()
46
48
{
47
49
/** @var \Magento\Quote\Model\Quote $quote */
48
50
$ quote = Bootstrap::getObjectManager ()->create (\Magento \Quote \Model \Quote::class);
49
- /** @var \Magento\Customer\Api\Data\ CustomerInterfaceFactory $customerFactory */
51
+ /** @var CustomerInterfaceFactory $customerFactory */
50
52
$ customerFactory = Bootstrap::getObjectManager ()->create (
51
- \ Magento \ Customer \ Api \ Data \ CustomerInterfaceFactory::class
53
+ CustomerInterfaceFactory::class
52
54
);
53
55
/** @var \Magento\Framework\Api\DataObjectHelper $dataObjectHelper */
54
56
$ dataObjectHelper = Bootstrap::getObjectManager ()->create (\Magento \Framework \Api \DataObjectHelper::class);
@@ -73,7 +75,7 @@ public function testUpdateCustomerData()
73
75
/** @var \Magento\Quote\Model\Quote $quote */
74
76
$ quote = Bootstrap::getObjectManager ()->create (\Magento \Quote \Model \Quote::class);
75
77
$ customerFactory = Bootstrap::getObjectManager ()->create (
76
- \ Magento \ Customer \ Api \ Data \ CustomerInterfaceFactory::class
78
+ CustomerInterfaceFactory::class
77
79
);
78
80
/** @var \Magento\Framework\Api\DataObjectHelper $dataObjectHelper */
79
81
$ dataObjectHelper = Bootstrap::getObjectManager ()->create (\Magento \Framework \Api \DataObjectHelper::class);
@@ -118,9 +120,9 @@ public function testUpdateCustomerData()
118
120
public function testGetCustomerGroupFromCustomer ()
119
121
{
120
122
/** Preconditions */
121
- /** @var \Magento\Customer\Api\Data\ CustomerInterfaceFactory $customerFactory */
123
+ /** @var CustomerInterfaceFactory $customerFactory */
122
124
$ customerFactory = Bootstrap::getObjectManager ()->create (
123
- \ Magento \ Customer \ Api \ Data \ CustomerInterfaceFactory::class
125
+ CustomerInterfaceFactory::class
124
126
);
125
127
$ customerGroupId = 3 ;
126
128
$ customerData = $ customerFactory ->create ()->setId (1 )->setGroupId ($ customerGroupId );
@@ -302,7 +304,7 @@ public function testAddProductUpdateItem()
302
304
$ productRepository = Bootstrap::getObjectManager ()->create (
303
305
\Magento \Catalog \Api \ProductRepositoryInterface::class
304
306
);
305
- $ product = $ productRepository ->get ('simple-1 ' );
307
+ $ product = $ productRepository ->get ('simple-1 ' , false , null , true );
306
308
307
309
$ quote ->addProduct ($ product , 50 );
308
310
$ quote ->setTotalsCollectedFlag (false )->collectTotals ();
@@ -423,4 +425,29 @@ public function testReserveOrderId()
423
425
$ quote ->reserveOrderId ();
424
426
$ this ->assertNotEquals ('100000001 ' , $ quote ->getReservedOrderId ());
425
427
}
428
+
429
+ /**
430
+ * Test to verify that disabled product cannot be added to cart
431
+ * @magentoDataFixture Magento/Quote/_files/disabled_product.php
432
+ * @magentoAppIsolation enabled
433
+ */
434
+ public function testAddedProductToQuoteIsSalable ()
435
+ {
436
+ $ productId = 1 ;
437
+ $ objectManager = Bootstrap::getObjectManager ();
438
+
439
+ /** @var ProductRepository $productRepository */
440
+ $ productRepository = $ objectManager ->get (ProductRepository::class);
441
+
442
+ /** @var \Magento\Quote\Model\Quote $quote */
443
+ $ product = $ productRepository ->getById ($ productId , false , null , true );
444
+
445
+ $ this ->setExpectedException (
446
+ LocalizedException::class,
447
+ 'Product that you are trying to add is not available. '
448
+ );
449
+
450
+ $ quote = $ objectManager ->create (\Magento \Quote \Model \Quote::class);
451
+ $ quote ->addProduct ($ product );
452
+ }
426
453
}
0 commit comments