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