Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions | Protected Member Functions | Protected Attributes
LinkTest Class Reference
Inheritance diagram for LinkTest:

Public Member Functions

 testExecuteFile ($fileType)
 
 testExecuteUrl ($fileType)
 
 executeDataProvider ()
 

Protected Member Functions

 setUp ()
 

Protected Attributes

 $link
 
 $objectManagerHelper
 
 $request
 
 $response
 
 $linkModel
 
 $objectManager
 
 $fileHelper
 
 $downloadHelper
 

Detailed Description

Definition at line 11 of file LinkTest.php.

Member Function Documentation

◆ executeDataProvider()

executeDataProvider ( )
Returns
array

Definition at line 220 of file LinkTest.php.

221  {
222  return [
223  ['link'],
224  ['sample']
225  ];
226  }

◆ setUp()

setUp ( )
protected

Definition at line 49 of file LinkTest.php.

50  {
51  $this->objectManagerHelper = new ObjectManagerHelper($this);
52 
53  $this->request = $this->getMockBuilder(\Magento\Framework\App\Request\Http::class)
54  ->disableOriginalConstructor()->getMock();
55  $this->response = $this->createPartialMock(
56  \Magento\Framework\App\ResponseInterface::class,
57  [
58  'setHttpResponseCode',
59  'clearBody',
60  'sendHeaders',
61  'sendResponse',
62  'setHeader'
63  ]
64  );
65  $this->fileHelper = $this->createPartialMock(\Magento\Downloadable\Helper\File::class, [
66  'getFilePath'
67  ]);
68  $this->downloadHelper = $this->createPartialMock(\Magento\Downloadable\Helper\Download::class, [
69  'setResource',
70  'getFilename',
71  'getContentType',
72  'output',
73  'getFileSize',
74  'getContentDisposition'
75  ]);
76  $this->linkModel = $this->createPartialMock(
77  \Magento\Downloadable\Controller\Adminhtml\Downloadable\Product\Edit\Link::class,
78  [
79  'load',
80  'getId',
81  'getLinkType',
82  'getLinkUrl',
83  'getSampleUrl',
84  'getSampleType',
85  'getBasePath',
86  'getBaseSamplePath',
87  'getLinkFile',
88  'getSampleFile'
89  ]
90  );
91  $this->objectManager = $this->createPartialMock(\Magento\Framework\ObjectManager\ObjectManager::class, [
92  'create',
93  'get'
94  ]);
95 
96  $this->link = $this->objectManagerHelper->getObject(
97  \Magento\Downloadable\Controller\Adminhtml\Downloadable\Product\Edit\Link::class,
98  [
99  'objectManager' => $this->objectManager,
100  'request' => $this->request,
101  'response' => $this->response
102  ]
103  );
104  }

◆ testExecuteFile()

testExecuteFile (   $fileType)

@dataProvider executeDataProvider

Parameters
string$fileType

Definition at line 110 of file LinkTest.php.

111  {
112  $fileSize = 58493;
113  $fileName = 'link.jpg';
114  $this->request->expects($this->at(0))->method('getParam')->with('id', 0)
115  ->will($this->returnValue(1));
116  $this->request->expects($this->at(1))->method('getParam')->with('type', 0)
117  ->will($this->returnValue($fileType));
118  $this->response->expects($this->once())->method('setHttpResponseCode')
119  ->will($this->returnSelf());
120  $this->response->expects($this->once())->method('clearBody')
121  ->will($this->returnSelf());
122  $this->response
123  ->expects($this->any())
124  ->method('setHeader')
125  ->withConsecutive(
126  ['Pragma', 'public', true],
127  [
128  'Cache-Control',
129  'must-revalidate, post-check=0, pre-check=0',
130  true,
131  ],
132  ['Content-type', 'text/html'],
133  ['Content-Length', $fileSize],
134  ['Content-Disposition', 'attachment; filename=' . $fileName]
135  )
136  ->will($this->returnSelf());
137  $this->response->expects($this->once())->method('sendHeaders')
138  ->will($this->returnSelf());
139  $this->objectManager->expects($this->at(1))->method('get')->with(\Magento\Downloadable\Helper\File::class)
140  ->will($this->returnValue($this->fileHelper));
141  $this->objectManager->expects($this->at(2))->method('get')->with(\Magento\Downloadable\Model\Link::class)
142  ->will($this->returnValue($this->linkModel));
143  $this->objectManager->expects($this->at(3))->method('get')->with(\Magento\Downloadable\Helper\Download::class)
144  ->will($this->returnValue($this->downloadHelper));
145  $this->fileHelper->expects($this->once())->method('getFilePath')
146  ->will($this->returnValue('filepath/' . $fileType . '.jpg'));
147  $this->downloadHelper->expects($this->once())->method('setResource')
148  ->will($this->returnSelf());
149  $this->downloadHelper->expects($this->once())->method('getFilename')
150  ->will($this->returnValue($fileName));
151  $this->downloadHelper->expects($this->once())->method('getContentType')
152  ->willReturn('text/html');
153  $this->downloadHelper->expects($this->once())->method('getFileSize')
154  ->will($this->returnValue($fileSize));
155  $this->downloadHelper->expects($this->once())->method('getContentDisposition')
156  ->will($this->returnValue('inline'));
157  $this->downloadHelper->expects($this->once())->method('output')
158  ->will($this->returnSelf());
159  $this->linkModel->expects($this->once())->method('load')
160  ->will($this->returnSelf());
161  $this->linkModel->expects($this->once())->method('getId')
162  ->will($this->returnValue('1'));
163  $this->linkModel->expects($this->any())->method('get' . $fileType . 'Type')
164  ->will($this->returnValue('file'));
165  $this->objectManager->expects($this->once())->method('create')
166  ->will($this->returnValue($this->linkModel));
167 
168  $this->link->execute();
169  }
$fileName
Definition: translate.phtml:15

