11<?php
22/**
3- * Copyright © Magento, Inc. All rights reserved.
4- * See COPYING.txt for license details .
3+ * Copyright 2011 Adobe
4+ * All Rights Reserved .
55 */
6+
67declare (strict_types=1 );
78
89namespace Magento \Quote \Model ;
910
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 ;
1014use Magento \Catalog \Api \ProductRepositoryInterface ;
1115use Magento \Catalog \Test \Fixture \Product as ProductFixture ;
1216use 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 ;
1320use Magento \Customer \Api \CustomerRepositoryInterface ;
1421use Magento \Customer \Api \Data \CustomerInterface ;
1522use Magento \Customer \Api \Data \CustomerInterfaceFactory ;
2128use Magento \Framework \Api \ExtensibleDataObjectConverter ;
2229use Magento \Framework \Exception \LocalizedException ;
2330use Magento \Framework \ObjectManagerInterface ;
31+ use Magento \Quote \Api \CartRepositoryInterface ;
2432use Magento \Quote \Api \Data \AddressInterface ;
2533use Magento \Quote \Api \Data \AddressInterfaceFactory ;
2634use Magento \Quote \Api \Data \CartInterface ;
3240use Magento \TestFramework \Fixture \DataFixtureStorage ;
3341use Magento \TestFramework \Fixture \DataFixtureStorageManager ;
3442use Magento \TestFramework \Helper \Bootstrap ;
43+ use Magento \TestFramework \ObjectManager ;
3544use Magento \TestFramework \Quote \Model \GetQuoteByReservedOrderId ;
3645use PHPUnit \Framework \TestCase ;
3746
4251 *
4352 * @magentoDbIsolation enabled
4453 * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
54+ * @SuppressWarnings(PHPMD.TooManyFields)
4555 */
4656class QuoteTest extends TestCase
4757{
@@ -87,6 +97,11 @@ class QuoteTest extends TestCase
8797 /** @var ExtensibleDataObjectConverter */
8898 private $ extensibleDataObjectConverter ;
8999
100+ /**
101+ * @var CartRepositoryInterface
102+ */
103+ private $ cartRepository ;
104+
90105 /**
91106 * @var DataFixtureStorage
92107 */
@@ -113,6 +128,7 @@ protected function setUp(): void
113128 $ this ->customerResourceModel = $ this ->objectManager ->get (CustomerResourceModel::class);
114129 $ this ->groupFactory = $ this ->objectManager ->get (GroupFactory::class);
115130 $ this ->extensibleDataObjectConverter = $ this ->objectManager ->get (ExtensibleDataObjectConverter::class);
131+ $ this ->cartRepository = $ this ->objectManager ->get (CartRepositoryInterface::class);
116132 $ this ->fixtures = $ this ->objectManager ->get (DataFixtureStorageManager::class)->getStorage ();
117133 }
118134
@@ -840,4 +856,78 @@ public function testQuoteItemWithPriceGreaterThan100Millions()
840856 round ((float )$ item ->getPrice (), 2 )
841857 );
842858 }
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+ }
843933}
0 commit comments