PageRenderTime 46ms CodeModel.GetById 15ms RepoModel.GetById 1ms app.codeStats 0ms

/vendor/magento/module-product-video/Test/Unit/Model/Product/Attribute/Media/ExternalVideoEntryConverterTest.php

https://gitlab.com/yousafsyed/easternglamor
PHP | 231 lines | 167 code | 36 blank | 28 comment | 0 complexity | 847d7013eb5df7467dfe3644d314661c MD5 | raw file
  1. <?php
  2. /**
  3. * Copyright © 2016 Magento. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\ProductVideo\Test\Unit\Model\Product\Attribute\Media;
  7. use Magento\ProductVideo\Model\Product\Attribute\Media\ExternalVideoEntryConverter;
  8. class ExternalVideoEntryConverterTest extends \PHPUnit_Framework_TestCase
  9. {
  10. /**
  11. * @var \PHPUnit_Framework_MockObject_MockObject
  12. * |\Magento\Catalog\Api\Data\ProductAttributeMediaGalleryEntryInterfaceFactory
  13. */
  14. protected $mediaGalleryEntryFactoryMock;
  15. /**
  16. * @var \PHPUnit_Framework_MockObject_MockObject
  17. * |\Magento\Catalog\Api\Data\ProductAttributeMediaGalleryEntryInterface
  18. */
  19. protected $mediaGalleryEntryMock;
  20. /** @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Framework\Api\DataObjectHelper */
  21. protected $dataObjectHelperMock;
  22. /** @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Framework\Api\Data\VideoContentInterfaceFactory */
  23. protected $videoEntryFactoryMock;
  24. /** @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Framework\Api\Data\VideoContentInterface */
  25. protected $videoEntryMock;
  26. /**
  27. * @var \PHPUnit_Framework_MockObject_MockObject
  28. * |\Magento\Catalog\Api\Data\ProductAttributeMediaGalleryEntryExtensionFactory
  29. */
  30. protected $mediaGalleryEntryExtensionFactoryMock;
  31. /**
  32. * @var \PHPUnit_Framework_MockObject_MockObject
  33. * |\Magento\Catalog\Api\Data\ProductAttributeMediaGalleryEntryExtensionFactory
  34. */
  35. protected $mediaGalleryEntryExtensionMock;
  36. /**
  37. * @var \Magento\Framework\TestFramework\Unit\Helper\ObjectManager
  38. * |\Magento\ProductVideo\Model\Product\Attribute\Media\ExternalVideoEntryConverter
  39. */
  40. protected $modelObject;
  41. public function setUp()
  42. {
  43. $this->mediaGalleryEntryFactoryMock =
  44. $this->getMock(
  45. '\Magento\Catalog\Api\Data\ProductAttributeMediaGalleryEntryInterfaceFactory',
  46. ['create'],
  47. [],
  48. '',
  49. false
  50. );
  51. $this->mediaGalleryEntryMock =
  52. $this->getMock(
  53. '\Magento\Catalog\Api\Data\ProductAttributeMediaGalleryEntryInterface',
  54. [
  55. 'getId',
  56. 'setId',
  57. 'getMediaType',
  58. 'setMediaType',
  59. 'getLabel',
  60. 'setLabel',
  61. 'getPosition',
  62. 'setPosition',
  63. 'isDisabled',
  64. 'setDisabled',
  65. 'getTypes',
  66. 'setTypes',
  67. 'getFile',
  68. 'setFile',
  69. 'getContent',
  70. 'setContent',
  71. 'getExtensionAttributes',
  72. 'setExtensionAttributes'
  73. ],
  74. [],
  75. '',
  76. false
  77. );
  78. $this->mediaGalleryEntryFactoryMock->expects($this->any())->method('create')->willReturn(
  79. $this->mediaGalleryEntryMock
  80. );
  81. $this->dataObjectHelperMock = $this->getMock('\Magento\Framework\Api\DataObjectHelper', [], [], '', false);
  82. $this->videoEntryFactoryMock =
  83. $this->getMock('\Magento\Framework\Api\Data\VideoContentInterfaceFactory', ['create'], [], '', false);
  84. $this->videoEntryMock = $this->getMock('\Magento\Framework\Api\Data\VideoContentInterface', [], [], '', false);
  85. $this->videoEntryFactoryMock->expects($this->any())->method('create')->willReturn($this->videoEntryMock);
  86. $this->mediaGalleryEntryExtensionFactoryMock =
  87. $this->getMock(
  88. '\Magento\Catalog\Api\Data\ProductAttributeMediaGalleryEntryExtensionFactory',
  89. ['create'],
  90. [],
  91. '',
  92. false
  93. );
  94. $this->mediaGalleryEntryExtensionMock = $this->getMock(
  95. '\Magento\Catalog\Api\Data\ProductAttributeMediaGalleryEntryExtension',
  96. ['setVideoContent', 'getVideoContent', 'getVideoProvider'],
  97. [],
  98. '',
  99. false
  100. );
  101. $this->mediaGalleryEntryExtensionMock->expects($this->any())->method('setVideoContent')->willReturn(null);
  102. $this->mediaGalleryEntryExtensionFactoryMock->expects($this->any())->method('create')->willReturn(
  103. $this->mediaGalleryEntryExtensionMock
  104. );
  105. $objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
  106. $this->modelObject = $objectManager->getObject(
  107. '\Magento\ProductVideo\Model\Product\Attribute\Media\ExternalVideoEntryConverter',
  108. [
  109. 'mediaGalleryEntryFactory' => $this->mediaGalleryEntryFactoryMock,
  110. 'dataObjectHelper' => $this->dataObjectHelperMock,
  111. 'videoEntryFactory' => $this->videoEntryFactoryMock,
  112. 'mediaGalleryEntryExtensionFactory' => $this->mediaGalleryEntryExtensionFactoryMock
  113. ]
  114. );
  115. }
  116. public function testGetMediaEntryType()
  117. {
  118. $this->assertEquals($this->modelObject->getMediaEntryType(), 'external-video');
  119. }
  120. public function testConvertTo()
  121. {
  122. /** @var $product \PHPUnit_Framework_MockObject_MockObject|\Magento\Catalog\Model\Product */
  123. $product = $this->getMock('\Magento\Catalog\Model\Product', [], [], '', false);
  124. $rowData = [
  125. 'value_id' => '4',
  126. 'file' => '/i/n/index111111.jpg',
  127. 'media_type' => ExternalVideoEntryConverter::MEDIA_TYPE_CODE,
  128. 'entity_id' => '1',
  129. 'label' => '',
  130. 'position' => '3',
  131. 'disabled' => '0',
  132. 'label_default' => null,
  133. 'position_default' => '3',
  134. 'disabled_default' => '0',
  135. 'video_provider' => null,
  136. 'video_url' => 'https://www.youtube.com/watch?v=abcdefghij',
  137. 'video_title' => '111',
  138. 'video_description' => null,
  139. 'video_metadata' => null,
  140. ];
  141. $productImages = [
  142. 'image' => '/s/a/sample_3.jpg',
  143. 'small_image' => '/s/a/sample-1_1.jpg',
  144. 'thumbnail' => '/s/a/sample-1_1.jpg',
  145. 'swatch_image' => '/s/a/sample_3.jpg',
  146. ];
  147. $product->expects($this->once())->method('getMediaAttributeValues')->willReturn($productImages);
  148. $this->mediaGalleryEntryMock->expects($this->once())->method('setExtensionAttributes')->will(
  149. $this->returnSelf()
  150. );
  151. $this->modelObject->convertTo($product, $rowData);
  152. }
  153. public function testConvertFrom()
  154. {
  155. $this->mediaGalleryEntryMock->expects($this->once())->method('getId')->willReturn('4');
  156. $this->mediaGalleryEntryMock->expects($this->once())->method('getFile')->willReturn('/i/n/index111111.jpg');
  157. $this->mediaGalleryEntryMock->expects($this->once())->method('getLabel')->willReturn('Some Label');
  158. $this->mediaGalleryEntryMock->expects($this->once())->method('getPosition')->willReturn('3');
  159. $this->mediaGalleryEntryMock->expects($this->once())->method('isDisabled')->willReturn('0');
  160. $this->mediaGalleryEntryMock->expects($this->once())->method('getTypes')->willReturn([]);
  161. $this->mediaGalleryEntryMock->expects($this->once())->method('getContent')->willReturn(null);
  162. $this->mediaGalleryEntryMock->expects($this->once())->method('getExtensionAttributes')->willReturn(
  163. $this->mediaGalleryEntryExtensionMock
  164. );
  165. $videoContentMock =
  166. $this->getMock('Magento\ProductVideo\Model\Product\Attribute\Media\VideoEntry', [], [], '', false);
  167. $videoContentMock->expects($this->once())->method('getVideoProvider')->willReturn('youtube');
  168. $videoContentMock->expects($this->once())->method('getVideoUrl')->willReturn(
  169. 'https://www.youtube.com/watch?v=abcdefghij'
  170. );
  171. $videoContentMock->expects($this->once())->method('getVideoTitle')->willReturn('Some video title');
  172. $videoContentMock->expects($this->once())->method('getVideoDescription')->willReturn('Some video description');
  173. $videoContentMock->expects($this->once())->method('getVideoMetadata')->willReturn('Meta data');
  174. $this->mediaGalleryEntryExtensionMock->expects($this->once())->method('getVideoContent')->willReturn(
  175. $videoContentMock
  176. );
  177. $expectedResult = [
  178. 'value_id' => '4',
  179. 'file' => '/i/n/index111111.jpg',
  180. 'label' => 'Some Label',
  181. 'position' => '3',
  182. 'disabled' => '0',
  183. 'types' => [],
  184. 'media_type' => null,
  185. 'content' => null,
  186. 'video_provider' => 'youtube',
  187. 'video_url' => 'https://www.youtube.com/watch?v=abcdefghij',
  188. 'video_title' => 'Some video title',
  189. 'video_description' => 'Some video description',
  190. 'video_metadata' => 'Meta data',
  191. ];
  192. $result = $this->modelObject->convertFrom($this->mediaGalleryEntryMock);
  193. $this->assertEquals($expectedResult, $result);
  194. }
  195. }