DictionaryTest.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Framework\App\Language;
  7. use Magento\TestFramework\Helper\Bootstrap;
  8. class DictionaryTest extends \PHPUnit\Framework\TestCase
  9. {
  10. /**
  11. * @var \Magento\Framework\ObjectManagerInterface
  12. */
  13. private $objectManager;
  14. /**
  15. * @var \Magento\Framework\App\Language\Dictionary
  16. */
  17. private $model;
  18. /**
  19. * @var \Magento\Framework\Filesystem\Directory\ReadFactory
  20. */
  21. private $directoryFactory;
  22. /**
  23. * @var \Magento\Framework\App\Language\ConfigFactory
  24. */
  25. private $configFactory;
  26. protected function setUp()
  27. {
  28. $this->objectManager = Bootstrap::getObjectManager();
  29. $this->directoryFactory = $this->objectManager->create(
  30. \Magento\Framework\Filesystem\Directory\ReadFactory::class
  31. );
  32. $this->configFactory = $this->objectManager->create(\Magento\Framework\App\Language\ConfigFactory::class);
  33. }
  34. /**
  35. * @param string $languageCode
  36. * @param array $expectation
  37. * @dataProvider dictionaryDataProvider
  38. * @magentoComponentsDir Magento/Framework/App/Language/_files
  39. */
  40. public function testDictionaryGetter($languageCode, $expectation)
  41. {
  42. $this->model = $this->objectManager->create(
  43. \Magento\Framework\App\Language\Dictionary::class,
  44. ['directoryReadFactory' => $this->directoryFactory, 'configFactory' => $this->configFactory]
  45. );
  46. $result = $this->model->getDictionary($languageCode);
  47. $this->assertSame($expectation, $result);
  48. }
  49. public function dictionaryDataProvider()
  50. {
  51. return [
  52. // First case with multiple inheritance, the obtained dictionary is en_AU
  53. 'a case with multiple inheritance' => $this->getDataMultipleInheritance(),
  54. // Second case with inheritance of package with the same language code
  55. 'a case with inheritance similar language code' => $this->getDataInheritanceWitSimilarCode(),
  56. // Third case with circular inheritance, when two packages depend on each other
  57. 'a case with circular inheritance' => $this->getDataCircularInheritance()
  58. ];
  59. }
  60. /**
  61. * @return array
  62. */
  63. private function getDataMultipleInheritance()
  64. {
  65. return [
  66. // Dictionary that will be requested
  67. 'language_code' => 'en_AU',
  68. // Expected merged dictionary data
  69. 'expectation' => [
  70. 'one' => '1.0',
  71. 'two' => '2',
  72. 'three' => '3',
  73. 'four' => '4',
  74. 'four and 5/10' => '4.50',
  75. 'four and 75/100' => '4.75',
  76. 'five' => '5.0',
  77. 'six' => '6.0',
  78. ]
  79. ];
  80. }
  81. /**
  82. * @return array
  83. */
  84. private function getDataInheritanceWitSimilarCode()
  85. {
  86. return [
  87. // Dictionary that will be requested
  88. 'language_code' => 'ru_RU',
  89. // Expected merged dictionary data
  90. 'expectation' => [
  91. 'one' => '1.0',
  92. 'two' => '2',
  93. 'three' => '3',
  94. ]
  95. ];
  96. }
  97. /**
  98. * @return array
  99. */
  100. private function getDataCircularInheritance()
  101. {
  102. return [
  103. // Dictionary that will be requested
  104. 'language_code' => 'en_US',
  105. // Expected merged dictionary data
  106. 'expectation' => [
  107. 'one' => '1.0',
  108. 'two' => '2',
  109. 'three' => '3',
  110. 'four' => '4',
  111. ]
  112. ];
  113. }
  114. }