Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
FileManagerTest.php
Go to the documentation of this file.
1 <?php
8 
10 
11 class FileManagerTest extends \PHPUnit\Framework\TestCase
12 {
16  private $model;
17 
21  private $assetRepoMock;
22 
26  private $directoryListMock;
27 
31  private $driverFileMock;
32 
33  protected function setUp()
34  {
35  $objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
36  $this->assetRepoMock = $this->createMock(\Magento\Framework\View\Asset\Repository::class);
37  $this->directoryListMock = $this->createMock(\Magento\Framework\App\Filesystem\DirectoryList::class);
38  $this->driverFileMock = $this->createMock(\Magento\Framework\Filesystem\Driver\File::class);
39 
40  $this->model = $objectManager->getObject(
41  \Magento\Translation\Model\FileManager::class,
42  [
43  'assetRepo' => $this->assetRepoMock,
44  'directoryList' => $this->directoryListMock,
45  'driverFile' => $this->driverFileMock,
46  ]
47  );
48  }
49 
51  {
52  $path = 'relative path';
53  $expectedPath = $path . '/' . FileManager::TRANSLATION_CONFIG_FILE_NAME;
54  $fileMock = $this->createMock(\Magento\Framework\View\Asset\File::class);
55  $contextMock = $this->getMockForAbstractClass(
56  \Magento\Framework\View\Asset\ContextInterface::class,
57  [],
58  '',
59  true,
60  true,
61  true,
62  ['getPath']
63  );
64  $this->assetRepoMock->expects($this->once())->method('getStaticViewFileContext')->willReturn($contextMock);
65  $contextMock->expects($this->once())->method('getPath')->willReturn($path);
66  $this->assetRepoMock
67  ->expects($this->once())
68  ->method('createArbitrary')
69  ->with($expectedPath, '')
70  ->willReturn($fileMock);
71 
72  $this->assertSame($fileMock, $this->model->createTranslateConfigAsset());
73  }
74 
76  {
77  $path = 'path';
78  $contextMock = $this->getMockForAbstractClass(
79  \Magento\Framework\View\Asset\ContextInterface::class,
80  [],
81  '',
82  true,
83  true,
84  true,
85  ['getPath']
86  );
87  $this->assetRepoMock->expects($this->atLeastOnce())
88  ->method('getStaticViewFileContext')
89  ->willReturn($contextMock);
90  $contextMock->expects($this->atLeastOnce())->method('getPath')->willReturn($path);
91  $this->directoryListMock->expects($this->atLeastOnce())->method('getPath')->willReturn($path);
92  $this->driverFileMock->expects($this->once())
93  ->method('isExists')
94  ->with('path/path/js-translation.json')
95  ->willReturn(true);
96  $this->driverFileMock->expects($this->once())->method('stat')->willReturn(['mtime' => 1445736974]);
97  $this->assertEquals(1445736974, $this->model->getTranslationFileTimestamp());
98  }
99 
100  public function testGetTranslationFilePath()
101  {
102  $path = 'path';
103  $contextMock = $this->getMockForAbstractClass(
104  \Magento\Framework\View\Asset\ContextInterface::class,
105  [],
106  '',
107  true,
108  true,
109  true,
110  ['getPath']
111  );
112  $this->assetRepoMock->expects($this->atLeastOnce())
113  ->method('getStaticViewFileContext')
114  ->willReturn($contextMock);
115  $contextMock->expects($this->atLeastOnce())->method('getPath')->willReturn($path);
116  $this->assertEquals($path, $this->model->getTranslationFilePath());
117  }
118 }
$objectManager
Definition: bootstrap.php:17