You are here

public function PaymentDeclinedMailTest::testSend in Commerce Recurring Framework 8

@covers ::send

File

tests/src/Kernel/Mail/PaymentDeclinedMailTest.php, line 68

Class

PaymentDeclinedMailTest
Tests the sending of payment declined emails.

Namespace

Drupal\Tests\commerce_recurring\Kernel\Mail

Code

public function testSend() {
  $schedule = [
    1,
    3,
    5,
  ];
  $max_retries = count($schedule);
  $time = \Drupal::time()
    ->getCurrentTime();
  $this->mail
    ->send($this->order, $schedule[0], 0, $max_retries);
  $emails = $this
    ->getMails();
  $this
    ->assertEquals(1, count($emails));
  $email = reset($emails);
  $this
    ->assertEquals('text/html; charset=UTF-8;', $email['headers']['Content-Type']);
  $this
    ->assertEquals('commerce_recurring_payment_declined', $email['id']);
  $this
    ->assertEquals($this->order
    ->getEmail(), $email['to']);
  $this
    ->assertEquals($this->order
    ->getStore()
    ->getEmail(), $email['from']);
  $this
    ->assertEquals('Payment declined - Order #1.', $email['subject']);
  $this
    ->assertMailString('body', 'We regret to inform you that the most recent charge attempt on your card failed.', 1);
  $this
    ->assertMailString('body', Url::fromRoute('entity.commerce_payment_method.collection', [
    'user' => $this->user
      ->id(),
  ], [
    'absolute' => TRUE,
  ])
    ->toString(), 1);
  $next_retry_time = strtotime("+1 day", $time);
  $this
    ->assertMailString('body', 'Our next charge attempt will be on: ' . date('F d', $next_retry_time), 1);
  $next_retry_time = strtotime('+3 days', $time);
  $this->mail
    ->send($this->order, $schedule[1], 1, $max_retries);
  $this
    ->assertMailString('body', 'Our next charge attempt will be on: ' . date('F d', $next_retry_time), 1);
  $next_retry_time = strtotime('+5days', $time);
  $this->mail
    ->send($this->order, $schedule[2], 2, $max_retries);
  $this
    ->assertMailString('body', 'Our final charge attempt will be on: ' . date('F d', $next_retry_time), 1);
  $this->mail
    ->send($this->order, 0, 3, $max_retries);
  $this
    ->assertMailString('body', 'This was our final charge attempt.', 1);
}