You are here

public function SmsFrameworkMessageEntityTest::testConvertToEntityFromStandardSmsMessage in SMS Framework 8

Same name and namespace in other branches
  1. 2.x tests/src/Kernel/SmsFrameworkMessageEntityTest.php \Drupal\Tests\sms\Kernel\SmsFrameworkMessageEntityTest::testConvertToEntityFromStandardSmsMessage()
  2. 2.1.x tests/src/Kernel/SmsFrameworkMessageEntityTest.php \Drupal\Tests\sms\Kernel\SmsFrameworkMessageEntityTest::testConvertToEntityFromStandardSmsMessage()

Ensure data from standard SMS message are passed to SMS message entity.

File

tests/src/Kernel/SmsFrameworkMessageEntityTest.php, line 239

Class

SmsFrameworkMessageEntityTest
Tests SMS message entity.

Namespace

Drupal\Tests\sms\Kernel

Code

public function testConvertToEntityFromStandardSmsMessage() {

  // Need ID otherwise we have to install system module and 'sequences' table.
  $user = User::create([
    'uid' => 1,
    'name' => 'user',
  ]);
  $user
    ->save();
  $gateway = $this
    ->createMemoryGateway();
  $sender_number = $this
    ->randomPhoneNumbers(1);
  $original = new StandardSmsMessage('', [], '', [], NULL);
  $original
    ->setAutomated(TRUE)
    ->setSender($this
    ->randomMachineName())
    ->setSenderNumber($sender_number[0])
    ->addRecipients([
    '123123123',
    '456456456',
  ])
    ->setMessage($this
    ->randomMachineName())
    ->setUid($user
    ->id())
    ->setGateway($gateway)
    ->setOption('foo', $this
    ->randomMachineName())
    ->setOption('bar', $this
    ->randomMachineName())
    ->setResult($this
    ->createMessageResult($original));
  $sms_message = SmsMessage::convertFromSmsMessage($original);
  $this
    ->assertEquals($original
    ->isAutomated(), $sms_message
    ->isAutomated());
  $this
    ->assertEquals($original
    ->getSender(), $sms_message
    ->getSender());
  $this
    ->assertEquals($original
    ->getSenderNumber(), $sms_message
    ->getSenderNumber());
  $this
    ->assertEquals($original
    ->getRecipients(), $sms_message
    ->getRecipients());
  $this
    ->assertEquals($original
    ->getMessage(), $sms_message
    ->getMessage());
  $this
    ->assertEquals($user
    ->id(), $sms_message
    ->getSenderEntity()
    ->id());
  $this
    ->assertEquals($original
    ->getOption('foo'), $sms_message
    ->getOption('foo'));
  $this
    ->assertEquals($original
    ->getOption('bar'), $sms_message
    ->getOption('bar'));
  $this
    ->assertEquals($original
    ->getGateway(), $sms_message
    ->getGateway());
  $this
    ->assertEquals($original
    ->getResult()
    ->getErrorMessage(), $sms_message
    ->getResult()
    ->getErrorMessage());
  $this
    ->assertEquals(count($original
    ->getReports()), count($sms_message
    ->getReports()));
  $this
    ->assertEquals($original
    ->getReport('123123123')
    ->getRecipient(), $sms_message
    ->getReport('123123123')
    ->getRecipient());
  $this
    ->assertEquals($original
    ->getReport('456456456')
    ->getRecipient(), $sms_message
    ->getReport('456456456')
    ->getRecipient());
}