LocaleResolverTest.php 3.5 KB

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