Skip to content

Commit 4483911

Browse files
authored
Merge branch '2.4-develop' into 25963-grid-export-labels
2 parents 34d1876 + 90a479f commit 4483911

23 files changed

+1604
-21
lines changed
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\TestFramework\Directory\Model;
9+
10+
use Magento\Directory\Model\ResourceModel\Currency;
11+
12+
/**
13+
* Remove currency rates by currency code
14+
*/
15+
class RemoveCurrencyRateByCode
16+
{
17+
/** @var Currency */
18+
private $currencyResource;
19+
20+
/**
21+
* @param Currency $currencyResource
22+
*/
23+
public function __construct(Currency $currencyResource)
24+
{
25+
$this->currencyResource = $currencyResource;
26+
}
27+
28+
/**
29+
* Remove currency rates
30+
*
31+
* @param string $currencyCode
32+
* @return void
33+
*/
34+
public function execute(string $currencyCode): void
35+
{
36+
$connection = $this->currencyResource->getConnection();
37+
$rateTable = $this->currencyResource->getTable('directory_currency_rate');
38+
$connection->delete($rateTable, $connection->quoteInto('currency_to = ? OR currency_from = ?', $currencyCode));
39+
}
40+
}
Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Catalog\Block\Product\View;
9+
10+
use Magento\Catalog\Api\Data\ProductInterface;
11+
use Magento\Catalog\Api\ProductRepositoryInterface;
12+
use Magento\Framework\ObjectManagerInterface;
13+
use Magento\Framework\Registry;
14+
use Magento\Framework\View\Result\PageFactory;
15+
use Magento\TestFramework\Helper\Bootstrap;
16+
use PHPUnit\Framework\TestCase;
17+
18+
/**
19+
* Class consist of general logic for currency tests
20+
*/
21+
abstract class AbstractCurrencyTest extends TestCase
22+
{
23+
protected const TIER_PRICE_BLOCK_NAME = 'product.price.tier';
24+
protected const FINAL_PRICE_BLOCK_NAME = 'product.price.final';
25+
26+
/** @var ObjectManagerInterface */
27+
protected $objectManager;
28+
29+
/** @var Registry */
30+
protected $registry;
31+
32+
/** @var PageFactory */
33+
private $pageFactory;
34+
35+
/** @var ProductRepositoryInterface */
36+
private $productRepository;
37+
38+
/**
39+
* @inheritdoc
40+
*/
41+
protected function setUp()
42+
{
43+
parent::setUp();
44+
45+
$this->objectManager = Bootstrap::getObjectManager();
46+
$this->registry = $this->objectManager->get(Registry::class);
47+
$this->productRepository = $this->objectManager->get(ProductRepositoryInterface::class);
48+
$this->productRepository->cleanCache();
49+
$this->pageFactory = $this->objectManager->get(PageFactory::class);
50+
}
51+
52+
/**
53+
* @inheridoc
54+
*/
55+
protected function tearDown()
56+
{
57+
$this->registry->unregister('product');
58+
59+
parent::tearDown();
60+
}
61+
62+
/**
63+
* Process price view on product page
64+
*
65+
* @param string|ProductInterface $product
66+
* @param string $blockName
67+
* @return string
68+
*/
69+
protected function processPriceView($product, string $blockName = self::FINAL_PRICE_BLOCK_NAME): string
70+
{
71+
$product = is_string($product) ? $this->productRepository->get($product) : $product;
72+
$this->registerProduct($product);
73+
74+
return trim(
75+
preg_replace('/(?:\s|&nbsp;)+/', ' ', strip_tags($this->getProductPriceBlockHtml($blockName)))
76+
);
77+
}
78+
79+
/**
80+
* Get product price block content
81+
*
82+
* @param string $blockName
83+
* @return string
84+
*/
85+
private function getProductPriceBlockHtml(string $blockName): string
86+
{
87+
$page = $this->pageFactory->create();
88+
$page->addHandle([
89+
'default',
90+
'catalog_product_view',
91+
'catalog_product_view_type_configurable',
92+
]);
93+
$page->getLayout()->generateXml();
94+
$block = $page->getLayout()->getBlock($blockName);
95+
$this->assertNotFalse($block);
96+
97+
return $block->toHtml();
98+
}
99+
100+
/**
101+
* Register the product
102+
*
103+
* @param ProductInterface $product
104+
* @return void
105+
*/
106+
private function registerProduct(ProductInterface $product): void
107+
{
108+
$this->registry->unregister('product');
109+
$this->registry->register('product', $product);
110+
}
111+
}
Lines changed: 147 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,147 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Catalog\Block\Product\View;
9+
10+
use Magento\Store\Model\StoreManagerInterface;
11+
12+
/**
13+
* Checks currency displaying and converting on the catalog pages on multi store mode
14+
*
15+
* @magentoAppArea frontend
16+
* @magentoDbIsolation disabled
17+
*/
18+
class MultiStoreCurrencyTest extends AbstractCurrencyTest
19+
{
20+
/** @var StoreManagerInterface */
21+
private $storeManager;
22+
23+
/**
24+
* @inheritdoc
25+
*/
26+
protected function setUp()
27+
{
28+
parent::setUp();
29+
30+
$this->storeManager = $this->objectManager->get(StoreManagerInterface::class);
31+
}
32+
33+
/**
34+
* @magentoConfigFixture default/currency/options/base USD
35+
* @magentoConfigFixture current_store currency/options/default CNY
36+
* @magentoConfigFixture current_store currency/options/allow CNY,USD
37+
* @magentoConfigFixture fixturestore_store currency/options/default UAH
38+
* @magentoConfigFixture fixturestore_store currency/options/allow UAH,USD
39+
*
40+
* @magentoDataFixture Magento/Store/_files/core_fixturestore.php
41+
* @magentoDataFixture Magento/Catalog/_files/second_product_simple.php
42+
* @magentoDataFixture Magento/Directory/_files/usd_cny_rate.php
43+
* @magentoDataFixture Magento/Directory/_files/usd_uah_rate.php
44+
*
45+
* @return void
46+
*/
47+
public function testMultiStoreRenderPrice(): void
48+
{
49+
$this->assertProductStorePrice('simple2', 'CN¥70.00');
50+
$this->reloadProductPriceInfo();
51+
$this->assertProductStorePrice('simple2', '₴240.00', 'fixturestore');
52+
}
53+
54+
/**
55+
* @magentoConfigFixture default/currency/options/base USD
56+
* @magentoConfigFixture current_store currency/options/default CNY
57+
* @magentoConfigFixture current_store currency/options/allow CNY,USD
58+
* @magentoConfigFixture fixturestore_store currency/options/default UAH
59+
* @magentoConfigFixture fixturestore_store currency/options/allow UAH,USD
60+
*
61+
* @magentoDataFixture Magento/Store/_files/core_fixturestore.php
62+
* @magentoDataFixture Magento/Catalog/_files/product_special_price.php
63+
* @magentoDataFixture Magento/Directory/_files/usd_cny_rate.php
64+
* @magentoDataFixture Magento/Directory/_files/usd_uah_rate.php
65+
*
66+
* @return void
67+
*/
68+
public function testMultiStoreRenderSpecialPrice(): void
69+
{
70+
$this->assertProductStorePrice('simple', 'Special Price CN¥41.93 Regular Price CN¥70.00');
71+
$this->reloadProductPriceInfo();
72+
$this->assertProductStorePrice('simple', 'Special Price ₴143.76 Regular Price ₴240.00', 'fixturestore');
73+
}
74+
75+
/**
76+
* @magentoConfigFixture default/currency/options/base USD
77+
* @magentoConfigFixture current_store currency/options/default CNY
78+
* @magentoConfigFixture current_store currency/options/allow CNY,USD
79+
* @magentoConfigFixture fixturestore_store currency/options/default UAH
80+
* @magentoConfigFixture fixturestore_store currency/options/allow UAH,USD
81+
*
82+
* @magentoDataFixture Magento/Store/_files/core_fixturestore.php
83+
* @magentoDataFixture Magento/Catalog/_files/product_simple_with_fixed_tier_price.php
84+
* @magentoDataFixture Magento/Directory/_files/usd_cny_rate.php
85+
* @magentoDataFixture Magento/Directory/_files/usd_uah_rate.php
86+
*
87+
* @return void
88+
*/
89+
public function testMultiStoreRenderTierPrice(): void
90+
{
91+
$this->assertProductStorePrice(
92+
'simple-product-tax-none',
93+
'Buy 2 for CN¥280.00 each and save 80%',
94+
'default',
95+
self::TIER_PRICE_BLOCK_NAME
96+
);
97+
$this->reloadProductPriceInfo();
98+
$this->assertProductStorePrice(
99+
'simple-product-tax-none',
100+
'Buy 2 for ₴960.00 each and save 80%',
101+
'fixturestore',
102+
self::TIER_PRICE_BLOCK_NAME
103+
);
104+
}
105+
106+
/**
107+
* Check price per stores
108+
*
109+
* @param string $productSku
110+
* @param string $expectedData
111+
* @param string $storeCode
112+
* @param string $priceBlockName
113+
* @return void
114+
*/
115+
private function assertProductStorePrice(
116+
string $productSku,
117+
string $expectedData,
118+
string $storeCode = 'default',
119+
string $priceBlockName = self::FINAL_PRICE_BLOCK_NAME
120+
): void {
121+
$currentStore = $this->storeManager->getStore();
122+
try {
123+
if ($currentStore->getCode() !== $storeCode) {
124+
$this->storeManager->setCurrentStore($storeCode);
125+
}
126+
127+
$actualData = $this->processPriceView($productSku, $priceBlockName);
128+
$this->assertEquals($expectedData, $actualData);
129+
} finally {
130+
if ($currentStore->getCode() !== $storeCode) {
131+
$this->storeManager->setCurrentStore($currentStore);
132+
}
133+
}
134+
}
135+
136+
/**
137+
* Reload product price info
138+
*
139+
* @return void
140+
*/
141+
private function reloadProductPriceInfo(): void
142+
{
143+
$product = $this->registry->registry('product');
144+
$this->assertNotNull($product);
145+
$product->reloadPriceInfo();
146+
}
147+
}
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Catalog\Block\Product\View;
9+
10+
/**
11+
* Checks currency displaying and converting on the catalog pages
12+
*
13+
* @magentoAppArea frontend
14+
*/
15+
class SingleStoreCurrencyTest extends AbstractCurrencyTest
16+
{
17+
/**
18+
* @magentoConfigFixture current_store currency/options/base USD
19+
* @magentoConfigFixture current_store currency/options/default CNY
20+
* @magentoConfigFixture current_store currency/options/allow CNY,USD
21+
*
22+
* @magentoDataFixture Magento/Catalog/_files/second_product_simple.php
23+
* @magentoDataFixture Magento/Directory/_files/usd_cny_rate.php
24+
*
25+
* @return void
26+
*/
27+
public function testRenderPrice(): void
28+
{
29+
$priceHtml = $this->processPriceView('simple2');
30+
$this->assertEquals('CN¥70.00', $priceHtml);
31+
}
32+
33+
/**
34+
* @magentoConfigFixture current_store currency/options/base USD
35+
* @magentoConfigFixture current_store currency/options/default CNY
36+
* @magentoConfigFixture current_store currency/options/allow EUR,CNY
37+
*
38+
* @magentoDataFixture Magento/Catalog/_files/product_special_price.php
39+
* @magentoDataFixture Magento/Directory/_files/usd_cny_rate.php
40+
*
41+
* @return void
42+
*/
43+
public function testRenderSpecialPrice(): void
44+
{
45+
$priceHtml = $this->processPriceView('simple');
46+
$this->assertEquals('Special Price CN¥41.93 Regular Price CN¥70.00', $priceHtml);
47+
}
48+
49+
/**
50+
* @magentoConfigFixture current_store currency/options/base USD
51+
* @magentoConfigFixture current_store currency/options/default CNY
52+
* @magentoConfigFixture current_store currency/options/allow CNY,USD
53+
*
54+
* @magentoDataFixture Magento/Catalog/_files/product_simple_with_fixed_tier_price.php
55+
* @magentoDataFixture Magento/Directory/_files/usd_cny_rate.php
56+
*
57+
* @return void
58+
*/
59+
public function testRenderTierPrice(): void
60+
{
61+
$priceHtml = $this->processPriceView('simple-product-tax-none', self::TIER_PRICE_BLOCK_NAME);
62+
$this->assertEquals('Buy 2 for CN¥280.00 each and save 80%', $priceHtml);
63+
}
64+
}

0 commit comments

Comments
 (0)