You are here

class SmsFrameworkUserAccountRegistrationServiceTest in SMS Framework 8

Same name and namespace in other branches
  1. 2.x modules/sms_user/tests/src/Kernel/SmsFrameworkUserAccountRegistrationServiceTest.php \Drupal\Tests\sms_user\Kernel\SmsFrameworkUserAccountRegistrationServiceTest
  2. 2.1.x modules/sms_user/tests/src/Kernel/SmsFrameworkUserAccountRegistrationServiceTest.php \Drupal\Tests\sms_user\Kernel\SmsFrameworkUserAccountRegistrationServiceTest

Tests account registration.

@group SMS Framework @coversDefaultClass \Drupal\sms_user\AccountRegistration

Hierarchy

Expanded class hierarchy of SmsFrameworkUserAccountRegistrationServiceTest

File

modules/sms_user/tests/src/Kernel/SmsFrameworkUserAccountRegistrationServiceTest.php, line 23

Namespace

Drupal\Tests\sms_user\Kernel
View source
class SmsFrameworkUserAccountRegistrationServiceTest extends SmsFrameworkKernelBase {
  use AssertMailTrait;

  /**
   * {@inheritdoc}
   */
  public static $modules = [
    'system',
    'sms',
    'sms_user',
    'sms_test_gateway',
    'user',
    'telephone',
    'dynamic_entity_reference',
    'field',
  ];

  /**
   * The account registration service.
   *
   * @var \Drupal\sms_user\AccountRegistrationInterface
   */
  protected $accountRegistration;

  /**
   * The default SMS provider.
   *
   * @var \Drupal\sms\Provider\SmsProviderInterface
   */
  protected $smsProvider;

  /**
   * A memory gateway.
   *
   * @var \Drupal\sms\Entity\SmsGatewayInterface
   */
  protected $gateway;

  /**
   * A phone field ofr testing.
   *
   * @var \Drupal\field\FieldStorageConfigInterface
   */
  protected $phoneField;

  /**
   * Phone number settings for user entity type.
   *
   * @var \Drupal\sms\Entity\PhoneNumberSettingsInterface
   */
  protected $phoneNumberSettings;

  /**
   * {@inheritdoc}
   */
  protected function setUp() {
    parent::setUp();
    $this
      ->installSchema('system', [
      'sequences',
    ]);
    $this
      ->installConfig('sms_user');
    $this->accountRegistration = $this->container
      ->get('sms_user.account_registration');
    $this->smsProvider = $this->container
      ->get('sms.provider');
    $this->gateway = $this
      ->createMemoryGateway([
      'skip_queue' => TRUE,
    ]);
    $this
      ->setFallbackGateway($this->gateway);
    $this
      ->installEntitySchema('user');
    $this
      ->installEntitySchema('sms');
    $this
      ->installEntitySchema('sms_result');
    $this
      ->installEntitySchema('sms_report');
    $this
      ->installEntitySchema('sms_phone_number_verification');
    $this->phoneField = FieldStorageConfig::create([
      'entity_type' => 'user',
      'field_name' => Unicode::strtolower($this
        ->randomMachineName()),
      'type' => 'telephone',
    ]);
    $this->phoneField
      ->save();
    FieldConfig::create([
      'entity_type' => 'user',
      'bundle' => 'user',
      'field_name' => $this->phoneField
        ->getName(),
    ])
      ->save();
    $this->phoneNumberSettings = PhoneNumberSettings::create();
    $this->phoneNumberSettings
      ->setPhoneNumberEntityTypeId('user')
      ->setPhoneNumberBundle('user')
      ->setFieldName('phone_number', $this->phoneField
      ->getName())
      ->setVerificationMessage($this
      ->randomString())
      ->save();
    $this
      ->config('system.mail')
      ->set('interface.default', 'test_mail_collector')
      ->save();
    $this
      ->config('user.settings')
      ->set('notify.register_no_approval_required', TRUE)
      ->save();
  }

  /**
   * Ensure incoming SMS does not create messages or users.
   */
  public function testUnrecognisedOffNoCreateUser() {
    $this
      ->config('sms_user.settings')
      ->set('account_registration.unrecognized_sender.status', 0)
      ->set('account_registration.unrecognized_sender.reply.status', 1)
      ->save();
    $this
      ->sendIncomingMessage('+123', $this
      ->randomString());
    $this
      ->assertEquals(0, count($this
      ->getTestMessages($this->gateway)), 'No messages were created');
    $this
      ->assertEquals(0, $this
      ->countUsers(), 'No users exist.');
  }

  /**
   * Test user is created if a unrecognised phone number is used as sender.
   */
  public function testUnrecognisedCreateUser() {
    $this
      ->config('sms_user.settings')
      ->set('account_registration.unrecognized_sender.status', 1)
      ->set('account_registration.unrecognized_sender.reply.status', 1)
      ->save();
    $sender_number = '+123123123';
    $this
      ->sendIncomingMessage($sender_number, $this
      ->randomString());
    $user = $this
      ->getLastUser();
    $this
      ->assertTrue($user instanceof UserInterface, 'One user created.');
    $this
      ->assertEquals($sender_number, $user->{$this->phoneField
      ->getName()}->value, 'Phone number associated');
  }

