77
88namespace Magento \SalesRule \Model \Rule \Condition \Product ;
99
10+ use Magento \Catalog \Test \Fixture \Product as ProductFixture ;
11+ use Magento \Customer \Test \Fixture \Customer ;
1012use Magento \Framework \ObjectManagerInterface ;
11- use Magento \Quote \Model \Quote ;
13+ use Magento \Quote \Test \Fixture \AddProductToCart ;
14+ use Magento \Quote \Test \Fixture \CustomerCart ;
15+ use Magento \TestFramework \Fixture \DataFixture ;
16+ use Magento \Catalog \Api \ProductRepositoryInterface ;
1217use Magento \SalesRule \Model \Rule \Condition \Product as SalesRuleProduct ;
18+ use Magento \TestFramework \Fixture \DataFixtureStorageManager ;
1319use Magento \TestFramework \Helper \Bootstrap ;
1420use PHPUnit \Framework \TestCase ;
1521
1622/**
1723 * Integration test for Subselect::validate() method returning true.
1824 *
1925 * @magentoAppArea frontend
20- * @magentoDbIsolation enabled
2126 */
2227class SubselectTest extends TestCase
2328{
@@ -32,28 +37,31 @@ class SubselectTest extends TestCase
3237 private $ subselectCondition ;
3338
3439 /**
35- * @var SalesRuleProduct
40+ * @var \Magento\Catalog\Api\ProductRepositoryInterface
3641 */
37- private $ productCondition ;
42+ protected $ productRepository ;
3843
3944 protected function setUp (): void
4045 {
4146 $ this ->objectManager = Bootstrap::getObjectManager ();
42- $ this ->productCondition = $ this ->objectManager ->create (SalesRuleProduct::class);
43- $ this ->subselectCondition = $ this ->objectManager ->create (
44- Subselect::class,
45- [
46- 'context ' => $ this ->objectManager ->get (\Magento \Rule \Model \Condition \Context::class),
47- 'ruleConditionProduct ' => $ this ->productCondition
48- ]
49- );
47+ $ this ->subselectCondition = $ this ->objectManager ->create (Subselect::class);
48+ $ this ->productRepository = $ this ->objectManager ->get (ProductRepositoryInterface::class);
5049 }
5150
5251 /**
5352 * Test validate() method returning true for total quantity >= 2 with single shipping.
5453 *
55- * @magentoDataFixture Magento/Catalog/_files/products.php
5654 */
55+ #[
56+ DataFixture(Customer::class, as: 'customer ' ),
57+ DataFixture(CustomerCart::class, ['customer_id ' => '$customer.id$ ' ], 'quote ' ),
58+ DataFixture(ProductFixture::class, ['sku ' => 'simple1 ' , 'price ' => 100.50 ], as: 'product ' ),
59+ DataFixture(
60+ AddProductToCart::class,
61+ ['cart_id ' => '$quote.id$ ' , 'product_id ' => '$product.id$ ' , 'qty ' => 2 ],
62+ 'item '
63+ ),
64+ ]
5765 public function testValidateReturnsTrueForSufficientQuantity ()
5866 {
5967 $ this ->subselectCondition ->setData ([
@@ -66,20 +74,13 @@ public function testValidateReturnsTrueForSufficientQuantity()
6674 $ productCondition ->setData ([
6775 'attribute ' => 'sku ' ,
6876 'operator ' => '== ' ,
69- 'value ' => 'simple ' ,
77+ 'value ' => 'simple1 ' ,
7078 ]);
7179 $ this ->subselectCondition ->setConditions ([$ productCondition ]);
72- $ productRepository = $ this ->objectManager ->create (\Magento \Catalog \Api \ProductRepositoryInterface::class);
73- $ product = $ productRepository ->get ('simple ' );
74- $ product ->setPrice (100.50 );
80+ $ product = $ this ->productRepository ->get ('simple1 ' );
7581 $ this ->assertNotNull ($ product ->getId ());
76- $ quote = $ this ->objectManager ->create (Quote::class);
77- $ quote ->setStoreId (1 )
78- ->setIsActive (true )
79- ->setIsMultiShipping (false )
80- ->setReservedOrderId ('test_quote ' )
81- ->addProduct ($ product , 2 );
82- $ quote ->collectTotals ()->save ();
82+ $ quote = DataFixtureStorageManager::getStorage ()->get ('quote ' );
83+ $ quote ->setStoreId (1 )->setIsActive (true )->setIsMultiShipping (false );
8384 $ this ->assertNotNull ($ quote ->getId ());
8485 $ this ->assertNotEmpty ($ quote ->getAllVisibleItems ());
8586 $ quoteItem = $ quote ->getAllVisibleItems ()[0 ];
0 commit comments