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));
 }
Ejemplo n.º 2
0
 /**
  * @param $type
  * @param $getRepositoryCalls
  * @param $getRepositoryArgument
  * @param $repoReturnObject
  * @param $oroToEntityCalls
  * @param $entityFromUploadedFileCalls
  *
  * @dataProvider attachmentProvider
  */
 public function testInitAttachmentEntity($type, $getRepositoryCalls, $getRepositoryArgument, $repoReturnObject, $oroToEntityCalls, $entityFromUploadedFileCalls)
 {
     $attachment = $this->getMock('Oro\\Bundle\\EmailBundle\\Form\\Model\\EmailAttachment');
     $attachment->expects($this->once())->method('setEmailAttachment');
     $uploadedFile = $this->getMockBuilder('Symfony\\Component\\HttpFoundation\\File\\UploadedFile')->enableOriginalConstructor()->setConstructorArgs([__DIR__ . '/../../Fixtures/attachment/test.txt', ''])->getMock();
     $attachment->expects($this->any())->method('getFile')->willReturn($uploadedFile);
     $formEvent = $this->getMockBuilder('Symfony\\Component\\Form\\FormEvent')->disableOriginalConstructor()->getMock();
     $formEvent->expects($this->once())->method('getData')->willReturn($attachment);
     $attachment->expects($this->once())->method('getEmailAttachment')->willReturn(false);
     $attachment->expects($this->once())->method('getType')->willReturn($type);
     if ($getRepositoryCalls) {
         $repo = $this->getMockBuilder('Doctrine\\ORM\\EntityRepository')->disableOriginalConstructor()->getMock();
         $this->em->expects($this->exactly($getRepositoryCalls))->method('getRepository')->with($getRepositoryArgument)->willReturn($repo);
         $repo->expects($this->once())->method('find')->willReturn($repoReturnObject);
     }
     $this->emailAttachmentTransformer->expects($this->exactly($oroToEntityCalls))->method('oroToEntity');
     $this->emailAttachmentTransformer->expects($this->exactly($entityFromUploadedFileCalls))->method('entityFromUploadedFile');
     $this->emailAttachmentType->initAttachmentEntity($formEvent);
 }