  /**
   * Test a user is not created if the sender phone number is already used.
   */
  public function testUnrecognisedCreateUserPhoneNumberRecognised() {
    $this
      ->config('sms_user.settings')
      ->set('account_registration.unrecognized_sender.status', 1)
      ->set('account_registration.unrecognized_sender.reply.status', 1)
      ->save();
    $sender_number = '+123123123';
    $this
      ->createEntityWithPhoneNumber($this->phoneNumberSettings, [
      $sender_number,
    ]);
    $this
      ->resetTestMessages();
    $this
      ->assertEquals(1, $this
      ->countUsers());
    $this
      ->sendIncomingMessage($sender_number, $this
      ->randomString());
    $this
      ->assertEquals(1, $this
      ->countUsers());
    $this
      ->assertEquals(0, count($this
      ->getTestMessages($this->gateway)));
  }

  /**
   * Ensure no reply sent if turned off.
   */
  public function testUnrecognisedNoReply() {
    $reply_message = $this
      ->randomString();
    $this
      ->config('sms_user.settings')
      ->set('account_registration.unrecognized_sender.status', TRUE)
      ->set('account_registration.unrecognized_sender.reply.status', FALSE)
      ->set('account_registration.unrecognized_sender.reply.message', $reply_message)
      ->save();
    $this
      ->sendIncomingMessage('+123123123', $this
      ->randomString());
    $this
      ->assertEquals(1, $this
      ->countUsers(), 'User created');
    $this
      ->assertFalse($this
      ->inTestMessages($this->gateway, $reply_message));
  }

  /**
   * Ensure reply sent if turned on.
   */
  public function testUnrecognisedGotReply() {
    $reply_message = $this
      ->randomString();
    $this
      ->config('sms_user.settings')
      ->set('account_registration.unrecognized_sender.status', TRUE)
      ->set('account_registration.unrecognized_sender.reply.status', TRUE)
      ->set('account_registration.unrecognized_sender.reply.message', $reply_message)
      ->save();
    $this
      ->sendIncomingMessage('+123123123', $this
      ->randomString());
    $this
      ->assertEquals(1, $this
      ->countUsers(), 'User created');
    $this
      ->assertTrue($this
      ->inTestMessages($this->gateway, $reply_message));
  }

  /**
   * Test if a user is created despite no email address.
   */
  public function testUnrecognisedNoEmail() {
    $this
      ->config('sms_user.settings')
      ->set('account_registration.unrecognized_sender.status', 1)
      ->save();
    $this
      ->assertEquals(0, $this
      ->countUsers());
    $this
      ->sendIncomingMessage('+123123123', $this
      ->randomString());
    $this
      ->assertFalse(empty($this
      ->getLastUser()
      ->getAccountName()));
    $this
      ->assertTrue(empty($this
      ->getLastUser()
      ->getEmail()));
  }

  /**
   * Test user is created from a incoming pattern message.
   */
  public function testIncomingPatternUserCreated() {
    $this
      ->config('sms_user.settings')
      ->set('account_registration.incoming_pattern.status', 1)
      ->set('account_registration.incoming_pattern.reply.status', 1)
      ->save();
    $username = $this
      ->randomMachineName();
    $email = 'email@email.com';
    $sender_number = '+123123123';
    $message = "E " . $email . "\nU " . $username;
    $this
      ->sendIncomingMessage($sender_number, $message);
    $user = user_load_by_name($username);
    $this
      ->assertTrue($user instanceof UserInterface, 'User was created');
    $this
      ->assertEquals($username, $user
      ->getAccountName());
    $this
      ->assertEquals($email, $user
      ->getEmail());
    $this
      ->assertEquals($sender_number, $user->{$this->phoneField
      ->getName()}->value, 'Phone number associated');
  }

  /**
   * Test all placeholders make their way into the user object.
   */
  public function testIncomingPatternPlaceholders() {
    $this
      ->config('sms_user.settings')
      ->set('account_registration.incoming_pattern.status', 1)
      ->set('account_registration.incoming_pattern.reply.status', 1)
      ->set('account_registration.incoming_pattern.incoming_messages.0', "[email] [username] [password]")
      ->save();
    $email = 'email@domain.tld';
    $username = $this
      ->randomMachineName();
    $password = $this
      ->randomMachineName();
    $message = "{$email} {$username} {$password}";
    $this
      ->sendIncomingMessage('+123123123', $message);
    $user = $this
      ->getLastUser();
    $this
      ->assertEquals($email, $user
      ->getEmail());
    $this
      ->assertEquals($username, $user
      ->getAccountName());

    // Ensure password is correct:

    /** @var \Drupal\user\UserAuthInterface $userAuth */
    $userAuth = \Drupal::service('user.auth');
    $this
      ->assertNotFalse($userAuth
      ->authenticate($username, $password));
  }

