You are here

public function SmsSendToPhoneBrowserTest::testSendToPhoneFilter in SMS Framework 2.x

Same name and namespace in other branches
  1. 8 modules/sms_sendtophone/tests/src/Functional/SmsSendToPhoneBrowserTest.php \Drupal\Tests\sms_sendtophone\Functional\SmsSendToPhoneBrowserTest::testSendToPhoneFilter()
  2. 2.1.x modules/sms_sendtophone/tests/src/Functional/SmsSendToPhoneBrowserTest.php \Drupal\Tests\sms_sendtophone\Functional\SmsSendToPhoneBrowserTest::testSendToPhoneFilter()

Tests sendtophone filter integration.

File

modules/sms_sendtophone/tests/src/Functional/SmsSendToPhoneBrowserTest.php, line 155

Class

SmsSendToPhoneBrowserTest
Integration tests for the SMS SendToPhone Module.

Namespace

Drupal\Tests\sms_sendtophone\Functional

Code

public function testSendToPhoneFilter() {
  $user = $this
    ->drupalCreateUser([
    'administer filters',
  ]);
  $this
    ->drupalLogin($user);
  $edit = [
    'filters[filter_inline_sms][status]' => TRUE,
    'filters[filter_inline_sms][settings][display]' => 'text',
  ];
  $this
    ->drupalPostForm('admin/config/content/formats/manage/plain_text', $edit, t('Save configuration'));

  // Create a new node sms markup and verify that a link is created.
  $type_names = array_keys(NodeType::loadMultiple());
  $node_body = $this
    ->randomMachineName(30);
  $node = $this
    ->drupalCreateNode([
    'type' => array_pop($type_names),
    'body' => [
      [
        'value' => "[sms]{$node_body}[/sms]",
        'format' => 'plain_text',
      ],
    ],
  ]);

  // Unconfirmed users.
  $this
    ->drupalGet('sms/sendtophone/inline');
  $this
    ->assertText('You need to set up and confirm your mobile phone to send messages');

  // Confirm phone number.
  $phone_number = $this
    ->randomPhoneNumbers(1)[0];
  $user->{$this->phoneField
    ->getName()} = [
    $phone_number,
  ];
  $user
    ->save();
  $this
    ->verifyPhoneNumber($user, $phone_number);
  $this
    ->drupalGet($node
    ->toUrl());

  // Confirm link was created for Send to phone.
  $this
    ->assertText("{$node_body} (Send to phone)");
  $this
    ->clickLink('(Send to phone)');
  $this
    ->assertResponse(200);
  $this
    ->assertText($node_body);

  // Submit phone number and confirm message received.
  $this
    ->drupalPostForm(NULL, [], t('Send'), [
    'query' => [
      'text' => $node_body,
    ],
  ]);
  $sms_message = $this
    ->getLastTestMessage($this->gateway);
  $this
    ->assertEqual($sms_message
    ->getMessage(), $node_body, 'Message body "' . $node_body . '" successfully sent.');
}