◆ testExecuteUrl()

testExecuteUrl (   $fileType)

@dataProvider executeDataProvider

Parameters
string$fileType

Definition at line 175 of file LinkTest.php.

176  {
177  $this->request->expects($this->at(0))->method('getParam')
178  ->with('id', 0)->will($this->returnValue(1));
179  $this->request->expects($this->at(1))->method('getParam')
180  ->with('type', 0)->will($this->returnValue($fileType));
181  $this->response->expects($this->once())->method('setHttpResponseCode')
182  ->will($this->returnSelf());
183  $this->response->expects($this->once())->method('clearBody')
184  ->will($this->returnSelf());
185  $this->response->expects($this->any())->method('setHeader')
186  ->will($this->returnSelf());
187  $this->response->expects($this->once())->method('sendHeaders')
188  ->will($this->returnSelf());
189  $this->objectManager->expects($this->at(1))->method('get')->with(\Magento\Downloadable\Helper\Download::class)
190  ->will($this->returnValue($this->downloadHelper));
191  $this->downloadHelper->expects($this->once())->method('setResource')
192  ->will($this->returnSelf());
193  $this->downloadHelper->expects($this->once())->method('getFilename')
194  ->will($this->returnValue('link.jpg'));
195  $this->downloadHelper->expects($this->once())->method('getContentType')
196  ->will($this->returnSelf('url'));
197  $this->downloadHelper->expects($this->once())->method('getFileSize')
198  ->will($this->returnValue(null));
199  $this->downloadHelper->expects($this->once())->method('getContentDisposition')
200  ->will($this->returnValue(null));
201  $this->downloadHelper->expects($this->once())->method('output')
202  ->will($this->returnSelf());
203  $this->linkModel->expects($this->once())->method('load')
204  ->will($this->returnSelf());
205  $this->linkModel->expects($this->once())->method('getId')
206  ->will($this->returnValue('1'));
207  $this->linkModel->expects($this->once())->method('get' . $fileType . 'Type')
208  ->will($this->returnValue('url'));
209  $this->linkModel->expects($this->once())->method('get' . $fileType . 'Url')
210  ->will($this->returnValue('http://url.magento.com'));
211  $this->objectManager->expects($this->once())->method('create')
212  ->will($this->returnValue($this->linkModel));
213 
214  $this->link->execute();
215  }

Field Documentation

◆ $downloadHelper

$downloadHelper
protected

Definition at line 47 of file LinkTest.php.

◆ $fileHelper

$fileHelper
protected

Definition at line 42 of file LinkTest.php.

◆ $link

$link
protected

Definition at line 14 of file LinkTest.php.

◆ $linkModel

$linkModel
protected

Definition at line 32 of file LinkTest.php.

◆ $objectManager

$objectManager
protected

Definition at line 37 of file LinkTest.php.

◆ $objectManagerHelper

$objectManagerHelper
protected

Definition at line 17 of file LinkTest.php.

◆ $request

$request
protected

Definition at line 22 of file LinkTest.php.

◆ $response

$response
protected

Definition at line 27 of file LinkTest.php.


The documentation for this class was generated from the following file: