11
11
use Magento \Catalog \Api \ProductRepositoryInterface ;
12
12
use Magento \Catalog \Model \Product ;
13
13
use Magento \Catalog \Model \Product \Option ;
14
- use Magento \Customer \Model \Session ;
15
14
use Magento \Framework \DataObject ;
16
15
use Magento \TestFramework \Helper \Bootstrap ;
17
16
use Magento \TestFramework \ObjectManager ;
@@ -40,68 +39,14 @@ class PriceTest extends TestCase
40
39
*/
41
40
private $ productRepository ;
42
41
43
- /**
44
- * @var Session
45
- */
46
- private $ customerSession ;
47
-
48
42
/**
49
43
* @inheritdoc
50
44
*/
51
- protected function setUp (): void
45
+ protected function setUp ()
52
46
{
53
47
$ this ->objectManager = Bootstrap::getObjectManager ();
54
48
$ this ->productPrice = $ this ->objectManager ->create (Price::class);
55
49
$ this ->productRepository = $ this ->objectManager ->create (ProductRepositoryInterface::class);
56
- $ this ->customerSession = $ this ->objectManager ->get (Session::class);
57
- }
58
-
59
- /**
60
- * Assert that for logged user product price equal to price from catalog rule.
61
- *
62
- * @magentoDataFixture Magento/Catalog/_files/product_simple.php
63
- * @magentoDataFixture Magento/CatalogRule/_files/catalog_rule_6_off_logged_user.php
64
- * @magentoDataFixture Magento/Customer/_files/customer.php
65
- *
66
- * @magentoDbIsolation disabled
67
- * @magentoAppArea frontend
68
- * @magentoAppIsolation enabled
69
- *
70
- * @return void
71
- */
72
- public function testPriceByRuleForLoggedUser (): void
73
- {
74
- $ product = $ this ->productRepository ->get ('simple ' );
75
- $ this ->assertEquals (10 , $ this ->productPrice ->getFinalPrice (1 , $ product ));
76
- $ this ->customerSession ->setCustomerId (1 );
77
- try {
78
- $ this ->assertEquals (4 , $ this ->productPrice ->getFinalPrice (1 , $ product ));
79
- } finally {
80
- $ this ->customerSession ->setCustomerId (null );
81
- }
82
- }
83
-
84
- /**
85
- * Assert price for different customer groups.
86
- *
87
- * @magentoDataFixture Magento/Catalog/_files/simple_product_with_tier_price_for_logged_user.php
88
- * @magentoDataFixture Magento/Customer/_files/customer.php
89
- *
90
- * @magentoAppIsolation enabled
91
- *
92
- * @return void
93
- */
94
- public function testTierPriceWithDifferentCustomerGroups (): void
95
- {
96
- $ product = $ this ->productRepository ->get ('simple ' );
97
- $ this ->assertEquals (8 , $ this ->productPrice ->getFinalPrice (2 , $ product ));
98
- $ this ->assertEquals (5 , $ this ->productPrice ->getFinalPrice (3 , $ product ));
99
- $ this ->customerSession ->setCustomerId (1 );
100
- try {
101
- $ this ->assertEquals (1 , $ this ->productPrice ->getFinalPrice (3 , $ product ));
102
- } finally {
103
- $ this ->customerSession ->setCustomerId (null );
104
- }
105
50
}
106
51
107
52
/**
@@ -134,6 +79,7 @@ public function testGetBasePrice(): void
134
79
public function testGetFinalPrice (): void
135
80
{
136
81
$ product = $ this ->productRepository ->get ('simple ' );
82
+ // fixture
137
83
138
84
// regular & tier prices
139
85
$ this ->assertEquals (10.0 , $ this ->productPrice ->getFinalPrice (1 , $ product ));
@@ -159,6 +105,7 @@ public function testGetFinalPrice(): void
159
105
public function testGetFormatedPrice (): void
160
106
{
161
107
$ product = $ this ->productRepository ->get ('simple ' );
108
+ // fixture
162
109
$ this ->assertEquals ('<span class="price">$10.00</span> ' , $ this ->productPrice ->getFormatedPrice ($ product ));
163
110
}
164
111
@@ -169,14 +116,8 @@ public function testGetFormatedPrice(): void
169
116
*/
170
117
public function testCalculatePrice (): void
171
118
{
172
- $ this ->assertEquals (
173
- 10 ,
174
- $ this ->productPrice ->calculatePrice (10 , 8 , '1970-12-12 23:59:59 ' , '1971-01-01 01:01:01 ' )
175
- );
176
- $ this ->assertEquals (
177
- 8 ,
178
- $ this ->productPrice ->calculatePrice (10 , 8 , '1970-12-12 23:59:59 ' , '2034-01-01 01:01:01 ' )
179
- );
119
+ $ this ->assertEquals (10 , $ this ->productPrice ->calculatePrice (10 , 8 , '1970-12-12 23:59:59 ' , '1971-01-01 01:01:01 ' ));
120
+ $ this ->assertEquals (8 , $ this ->productPrice ->calculatePrice (10 , 8 , '1970-12-12 23:59:59 ' , '2034-01-01 01:01:01 ' ));
180
121
}
181
122
182
123
/**
@@ -207,15 +148,15 @@ public function testIsTierPriceFixed(): void
207
148
}
208
149
209
150
/**
210
- * Build buy request based on product custom options.
151
+ * Build buy request based on product custom options
211
152
*
212
153
* @param Product $product
213
154
* @return DataObject
214
155
*/
215
156
private function prepareBuyRequest (Product $ product ): DataObject
216
157
{
217
158
$ options = [];
218
- /** @var Option $option */
159
+ /** @var $option Option */
219
160
foreach ($ product ->getOptions () as $ option ) {
220
161
switch ($ option ->getGroupByType ()) {
221
162
case ProductCustomOptionInterface::OPTION_GROUP_DATE :
@@ -231,6 +172,6 @@ private function prepareBuyRequest(Product $product): DataObject
231
172
$ options [$ option ->getId ()] = $ value ;
232
173
}
233
174
234
- return $ this -> objectManager -> create (DataObject::class, [ ' data ' => [ ' qty ' => 1 , 'options ' => $ options] ]);
175
+ return new DataObject ([ ' qty ' => 1 , 'options ' => $ options ]);
235
176
}
236
177
}
0 commit comments