SmsFrameworkBrowserTestBase.php in SMS Framework 2.x
File
tests/src/Functional/SmsFrameworkBrowserTestBase.php
View source
<?php
declare (strict_types=1);
namespace Drupal\Tests\sms\Functional;
use Drupal\Core\Entity\Entity\EntityFormDisplay;
use Drupal\Tests\BrowserTestBase;
abstract class SmsFrameworkBrowserTestBase extends BrowserTestBase {
use SmsFrameworkTestTrait;
public static $modules = [
'sms',
'sms_test_gateway',
'telephone',
'dynamic_entity_reference',
];
protected $defaultTheme = 'classy';
protected $gatewayManager;
protected $defaultSmsProvider;
protected function setUp() {
parent::setUp();
$this->gatewayManager = $this->container
->get('plugin.manager.sms_gateway');
$this->defaultSmsProvider = $this->container
->get('sms.provider');
}
protected function createPhoneNumberSettings($entity_type_id, $bundle) {
$entity_type_manager = \Drupal::entityTypeManager();
$field_storage = $entity_type_manager
->getStorage('field_storage_config')
->create([
'entity_type' => $entity_type_id,
'field_name' => mb_strtolower($this
->randomMachineName()),
'type' => 'telephone',
]);
$field_storage
->setCardinality(1)
->save();
$entity_type_manager
->getStorage('field_config')
->create([
'entity_type' => $entity_type_id,
'bundle' => $bundle,
'field_name' => $field_storage
->getName(),
])
->save();
$entity_form_display = EntityFormDisplay::load($entity_type_id . '.' . $bundle . '.default');
if (!$entity_form_display) {
$entity_form_display = EntityFormDisplay::create([
'targetEntityType' => $entity_type_id,
'bundle' => $bundle,
'mode' => 'default',
'status' => TRUE,
]);
}
$entity_form_display
->save();
$entity_form_display
->setComponent($field_storage
->getName(), [
'type' => 'sms_telephone',
])
->save();
$phone_number_settings = $entity_type_manager
->getStorage('phone_number_settings')
->create();
$phone_number_settings
->setFieldName('phone_number', $field_storage
->getName())
->setPhoneNumberEntityTypeId($entity_type_id)
->setPhoneNumberBundle($bundle)
->setVerificationCodeLifetime(3601)
->setVerificationMessage('Verification code is [sms:verification-code]')
->setPurgeVerificationPhoneNumber(TRUE)
->save();
return $phone_number_settings;
}
}