Skip to content

Commit 6602711

Browse files
MC-29866: getBasePrice function returns a string sometimes
1 parent 0a45ec2 commit 6602711

File tree

1 file changed

+8
-67
lines changed
  • dev/tests/integration/testsuite/Magento/Catalog/Model/Product/Type

1 file changed

+8
-67
lines changed

dev/tests/integration/testsuite/Magento/Catalog/Model/Product/Type/PriceTest.php

Lines changed: 8 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
use Magento\Catalog\Api\ProductRepositoryInterface;
1212
use Magento\Catalog\Model\Product;
1313
use Magento\Catalog\Model\Product\Option;
14-
use Magento\Customer\Model\Session;
1514
use Magento\Framework\DataObject;
1615
use Magento\TestFramework\Helper\Bootstrap;
1716
use Magento\TestFramework\ObjectManager;
@@ -40,68 +39,14 @@ class PriceTest extends TestCase
4039
*/
4140
private $productRepository;
4241

43-
/**
44-
* @var Session
45-
*/
46-
private $customerSession;
47-
4842
/**
4943
* @inheritdoc
5044
*/
51-
protected function setUp(): void
45+
protected function setUp()
5246
{
5347
$this->objectManager = Bootstrap::getObjectManager();
5448
$this->productPrice = $this->objectManager->create(Price::class);
5549
$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-
}
10550
}
10651

10752
/**
@@ -134,6 +79,7 @@ public function testGetBasePrice(): void
13479
public function testGetFinalPrice(): void
13580
{
13681
$product = $this->productRepository->get('simple');
82+
// fixture
13783

13884
// regular & tier prices
13985
$this->assertEquals(10.0, $this->productPrice->getFinalPrice(1, $product));
@@ -159,6 +105,7 @@ public function testGetFinalPrice(): void
159105
public function testGetFormatedPrice(): void
160106
{
161107
$product = $this->productRepository->get('simple');
108+
// fixture
162109
$this->assertEquals('<span class="price">$10.00</span>', $this->productPrice->getFormatedPrice($product));
163110
}
164111

@@ -169,14 +116,8 @@ public function testGetFormatedPrice(): void
169116
*/
170117
public function testCalculatePrice(): void
171118
{
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'));
180121
}
181122

182123
/**
@@ -207,15 +148,15 @@ public function testIsTierPriceFixed(): void
207148
}
208149

209150
/**
210-
* Build buy request based on product custom options.
151+
* Build buy request based on product custom options
211152
*
212153
* @param Product $product
213154
* @return DataObject
214155
*/
215156
private function prepareBuyRequest(Product $product): DataObject
216157
{
217158
$options = [];
218-
/** @var Option $option */
159+
/** @var $option Option */
219160
foreach ($product->getOptions() as $option) {
220161
switch ($option->getGroupByType()) {
221162
case ProductCustomOptionInterface::OPTION_GROUP_DATE:
@@ -231,6 +172,6 @@ private function prepareBuyRequest(Product $product): DataObject
231172
$options[$option->getId()] = $value;
232173
}
233174

234-
return $this->objectManager->create(DataObject::class, ['data' => ['qty' => 1, 'options' => $options]]);
175+
return new DataObject(['qty' => 1, 'options' => $options]);
235176
}
236177
}

0 commit comments

Comments
 (0)