SmsFrameworkTokenTest.php in SMS Framework 8
File
tests/src/Kernel/SmsFrameworkTokenTest.php
View source
<?php
namespace Drupal\Tests\sms\Kernel;
use Drupal\sms\Message\SmsMessage;
use Drupal\Component\Utility\Html;
class SmsFrameworkTokenTest extends SmsFrameworkKernelBase {
public static $modules = [
'system',
'sms',
'entity_test',
'user',
'field',
'telephone',
'dynamic_entity_reference',
];
protected $tokenService;
protected function setUp() {
parent::setUp();
$this->tokenService = $this->container
->get('token');
$this
->installConfig([
'system',
]);
$this
->installSchema('system', [
'router',
]);
\Drupal::service('router.builder')
->rebuild();
}
public function testSmsTokens() {
$url_options = [
'absolute' => TRUE,
];
$this
->assertEquals(\Drupal::url('sms.phone.verify', [], $url_options), $this->tokenService
->replace('[sms:verification-url]'));
}
public function testVerificationCode() {
$data['sms_verification_code'] = $this
->randomMachineName();
$this
->assertEquals($data['sms_verification_code'], $this->tokenService
->replace('[sms-message:verification-code]', $data));
}
public function testSmsMessageTokens() {
$phone_numbers = [
'+123123123',
'+456456456',
];
$message = $this
->randomString();
$sms_message = new SmsMessage();
$sms_message
->setSenderNumber('+999888777')
->setMessage($message)
->addRecipients($phone_numbers);
$data['sms-message'] = $sms_message;
$this
->assertEquals($phone_numbers[0], $this->tokenService
->replace('[sms-message:phone-number]', $data));
$this
->assertEquals(Html::escape($message), $this->tokenService
->replace('[sms-message:message]', $data));
}
}