/** * @param array $itemOptionValues * @param array $productOptionValues * @param bool $noRouteOccurs * @dataProvider executeDataProvider */ public function testExecute($itemOptionValues, $productOptionValues, $noRouteOccurs) { if (!empty($itemOptionValues)) { $this->itemOptionMock->expects($this->once())->method('load')->willReturnSelf(); $this->itemOptionMock->expects($this->once())->method('getId')->willReturn($itemOptionValues[self::OPTION_ID]); $this->itemOptionMock->expects($this->any())->method('getCode')->willReturn($itemOptionValues[self::OPTION_CODE]); $this->itemOptionMock->expects($this->any())->method('getProductId')->willReturn($itemOptionValues[self::OPTION_PRODUCT_ID]); $this->itemOptionMock->expects($this->any())->method('getValue')->willReturn($itemOptionValues[self::OPTION_VALUE]); } if (!empty($productOptionValues)) { $this->productOptionMock->expects($this->once())->method('load')->willReturnSelf(); $this->productOptionMock->expects($this->any())->method('getId')->willReturn($productOptionValues[self::OPTION_ID]); $this->productOptionMock->expects($this->any())->method('getProductId')->willReturn($productOptionValues[self::OPTION_PRODUCT_ID]); $this->productOptionMock->expects($this->any())->method('getType')->willReturn($productOptionValues[self::OPTION_TYPE]); } if ($noRouteOccurs) { $this->resultForwardMock->expects($this->once())->method('forward')->with('noroute')->willReturn(true); } else { $unserializeResult = [self::SECRET_KEY => self::SECRET_KEY]; $this->unserializeMock->expects($this->once())->method('unserialize')->with($itemOptionValues[self::OPTION_VALUE])->willReturn($unserializeResult); $this->downloadMock->expects($this->once())->method('downloadFile')->with($unserializeResult)->willReturn(true); $this->objectMock->expects($this->once())->method('endExecute')->willReturn(true); } $this->objectMock->execute(); }
public function testDownloadFile() { $info = ['order_path' => 'test/path', 'quote_path' => 'test/path2', 'title' => 'test title']; $isFile = true; $isReadable = false; $writeMock = $this->getMockBuilder('Magento\\Framework\\Filesystem\\File\\Write')->disableOriginalConstructor()->getMock(); $writeMock->expects($this->any())->method('lock'); $writeMock->expects($this->any())->method('write'); $writeMock->expects($this->any())->method('unlock'); $writeMock->expects($this->any())->method('close'); $this->writeDirectoryMock->expects($this->any())->method('getAbsolutePath')->will($this->returnArgument(0)); $this->writeDirectoryMock->expects($this->any())->method('isFile')->will($this->returnValue($isFile)); $this->writeDirectoryMock->expects($this->any())->method('isReadable')->will($this->returnValue($isReadable)); $this->writeDirectoryMock->expects($this->any())->method('openFile')->will($this->returnValue($writeMock)); $this->writeDirectoryMock->expects($this->once())->method('getRelativePath')->with($info['order_path'])->will($this->returnArgument(0)); $this->storageMock->expects($this->any())->method('checkDbUsage')->will($this->returnValue(true)); $this->storageMock->expects($this->any())->method('getMediaRelativePath')->will($this->returnArgument(0)); $storageDatabaseMock = $this->getMockBuilder('Magento\\Core\\Model\\File\\Storage\\Database')->disableOriginalConstructor()->setMethods(['loadByFilename', 'getId', '__wakeup'])->getMock(); $storageDatabaseMock->expects($this->any())->method('loadByFilename')->will($this->returnSelf()); $storageDatabaseMock->expects($this->any())->method('getId')->will($this->returnValue(true)); $this->storageFactoryMock->expects($this->any())->method('create')->will($this->returnValue($storageDatabaseMock)); $this->httpFileFactoryMock->expects($this->once())->method('create')->with($info['title'], ['value' => $info['order_path'], 'type' => 'filename'], \Magento\Framework\App\Filesystem::ROOT_DIR, 'application/octet-stream', null); $result = $this->model->downloadFile($info); $this->assertNull($result); }
/** * Custom options download action * * @return void|\Magento\Framework\Controller\Result\Forward * * @SuppressWarnings(PHPMD.CyclomaticComplexity) * @SuppressWarnings(PHPMD.ExitExpression) */ public function execute() { $quoteItemOptionId = $this->getRequest()->getParam('id'); /** @var $option \Magento\Quote\Model\Quote\Item\Option */ $option = $this->_objectManager->create('Magento\\Quote\\Model\\Quote\\Item\\Option')->load($quoteItemOptionId); /** @var \Magento\Framework\Controller\Result\Forward $resultForward */ $resultForward = $this->resultForwardFactory->create(); if (!$option->getId()) { return $resultForward->forward('noroute'); } $optionId = null; if (strpos($option->getCode(), AbstractType::OPTION_PREFIX) === 0) { $optionId = str_replace(AbstractType::OPTION_PREFIX, '', $option->getCode()); if ((int) $optionId != $optionId) { $optionId = null; } } $productOption = null; if ($optionId) { /** @var $productOption \Magento\Catalog\Model\Product\Option */ $productOption = $this->_objectManager->create('Magento\\Catalog\\Model\\Product\\Option')->load($optionId); } if (!$productOption || !$productOption->getId() || $productOption->getProductId() != $option->getProductId() || $productOption->getType() != 'file') { return $resultForward->forward('noroute'); } try { $info = unserialize($option->getValue()); if ($this->getRequest()->getParam('key') != $info['secret_key']) { return $resultForward->forward('noroute'); } $this->download->downloadFile($info); } catch (\Exception $e) { return $resultForward->forward('noroute'); } exit(0); }
/** * Payment custom options download action * * @return void */ public function execute() { $recurringPayment = $this->_objectManager->create('Magento\\RecurringPayment\\Model\\Payment')->load($this->getRequest()->getParam('id')); if (!$recurringPayment->getId()) { $this->_forward('noroute'); } $orderItemInfo = $recurringPayment->getData('order_item_info'); try { $buyRequest = unserialize($orderItemInfo['info_buyRequest']); if ($buyRequest['product'] != $orderItemInfo['product_id']) { throw new \Exception(); } $this->download->downloadFile($this->getOptionInfo($buyRequest)); } catch (\Exception $e) { $this->_forward('noroute'); } }