You are here

protected function SmsFrameworkTestTrait::createEntityWithPhoneNumber in SMS Framework 8

Same name and namespace in other branches
  1. 2.x tests/src/Functional/SmsFrameworkTestTrait.php \Drupal\Tests\sms\Functional\SmsFrameworkTestTrait::createEntityWithPhoneNumber()
  2. 2.1.x tests/src/Functional/SmsFrameworkTestTrait.php \Drupal\Tests\sms\Functional\SmsFrameworkTestTrait::createEntityWithPhoneNumber()

Creates an entity, and optionally adds phone numbers.

Parameters

\Drupal\sms\Entity\PhoneNumberSettingsInterface $phone_number_settings: Phone number settings.

array $phone_numbers: An array of phone numbers to add to the entity.

Return value

\Drupal\Core\Entity\EntityInterface An entity with phone numbers.

25 calls to SmsFrameworkTestTrait::createEntityWithPhoneNumber()
SmsBlastBrowserTest::testSendBlast in modules/sms_blast/tests/src/Functional/SmsBlastBrowserTest.php
Tests sending SMS blast.
SmsFrameworkPhoneNumberProviderTest::testGetPhoneNumbersUnverified in tests/src/Kernel/SmsFrameworkPhoneNumberProviderTest.php
Tests phone numbers.
SmsFrameworkPhoneNumberProviderTest::testGetPhoneNumbersVerified in tests/src/Kernel/SmsFrameworkPhoneNumberProviderTest.php
Tests phone numbers.
SmsFrameworkPhoneNumberProviderTest::testSendMessageOneMessage in tests/src/Kernel/SmsFrameworkPhoneNumberProviderTest.php
Ensure default behaviour is to send one phone number per entity.
SmsFrameworkPhoneNumberProviderTest::testSendMessageUnverified in tests/src/Kernel/SmsFrameworkPhoneNumberProviderTest.php
Tests SMS message sent to entities with unverified phone number.

... See full list

File

tests/src/Functional/SmsFrameworkTestTrait.php, line 214

Class

SmsFrameworkTestTrait
Shared SMS Framework helpers for kernel and web tests.

Namespace

Drupal\Tests\sms\Functional

Code

protected function createEntityWithPhoneNumber(PhoneNumberSettingsInterface $phone_number_settings, array $phone_numbers = []) {
  $entity_type = $phone_number_settings
    ->getPhoneNumberEntityTypeId();
  $field_name = $phone_number_settings
    ->getFieldName('phone_number');
  $entity_type_manager = \Drupal::entityTypeManager();
  $test_entity = $entity_type_manager
    ->getStorage($entity_type)
    ->create([
    'name' => $this
      ->randomMachineName(),
  ]);
  foreach ($phone_numbers as $phone_number) {
    $test_entity->{$field_name}[] = $phone_number;
  }
  $test_entity
    ->save();
  return $test_entity;
}