public function testUnsupportedAttachments()
 {
     $entity = new TestClass();
     $this->attachmentConfig->expects($this->once())->method('isAttachmentAssociationEnabled')->with($entity)->willReturn(false);
     $result = $this->attachmentProvider->getEntityAttachments($entity);
     $this->assertEquals([], $result);
 }
 /**
  * @param $entity
  *
  * @return array
  */
 public function getScopeEntityAttachments($entity)
 {
     $attachments = [];
     $oroAttachments = $this->attachmentProvider->getEntityAttachments($entity);
     foreach ($oroAttachments as $oroAttachment) {
         $attachments[] = $this->emailAttachmentTransformer->oroToModel($oroAttachment);
     }
     return $attachments;
 }
 public function testGetScopeEntityAttachments()
 {
     $entity = $this->getMock('\\stdClass');
     $oroAttachments = [];
     $size = 3;
     for ($i = 0; $i < $size; $i++) {
         $oroAttachments[] = $this->getMock('Oro\\Bundle\\AttachmentBundle\\Entity\\Attachment');
     }
     $this->attachmentProvider->expects($this->once())->method('getEntityAttachments')->with($entity)->willReturn($oroAttachments);
     $this->emailAttachmentTransformer->expects($this->exactly($size))->method('oroToModel');
     $result = $this->emailAttachmentProvider->getScopeEntityAttachments($entity);
     $this->assertTrue(is_array($result));
     $this->assertEquals($size, sizeof($result));
 }
 public function testDuplicateFailed()
 {
     $product = (new StubProduct())->setSku(self::PRODUCT_SKU);
     $this->skuIncrementor->expects($this->once())->method('increment')->with(self::PRODUCT_SKU)->will($this->returnValue(self::PRODUCT_COPY_SKU));
     $this->attachmentProvider->expects($this->once())->method('getEntityAttachments')->with($product)->will($this->returnValue([]));
     $this->connection->expects($this->once())->method('beginTransaction');
     $this->connection->expects($this->once())->method('commit')->will($this->throwException(new \Exception()));
     $this->connection->expects($this->once())->method('rollback');
     $this->setExpectedException('Exception');
     $this->duplicator->duplicate($product);
 }
 /**
  * @param Product $product
  * @param Product $productCopy
  */
 protected function cloneChildObjects(Product $product, Product $productCopy)
 {
     foreach ($product->getUnitPrecisions() as $unitPrecision) {
         $productCopy->addUnitPrecision(clone $unitPrecision);
     }
     if ($imageFile = $product->getImage()) {
         $imageFileCopy = $this->attachmentManager->copyAttachmentFile($imageFile);
         $productCopy->setImage($imageFileCopy);
     }
     $attachments = $this->attachmentProvider->getEntityAttachments($product);
     foreach ($attachments as $attachment) {
         $attachmentCopy = clone $attachment;
         $attachmentFileCopy = $this->attachmentManager->copyAttachmentFile($attachment->getFile());
         $attachmentCopy->setFile($attachmentFileCopy);
         $attachmentCopy->setTarget($productCopy);
         $this->doctrineHelper->getEntityManager($attachmentCopy)->persist($attachmentCopy);
     }
 }