You are here

public function SmsSendToPhoneWebTest::testSendToPhoneFilter in SMS Framework 7

Tests sendtophone filter integration.

File

modules/sms_sendtophone/sms_sendtophone.test, line 93
Contains tests for sms_sendtophone.module

Class

SmsSendToPhoneWebTest
Tests the SMS SendToPhone functionality.

Code

public function testSendToPhoneFilter() {
  $filtered_html_format = filter_format_load('filtered_html');
  $user = $this
    ->drupalCreateUser(array(
    'administer filters',
    filter_permission_name($filtered_html_format),
  ));
  $this
    ->drupalLogin($user);
  $edit = array(
    'filters[sms_sendtophone][status]' => true,
    'filters[sms_sendtophone][settings][sms_sendtophone_filter_inline_display]' => 'text',
  );
  $this
    ->drupalPost('admin/config/content/formats/filtered_html', $edit, t('Save configuration'));

  // Create a new node sms markup and verify that a link is created.
  $type_names = array_keys(node_type_get_types());
  $node_body = $this
    ->randomName(30);
  $node = $this
    ->drupalCreateNode(array(
    'type' => array_pop($type_names),
    'body' => array(
      LANGUAGE_NONE => array(
        array(
          'value' => "[sms]{$node_body}[/sms]",
          'format' => 'filtered_html',
        ),
      ),
    ),
  ));
  $this
    ->drupalGet('node/' . $node->nid);

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

  // Add confirmed phone number assert the corresponding message.
  $edit['sms_user'] = array(
    'number' => '97623234568',
    'status' => 2,
  );
  user_save($user, $edit);
  $this
    ->clickLink('Send to phone');
  $this
    ->assertText($node_body);

  // Submit phone number and confirm message received.
  variable_set('sms_default_gateway', 'test');
  $this
    ->drupalPost('sms/sendtophone/inline', array(), t('Send'), array(
    'query' => array(
      'text' => $node_body,
      'destination' => 'node/' . $node->nid,
    ),
  ));
  $result = sms_test_gateway_result();
  $this
    ->assertEqual($result['message'], $node_body, 'Message body "' . $node_body . '" successfully sent.');

  // For number not registered, assert the corresponding message.
  sms_user_delete_user_info($user->uid);
  $this
    ->drupalGet('sms/sendtophone/inline');
  $this
    ->assertText('You need to setup your mobile phone to send messages.');

  // Check for unconfirmed number.
  $edit['sms_user'] = array(
    'number' => '97623234568',
    'status' => 1,
  );
  user_save($user, $edit);
  $this
    ->drupalGet('sms/sendtophone/inline');
  $this
    ->assertText('You need to confirm your mobile phone number to send messages.');
}