SignatureTest.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Theme\Test\Unit\Model\Url\Plugin;
  7. use \Magento\Theme\Model\Url\Plugin\Signature;
  8. class SignatureTest extends \PHPUnit\Framework\TestCase
  9. {
  10. /**
  11. * @var Signature
  12. */
  13. private $object;
  14. /**
  15. * @var \PHPUnit_Framework_MockObject_MockObject
  16. */
  17. private $config;
  18. /**
  19. * @var \PHPUnit_Framework_MockObject_MockObject
  20. */
  21. private $deploymentVersion;
  22. protected function setUp()
  23. {
  24. $this->config = $this->createMock(\Magento\Framework\View\Url\ConfigInterface::class);
  25. $this->deploymentVersion = $this->createMock(\Magento\Framework\App\View\Deployment\Version::class);
  26. $this->object = new Signature($this->config, $this->deploymentVersion);
  27. }
  28. /**
  29. * @param bool|int $fixtureConfigFlag
  30. * @param string $inputUrlType
  31. * @dataProvider afterGetBaseUrlInactiveDataProvider
  32. */
  33. public function testAfterGetBaseUrlInactive($fixtureConfigFlag, $inputUrlType)
  34. {
  35. $this->config
  36. ->expects($this->any())
  37. ->method('getValue')
  38. ->with(Signature::XML_PATH_STATIC_FILE_SIGNATURE)
  39. ->will($this->returnValue($fixtureConfigFlag));
  40. $this->deploymentVersion->expects($this->never())->method($this->anything());
  41. $url = $this->getMockForAbstractClass(\Magento\Framework\Url\ScopeInterface::class);
  42. $actualResult = $this->object->afterGetBaseUrl($url, 'http://127.0.0.1/magento/pub/static/', $inputUrlType);
  43. $this->assertEquals('http://127.0.0.1/magento/pub/static/', $actualResult);
  44. }
  45. /**
  46. * @return array
  47. */
  48. public function afterGetBaseUrlInactiveDataProvider()
  49. {
  50. return [
  51. 'disabled in config, relevant URL type' => [0, \Magento\Framework\UrlInterface::URL_TYPE_STATIC],
  52. 'enabled in config, irrelevant URL type' => [1, \Magento\Framework\UrlInterface::URL_TYPE_LINK],
  53. ];
  54. }
  55. public function testAroundGetBaseUrlActive()
  56. {
  57. $this->config
  58. ->expects($this->once())
  59. ->method('getValue')
  60. ->with(Signature::XML_PATH_STATIC_FILE_SIGNATURE)
  61. ->will($this->returnValue(1));
  62. $this->deploymentVersion->expects($this->once())->method('getValue')->will($this->returnValue('123'));
  63. $url = $this->getMockForAbstractClass(\Magento\Framework\Url\ScopeInterface::class);
  64. $actualResult = $this->object->afterGetBaseUrl(
  65. $url,
  66. 'http://127.0.0.1/magento/pub/static/',
  67. \Magento\Framework\UrlInterface::URL_TYPE_STATIC
  68. );
  69. $this->assertEquals('http://127.0.0.1/magento/pub/static/version123/', $actualResult);
  70. }
  71. }