PageRenderTime 42ms CodeModel.GetById 17ms RepoModel.GetById 1ms app.codeStats 0ms

/vendor/magento/module-downloadable/Test/Unit/Block/Adminhtml/Catalog/Product/Edit/Tab/Downloadable/SamplesTest.php

https://gitlab.com/yousafsyed/easternglamor
PHP | 182 lines | 138 code | 13 blank | 31 comment | 0 complexity | e44ac2e4d73c1651ef10073e48378c58 MD5 | raw file
  1. <?php
  2. /**
  3. * Copyright © 2016 Magento. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Downloadable\Test\Unit\Block\Adminhtml\Catalog\Product\Edit\Tab\Downloadable;
  7. class SamplesTest extends \PHPUnit_Framework_TestCase
  8. {
  9. /**
  10. * @var \Magento\Downloadable\Block\Adminhtml\Catalog\Product\Edit\Tab\Downloadable\Samples
  11. */
  12. protected $block;
  13. /**
  14. * @var \Magento\Catalog\Model\Product
  15. */
  16. protected $productModel;
  17. /**
  18. * @var \Magento\Downloadable\Model\Product\Type
  19. */
  20. protected $downloadableProductModel;
  21. /**
  22. * @var \Magento\Downloadable\Model\Sample
  23. */
  24. protected $downloadableSampleModel;
  25. /**
  26. * @var \Magento\Framework\Escaper
  27. */
  28. protected $escaper;
  29. /**
  30. * @var \Magento\Downloadable\Helper\File
  31. */
  32. protected $fileHelper;
  33. /**
  34. * @var \Magento\Framework\Registry
  35. */
  36. protected $coreRegistry;
  37. /**
  38. * @var \Magento\Backend\Model\Url
  39. */
  40. protected $urlBuilder;
  41. protected function setUp()
  42. {
  43. $objectManagerHelper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
  44. $this->urlBuilder = $this->getMock('Magento\Backend\Model\Url', ['getUrl'], [], '', false);
  45. $urlFactory = $this->getMock('Magento\Backend\Model\UrlFactory', [], [], '', false);
  46. $this->fileHelper = $this->getMock(
  47. '\Magento\Downloadable\Helper\File',
  48. [
  49. 'getFilePath',
  50. 'ensureFileInFilesystem',
  51. 'getFileSize'
  52. ],
  53. [],
  54. '',
  55. false
  56. );
  57. $this->productModel = $this->getMock(
  58. 'Magento\Catalog\Model\Product',
  59. [
  60. '__wakeup',
  61. 'getTypeId',
  62. 'getTypeInstance',
  63. 'getStoreId'
  64. ],
  65. [],
  66. '',
  67. false
  68. );
  69. $this->downloadableProductModel = $this->getMock(
  70. '\Magento\Downloadable\Model\Product\Type',
  71. [
  72. '__wakeup',
  73. 'getSamples'
  74. ],
  75. [],
  76. '',
  77. false
  78. );
  79. $this->downloadableSampleModel = $this->getMock(
  80. '\Magento\Downloadable\Model\Sample',
  81. [
  82. '__wakeup',
  83. 'getId',
  84. 'getTitle',
  85. 'getSampleFile',
  86. 'getSampleType',
  87. 'getSortOrder'
  88. ],
  89. [],
  90. '',
  91. false
  92. );
  93. $this->coreRegistry = $this->getMock(
  94. '\Magento\Framework\Registry',
  95. [
  96. '__wakeup',
  97. 'registry'
  98. ],
  99. [],
  100. '',
  101. false
  102. );
  103. $this->escaper = $this->getMock('\Magento\Framework\Escaper', ['escapeHtml'], [], '', false);
  104. $this->block = $objectManagerHelper->getObject(
  105. 'Magento\Downloadable\Block\Adminhtml\Catalog\Product\Edit\Tab\Downloadable\Samples',
  106. [
  107. 'urlBuilder' => $this->urlBuilder,
  108. 'urlFactory' => $urlFactory,
  109. 'coreRegistry' => $this->coreRegistry,
  110. 'escaper' => $this->escaper,
  111. 'downloadableFile' => $this->fileHelper]
  112. );
  113. }
  114. /**
  115. * Test that getConfig method retrieve \Magento\Framework\DataObject object
  116. */
  117. public function testGetConfig()
  118. {
  119. $this->assertInstanceOf('Magento\Framework\DataObject', $this->block->getConfig());
  120. }
  121. public function testGetSampleData()
  122. {
  123. $expectingFileData = [
  124. 'sample_file' => [
  125. 'file' => 'file/sample.gif',
  126. 'name' => '<a href="final_url">sample.gif</a>',
  127. 'size' => '1.1',
  128. 'status' => 'old',
  129. ],
  130. ];
  131. $this->productModel->expects($this->any())->method('getTypeId')
  132. ->will($this->returnValue('downloadable'));
  133. $this->productModel->expects($this->any())->method('getTypeInstance')
  134. ->will($this->returnValue($this->downloadableProductModel));
  135. $this->productModel->expects($this->any())->method('getStoreId')
  136. ->will($this->returnValue(0));
  137. $this->downloadableProductModel->expects($this->any())->method('getSamples')
  138. ->will($this->returnValue([$this->downloadableSampleModel]));
  139. $this->coreRegistry->expects($this->any())->method('registry')
  140. ->will($this->returnValue($this->productModel));
  141. $this->downloadableSampleModel->expects($this->any())->method('getId')
  142. ->will($this->returnValue(1));
  143. $this->downloadableSampleModel->expects($this->any())->method('getTitle')
  144. ->will($this->returnValue('Sample Title'));
  145. $this->downloadableSampleModel->expects($this->any())->method('getSampleUrl')
  146. ->will($this->returnValue(null));
  147. $this->downloadableSampleModel->expects($this->any())->method('getSampleFile')
  148. ->will($this->returnValue('file/sample.gif'));
  149. $this->downloadableSampleModel->expects($this->any())->method('getSampleType')
  150. ->will($this->returnValue('file'));
  151. $this->downloadableSampleModel->expects($this->any())->method('getSortOrder')
  152. ->will($this->returnValue(0));
  153. $this->escaper->expects($this->any())->method('escapeHtml')
  154. ->will($this->returnValue('Sample Title'));
  155. $this->fileHelper->expects($this->any())->method('getFilePath')
  156. ->will($this->returnValue('/file/path/sample.gif'));
  157. $this->fileHelper->expects($this->any())->method('ensureFileInFilesystem')
  158. ->will($this->returnValue(true));
  159. $this->fileHelper->expects($this->any())->method('getFileSize')
  160. ->will($this->returnValue('1.1'));
  161. $this->urlBuilder->expects($this->any())->method('getUrl')
  162. ->will($this->returnValue('final_url'));
  163. $sampleData = $this->block->getSampleData();
  164. foreach ($sampleData as $sample) {
  165. $fileSave = $sample->getFileSave(0);
  166. $this->assertEquals($expectingFileData['sample_file'], $fileSave);
  167. }
  168. }
  169. }