PathTest.php 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. /**
  7. * Test of image path model
  8. */
  9. namespace Magento\Theme\Test\Unit\Model\Theme\Image;
  10. use \Magento\Theme\Model\Theme\Image\Path;
  11. use Magento\Framework\App\Filesystem\DirectoryList;
  12. use Magento\Framework\View\Design\Theme\Image\PathInterface;
  13. class PathTest extends \PHPUnit\Framework\TestCase
  14. {
  15. /**
  16. * @var \Magento\Theme\Model\Theme\Image\Path|\PHPUnit_Framework_MockObject_MockObject
  17. */
  18. protected $model;
  19. /**
  20. * @var \PHPUnit_Framework_MockObject_MockObject
  21. */
  22. protected $filesystem;
  23. /**
  24. * @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Framework\View\Asset\Repository
  25. */
  26. protected $_assetRepo;
  27. /**
  28. * @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Store\Model\StoreManager
  29. */
  30. protected $_storeManager;
  31. /**
  32. * @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Framework\Filesystem\Directory\ReadInterface
  33. */
  34. protected $mediaDirectory;
  35. protected function setUp()
  36. {
  37. $this->filesystem = $this->createMock(\Magento\Framework\Filesystem::class);
  38. $this->mediaDirectory = $this->createMock(\Magento\Framework\Filesystem\Directory\ReadInterface::class);
  39. $this->_assetRepo = $this->createMock(\Magento\Framework\View\Asset\Repository::class);
  40. $this->_storeManager = $this->createMock(\Magento\Store\Model\StoreManager::class);
  41. $this->mediaDirectory->expects($this->any())
  42. ->method('getRelativePath')
  43. ->with('/theme/origin')
  44. ->will($this->returnValue('/theme/origin'));
  45. $this->filesystem->expects($this->any())->method('getDirectoryRead')
  46. ->with(DirectoryList::MEDIA)
  47. ->will($this->returnValue($this->mediaDirectory));
  48. $this->model = new Path(
  49. $this->filesystem,
  50. $this->_assetRepo,
  51. $this->_storeManager
  52. );
  53. $this->_model = new Path($this->filesystem, $this->_assetRepo, $this->_storeManager);
  54. }
  55. public function testGetPreviewImageUrl()
  56. {
  57. /** @var $theme \Magento\Theme\Model\Theme|\PHPUnit_Framework_MockObject_MockObject */
  58. $theme = $this->createPartialMock(
  59. \Magento\Theme\Model\Theme::class,
  60. ['getPreviewImage', 'isPhysical', '__wakeup']
  61. );
  62. $theme->expects($this->any())
  63. ->method('getPreviewImage')
  64. ->will($this->returnValue('image.png'));
  65. $store = $this->createMock(\Magento\Store\Model\Store::class);
  66. $store->expects($this->any())->method('getBaseUrl')->will($this->returnValue('http://localhost/'));
  67. $this->_storeManager->expects($this->any())->method('getStore')->will($this->returnValue($store));
  68. $this->assertEquals('http://localhost/theme/preview/image.png', $this->model->getPreviewImageUrl($theme));
  69. }
  70. public function testGetPreviewImagePath()
  71. {
  72. $previewImage = 'preview.jpg';
  73. $expectedPath = 'theme/preview/preview.jpg';
  74. /** @var $theme \Magento\Theme\Model\Theme|\PHPUnit_Framework_MockObject_MockObject */
  75. $theme = $this->createPartialMock(
  76. \Magento\Theme\Model\Theme::class,
  77. ['getPreviewImage', 'isPhysical', '__wakeup']
  78. );
  79. $this->mediaDirectory->expects($this->once())
  80. ->method('getAbsolutePath')
  81. ->with(PathInterface::PREVIEW_DIRECTORY_PATH . '/' . $previewImage)
  82. ->willReturn($expectedPath);
  83. $theme->expects($this->once())
  84. ->method('getPreviewImage')
  85. ->will($this->returnValue($previewImage));
  86. $result = $this->model->getPreviewImagePath($theme);
  87. $this->assertEquals($expectedPath, $result);
  88. }
  89. /**
  90. * @covers Magento\Theme\Model\Theme\Image\Path::getPreviewImageDefaultUrl
  91. */
  92. public function testDefaultPreviewImageUrlGetter()
  93. {
  94. $this->_assetRepo->expects($this->once())->method('getUrl')
  95. ->with(\Magento\Theme\Model\Theme\Image\Path::DEFAULT_PREVIEW_IMAGE);
  96. $this->model->getPreviewImageDefaultUrl();
  97. }
  98. /**
  99. * @covers \Magento\Theme\Model\Theme\Image\Path::getImagePreviewDirectory
  100. */
  101. public function testImagePreviewDirectoryGetter()
  102. {
  103. $this->mediaDirectory->expects($this->any())
  104. ->method('getAbsolutePath')
  105. ->with(\Magento\Framework\View\Design\Theme\Image\PathInterface::PREVIEW_DIRECTORY_PATH)
  106. ->will($this->returnValue('/theme/preview'));
  107. $this->assertEquals(
  108. '/theme/preview',
  109. $this->model->getImagePreviewDirectory()
  110. );
  111. }
  112. /**
  113. * @covers \Magento\Theme\Model\Theme\Image\Path::getTemporaryDirectory
  114. */
  115. public function testTemporaryDirectoryGetter()
  116. {
  117. $this->assertEquals(
  118. '/theme/origin',
  119. $this->model->getTemporaryDirectory()
  120. );
  121. }
  122. }