Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
LocaleResolverTest.php
Go to the documentation of this file.
1 <?php
6 declare(strict_types=1);
7 
9 
13 
17 class LocaleResolverTest extends \PHPUnit\Framework\TestCase
18 {
24  private $localeResolver;
25 
29  private $configMock;
30 
34  private $resolverMock;
35 
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 
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 
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 
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 
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 
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 
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 
133  public function testRevert()
134  {
135  $this->resolverMock->expects($this->once())->method('revert');
136  $this->localeResolver->revert();
137  }
138 }