ConfigTest.php 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\RequireJs\Test\Unit\Block\Html\Head;
  7. use \Magento\RequireJs\Block\Html\Head\Config;
  8. class ConfigTest extends \PHPUnit\Framework\TestCase
  9. {
  10. /**
  11. * @var \Magento\Framework\View\Element\Context|\PHPUnit_Framework_MockObject_MockObject
  12. */
  13. private $context;
  14. /**
  15. * @var \Magento\Framework\RequireJs\Config|\PHPUnit_Framework_MockObject_MockObject
  16. */
  17. private $config;
  18. /**
  19. * @var \Magento\RequireJs\Model\FileManager|\PHPUnit_Framework_MockObject_MockObject
  20. */
  21. private $fileManager;
  22. /**
  23. * @var \Magento\Framework\View\Page\Config|\PHPUnit_Framework_MockObject_MockObject
  24. */
  25. protected $pageConfig;
  26. /**
  27. * @var Config
  28. */
  29. protected $blockConfig;
  30. /**
  31. * @var \Magento\Framework\View\Asset\ConfigInterface|\PHPUnit_Framework_MockObject_MockObject
  32. */
  33. protected $bundleConfig;
  34. /**
  35. * @var \Magento\Framework\View\Asset\Minification|\PHPUnit_Framework_MockObject_MockObject
  36. */
  37. private $minificationMock;
  38. protected function setUp()
  39. {
  40. $this->context = $this->createMock(\Magento\Framework\View\Element\Context::class);
  41. $this->config = $this->createMock(\Magento\Framework\RequireJs\Config::class);
  42. $this->fileManager = $this->createMock(\Magento\RequireJs\Model\FileManager::class);
  43. $this->pageConfig = $this->createMock(\Magento\Framework\View\Page\Config::class);
  44. $this->bundleConfig = $this->createMock(\Magento\Framework\View\Asset\ConfigInterface::class);
  45. }
  46. public function testSetLayout()
  47. {
  48. $this->bundleConfig
  49. ->expects($this->once())
  50. ->method('isBundlingJsFiles')
  51. ->willReturn(true);
  52. $filePath = 'require_js_fie_path';
  53. $asset = $this->getMockForAbstractClass(\Magento\Framework\View\Asset\LocalInterface::class);
  54. $asset->expects($this->atLeastOnce())
  55. ->method('getFilePath')
  56. ->willReturn($filePath);
  57. $requireJsAsset = $this->getMockForAbstractClass(\Magento\Framework\View\Asset\LocalInterface::class);
  58. $requireJsAsset
  59. ->expects($this->atLeastOnce())
  60. ->method('getFilePath')
  61. ->willReturn('/path/to/require/require.js');
  62. $minResolverAsset = $this->getMockForAbstractClass(\Magento\Framework\View\Asset\LocalInterface::class);
  63. $minResolverAsset
  64. ->expects($this->atLeastOnce())
  65. ->method('getFilePath')
  66. ->willReturn('/path/to/require/require-min-resolver.js');
  67. $this->fileManager
  68. ->expects($this->once())
  69. ->method('createRequireJsConfigAsset')
  70. ->will($this->returnValue($requireJsAsset));
  71. $this->fileManager
  72. ->expects($this->once())
  73. ->method('createRequireJsMixinsAsset')
  74. ->will($this->returnValue($requireJsAsset));
  75. $this->fileManager
  76. ->expects($this->once())
  77. ->method('createStaticJsAsset')
  78. ->will($this->returnValue($requireJsAsset));
  79. $this->fileManager
  80. ->expects($this->once())
  81. ->method('createBundleJsPool')
  82. ->will($this->returnValue([$asset]));
  83. $this->fileManager
  84. ->expects($this->once())
  85. ->method('createMinResolverAsset')
  86. ->will($this->returnValue($minResolverAsset));
  87. $layout = $this->createMock(\Magento\Framework\View\LayoutInterface::class);
  88. $assetCollection = $this->getMockBuilder(\Magento\Framework\View\Asset\GroupedCollection::class)
  89. ->disableOriginalConstructor()
  90. ->getMock();
  91. $this->pageConfig->expects($this->atLeastOnce())
  92. ->method('getAssetCollection')
  93. ->willReturn($assetCollection);
  94. $assetCollection
  95. ->expects($this->atLeastOnce())
  96. ->method('insert')
  97. ->willReturn(true);
  98. $this->minificationMock = $this->getMockBuilder(\Magento\Framework\View\Asset\Minification::class)
  99. ->disableOriginalConstructor()
  100. ->getMock();
  101. $this->minificationMock
  102. ->expects($this->any())
  103. ->method('isEnabled')
  104. ->with('js')
  105. ->willReturn(true);
  106. $object = new Config(
  107. $this->context,
  108. $this->config,
  109. $this->fileManager,
  110. $this->pageConfig,
  111. $this->bundleConfig,
  112. $this->minificationMock
  113. );
  114. $object->setLayout($layout);
  115. }
  116. }