  /**
   * Test if a duplicated placeholder is confirmed.
   */
  public function testIncomingPatternMultiplePlaceholderSuccess() {
    $this
      ->config('sms_user.settings')
      ->set('account_registration.incoming_pattern.status', 1)
      ->set('account_registration.incoming_pattern.reply.status', 1)
      ->set('account_registration.incoming_pattern.incoming_messages.0', "[password] [username] [password]")
      ->save();
    $username = $this
      ->randomMachineName();
    $password = $this
      ->randomMachineName();
    $message = "{$password} {$username} {$password}";
    $this
      ->sendIncomingMessage('+123123123', $message);
  }

  /**
   * Test if a duplicated placeholder is not confirmed.
   */
  public function testIncomingPatternMultiplePlaceholderFailure() {
    $this
      ->config('sms_user.settings')
      ->set('account_registration.incoming_pattern.status', 1)
      ->set('account_registration.incoming_pattern.reply.status', 1)
      ->set('account_registration.incoming_pattern.incoming_messages.0', "[password] [username] [password]")
      ->save();
    $username = $this
      ->randomMachineName();
    $password = $this
      ->randomMachineName();
    $password2 = $this
      ->randomMachineName();
    $message = "{$password} {$username} {$password2}";
    $this
      ->sendIncomingMessage('+123123123', $message);
    $this
      ->assertFalse(user_load_by_name($username) instanceof UserInterface, 'User was not created');
  }

  /**
   * Test if a user is created despite no email address.
   */
  public function testIncomingPatternNoEmail() {
    $this
      ->config('sms_user.settings')
      ->set('account_registration.incoming_pattern.status', 1)
      ->set('account_registration.incoming_pattern.incoming_messages.0', "[username] [password]")
      ->save();
    $this
      ->assertEquals(0, $this
      ->countUsers());
    $username = $this
      ->randomMachineName();
    $message = "{$username} " . $this
      ->randomMachineName();
    $this
      ->sendIncomingMessage('+123123123', $message);
    $this
      ->assertEquals($username, $this
      ->getLastUser()
      ->getAccountName());
    $this
      ->assertTrue(empty($this
      ->getLastUser()
      ->getEmail()));
  }

  /**
   * Test if a user is created despite no placeholders.
   */
  public function testIncomingPatternNoPlaceholders() {
    $incoming_message = $this
      ->randomString();
    $this
      ->config('sms_user.settings')
      ->set('account_registration.incoming_pattern.status', 1)
      ->set('account_registration.incoming_pattern.incoming_messages.0', $incoming_message)
      ->set('account_registration.incoming_pattern.reply.status', TRUE)
      ->set('account_registration.incoming_pattern.reply.message', '[user:account-name] Foo [user:mail]')
      ->save();
    $this
      ->assertEquals(0, $this
      ->countUsers());
    $this
      ->sendIncomingMessage('+123123123', $incoming_message);
    $this
      ->assertEquals(1, $this
      ->countUsers());

    // Check reply contains randomly generated username, and empty email token.
    $user = $this
      ->getLastUser();
    $reply_message = $user
      ->getAccountName() . ' Foo ' . $user
      ->getEmail();
    $reply = $this
      ->getLastTestMessage($this->gateway);
    $this
      ->assertEquals($reply_message, $reply
      ->getMessage());
  }

  /**
   * Ensure escaped delimiters.
   */
  public function testIncomingPatternPlaceholderEscapedDelimiters() {

    // AccountRegistration::createAccount uses '/' delimiters. Ensure that they
    // are escaped otherwise a "preg_match_all(): Unknown modifier error" will
    // be thrown.
    $incoming_message = $this
      ->randomString() . '/';
    $this
      ->config('sms_user.settings')
      ->set('account_registration.incoming_pattern.status', 1)
      ->set('account_registration.incoming_pattern.incoming_messages.0', $incoming_message)
      ->save();
    $this
      ->sendIncomingMessage('+123123123', $this
      ->randomString());
  }

  /**
   * Ensure no reply sent if turned off.
   */
  public function testIncomingPatternNoReply() {
    $reply_message = $this
      ->randomString();
    $this
      ->config('sms_user.settings')
      ->set('account_registration.incoming_pattern.status', TRUE)
      ->set('account_registration.incoming_pattern.incoming_messages.0', "[username] [password]")
      ->set('account_registration.incoming_pattern.reply.status', FALSE)
      ->set('account_registration.incoming_pattern.reply.message', $reply_message)
      ->save();
    $incoming_message = $this
      ->randomMachineName() . ' ' . $this
      ->randomMachineName();
    $this
      ->sendIncomingMessage('+123123123', $incoming_message);
    $this
      ->assertEquals(1, $this
      ->countUsers(), 'User created');
    $this
      ->assertFalse($this
      ->inTestMessages($this->gateway, $reply_message));
  }

