public function testGetEntityQueryBuilder()
 {
     $qb = $this->getMockBuilder('Doctrine\\ORM\\QueryBuilder')->disableOriginalConstructor()->getMock();
     $qb->expects($this->once())->method('select')->will($this->returnSelf());
     $qb->expects($this->once())->method('from')->will($this->returnSelf());
     $qb->expects($this->once())->method('where')->will($this->returnSelf());
     $qb->expects($this->once())->method('orderBy')->will($this->returnSelf());
     $qb->expects($this->once())->method('setParameter')->will($this->returnSelf());
     $this->entityManager->expects($this->once())->method('createQueryBuilder')->will($this->returnValue($qb));
     $this->repository->getEntityTemplatesQueryBuilder('Oro\\Bundle\\UserBundle\\Entity\\User');
 }
 public function testGetEntityTemplatesQueryBuilderExcludeSystemTemplates()
 {
     $qb = $this->getMockBuilder('Doctrine\\ORM\\QueryBuilder')->disableOriginalConstructor()->getMock();
     $qb->expects($this->once())->method('select')->will($this->returnSelf());
     $qb->expects($this->once())->method('from')->will($this->returnSelf());
     $qb->expects($this->once())->method('where')->will($this->returnSelf());
     $qb->expects($this->once())->method('orWhere')->will($this->returnSelf());
     $qb->expects($this->exactly(2))->method('andWhere')->will($this->returnSelf());
     $qb->expects($this->once())->method('orderBy')->will($this->returnSelf());
     $qb->expects($this->exactly(3))->method('setParameter')->will($this->returnSelf());
     $this->entityManager->expects($this->once())->method('createQueryBuilder')->will($this->returnValue($qb));
     $this->repository->getEntityTemplatesQueryBuilder('Oro\\Bundle\\UserBundle\\Entity\\User', new Organization(), true, false);
 }
 /**
  * @dataProvider executeOptionsDataProvider
  * @param array $options
  * @param array $expected
  */
 public function testExecute($options, $expected)
 {
     $context = [];
     $this->contextAccessor->expects($this->any())->method('getValue')->will($this->returnArgument(1));
     $this->entityNameResolver->expects($this->any())->method('getName')->will($this->returnCallback(function () {
         return '_Formatted';
     }));
     $this->objectRepository->expects($this->once())->method('findByName')->with($options['template'])->willReturn($this->emailTemplate);
     $this->emailTemplate->expects($this->once())->method('getType')->willReturn('txt');
     $this->renderer->expects($this->once())->method('compileMessage')->willReturn([$expected['subject'], $expected['body']]);
     $self = $this;
     $emailUserEntity = $this->getMockBuilder('\\Oro\\Bundle\\EmailBundle\\Entity\\EmailUser')->disableOriginalConstructor()->setMethods(['getEmail'])->getMock();
     $emailEntity = $this->getMock('\\Oro\\Bundle\\EmailBundle\\Entity\\Email');
     $emailUserEntity->expects($this->any())->method('getEmail')->willReturn($emailEntity);
     $this->emailProcessor->expects($this->once())->method('process')->with($this->isInstanceOf('Oro\\Bundle\\EmailBundle\\Form\\Model\\Email'))->will($this->returnCallback(function (Email $model) use($emailUserEntity, $expected, $self) {
         $self->assertEquals($expected['body'], $model->getBody());
         $self->assertEquals($expected['subject'], $model->getSubject());
         $self->assertEquals($expected['from'], $model->getFrom());
         $self->assertEquals($expected['to'], $model->getTo());
         return $emailUserEntity;
     }));
     if (array_key_exists('attribute', $options)) {
         $this->contextAccessor->expects($this->once())->method('setValue')->with($context, $options['attribute'], $emailEntity);
     }
     $this->action->initialize($options);
     $this->action->execute($context);
 }
 /**
  * @param string         $templateName
  * @param array          $templateParams
  * @param \Swift_Message $expectedMessage
  * @param string         $emailType
  */
 protected function assertSendCalled($templateName, array $templateParams, \Swift_Message $expectedMessage, $emailType = 'txt')
 {
     $this->emailTemplate->expects($this->once())->method('getType')->willReturn($emailType);
     $this->objectRepository->expects($this->once())->method('findOneBy')->with(['name' => $templateName])->willReturn($this->emailTemplate);
     $this->renderer->expects($this->once())->method('compileMessage')->with($this->emailTemplate, $templateParams)->willReturn([$expectedMessage->getSubject(), $expectedMessage->getBody()]);
     $to = $expectedMessage->getTo();
     $toKeys = array_keys($to);
     $this->emailHolderHelper->expects($this->once())->method('getEmail')->with($this->isInstanceOf('Oro\\Bundle\\UserBundle\\Entity\\UserInterface'))->willReturn(array_shift($toKeys));
     $this->mailer->expects($this->once())->method('send')->with($this->callback(function (\Swift_Message $actualMessage) use($expectedMessage) {
         $this->assertEquals($expectedMessage->getSubject(), $actualMessage->getSubject());
         $this->assertEquals($expectedMessage->getFrom(), $actualMessage->getFrom());
         $this->assertEquals($expectedMessage->getTo(), $actualMessage->getTo());
         $this->assertEquals($expectedMessage->getBody(), $actualMessage->getBody());
         $this->assertEquals($expectedMessage->getContentType(), $actualMessage->getContentType());
         return true;
     }));
 }