JsTest.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Translation\Test\Unit\Block;
  7. use Magento\Translation\Block\Js;
  8. class JsTest extends \PHPUnit\Framework\TestCase
  9. {
  10. /**
  11. * @var Js
  12. */
  13. protected $model;
  14. /**
  15. * @var \PHPUnit_Framework_MockObject_MockObject
  16. */
  17. protected $configMock;
  18. /**
  19. * @var \PHPUnit_Framework_MockObject_MockObject
  20. */
  21. protected $fileManagerMock;
  22. protected function setUp()
  23. {
  24. $objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
  25. $this->configMock = $this->getMockBuilder(\Magento\Translation\Model\Js\Config::class)
  26. ->disableOriginalConstructor()
  27. ->getMock();
  28. $this->fileManagerMock = $this->getMockBuilder(\Magento\Translation\Model\FileManager::class)
  29. ->disableOriginalConstructor()
  30. ->getMock();
  31. $this->model = $objectManager->getObject(
  32. \Magento\Translation\Block\Js::class,
  33. [
  34. 'config' => $this->configMock,
  35. 'fileManager' => $this->fileManagerMock
  36. ]
  37. );
  38. }
  39. public function testIsDictionaryStrategy()
  40. {
  41. $this->configMock->expects($this->once())
  42. ->method('dictionaryEnabled')
  43. ->willReturn(true);
  44. $this->assertTrue($this->model->dictionaryEnabled());
  45. }
  46. public function testGetTranslationFileTimestamp()
  47. {
  48. $this->fileManagerMock->expects($this->once())
  49. ->method('getTranslationFileTimestamp')
  50. ->willReturn(1445736974);
  51. $this->assertEquals(1445736974, $this->model->getTranslationFileTimestamp());
  52. }
  53. public function testGetTranslationFilePath()
  54. {
  55. $this->fileManagerMock->expects($this->once())
  56. ->method('getTranslationFilePath')
  57. ->willReturn('frontend/Magento/luma/en_EN');
  58. $this->assertEquals('frontend/Magento/luma/en_EN', $this->model->getTranslationFilePath());
  59. }
  60. public function testGetTranslationFileVersion()
  61. {
  62. $version = sha1('translationFile');
  63. $this->fileManagerMock->expects($this->once())
  64. ->method('getTranslationFileVersion')
  65. ->willReturn($version);
  66. $this->assertEquals($version, $this->model->getTranslationFileVersion());
  67. }
  68. }