1
1
<?php
2
2
/**
3
- * Copyright © Magento, Inc. All rights reserved.
4
- * See COPYING.txt for license details .
3
+ * Copyright 2011 Adobe
4
+ * All Rights Reserved .
5
5
*/
6
+
6
7
declare (strict_types=1 );
7
8
8
9
namespace Magento \Quote \Model ;
9
10
11
+ use Magento \Bundle \Test \Fixture \AddProductToCart as AddBundleProductToCartFixture ;
12
+ use Magento \Bundle \Test \Fixture \Option as BundleOptionFixture ;
13
+ use Magento \Bundle \Test \Fixture \Product as BundleProductFixture ;
10
14
use Magento \Catalog \Api \ProductRepositoryInterface ;
11
15
use Magento \Catalog \Test \Fixture \Product as ProductFixture ;
12
16
use Magento \Checkout \Model \Session as CheckoutSession ;
17
+ use Magento \ConfigurableProduct \Test \Fixture \AddProductToCart as AddConfigurableProductToCartFixture ;
18
+ use Magento \ConfigurableProduct \Test \Fixture \Attribute as AttributeFixture ;
19
+ use Magento \ConfigurableProduct \Test \Fixture \Product as ConfigurableProductFixture ;
13
20
use Magento \Customer \Api \CustomerRepositoryInterface ;
14
21
use Magento \Customer \Api \Data \CustomerInterface ;
15
22
use Magento \Customer \Api \Data \CustomerInterfaceFactory ;
21
28
use Magento \Framework \Api \ExtensibleDataObjectConverter ;
22
29
use Magento \Framework \Exception \LocalizedException ;
23
30
use Magento \Framework \ObjectManagerInterface ;
31
+ use Magento \Quote \Api \CartRepositoryInterface ;
24
32
use Magento \Quote \Api \Data \AddressInterface ;
25
33
use Magento \Quote \Api \Data \AddressInterfaceFactory ;
26
34
use Magento \Quote \Api \Data \CartInterface ;
32
40
use Magento \TestFramework \Fixture \DataFixtureStorage ;
33
41
use Magento \TestFramework \Fixture \DataFixtureStorageManager ;
34
42
use Magento \TestFramework \Helper \Bootstrap ;
43
+ use Magento \TestFramework \ObjectManager ;
35
44
use Magento \TestFramework \Quote \Model \GetQuoteByReservedOrderId ;
36
45
use PHPUnit \Framework \TestCase ;
37
46
42
51
*
43
52
* @magentoDbIsolation enabled
44
53
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
54
+ * @SuppressWarnings(PHPMD.TooManyFields)
45
55
*/
46
56
class QuoteTest extends TestCase
47
57
{
@@ -87,6 +97,11 @@ class QuoteTest extends TestCase
87
97
/** @var ExtensibleDataObjectConverter */
88
98
private $ extensibleDataObjectConverter ;
89
99
100
+ /**
101
+ * @var CartRepositoryInterface
102
+ */
103
+ private $ cartRepository ;
104
+
90
105
/**
91
106
* @var DataFixtureStorage
92
107
*/
@@ -113,6 +128,7 @@ protected function setUp(): void
113
128
$ this ->customerResourceModel = $ this ->objectManager ->get (CustomerResourceModel::class);
114
129
$ this ->groupFactory = $ this ->objectManager ->get (GroupFactory::class);
115
130
$ this ->extensibleDataObjectConverter = $ this ->objectManager ->get (ExtensibleDataObjectConverter::class);
131
+ $ this ->cartRepository = $ this ->objectManager ->get (CartRepositoryInterface::class);
116
132
$ this ->fixtures = $ this ->objectManager ->get (DataFixtureStorageManager::class)->getStorage ();
117
133
}
118
134
@@ -840,4 +856,78 @@ public function testQuoteItemWithPriceGreaterThan100Millions()
840
856
round ((float )$ item ->getPrice (), 2 )
841
857
);
842
858
}
859
+
860
+ #[
861
+ DataFixture(ProductFixture::class, ['price ' => 10 ], as: 'p ' , count: 2 ),
862
+ DataFixture(AttributeFixture::class, as: 'attr ' ),
863
+ DataFixture(
864
+ ConfigurableProductFixture::class,
865
+ ['_options ' => ['$attr$ ' ], '_links ' => ['$p1$ ' , '$p2$ ' ]],
866
+ 'cp1 '
867
+ ),
868
+ DataFixture(GuestCartFixture::class, as: 'cart ' ),
869
+ DataFixture(
870
+ AddConfigurableProductToCartFixture::class,
871
+ ['cart_id ' => '$cart.id$ ' , 'product_id ' => '$cp1.id$ ' , 'child_product_id ' => '$p1.id$ ' , 'qty ' => 2 ],
872
+ ),
873
+ DataFixture(
874
+ AddConfigurableProductToCartFixture::class,
875
+ ['cart_id ' => '$cart.id$ ' , 'product_id ' => '$cp1.id$ ' , 'child_product_id ' => '$p2.id$ ' , 'qty ' => 2 ],
876
+ ),
877
+ DataFixture('deleteProduct ' )
878
+ ]
879
+ public function testCollectTotalsWhenConfigurableChildIsDeleted (): void
880
+ {
881
+ $ cart = $ this ->fixtures ->get ('cart ' );
882
+ $ cart = $ this ->cartRepository ->get ($ cart ->getId ());
883
+ $ cart ->setTotalsCollectedFlag (false )->collectTotals ();
884
+ $ items = $ cart ->getAllItems ();
885
+ $ this ->assertCount (3 , $ items );
886
+ $ this ->assertCount (0 , $ items [0 ]->getChildren ());
887
+ $ this ->assertTrue ($ items [0 ]->getHasError ());
888
+ }
889
+
890
+ #[
891
+ DataFixture(ProductFixture::class, ['price ' => 10 ], as: 'p ' , count: 2 ),
892
+ DataFixture(BundleOptionFixture::class, ['product_links ' => ['$p1$ ' ]], 'opt1 ' ),
893
+ DataFixture(BundleOptionFixture::class, ['product_links ' => ['$p2$ ' ]], 'opt2 ' ),
894
+ DataFixture(BundleProductFixture::class, ['_options ' => ['$opt1$ ' , '$opt2$ ' ]], 'bp1 ' ),
895
+ DataFixture(GuestCartFixture::class, as: 'cart ' ),
896
+ DataFixture(
897
+ AddBundleProductToCartFixture::class,
898
+ [
899
+ 'cart_id ' => '$cart.id$ ' ,
900
+ 'product_id ' => '$bp1.id$ ' ,
901
+ 'selections ' => [['$p1.id$ ' ], ['$p2.id$ ' ]],
902
+ 'qty ' => 1
903
+ ],
904
+ ),
905
+ DataFixture('deleteProduct ' )
906
+ ]
907
+ public function testCollectTotalsWhenBundleChildIsDeleted (): void
908
+ {
909
+ $ cart = $ this ->fixtures ->get ('cart ' );
910
+ $ cart = $ this ->cartRepository ->get ($ cart ->getId ());
911
+ $ cart ->setTotalsCollectedFlag (false )->collectTotals ();
912
+ $ items = $ cart ->getAllItems ();
913
+ $ this ->assertCount (2 , $ items );
914
+ $ this ->assertCount (1 , $ items [0 ]->getChildren ());
915
+ $ this ->assertTrue ($ items [0 ]->getHasError ());
916
+ }
917
+
918
+ public static function deleteProduct (): void
919
+ {
920
+ $ registry = Bootstrap::getObjectManager ()->get (\Magento \Framework \Registry::class);
921
+ $ isSecureArea = $ registry ->registry ('isSecureArea ' );
922
+ $ registry ->unregister ('isSecureArea ' );
923
+ $ registry ->register ('isSecureArea ' , true );
924
+ try {
925
+ ObjectManager::getInstance ()->get (ProductRepositoryInterface::class)->deleteById (
926
+ DataFixtureStorageManager::getStorage ()->get ('p1 ' )->getSku ()
927
+ );
928
+ } finally {
929
+ $ registry ->unregister ('isSecureArea ' );
930
+ $ registry ->register ('isSecureArea ' , $ isSecureArea );
931
+ }
932
+ }
843
933
}
0 commit comments