You are here

public function SmsFrameworkMessageEntityTest::testCascadeDelete in SMS Framework 8

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

Tests cascade delete on the SMS message, result and reports.

File

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

Class

SmsFrameworkMessageEntityTest
Tests SMS message entity.

Namespace

Drupal\Tests\sms\Kernel

Code

public function testCascadeDelete() {

  /** @var \Drupal\sms\Entity\SmsMessageInterface $sms_message */
  $sms_message = SmsMessage::create()
    ->setMessage($this
    ->getRandomGenerator()
    ->paragraphs())
    ->setGateway($this
    ->createMemoryGateway())
    ->addRecipients($this
    ->randomPhoneNumbers())
    ->setSender($this
    ->randomMachineName());
  $this
    ->assertNull($sms_message
    ->getResult());
  $sms_result = $this
    ->createMessageResult($sms_message);
  $sms_message
    ->setResult($sms_result)
    ->save();
  $sms_reports = $sms_result
    ->getReports();
  $this
    ->assertInstanceOf(SmsMessageResultInterface::class, $sms_message
    ->getResult());
  $this
    ->assertInstanceOf(SmsMessageInterface::class, SmsMessage::load($sms_message
    ->id()));
  $this
    ->assertEquals(count($sms_reports), count(SmsDeliveryReport::loadMultiple()));

  // Delete the message and confirm that all has been removed.
  $sms_message
    ->delete();
  $this
    ->assertNull(SmsMessage::load($sms_message
    ->id()));
  $this
    ->assertEquals([], SmsMessageResult::loadMultiple());
  $this
    ->assertEquals([], SmsDeliveryReport::loadMultiple());
}