SmsFrameworkUpdateTest.php in SMS Framework 2.x
File
tests/src/Functional/SmsFrameworkUpdateTest.php
View source
<?php
declare (strict_types=1);
namespace Drupal\Tests\sms\Functional;
use Drupal\sms\Direction;
use Drupal\sms\Entity\SmsDeliveryReport;
use Drupal\sms\Entity\SmsMessage;
use Drupal\sms\Entity\SmsMessageResult;
use Drupal\sms\Entity\SmsMessageResultInterface;
use Drupal\sms\Message\SmsMessageReportStatus;
use Drupal\FunctionalTests\Update\UpdatePathTestBase;
class SmsFrameworkUpdateTest extends UpdatePathTestBase {
use SmsFrameworkTestTrait;
protected static $modules = [
'user',
'telephone',
'dynamic_entity_reference',
'sms',
];
protected function setDatabaseDumpFiles() {
$this->databaseDumpFiles = [
__DIR__ . '/../../../../../../core/modules/system/tests/fixtures/update/drupal-8.8.0.bare.standard.php.gz',
__DIR__ . '/../../../tests/fixtures/update/sms-8.x-1.x-result-field-2836157.php.gz',
];
}
public function testSmsUpdate8101() {
$db_schema = \Drupal::database()
->schema();
$this
->assertTrue($db_schema
->tableExists('sms'));
$this
->assertTrue($db_schema
->tableExists('sms__recipient_phone_number'));
$this
->assertTrue($db_schema
->tableExists('sms_phone_number_verification'));
$this
->assertFalse($db_schema
->tableExists('sms_result'));
$this
->assertFalse($db_schema
->tableExists('sms_report'));
$this
->assertFalse($db_schema
->tableExists('sms_report_revision'));
$this
->runUpdates();
$this
->assertTrue($db_schema
->tableExists('sms'));
$this
->assertTrue($db_schema
->tableExists('sms__recipient_phone_number'));
$this
->assertTrue($db_schema
->tableExists('sms_phone_number_verification'));
$this
->assertTrue($db_schema
->tableExists('sms_result'));
$this
->assertTrue($db_schema
->tableExists('sms_report'));
$this
->assertTrue($db_schema
->tableExists('sms_report_revision'));
$sms_messages = SmsMessage::loadMultiple();
$this
->assertEqual(1, count($sms_messages));
$this
->assertEqual(2, count($sms_messages[1]
->getRecipients()));
$this
->assertNull($sms_messages[1]
->getResult());
$sms_message = SmsMessage::create()
->addRecipients($this
->randomPhoneNumbers())
->setSender($this
->randomMachineName())
->setDirection(Direction::OUTGOING)
->setAutomated(TRUE);
$reports = array_map(function ($recipient) {
return SmsDeliveryReport::create()
->setMessageId($this
->randomString())
->setRecipient($recipient)
->setStatus(SmsMessageReportStatus::DELIVERED)
->setStatusMessage($this
->randomString());
}, $sms_message
->getRecipients());
$result = SmsMessageResult::create()
->setReports($reports);
$sms_message
->setResult($result)
->save();
\Drupal::entityTypeManager()
->getStorage('sms')
->resetCache();
$sms_messages = SmsMessage::loadMultiple();
$this
->assertEqual(2, count($sms_messages));
$this
->assertTrue($sms_messages[2]
->getResult() instanceof SmsMessageResultInterface);
$this
->assertEqual(count($sms_message
->getRecipients()), count($sms_messages[2]
->getResult()
->getReports()));
}
}