Skip to content

Commit 3e2f8c4

Browse files
author
Serhii Bohomaz
committed
MC-39634: Incerase test coverage of "Magento/Catalog/Model/Locator/RegistryLocator.php"
1 parent 6418d48 commit 3e2f8c4

File tree

1 file changed

+117
-0
lines changed

1 file changed

+117
-0
lines changed
Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
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\Model\Locator;
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\Store\Api\Data\StoreInterface;
15+
use Magento\TestFramework\Helper\Bootstrap;
16+
use PHPUnit\Framework\TestCase;
17+
use Magento\Store\Model\StoreManagerInterface;
18+
19+
/**
20+
* Test registry locator
21+
*
22+
* @see \Magento\Catalog\Model\Locator\RegistryLocator
23+
* @magentoAppArea frontend
24+
* @magentoDbIsolation enabled
25+
*/
26+
class RegistryLocatorTest extends TestCase
27+
{
28+
/** @var ObjectManagerInterface */
29+
private $objectManager;
30+
31+
/** @var StoreManagerInterface */
32+
private $storeManager;
33+
34+
/** @var RegistryLocator */
35+
private $registryLocator;
36+
37+
/** @var Registry */
38+
protected $registry;
39+
40+
/** @var ProductRepositoryInterface */
41+
private $productRepository;
42+
43+
44+
/**
45+
* @inheritDoc
46+
*/
47+
protected function setUp(): void
48+
{
49+
parent::setUp();
50+
51+
$this->objectManager = Bootstrap::getObjectManager();
52+
$this->storeManager = $this->objectManager->get(StoreManagerInterface::class);
53+
$this->registryLocator = $this->objectManager->get(RegistryLocator::class);
54+
$this->registry = $this->objectManager->get(Registry::class);
55+
$this->productRepository = $this->objectManager->get(ProductRepositoryInterface::class);
56+
$this->productRepository->cleanCache();
57+
}
58+
59+
/**
60+
* @inheridoc
61+
*/
62+
protected function tearDown(): void
63+
{
64+
$this->registry->unregister('current_product');
65+
$this->registry->unregister('current_store');
66+
67+
parent::tearDown();
68+
}
69+
70+
71+
/**
72+
* @magentoDbIsolation disabled
73+
* @magentoDataFixture Magento/Catalog/_files/product_two_websites.php
74+
*
75+
* @return void
76+
*/
77+
public function testGetWebsiteIds(): void
78+
{
79+
$product = $this->productRepository->get('simple-on-two-websites');
80+
$this->registerProduct($product);
81+
$this->assertEquals($product->getExtensionAttributes()->getWebsiteIds(), $this->registryLocator->getWebsiteIds());
82+
}
83+
84+
/**
85+
* @return void
86+
*/
87+
public function testGetBaseCurrencyCode(): void
88+
{
89+
$store = $this->storeManager->getStore();
90+
$this->registerStore($store);
91+
$this->assertEquals($store->getBaseCurrencyCode(), $this->registryLocator->getBaseCurrencyCode());
92+
}
93+
94+
/**
95+
* Register the product
96+
*
97+
* @param ProductInterface $product
98+
* @return void
99+
*/
100+
private function registerProduct(ProductInterface $product): void
101+
{
102+
$this->registry->unregister('current_product');
103+
$this->registry->register('current_product', $product);
104+
}
105+
106+
/**
107+
* Register the store
108+
*
109+
* @param StoreInterface $store
110+
* @return void
111+
*/
112+
private function registerStore(StoreInterface $store): void
113+
{
114+
$this->registry->unregister('current_store');
115+
$this->registry->register('current_store', $store);
116+
}
117+
}

0 commit comments

Comments
 (0)