You are here

public function SmsFrameworkMessageTestTrait::testResults in SMS Framework 8

Same name and namespace in other branches
  1. 2.x tests/src/Functional/SmsFrameworkMessageTestTrait.php \Drupal\Tests\sms\Functional\SmsFrameworkMessageTestTrait::testResults()
  2. 2.1.x tests/src/Functional/SmsFrameworkMessageTestTrait.php \Drupal\Tests\sms\Functional\SmsFrameworkMessageTestTrait::testResults()

Tests result and reports for SMS messages.

@covers ::getResult @covers ::setResult @covers ::getReport @covers ::getReports

File

tests/src/Functional/SmsFrameworkMessageTestTrait.php, line 196

Class

SmsFrameworkMessageTestTrait
SMS Message object test trait.

Namespace

Drupal\Tests\sms\Functional

Code

public function testResults() {
  $error_message = $this
    ->getRandomGenerator()
    ->string();
  $recipients = [
    '2345678901',
    '1234567890',
  ];
  $reports = array_combine($recipients, array_map(function ($recipient) {
    return (new SmsDeliveryReport())
      ->setRecipient($recipient)
      ->setStatus(SmsMessageReportStatus::DELIVERED);
  }, $recipients));
  $result = (new SmsMessageResult())
    ->setErrorMessage($error_message)
    ->setReports($reports);
  $sms_message = $this
    ->createSmsMessage()
    ->addRecipients($recipients)
    ->setResult($result);
  $result_actual = $sms_message
    ->getResult();
  $this
    ->assertEquals($error_message, $result_actual
    ->getErrorMessage());
  $this
    ->assertEquals($result
    ->getErrorMessage(), $result_actual
    ->getErrorMessage());
  $this
    ->assertEquals($reports['1234567890']
    ->getStatus(), $sms_message
    ->getReport('1234567890')
    ->getStatus());
  $this
    ->assertEquals($reports['2345678901']
    ->getStatus(), $sms_message
    ->getReport('2345678901')
    ->getStatus());
}