コード例 #1
0
 public function testExecuteBadSecretKey()
 {
     $this->itemOptionMock->expects($this->once())->method('load')->willReturnSelf();
     $this->itemOptionMock->expects($this->once())->method('getId')->willReturn(self::OPTION_ID);
     $this->itemOptionMock->expects($this->any())->method('getCode')->willReturn(self::OPTION_CODE);
     $this->itemOptionMock->expects($this->any())->method('getProductId')->willReturn(self::OPTION_PRODUCT_ID);
     $this->itemOptionMock->expects($this->any())->method('getValue')->willReturn(self::OPTION_VALUE);
     $this->productOptionMock->expects($this->once())->method('load')->willReturnSelf();
     $this->productOptionMock->expects($this->any())->method('getId')->willReturn(self::OPTION_ID);
     $this->productOptionMock->expects($this->any())->method('getProductId')->willReturn(self::OPTION_PRODUCT_ID);
     $this->productOptionMock->expects($this->any())->method('getType')->willReturn(self::OPTION_TYPE);
     $this->unserializeMock->expects($this->once())->method('unserialize')->with(self::OPTION_VALUE)->willReturn([self::SECRET_KEY => 'bad_test_secret_key']);
     $this->resultForwardMock->expects($this->once())->method('forward')->with('noroute')->willReturn(true);
     $this->objectMock->execute();
 }
コード例 #2
0
 /**
  * Custom options download action
  *
  * @return void|\Magento\Framework\Controller\Result\Forward
  *
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  */
 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->getType() != 'file') {
         return $resultForward->forward('noroute');
     }
     try {
         $info = $this->unserialize->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');
     }
     $this->endExecute();
 }
コード例 #3
0
 /**
  * @expectedException Exception
  * @expectedExceptionMessage String contains serialized object
  */
 public function testUnserializeObject()
 {
     $serialized = 'a:2:{i:0;s:3:"foo";i:1;O:6:"Object":1:{s:11:"Objectvar";i:123;}}';
     $this->assertFalse($this->unserialize->unserialize($serialized));
 }
コード例 #4
0
 /**
  * @param string $serialized The string containing serialized object
  *
  * @expectedException \Exception
  * @expectedExceptionMessage String contains serialized object
  * @dataProvider serializedObjectDataProvider
  */
 public function testUnserializeObject($serialized)
 {
     $this->assertFalse($this->unserialize->unserialize($serialized));
 }