  /**
   * Ensure reply sent if turned on.
   */
  public function testIncomingPatternHasReply() {
    $reply_message = $this
      ->randomString();
    $this
      ->config('sms_user.settings')
      ->set('account_registration.incoming_pattern.status', TRUE)
      ->set('account_registration.incoming_pattern.incoming_messages.0', "[username] [password]")
      ->set('account_registration.incoming_pattern.reply.status', TRUE)
      ->set('account_registration.incoming_pattern.reply.message', $reply_message)
      ->save();
    $incoming_message = $this
      ->randomMachineName() . ' ' . $this
      ->randomMachineName();
    $this
      ->sendIncomingMessage('+123123123', $incoming_message);
    $this
      ->assertEquals(1, $this
      ->countUsers(), 'User created');
    $this
      ->assertTrue($this
      ->inTestMessages($this->gateway, $reply_message));
  }

  /**
   * Ensure account activation email sent.
   */
  public function testIncomingPatternActivateEmail() {
    $this
      ->config('sms_user.settings')
      ->set('account_registration.incoming_pattern.status', TRUE)
      ->set('account_registration.incoming_pattern.incoming_messages.0', "E [email] U [username]")
      ->set('account_registration.incoming_pattern.send_activation_email', TRUE)
      ->save();
    $subject = $this
      ->randomMachineName();
    $this
      ->config('user.mail')
      ->set('register_no_approval_required.subject', $subject)
      ->set('register_no_approval_required.body', 'Foo [user:display-name] Bar')
      ->save();
    $email = 'email@domain.tld';
    $username = $this
      ->randomMachineName();
    $this
      ->sendIncomingMessage('+123123123', 'E ' . $email . ' U ' . $username);
    $emails = $this
      ->getMails();
    $this
      ->assertEquals(1, count($emails), 'One email was sent.');
    $this
      ->assertMailString('to', $email, 1);
    $this
      ->assertMailString('subject', $subject, 1);
    $this
      ->assertMailString('body', 'Foo ' . $username . ' Bar', 1);
  }

  /**
   * Ensure no activation email sent.
   */
  public function testIncomingPatternNoActivateEmail() {
    $this
      ->config('sms_user.settings')
      ->set('account_registration.incoming_pattern.status', TRUE)
      ->set('account_registration.incoming_pattern.incoming_messages.0', "E [email] P [password]")
      ->set('account_registration.incoming_pattern.send_activation_email', TRUE)
      ->save();
    $this
      ->config('user.mail')
      ->set('register_no_approval_required.subject', $this
      ->randomMachineName())
      ->set('register_no_approval_required.body', $this
      ->randomMachineName())
      ->save();
    $email = 'email@domain.tld';
    $password = $this
      ->randomMachineName();
    $this
      ->sendIncomingMessage('+123123123', 'E ' . $email . ' P ' . $password);
    $emails = $this
      ->getMails();
    $this
      ->assertEquals(0, count($emails), 'Zero emails sent because incoming message contained password.');
  }

  /**
   * Test error builder.
   *
   * @covers ::buildError
   */
  public function testErrorBuilder() {
    $failure_prefix = 'foo: ';
    $this
      ->config('sms_user.settings')
      ->set('account_registration.incoming_pattern.status', 1)
      ->set('account_registration.incoming_pattern.incoming_messages.0', "[username] [email]")
      ->set('account_registration.incoming_pattern.reply.status', 1)
      ->set('account_registration.incoming_pattern.reply.message_failure', $failure_prefix . '[error]')
      ->save();
    $username = $this
      ->randomMachineName();
    $email = 'email@domain.tld';
    User::create([
      'name' => $username,
      'mail' => $email,
    ])
      ->save();
    $message = "{$username} " . $this
      ->randomMachineName();
    $this
      ->sendIncomingMessage('+123123123', $message);
    $expected_error = 'The username ' . $username . ' is already taken. This value is not a valid email address. ';
    $actual = $this
      ->getLastTestMessage($this->gateway)
      ->getMessage();
    $this
      ->assertEquals($failure_prefix . $expected_error, $actual);
  }

  /**
   * Test unique username.
   *
   * @covers ::generateUniqueUsername
   */
  public function testUniqueUsername() {
    $this
      ->config('sms_user.settings')
      ->set('account_registration.unrecognized_sender.status', 1)
      ->save();
    $this
      ->sendIncomingMessage('+123123123', $this
      ->randomString());
    $user1 = $this
      ->getLastUser();
    $this
      ->sendIncomingMessage('+456456456', $this
      ->randomString());
    $user2 = $this
      ->getLastUser();
    $this
      ->assertNotEquals($user1
      ->getAccountName(), $user2
      ->getAccountName());
  }

  /**
   * Ensure non-global tokens and [user:password] are replaced in reply message.
   */
  public function testReplyTokens() {
    $this
      ->config('sms_user.settings')
      ->set('account_registration.incoming_pattern.status', TRUE)
      ->set('account_registration.incoming_pattern.incoming_messages.0', "[username] [password]")
      ->set('account_registration.incoming_pattern.reply.status', TRUE)
      ->set('account_registration.incoming_pattern.reply.message', 'Username is [user:account-name] Password is [user:password]')
      ->save();
    $username = $this
      ->randomMachineName();
    $password = $this
      ->randomMachineName();
    $incoming_message = $username . ' ' . $password;
    $this
      ->sendIncomingMessage('+123123123', $incoming_message);
    $reply_message = 'Username is ' . $username . ' Password is ' . $password;
    $this
      ->assertTrue($this
      ->inTestMessages($this->gateway, $reply_message));
  }

