You are here

public function SmsSendToPhoneWebTest::testFieldFormatAndWidget in SMS Framework 7

Tests field format integration and widget.

File

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

Class

SmsSendToPhoneWebTest
Tests the SMS SendToPhone functionality.

Code

public function testFieldFormatAndWidget() {
  $user = $this
    ->drupalCreateUser();
  $this
    ->drupalLogin($user);

  // Create a custom field of type 'text' using the sms_sendtophone formatter.
  $bundles = array_keys(node_type_get_types());
  $field_name = strtolower($this
    ->randomName());
  $instance = array(
    'field_name' => $field_name,
    'entity_type' => 'node',
    'bundle' => $bundles[0],
    'display' => array(
      'default' => array(
        'type' => 'sms_sendtophone',
      ),
    ),
  );
  field_create_field(array(
    'field_name' => $field_name,
    'type' => 'text',
  ));
  field_create_instance($instance);
  $random_text = $this
    ->randomName(32);
  $test_node = $this
    ->drupalCreateNode(array(
    'type' => $bundles[0],
    $field_name => array(
      'und' => array(
        array(
          'value' => $random_text,
        ),
      ),
    ),
  ));

  // Setup users phone number to check sending.
  $edit['sms_user'] = array(
    'number' => '97623234568',
    'status' => 2,
  );
  user_save($user, $edit);

  // Set test gateway and click send button.
  variable_set('sms_default_gateway', 'test');
  $this
    ->drupalGet('node/' . $test_node->nid);
  $this
    ->assertText($random_text . ' (Send to phone)');
  $this
    ->clickLink('Send to phone');
  $this
    ->assertText($random_text, 'Field format works');

  // Click the send button there.
  $this
    ->drupalPost('sms/sendtophone/field', NULL, 'Send', array(
    'query' => array(
      'text' => $random_text,
    ),
  ));
  $result = sms_test_gateway_result();
  $this
    ->assertEqual($result['number'], $edit['sms_user']['number'], 'Message sent to correct number');
  $this
    ->assertEqual($result['message'], $random_text, 'Field content sent to user with number ' . $result['number']);
}