80 $resultForwardFactoryMock = $this->getMockBuilder(\
Magento\Framework\Controller\Result\ForwardFactory::class)
81 ->disableOriginalConstructor()
82 ->setMethods([
'create'])
84 $this->resultForwardMock = $this->getMockBuilder(\
Magento\Framework\Controller\Result\Forward::class)
85 ->disableOriginalConstructor()
86 ->setMethods([
'forward'])
88 $resultForwardFactoryMock->expects($this->any())->method(
'create')->willReturn($this->resultForwardMock);
90 $this->downloadMock = $this->getMockBuilder(\
Magento\Sales\Model\Download::class)
91 ->disableOriginalConstructor()
92 ->setMethods([
'downloadFile'])
95 $this->serializerMock = $this->getMockBuilder(Json::class)
96 ->disableOriginalConstructor()
97 ->setMethods([
'serialize',
'unserialize'])
100 $requestMock = $this->getMockBuilder(\
Magento\Framework\
App\Request\Http::class)
101 ->disableOriginalConstructor()
102 ->setMethods([
'getParam'])
104 $requestMock->expects($this->any())->method(
'getParam')
106 $this->returnValueMap(
108 [
'id',
null, self::OPTION_ID],
109 [
'key',
null, self::SECRET_KEY],
114 $this->itemOptionMock = $this->getMockBuilder(\
Magento\Quote\Model\Quote\Item\Option::class)
115 ->disableOriginalConstructor()
116 ->setMethods([
'load',
'getId',
'getCode',
'getProductId',
'getValue'])
119 $this->productOptionMock = $this->getMockBuilder(\
Magento\Catalog\Model\Product\Option::class)
120 ->disableOriginalConstructor()
121 ->setMethods([
'load',
'getId',
'getProductId',
'getType'])
124 $objectManagerMock = $this->getMockBuilder(\
Magento\Sales\Model\Download::class)
125 ->disableOriginalConstructor()
126 ->setMethods([
'create'])
128 $objectManagerMock->expects($this->any())->method(
'create')
130 $this->returnValueMap(
132 [\
Magento\Quote\Model\Quote\Item\Option::class, $this->itemOptionMock],
133 [\
Magento\Catalog\Model\Product\Option::class, $this->productOptionMock],
138 $contextMock = $this->getMockBuilder(\
Magento\Backend\
App\Action\Context::class)
139 ->disableOriginalConstructor()
147 $contextMock->expects($this->once())->method(
'getObjectManager')->willReturn($objectManagerMock);
148 $contextMock->expects($this->once())->method(
'getRequest')->willReturn($requestMock);
150 $this->objectMock = $this->getMockBuilder(\
Magento\Sales\Controller\Download\DownloadCustomOption::class)
151 ->setMethods([
'endExecute'])
152 ->setConstructorArgs(
154 'context' => $contextMock,
155 'resultForwardFactory' => $resultForwardFactoryMock,
156 'download' => $this->downloadMock,
157 'unserialize' => $this->createMock(Unserialize::class),
158 'serializer' => $this->serializerMock
170 public function testExecute($itemOptionValues, $productOptionValues, $noRouteOccurs)
172 if (!empty($itemOptionValues)) {
173 $this->itemOptionMock->expects($this->once())->method(
'load')->willReturnSelf();
174 $this->itemOptionMock->expects($this->once())
176 ->willReturn($itemOptionValues[self::OPTION_ID]);
177 $this->itemOptionMock->expects($this->any())
179 ->willReturn($itemOptionValues[self::OPTION_CODE]);
180 $this->itemOptionMock->expects($this->any())
181 ->method(
'getProductId')
182 ->willReturn($itemOptionValues[self::OPTION_PRODUCT_ID]);
183 $this->itemOptionMock->expects($this->any())
185 ->willReturn($itemOptionValues[self::OPTION_VALUE]);
187 if (!empty($productOptionValues)) {
188 $this->productOptionMock->expects($this->once())->method(
'load')->willReturnSelf();
189 $this->productOptionMock->expects($this->any())
191 ->willReturn($productOptionValues[self::OPTION_ID]);
192 $this->productOptionMock->expects($this->any())
193 ->method(
'getProductId')
194 ->willReturn($productOptionValues[self::OPTION_PRODUCT_ID]);
195 $this->productOptionMock->expects($this->any())
197 ->willReturn($productOptionValues[self::OPTION_TYPE]);
199 if ($noRouteOccurs) {
200 $this->resultForwardMock->expects($this->once())->method(
'forward')->with(
'noroute')->willReturn(
true);
204 $this->serializerMock->expects($this->once())
205 ->method(
'unserialize')
206 ->with($itemOptionValues[self::OPTION_VALUE])
207 ->willReturn($unserializeResult);
209 $this->downloadMock->expects($this->once())
210 ->method(
'downloadFile')
211 ->with($unserializeResult)
214 $this->objectMock->expects($this->once())->method(
'endExecute')->willReturn(
true);
216 $this->objectMock->execute();
241 self::OPTION_ID =>
false,
267 self::OPTION_ID =>
null,
277 self::OPTION_PRODUCT_ID =>
'bad_test_product_ID',
296 self::OPTION_PRODUCT_ID =>
'bad_test_product_ID',
311 self::OPTION_TYPE =>
'bad_test_option_type',
320 $this->itemOptionMock->expects($this->once())->method(
'load')->willReturnSelf();
321 $this->itemOptionMock->expects($this->once())->method(
'getId')->willReturn(self::OPTION_ID);
322 $this->itemOptionMock->expects($this->any())->method(
'getCode')->willReturn(self::OPTION_CODE);
323 $this->itemOptionMock->expects($this->any())->method(
'getProductId')->willReturn(self::OPTION_PRODUCT_ID);
324 $this->itemOptionMock->expects($this->any())->method(
'getValue')->willReturn(self::OPTION_VALUE);
326 $this->productOptionMock->expects($this->once())->method(
'load')->willReturnSelf();
327 $this->productOptionMock->expects($this->any())->method(
'getId')->willReturn(self::OPTION_ID);
328 $this->productOptionMock->expects($this->any())->method(
'getProductId')->willReturn(self::OPTION_PRODUCT_ID);
329 $this->productOptionMock->expects($this->any())->method(
'getType')->willReturn(self::OPTION_TYPE);
331 $this->serializerMock->expects($this->once())
332 ->method(
'unserialize')
333 ->with(self::OPTION_VALUE)
334 ->willReturn([self::SECRET_KEY =>
'bad_test_secret_key']);
336 $this->resultForwardMock->expects($this->once())->method(
'forward')->with(
'noroute')->willReturn(
true);
338 $this->objectMock->execute();
testExecute($itemOptionValues, $productOptionValues, $noRouteOccurs)
testExecuteBadSecretKey()