  /**
   * Send an incoming SMS message.
   *
   * @param string $sender_number
   *   The sender phone number.
   * @param string $message
   *   The message to send inwards.
   */
  protected function sendIncomingMessage($sender_number, $message) {

    /** @var \Drupal\sms\Entity\SmsMessage $incoming */
    $incoming = SmsMessage::create()
      ->setSenderNumber($sender_number)
      ->setDirection(Direction::INCOMING)
      ->setMessage($message)
      ->addRecipients($this
      ->randomPhoneNumbers(1))
      ->setGateway($this->gateway);
    $incoming
      ->setResult($this
      ->createMessageResult($incoming));
    $this->smsProvider
      ->queue($incoming);
  }

  /**
   * Count number of registered users.
   *
   * @return int
   *   Number of users in database.
   */
  protected function countUsers() {
    return count(User::loadMultiple());
  }

  /**
   * Count number of registered users.
   *
   * @return \Drupal\user\UserInterface|null
   *   Get last created user, or NULL if no users in database.
   */
  protected function getLastUser() {
    $users = User::loadMultiple();
    return $users ? end($users) : NULL;
  }

  /**
   * Check if the message body can be found in the test message memory buffer.
   *
   * @param \Drupal\sms\Entity\SmsGatewayInterface $sms_gateway
   *   A gateway plugin instance.
   * @param string $message
   *   The message to check.
   *
   * @return bool
   *   Whether message was found in any memory messages.
   */
  public function inTestMessages(SmsGatewayInterface $sms_gateway, $message) {
    foreach ($this
      ->getTestMessages($sms_gateway) as $sms_message) {
      if ($sms_message
        ->getMessage() == $message) {
        return TRUE;
      }
    }
    return FALSE;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
AssertContentTrait::$content protected property The current raw content.
AssertContentTrait::$drupalSettings protected property The drupalSettings value from the current raw $content.
AssertContentTrait::$elements protected property The XML structure parsed from the current raw $content. 1
AssertContentTrait::$plainTextContent protected property The plain-text content of raw $content (text nodes).
AssertContentTrait::assertEscaped protected function Passes if the raw text IS found escaped on the loaded page, fail otherwise.
AssertContentTrait::assertField protected function Asserts that a field exists with the given name or ID.
AssertContentTrait::assertFieldById protected function Asserts that a field exists with the given ID and value.
AssertContentTrait::assertFieldByName protected function Asserts that a field exists with the given name and value.
AssertContentTrait::assertFieldByXPath protected function Asserts that a field exists in the current page by the given XPath.
AssertContentTrait::assertFieldChecked protected function Asserts that a checkbox field in the current page is checked.
AssertContentTrait::assertFieldsByValue protected function Asserts that a field exists in the current page with a given Xpath result.
AssertContentTrait::assertLink protected function Passes if a link with the specified label is found.
AssertContentTrait::assertLinkByHref protected function Passes if a link containing a given href (part) is found.
AssertContentTrait::assertNoDuplicateIds protected function Asserts that each HTML ID is used for just a single element.
AssertContentTrait::assertNoEscaped protected function Passes if the raw text IS NOT found escaped on the loaded page, fail otherwise.
AssertContentTrait::assertNoField protected function Asserts that a field does not exist with the given name or ID.
AssertContentTrait::assertNoFieldById protected function Asserts that a field does not exist with the given ID and value.
AssertContentTrait::assertNoFieldByName protected function Asserts that a field does not exist with the given name and value.
AssertContentTrait::assertNoFieldByXPath protected function Asserts that a field does not exist or its value does not match, by XPath.
AssertContentTrait::assertNoFieldChecked protected function Asserts that a checkbox field in the current page is not checked.
AssertContentTrait::assertNoLink protected function Passes if a link with the specified label is not found.
AssertContentTrait::assertNoLinkByHref protected function Passes if a link containing a given href (part) is not found.
AssertContentTrait::assertNoLinkByHrefInMainRegion protected function Passes if a link containing a given href is not found in the main region.
AssertContentTrait::assertNoOption protected function Asserts that a select option in the current page does not exist.
AssertContentTrait::assertNoOptionSelected protected function Asserts that a select option in the current page is not checked.
AssertContentTrait::assertNoPattern protected function Triggers a pass if the perl regex pattern is not found in raw content.
AssertContentTrait::assertNoRaw protected function Passes if the raw text is NOT found on the loaded page, fail otherwise.
AssertContentTrait::assertNoText protected function Passes if the page (with HTML stripped) does not contains the text.
AssertContentTrait::assertNoTitle protected function Pass if the page title is not the given string.
AssertContentTrait::assertNoUniqueText protected function Passes if the text is found MORE THAN ONCE on the text version of the page.
AssertContentTrait::assertOption protected function Asserts that a select option in the current page exists.
AssertContentTrait::assertOptionByText protected function Asserts that a select option with the visible text exists.
AssertContentTrait::assertOptionSelected protected function Asserts that a select option in the current page is checked.
AssertContentTrait::assertOptionSelectedWithDrupalSelector protected function Asserts that a select option in the current page is checked.
AssertContentTrait::assertOptionWithDrupalSelector protected function Asserts that a select option in the current page exists.
AssertContentTrait::assertPattern protected function Triggers a pass if the Perl regex pattern is found in the raw content.
AssertContentTrait::assertRaw protected function Passes if the raw text IS found on the loaded page, fail otherwise.
AssertContentTrait::assertText protected function Passes if the page (with HTML stripped) contains the text.
AssertContentTrait::assertTextHelper protected function Helper for assertText and assertNoText.
AssertContentTrait::assertTextPattern protected function Asserts that a Perl regex pattern is found in the plain-text content.
AssertContentTrait::assertThemeOutput protected function Asserts themed output.
AssertContentTrait::assertTitle protected function Pass if the page title is the given string.
AssertContentTrait::assertUniqueText protected function Passes if the text is found ONLY ONCE on the text version of the page.
AssertContentTrait::assertUniqueTextHelper protected function Helper for assertUniqueText and assertNoUniqueText.
AssertContentTrait::buildXPathQuery protected function Builds an XPath query.
AssertContentTrait::constructFieldXpath protected function Helper: Constructs an XPath for the given set of attributes and value.
AssertContentTrait::cssSelect protected function Searches elements using a CSS selector in the raw content.
AssertContentTrait::getAllOptions protected function Get all option elements, including nested options, in a select.
AssertContentTrait::getDrupalSettings protected function Gets the value of drupalSettings for the currently-loaded page.
AssertContentTrait::getRawContent protected function Gets the current raw content.
AssertContentTrait::getSelectedItem protected function Get the selected value from a select field.
AssertContentTrait::getTextContent protected function Retrieves the plain-text content from the current raw content.
AssertContentTrait::getUrl protected function Get the current URL from the cURL handler. 1
AssertContentTrait::parse protected function Parse content returned from curlExec using DOM and SimpleXML.
AssertContentTrait::removeWhiteSpace protected function Removes all white-space between HTML tags from the raw content.
AssertContentTrait::setDrupalSettings protected function Sets the value of drupalSettings for the currently-loaded page.
AssertContentTrait::setRawContent protected function Sets the raw content (e.g. HTML).
AssertContentTrait::xpath protected function Performs an xpath search on the contents of the internal browser.
AssertHelperTrait::castSafeStrings protected static function Casts MarkupInterface objects into strings.
AssertLegacyTrait::assert protected function Deprecated Scheduled for removal in Drupal 10.0.0. Use self::assertTrue() instead.
AssertLegacyTrait::assertEqual protected function Deprecated Scheduled for removal in Drupal 10.0.0. Use self::assertEquals() instead.
AssertLegacyTrait::assertIdentical protected function Deprecated Scheduled for removal in Drupal 10.0.0. Use self::assertSame() instead.
AssertLegacyTrait::assertIdenticalObject protected function Deprecated Scheduled for removal in Drupal 10.0.0. Use self::assertEquals() instead.
AssertLegacyTrait::assertNotEqual protected function Deprecated Scheduled for removal in Drupal 10.0.0. Use self::assertNotEquals() instead.
AssertLegacyTrait::assertNotIdentical protected function Deprecated Scheduled for removal in Drupal 10.0.0. Use self::assertNotSame() instead.
AssertLegacyTrait::pass protected function Deprecated Scheduled for removal in Drupal 10.0.0. Use self::assertTrue() instead.
AssertLegacyTrait::verbose protected function
AssertMailTrait::assertMail protected function Asserts that the most recently sent email message has the given value.
AssertMailTrait::assertMailPattern protected function Asserts that the most recently sent email message has the pattern in it.
AssertMailTrait::assertMailString protected function Asserts that the most recently sent email message has the string in it.
AssertMailTrait::getMails protected function Gets an array containing all emails sent during this test case.
AssertMailTrait::verboseEmail protected function Outputs to verbose the most recent $count emails sent.
ConfigTestTrait::configImporter protected function Returns a ConfigImporter object to import test configuration.
ConfigTestTrait::copyConfig protected function Copies configuration objects from source storage to target storage.
KernelTestBase::$backupGlobals protected property Back up and restore any global variables that may be changed by tests.
KernelTestBase::$backupStaticAttributes protected property Back up and restore static class properties that may be changed by tests.
KernelTestBase::$backupStaticAttributesBlacklist protected property Contains a few static class properties for performance.
KernelTestBase::$classLoader protected property
KernelTestBase::$configImporter protected property @todo Move into Config test base class. 7
KernelTestBase::$configSchemaCheckerExclusions protected static property An array of config object names that are excluded from schema checking.
KernelTestBase::$container protected property
KernelTestBase::$databasePrefix protected property
KernelTestBase::$preserveGlobalState protected property Do not forward any global state from the parent process to the processes that run the actual tests.
KernelTestBase::$root protected property The app root.
KernelTestBase::$runTestInSeparateProcess protected property Kernel tests are run in separate processes because they allow autoloading of code from extensions. Running the test in a separate process isolates this behavior from other tests. Subclasses should not override this property.
KernelTestBase::$siteDirectory protected property
KernelTestBase::$strictConfigSchema protected property Set to TRUE to strict check all configuration saved. 6
KernelTestBase::$vfsRoot protected property The virtual filesystem root directory.
KernelTestBase::assertPostConditions protected function 1
KernelTestBase::bootEnvironment protected function Bootstraps a basic test environment.
KernelTestBase::bootKernel private function Bootstraps a kernel for a test.
KernelTestBase::config protected function Configuration accessor for tests. Returns non-overridden configuration.
KernelTestBase::disableModules protected function Disables modules for this test.
KernelTestBase::enableModules protected function Enables modules for this test.
KernelTestBase::getConfigSchemaExclusions protected function Gets the config schema exclusions for this test.
KernelTestBase::getDatabaseConnectionInfo protected function Returns the Database connection info to be used for this test. 1
KernelTestBase::getDatabasePrefix public function
KernelTestBase::getExtensionsForModules private function Returns Extension objects for $modules to enable.
KernelTestBase::getModulesToEnable private static function Returns the modules to enable for this test.
KernelTestBase::initFileCache protected function Initializes the FileCache component.
KernelTestBase::installConfig protected function Installs default configuration for a given list of modules.
KernelTestBase::installEntitySchema protected function Installs the storage schema for a specific entity type.
KernelTestBase::installSchema protected function Installs database tables from a module schema definition.
KernelTestBase::isTestInIsolation Deprecated protected function Returns whether the current test method is running in a separate process.
KernelTestBase::prepareTemplate protected function
KernelTestBase::register public function Registers test-specific services. Overrides ServiceProviderInterface::register 26
KernelTestBase::render protected function Renders a render array. 1
KernelTestBase::setInstallProfile protected function Sets the install profile and rebuilds the container to update it.
KernelTestBase::setSetting protected function Sets an in-memory Settings variable.
KernelTestBase::setUpBeforeClass public static function 1
KernelTestBase::setUpFilesystem protected function Sets up the filesystem, so things like the file directory. 2
KernelTestBase::stop protected function Stops test execution.
KernelTestBase::tearDown protected function 6
KernelTestBase::tearDownCloseDatabaseConnection public function @after
KernelTestBase::vfsDump protected function Dumps the current state of the virtual filesystem to STDOUT.
KernelTestBase::__get Deprecated public function BC: Automatically resolve former KernelTestBase class properties.
KernelTestBase::__sleep public function Prevents serializing any properties.
PhpunitCompatibilityTrait::getMock Deprecated public function Returns a mock object for the specified class using the available method.
PhpunitCompatibilityTrait::setExpectedException Deprecated public function Compatibility layer for PHPUnit 6 to support PHPUnit 4 code.
RandomGeneratorTrait::$randomGenerator protected property The random generator.
RandomGeneratorTrait::getRandomGenerator protected function Gets the random generator for the utility methods.
RandomGeneratorTrait::randomMachineName protected function Generates a unique random string containing letters and numbers. 1
RandomGeneratorTrait::randomObject public function Generates a random PHP object.
RandomGeneratorTrait::randomString public function Generates a pseudo-random string of ASCII characters of codes 32 to 126.
RandomGeneratorTrait::randomStringValidate public function Callback for random string validation.
SmsFrameworkTestTrait::createEntityWithPhoneNumber protected function Creates an entity, and optionally adds phone numbers.
SmsFrameworkTestTrait::createMemoryGateway protected function Creates a memory gateway.
SmsFrameworkTestTrait::createMessageResult protected function Create a result and reports for a message.
SmsFrameworkTestTrait::getIncomingMessages protected function Get all messages received by a gateway.
SmsFrameworkTestTrait::getLastIncomingMessage protected function Get the last message sent to gateway.
SmsFrameworkTestTrait::getLastTestMessage public function Get the last SMS message sent to 'Memory' gateway.
SmsFrameworkTestTrait::getLastTestMessageReport protected function Gets the last SMS report for messages sent to 'Memory' gateway.
SmsFrameworkTestTrait::getLastVerification protected function Gets the last phone number verification that was created.
SmsFrameworkTestTrait::getTestMessageReport protected function Gets an SMS report for message with message ID.
SmsFrameworkTestTrait::getTestMessageReports protected function Gets all SMS reports for messages sent to 'Memory' gateway.
SmsFrameworkTestTrait::getTestMessages public function Get all SMS messages sent to a 'Memory' gateway.
SmsFrameworkTestTrait::randomPhoneNumbers protected function Generates random phone numbers for tests.
SmsFrameworkTestTrait::randomSmsMessage protected function Generates a random SMS message by the specified user.
SmsFrameworkTestTrait::resetIncomingMessages protected function Resets incoming messages stored in memory by gateway.
SmsFrameworkTestTrait::resetTestMessageReports protected function Resets the SMS reports stored in memory by 'Memory' gateway.
SmsFrameworkTestTrait::resetTestMessages public function Resets SMS messages stored in memory by 'Memory' gateway.
SmsFrameworkTestTrait::setFallbackGateway protected function Sets the fallback gateway.
SmsFrameworkTestTrait::verifyPhoneNumber protected function Forces verification of a phone number for an entity.
SmsFrameworkUserAccountRegistrationServiceTest::$accountRegistration protected property The account registration service.
SmsFrameworkUserAccountRegistrationServiceTest::$gateway protected property A memory gateway.
SmsFrameworkUserAccountRegistrationServiceTest::$modules public static property Modules to enable. Overrides KernelTestBase::$modules
SmsFrameworkUserAccountRegistrationServiceTest::$phoneField protected property A phone field ofr testing.
SmsFrameworkUserAccountRegistrationServiceTest::$phoneNumberSettings protected property Phone number settings for user entity type.
SmsFrameworkUserAccountRegistrationServiceTest::$smsProvider protected property The default SMS provider.
SmsFrameworkUserAccountRegistrationServiceTest::countUsers protected function Count number of registered users.
SmsFrameworkUserAccountRegistrationServiceTest::getLastUser protected function Count number of registered users.
SmsFrameworkUserAccountRegistrationServiceTest::inTestMessages public function Check if the message body can be found in the test message memory buffer.
SmsFrameworkUserAccountRegistrationServiceTest::sendIncomingMessage protected function Send an incoming SMS message.
SmsFrameworkUserAccountRegistrationServiceTest::setUp protected function Overrides SmsFrameworkKernelBase::setUp
SmsFrameworkUserAccountRegistrationServiceTest::testErrorBuilder public function Test error builder.
SmsFrameworkUserAccountRegistrationServiceTest::testIncomingPatternActivateEmail public function Ensure account activation email sent.
SmsFrameworkUserAccountRegistrationServiceTest::testIncomingPatternHasReply public function Ensure reply sent if turned on.
SmsFrameworkUserAccountRegistrationServiceTest::testIncomingPatternMultiplePlaceholderFailure public function Test if a duplicated placeholder is not confirmed.
SmsFrameworkUserAccountRegistrationServiceTest::testIncomingPatternMultiplePlaceholderSuccess public function Test if a duplicated placeholder is confirmed.
SmsFrameworkUserAccountRegistrationServiceTest::testIncomingPatternNoActivateEmail public function Ensure no activation email sent.
SmsFrameworkUserAccountRegistrationServiceTest::testIncomingPatternNoEmail public function Test if a user is created despite no email address.
SmsFrameworkUserAccountRegistrationServiceTest::testIncomingPatternNoPlaceholders public function Test if a user is created despite no placeholders.
SmsFrameworkUserAccountRegistrationServiceTest::testIncomingPatternNoReply public function Ensure no reply sent if turned off.
SmsFrameworkUserAccountRegistrationServiceTest::testIncomingPatternPlaceholderEscapedDelimiters public function Ensure escaped delimiters.
SmsFrameworkUserAccountRegistrationServiceTest::testIncomingPatternPlaceholders public function Test all placeholders make their way into the user object.
SmsFrameworkUserAccountRegistrationServiceTest::testIncomingPatternUserCreated public function Test user is created from a incoming pattern message.
SmsFrameworkUserAccountRegistrationServiceTest::testReplyTokens public function Ensure non-global tokens and [user:password] are replaced in reply message.
SmsFrameworkUserAccountRegistrationServiceTest::testUniqueUsername public function Test unique username.
SmsFrameworkUserAccountRegistrationServiceTest::testUnrecognisedCreateUser public function Test user is created if a unrecognised phone number is used as sender.
SmsFrameworkUserAccountRegistrationServiceTest::testUnrecognisedCreateUserPhoneNumberRecognised public function Test a user is not created if the sender phone number is already used.
SmsFrameworkUserAccountRegistrationServiceTest::testUnrecognisedGotReply public function Ensure reply sent if turned on.
SmsFrameworkUserAccountRegistrationServiceTest::testUnrecognisedNoEmail public function Test if a user is created despite no email address.
SmsFrameworkUserAccountRegistrationServiceTest::testUnrecognisedNoReply public function Ensure no reply sent if turned off.
SmsFrameworkUserAccountRegistrationServiceTest::testUnrecognisedOffNoCreateUser public function Ensure incoming SMS does not create messages or users.
StorageCopyTrait::replaceStorageContents protected static function Copy the configuration from one storage to another and remove stale items.
TestRequirementsTrait::checkModuleRequirements private function Checks missing module requirements.
TestRequirementsTrait::checkRequirements protected function Check module requirements for the Drupal use case. 1
TestRequirementsTrait::getDrupalRoot protected static function Returns the Drupal root directory.