Skip to content

Commit 23f12b9

Browse files
dmytro-chronak2ram
authored andcommitted
Braintree: Add unit test for LocaleResolver
1 parent 13fc94b commit 23f12b9

File tree

1 file changed

+138
-0
lines changed

1 file changed

+138
-0
lines changed
Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
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\Braintree\Test\Unit\Model;
9+
10+
use Magento\Braintree\Gateway\Config\PayPal\Config;
11+
use Magento\Braintree\Model\LocaleResolver;
12+
use Magento\Framework\Locale\ResolverInterface;
13+
14+
/**
15+
* @covers \Magento\Braintree\Model\LocaleResolver
16+
*/
17+
class LocaleResolverTest extends \PHPUnit\Framework\TestCase
18+
{
19+
/**
20+
* Testable Object
21+
*
22+
* @var LocaleResolver
23+
*/
24+
private $localeResolver;
25+
26+
/**
27+
* @var Config|\PHPUnit_Framework_MockObject_MockObject
28+
*/
29+
private $configMock;
30+
31+
/**
32+
* @var ResolverInterface|\PHPUnit_Framework_MockObject_MockObject
33+
*/
34+
private $resolverMock;
35+
36+
/**
37+
* Set Up
38+
*
39+
* @return void
40+
*/
41+
protected function setUp()
42+
{
43+
$this->configMock = $this->createMock(Config::class);
44+
$this->resolverMock = $this->createMock(ResolverInterface::class);
45+
$this->localeResolver = new LocaleResolver($this->resolverMock, $this->configMock);
46+
}
47+
48+
/**
49+
* Test getDefaultLocalePath method
50+
*
51+
* @return void
52+
*/
53+
public function testGetDefaultLocalePath()
54+
{
55+
$expected = 'general/locale/code';
56+
$this->resolverMock->expects($this->once())->method('getDefaultLocalePath')->willReturn($expected);
57+
$actual = $this->localeResolver->getDefaultLocalePath();
58+
self::assertEquals($expected, $actual);
59+
}
60+
61+
/**
62+
* Test setDefaultLocale method
63+
*
64+
* @return void
65+
*/
66+
public function testSetDefaultLocale()
67+
{
68+
$defaultLocale = 'en_US';
69+
$this->resolverMock->expects($this->once())->method('setDefaultLocale')->with($defaultLocale);
70+
$this->localeResolver->setDefaultLocale($defaultLocale);
71+
}
72+
73+
/**
74+
* Test getDefaultLocale method
75+
*
76+
* @return void
77+
*/
78+
public function testGetDefaultLocale()
79+
{
80+
$expected = 'fr_FR';
81+
$this->resolverMock->expects($this->once())->method('getDefaultLocale')->willReturn($expected);
82+
$actual = $this->localeResolver->getDefaultLocale();
83+
self::assertEquals($expected, $actual);
84+
}
85+
86+
/**
87+
* Test setLocale method
88+
*
89+
* @return void
90+
*/
91+
public function testSetLocale()
92+
{
93+
$locale = 'en_GB';
94+
$this->resolverMock->expects($this->once())->method('setLocale')->with($locale);
95+
$this->localeResolver->setLocale($locale);
96+
}
97+
98+
/**
99+
* Test getLocale method
100+
*
101+
* @return void
102+
*/
103+
public function testGetLocale()
104+
{
105+
$locale = 'en_TEST';
106+
$allowedLocales = 'en_US,en_GB,en_AU,da_DK,fr_FR,fr_CA,de_DE,zh_HK,it_IT,nl_NL';
107+
$this->resolverMock->expects($this->once())->method('getLocale')->willReturn($locale);
108+
$this->configMock->expects($this->once())->method('getValue')->with('supported_locales')
109+
->willReturn($allowedLocales);
110+
111+
$expected = 'en_US';
112+
$actual = $this->localeResolver->getLocale();
113+
self::assertEquals($expected, $actual);
114+
}
115+
116+
/**
117+
* Test emulate method
118+
*
119+
* @return void
120+
*/
121+
public function testEmulate()
122+
{
123+
$scopeId = 12;
124+
$this->resolverMock->expects($this->once())->method('emulate')->with($scopeId);
125+
$this->localeResolver->emulate($scopeId);
126+
}
127+
128+
/**
129+
* Test revert method
130+
*
131+
* @return void
132+
*/
133+
public function testRevert()
134+
{
135+
$this->resolverMock->expects($this->once())->method('revert');
136+
$this->localeResolver->revert();
137+
}
138+
}

0 commit comments

Comments
 (0)