DeployTranslationsDictionaryTest.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Deploy\Test\Unit\Service;
  7. use Magento\Deploy\Service\DeployTranslationsDictionary;
  8. use Magento\Deploy\Service\DeployStaticFile;
  9. use Magento\Framework\App\State;
  10. use Magento\Framework\Translate\Js\Config as JsTranslationConfig;
  11. use Psr\Log\LoggerInterface;
  12. use PHPUnit_Framework_MockObject_MockObject as Mock;
  13. /**
  14. * Translation Dictionaries deploy service class unit tests
  15. */
  16. class DeployTranslationsDictionaryTest extends \PHPUnit\Framework\TestCase
  17. {
  18. /**
  19. * @var DeployTranslationsDictionary
  20. */
  21. private $service;
  22. /**
  23. * @var JsTranslationConfig|Mock
  24. */
  25. private $jsTranslationConfig;
  26. /**
  27. * @var DeployStaticFile|Mock
  28. */
  29. private $deployStaticFile;
  30. /**
  31. * @var State|Mock
  32. */
  33. private $state;
  34. /**
  35. * @var LoggerInterface|Mock
  36. */
  37. private $logger;
  38. /**
  39. * @inheritdoc
  40. */
  41. protected function setUp()
  42. {
  43. $dictionary = 'js-translation.json';
  44. $area = 'adminhtml';
  45. $theme = 'Magento/backend';
  46. $locale = 'uk_UA';
  47. $this->jsTranslationConfig = $this->createPartialMock(JsTranslationConfig::class, ['getDictionaryFileName']);
  48. $this->jsTranslationConfig
  49. ->expects($this->exactly(2))
  50. ->method('getDictionaryFileName')
  51. ->willReturn($dictionary);
  52. $this->deployStaticFile = $this->getMockBuilder(DeployStaticFile::class)
  53. ->disableOriginalConstructor()
  54. ->setMethods(['deployFile'])
  55. ->getMock();
  56. $this->deployStaticFile->expects($this->exactly(1))->method('deployFile')
  57. ->willReturnCallback(
  58. function ($checkDictionary, $params) use ($dictionary, $area, $theme, $locale) {
  59. $this->assertEquals($dictionary, $checkDictionary);
  60. $this->assertEquals($dictionary, $params['fileName']);
  61. $this->assertEquals($area, $params['area']);
  62. $this->assertEquals($theme, $params['theme']);
  63. $this->assertEquals($locale, $params['locale']);
  64. }
  65. );
  66. $this->state = $this->getMockBuilder(State::class)
  67. ->disableOriginalConstructor()
  68. ->setMethods(['emulateAreaCode'])
  69. ->getMock();
  70. $this->state->expects($this->exactly(1))->method('emulateAreaCode')
  71. ->willReturnCallback(
  72. function ($area, $callback) {
  73. $this->assertEquals('adminhtml', $area);
  74. $callback();
  75. }
  76. );
  77. $this->logger = $this->getMockForAbstractClass(
  78. LoggerInterface::class,
  79. [],
  80. '',
  81. false
  82. );
  83. $this->service = new DeployTranslationsDictionary(
  84. $this->jsTranslationConfig,
  85. $this->deployStaticFile,
  86. $this->state,
  87. $this->logger
  88. );
  89. }
  90. /**
  91. * @see DeployTranslationsDictionary::deploy()
  92. */
  93. public function testDeploy()
  94. {
  95. $area = 'adminhtml';
  96. $theme = 'Magento/backend';
  97. $locale = 'uk_UA';
  98. $this->service->deploy($area, $theme, $locale);
  99. }
  100. }