/**
  * Tests the sendMailMessages method.
  *
  * @dataProvider getSendMailMessages
  *
  * @covers ::sendMailMessages
  */
 public function testSendMailMessages(MessageInterface $message, AccountInterface $sender, $results)
 {
     $this->logger->expects($this->once())->method('notice');
     $this->mailManager->expects($this->any())->method('mail')->willReturnCallback(function ($module, $key, $to, $langcode, $params, $from) use(&$results) {
         $result = array_shift($results);
         $this->assertEquals($module, $result['module']);
         $this->assertEquals($key, $result['key']);
         $this->assertEquals($to, $result['to']);
         $this->assertEquals($langcode, $result['langcode']);
         $this->assertArrayEquals($params, $result['params']);
         $this->assertEquals($from, $result['from']);
     });
     $this->userStorage->expects($this->any())->method('load')->willReturn(clone $sender);
     $this->contactMailHandler->sendMailMessages($message, $sender);
 }
예제 #2
0
 /**
  * {@inheritdoc}
  */
 public function save(array $form, FormStateInterface $form_state)
 {
     $message = $this->entity;
     $user = $this->currentUser();
     $this->mailHandler->sendMailMessages($message, $user);
     $this->flood->register('contact', $this->config('contact.settings')->get('flood.interval'));
     drupal_set_message($this->t('Your message has been sent.'));
     // To avoid false error messages caused by flood control, redirect away from
     // the contact form; either to the contacted user account or the front page.
     if ($message->isPersonal() && $user->hasPermission('access user profiles')) {
         $form_state->setRedirectUrl($message->getPersonalRecipient()->urlInfo());
     } else {
         $form_state->setRedirect('<front>');
     }
     // Save the message. In core this is a no-op but should contrib wish to
     // implement message storage, this will make the task of swapping in a real
     // storage controller straight-forward.
     $message->save();
 }