Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
DeployTranslationsDictionaryTest.php
Go to the documentation of this file.
1 <?php
7 
10 
12 use Magento\Framework\Translate\Js\Config as JsTranslationConfig;
13 
14 use Psr\Log\LoggerInterface;
15 
16 use PHPUnit_Framework_MockObject_MockObject as Mock;
17 
21 class DeployTranslationsDictionaryTest extends \PHPUnit\Framework\TestCase
22 {
26  private $service;
27 
31  private $jsTranslationConfig;
32 
36  private $deployStaticFile;
37 
41  private $state;
42 
46  private $logger;
47 
51  protected function setUp()
52  {
53  $dictionary = 'js-translation.json';
54  $area = 'adminhtml';
55  $theme = 'Magento/backend';
56  $locale = 'uk_UA';
57 
58  $this->jsTranslationConfig = $this->createPartialMock(JsTranslationConfig::class, ['getDictionaryFileName']);
59  $this->jsTranslationConfig
60  ->expects($this->exactly(2))
61  ->method('getDictionaryFileName')
62  ->willReturn($dictionary);
63 
64  $this->deployStaticFile = $this->getMockBuilder(DeployStaticFile::class)
65  ->disableOriginalConstructor()
66  ->setMethods(['deployFile'])
67  ->getMock();
68  $this->deployStaticFile->expects($this->exactly(1))->method('deployFile')
69  ->willReturnCallback(
70  function ($checkDictionary, $params) use ($dictionary, $area, $theme, $locale) {
71  $this->assertEquals($dictionary, $checkDictionary);
72  $this->assertEquals($dictionary, $params['fileName']);
73  $this->assertEquals($area, $params['area']);
74  $this->assertEquals($theme, $params['theme']);
75  $this->assertEquals($locale, $params['locale']);
76  }
77  );
78 
79  $this->state = $this->getMockBuilder(State::class)
80  ->disableOriginalConstructor()
81  ->setMethods(['emulateAreaCode'])
82  ->getMock();
83  $this->state->expects($this->exactly(1))->method('emulateAreaCode')
84  ->willReturnCallback(
85  function ($area, $callback) {
86  $this->assertEquals('adminhtml', $area);
87  $callback();
88  }
89  );
90 
91  $this->logger = $this->getMockForAbstractClass(
92  LoggerInterface::class,
93  [],
94  '',
95  false
96  );
97 
98  $this->service = new DeployTranslationsDictionary(
99  $this->jsTranslationConfig,
100  $this->deployStaticFile,
101  $this->state,
102  $this->logger
103  );
104  }
105 
109  public function testDeploy()
110  {
111  $area = 'adminhtml';
112  $theme = 'Magento/backend';
113  $locale = 'uk_UA';
114  $this->service->deploy($area, $theme, $locale);
115  }
116 }
$theme
$params[\Magento\Store\Model\StoreManager::PARAM_RUN_CODE]
Definition: website.php:18