7
7
8
8
namespace Magento \SalesRule \Model \Rule \Condition \Product ;
9
9
10
+ use Magento \Catalog \Test \Fixture \Product as ProductFixture ;
11
+ use Magento \Customer \Test \Fixture \Customer ;
10
12
use 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 ;
12
17
use Magento \SalesRule \Model \Rule \Condition \Product as SalesRuleProduct ;
18
+ use Magento \TestFramework \Fixture \DataFixtureStorageManager ;
13
19
use Magento \TestFramework \Helper \Bootstrap ;
14
20
use PHPUnit \Framework \TestCase ;
15
21
16
22
/**
17
23
* Integration test for Subselect::validate() method returning true.
18
24
*
19
25
* @magentoAppArea frontend
20
- * @magentoDbIsolation enabled
21
26
*/
22
27
class SubselectTest extends TestCase
23
28
{
@@ -32,28 +37,31 @@ class SubselectTest extends TestCase
32
37
private $ subselectCondition ;
33
38
34
39
/**
35
- * @var SalesRuleProduct
40
+ * @var \Magento\Catalog\Api\ProductRepositoryInterface
36
41
*/
37
- private $ productCondition ;
42
+ protected $ productRepository ;
38
43
39
44
protected function setUp (): void
40
45
{
41
46
$ 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);
50
49
}
51
50
52
51
/**
53
52
* Test validate() method returning true for total quantity >= 2 with single shipping.
54
53
*
55
- * @magentoDataFixture Magento/Catalog/_files/products.php
56
54
*/
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
+ ]
57
65
public function testValidateReturnsTrueForSufficientQuantity ()
58
66
{
59
67
$ this ->subselectCondition ->setData ([
@@ -66,20 +74,13 @@ public function testValidateReturnsTrueForSufficientQuantity()
66
74
$ productCondition ->setData ([
67
75
'attribute ' => 'sku ' ,
68
76
'operator ' => '== ' ,
69
- 'value ' => 'simple ' ,
77
+ 'value ' => 'simple1 ' ,
70
78
]);
71
79
$ 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 ' );
75
81
$ 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 );
83
84
$ this ->assertNotNull ($ quote ->getId ());
84
85
$ this ->assertNotEmpty ($ quote ->getAllVisibleItems ());
85
86
$ quoteItem = $ quote ->getAllVisibleItems ()[0 ];
0 commit comments