public function SmsFrameworkMessageResultEntityTest::testSaveAndRetrieveResult in SMS Framework 8
Same name and namespace in other branches
- 2.x tests/src/Kernel/SmsFrameworkMessageResultEntityTest.php \Drupal\Tests\sms\Kernel\SmsFrameworkMessageResultEntityTest::testSaveAndRetrieveResult()
- 2.1.x tests/src/Kernel/SmsFrameworkMessageResultEntityTest.php \Drupal\Tests\sms\Kernel\SmsFrameworkMessageResultEntityTest::testSaveAndRetrieveResult()
Tests saving and retrieval of complete entity.
File
- tests/
src/ Kernel/ SmsFrameworkMessageResultEntityTest.php, line 57
Class
- SmsFrameworkMessageResultEntityTest
- Tests the SMS message result entity.
Namespace
Drupal\Tests\sms\KernelCode
public function testSaveAndRetrieveResult() {
/** @var \Drupal\sms\Entity\SmsMessageResult $result */
$result = $this
->createMessageResult()
->setCreditsUsed(rand(5, 10))
->setCreditsBalance(rand(10, 20))
->setError(SmsMessageResultStatus::INVALID_SENDER)
->setErrorMessage('Invalid sender ID')
->setReports([
SmsDeliveryReport::create()
->setRecipient('1234567890'),
]);
// Add the result to an SMS entity and save.
$sms_message = SmsMessage::create()
->addRecipient('1234567890')
->setResult($result);
$sms_message
->save();
$storage = $this->container
->get('entity_type.manager')
->getStorage('sms_result');
$saved = $storage
->load($result
->id());
/** @var \Drupal\sms\Entity\SmsMessageResult $saved */
$this
->assertEquals($result
->getCreditsBalance(), $saved
->getCreditsBalance());
$this
->assertEquals($result
->getCreditsUsed(), $saved
->getCreditsUsed());
$this
->assertEquals($result
->getError(), $saved
->getError());
$this
->assertEquals($result
->getErrorMessage(), $saved
->getErrorMessage());
$this
->assertEquals($result
->getReports()[0]
->getRecipient(), $saved
->getReports()[0]
->getRecipient());
$this
->assertEquals($result
->uuid(), $saved
->uuid());
}