CodesTest.php 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Framework\Locale\Test\Unit\Deployed;
  7. use Magento\Framework\App\Filesystem\DirectoryList;
  8. use Magento\Framework\Filesystem;
  9. use Magento\Framework\Filesystem\Directory\ReadInterface;
  10. use Magento\Framework\Locale\Deployed\Codes;
  11. use Magento\Framework\View\Design\Theme\FlyweightFactory;
  12. use Magento\Framework\View\Design\ThemeInterface;
  13. use \PHPUnit_Framework_MockObject_MockObject as MockObject;
  14. /**
  15. * Test for Codes class.
  16. *
  17. * @see Codes
  18. */
  19. class CodesTest extends \PHPUnit\Framework\TestCase
  20. {
  21. /**
  22. * @var Filesystem|MockObject
  23. */
  24. private $fileSystemMock;
  25. /**
  26. * @var FlyweightFactory|MockObject
  27. */
  28. private $flyweightFactoryMock;
  29. /**
  30. * @var Codes
  31. */
  32. private $model;
  33. /**
  34. * @inheritdoc
  35. */
  36. protected function setUp()
  37. {
  38. $this->fileSystemMock = $this->getMockBuilder(Filesystem::class)
  39. ->disableOriginalConstructor()
  40. ->getMock();
  41. $this->flyweightFactoryMock = $this->getMockBuilder(FlyweightFactory::class)
  42. ->disableOriginalConstructor()
  43. ->getMock();
  44. $this->model = new Codes(
  45. $this->flyweightFactoryMock,
  46. $this->fileSystemMock
  47. );
  48. }
  49. public function testGetList()
  50. {
  51. $code = 'code';
  52. $area = 'area';
  53. $fullPath = 'some/full/path';
  54. $themeMock = $this->getMockBuilder(ThemeInterface::class)
  55. ->getMockForAbstractClass();
  56. $themeMock->expects($this->once())
  57. ->method('getFullPath')
  58. ->willReturn($fullPath);
  59. $this->flyweightFactoryMock->expects($this->once())
  60. ->method('create')
  61. ->with($code, $area)
  62. ->willReturn($themeMock);
  63. $reader = $this->getMockBuilder(ReadInterface::class)
  64. ->getMockForAbstractClass();
  65. $reader->expects($this->once())
  66. ->method('read')
  67. ->with($fullPath)
  68. ->willReturn([
  69. $fullPath . '/de_DE',
  70. $fullPath . '/en_US',
  71. $fullPath . '/fr_FR'
  72. ]);
  73. $this->fileSystemMock->expects($this->once())
  74. ->method('getDirectoryRead')
  75. ->with(DirectoryList::STATIC_VIEW)
  76. ->willReturn($reader);
  77. $this->assertEquals(
  78. [
  79. 'de_DE',
  80. 'en_US',
  81. 'fr_FR'
  82. ],
  83. $this->model->getList($code, $area)
  84. );
  85. }
  86. }