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);
 }
Example #2
0
 /**
  * Delegated method
  *
  * @param object $entity
  * @return bool
  */
 public function isAttachmentAssociationEnabled($entity)
 {
     if (!is_object($entity) || !$this->doctrineHelper->isManageableEntity($entity) || $this->doctrineHelper->isNewEntity($entity)) {
         return false;
     }
     return $this->config->isAttachmentAssociationEnabled($entity);
 }
 /**
  * @param null|object $entity
  * @param bool        $attachmentConfigReturn
  * @param bool        $isNewRecord
  * @param bool        $isManaged
  * @param bool        $expected
  * @dataProvider configResultProvider
  */
 public function testIsAttachmentAssociationEnabled($entity, $attachmentConfigReturn, $isNewRecord, $isManaged, $expected)
 {
     $this->attachmentConfig->expects(is_object($entity) && !$isNewRecord ? $this->once() : $this->never())->method('isAttachmentAssociationEnabled')->with($entity)->willReturn($attachmentConfigReturn);
     $this->doctrineHelper->expects(is_object($entity) && $isManaged ? $this->once() : $this->never())->method('isNewEntity')->willReturn($isNewRecord);
     $this->doctrineHelper->expects(is_object($entity) ? $this->once() : $this->never())->method('isManageableEntity')->willReturn($isManaged);
     $actual = $this->filter->isAttachmentAssociationEnabled($entity);
     $this->assertEquals($expected, $actual);
 }
 public function testIsAttachmentAssociationEnabled()
 {
     $config = new Config(new EntityConfigId('attachment', 'stdClass'));
     $config->set('enabled', true);
     $this->attachmentConfigProvider->expects($this->once())->method('hasConfig')->with('stdClass')->will($this->returnValue(true));
     $this->attachmentConfigProvider->expects($this->once())->method('getConfig')->with('stdClass')->will($this->returnValue($config));
     $this->entityConfigProvider->expects($this->once())->method('hasConfig')->with(AttachmentScope::ATTACHMENT, ExtendHelper::buildAssociationName('stdClass'))->will($this->returnValue(true));
     $this->assertTrue($this->attachmentConfig->isAttachmentAssociationEnabled(new \stdClass()));
 }
Example #5
0
 /**
  * @param object $entity
  *
  * @return Attachment[]
  */
 public function getEntityAttachments($entity)
 {
     if ($this->attachmentConfig->isAttachmentAssociationEnabled($entity)) {
         $className = ClassUtils::getClass($entity);
         $fieldName = ExtendHelper::buildAssociationName($className);
         $repo = $this->em->getRepository('OroAttachmentBundle:Attachment');
         $qb = $repo->createQueryBuilder('a');
         $qb->leftJoin('a.' . $fieldName, 'entity')->where('entity.id = :entityId')->setParameter('entityId', $entity->getId());
         return $qb->getQuery()->getResult();
     }
     return [];
 }
 /**
  * Check is attached file to target entity
  *
  * @param EmailAttachment $attachment
  * @param object $target
  *
  * @return bool
  */
 public function isAttached($attachment, $target)
 {
     $targetEntityClass = ClassUtils::getClass($target);
     if ($this->attachmentConfig->isAttachmentAssociationEnabled($target)) {
         $attached = $this->em->getRepository('OroAttachmentBundle:Attachment')->findOneBy([ExtendHelper::buildAssociationName($targetEntityClass) => $target, 'file' => $attachment->getFile()]);
         return null !== $attached;
     }
     return false;
 }
 /**
  * Delegated method
  *
  * @param object $entity
  * @return bool
  */
 public function isAttachmentAssociationEnabled($entity)
 {
     return $this->config->isAttachmentAssociationEnabled($entity);
 }