/**
  * @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);
 }
Esempio n. 2
0
 /**
  * @dataProvider executeOptionsDataProvider
  * @param array $options
  * @param array $expected
  */
 public function testExecute($options, $expected)
 {
     $context = array();
     $this->contextAccessor->expects($this->any())->method('getValue')->will($this->returnArgument(1));
     $this->nameFormatter->expects($this->any())->method('format')->will($this->returnCallback(function () {
         return '_Formatted';
     }));
     $self = $this;
     $emailEntity = $this->getMockBuilder('\\Oro\\Bundle\\EmailBundle\\Entity\\Email')->disableOriginalConstructor()->getMock();
     $this->emailProcessor->expects($this->once())->method('process')->with($this->isInstanceOf('Oro\\Bundle\\EmailBundle\\Form\\Model\\Email'))->will($this->returnCallback(function (Email $model) use($emailEntity, $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 $emailEntity;
     }));
     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);
 }