Esempio n. 1
0
 public function testGetLinkAmount()
 {
     $amount = 100;
     $convertedAmount = 50;
     $this->linkMock->expects($this->once())->method('getPrice')->will($this->returnValue($amount));
     $this->linkMock->expects($this->once())->method('getProduct')->will($this->returnValue($this->saleableItemMock));
     $this->priceCurrencyMock->expects($this->once())->method('convertAndRound')->with($amount)->will($this->returnValue($convertedAmount));
     $this->calculatorMock->expects($this->once())->method('getAmount')->with($convertedAmount, $this->equalTo($this->saleableItemMock))->will($this->returnValue($convertedAmount));
     $result = $this->linkPrice->getLinkAmount($this->linkMock);
     $this->assertEquals($convertedAmount, $result);
 }
Esempio n. 2
0
 public function testDelete()
 {
     $linkId = 1;
     $linkMock = $this->getMock('\\Magento\\Downloadable\\Model\\Link', [], [], '', false);
     $this->linkFactoryMock->expects($this->once())->method('create')->willReturn($linkMock);
     $linkMock->expects($this->once())->method('load')->with($linkId)->willReturnSelf();
     $linkMock->expects($this->any())->method('getId')->willReturn($linkId);
     $this->linkResourceMock->expects($this->once())->method('delete')->willReturn(true);
     $this->assertTrue($this->service->delete($linkId));
 }
 /**
  * {@inheritdoc}
  */
 public function delete($id)
 {
     /** @var $link \Magento\Downloadable\Model\Link */
     $link = $this->linkFactory->create()->load($id);
     if (!$link->getId()) {
         throw new NoSuchEntityException(__('There is no downloadable link with provided ID.'));
     }
     try {
         $this->resourceModel->delete($link);
     } catch (\Exception $exception) {
         throw new StateException(__('Cannot delete link with id %1', $link->getId()), $exception);
     }
     return true;
 }
Esempio n. 4
0
 /**
  * Delete data specific for Downloadable product type
  *
  * @param \Magento\Catalog\Model\Product $product
  * @return void
  */
 public function deleteTypeSpecificData(\Magento\Catalog\Model\Product $product)
 {
     if ($product->getOrigData('type_id') === \Magento\Downloadable\Model\Product\Type::TYPE_DOWNLOADABLE) {
         $downloadableData = $product->getDownloadableData();
         $sampleItems = [];
         if (isset($downloadableData['sample'])) {
             foreach ($downloadableData['sample'] as $sample) {
                 $sampleItems[] = $sample['sample_id'];
             }
         }
         if ($sampleItems) {
             $this->_sampleResFactory->create()->deleteItems($sampleItems);
         }
         $linkItems = [];
         if (isset($downloadableData['link'])) {
             foreach ($downloadableData['link'] as $link) {
                 $linkItems[] = $link['link_id'];
             }
         }
         if ($linkItems) {
             $this->_linkResource->deleteItems($linkItems);
         }
     }
 }
Esempio n. 5
0
 /**
  * @return void
  */
 protected function processDelete()
 {
     if ($this->deletedItems) {
         $this->linkResource->deleteItems($this->deletedItems);
     }
 }
Esempio n. 6
0
 /**
  * @param \Magento\Catalog\Model\Product|\PHPUnit_Framework_MockObject_MockObject $product
  * @param array $data
  * @param array $expectedItems
  * @dataProvider deleteDataProvider
  */
 public function testDelete($product, array $data, array $expectedItems)
 {
     $this->sampleResource->expects($this->once())->method('deleteItems')->with($this->equalTo($expectedItems));
     $this->target->save($product, $data);
 }