public function SmsSendToPhoneWebTest::testAdminSettingsAndSendToPhone in SMS Framework 7
Tests admin settings page and sendtophone node integration.
File
- modules/
sms_sendtophone/ sms_sendtophone.test, line 34 - Contains tests for sms_sendtophone.module
Class
- SmsSendToPhoneWebTest
- Tests the SMS SendToPhone functionality.
Code
public function testAdminSettingsAndSendToPhone() {
$user = $this
->drupalCreateUser(array(
'administer smsframework',
));
$this
->drupalLogin($user);
$this
->drupalGet('admin/smsframework/sendtophone');
$edit = array();
$expected = array();
foreach (node_type_get_types() as $type) {
$this
->assertText($type->name);
$edit["sms_sendtophone_content_types[{$type->type}]"] = $expected[$type->type] = rand(0, 1) > 0.5;
}
// Ensure at least one type is enabled.
$edit["sms_sendtophone_content_types[page]"] = $expected['page'] = true;
$this
->drupalPost('admin/smsframework/sendtophone', $edit, t('Save configuration'));
$saved = variable_get('sms_sendtophone_content_types', array());
$this
->assertEqual($expected, $saved);
// Create a new node with sendtophone enabled and verify that the button is
// added.
$types = array_keys(array_filter($expected));
$node = $this
->drupalCreateNode(array(
'type' => $types[0],
));
$this
->drupalGet('node/' . $node->nid);
// Confirm message for user without confirmed number.
$this
->assertText('Setup your mobile number to send to phone.');
// Add unconfirmed phone number.
$edit['sms_user']['number'] = '23456897623';
user_save($user, $edit);
$this
->drupalGet('user/' . $user->uid . 'edit');
$this
->drupalGet('node/' . $node->nid);
// Confirm message for user without confirmed number.
$this
->assertText('Confirm your mobile number to send to phone.');
// Confirm phone number.
$edit['sms_user']['status'] = 2;
user_save($user, $edit);
$this
->drupalGet('node/' . $node->nid);
// Confirm message for user without confirmed number.
$this
->assertText('Send to phone');
$this
->assertFieldByXPath('//a[@title="Send a link via SMS." and @class="sms-sendtophone"]', NULL);
// Navigate to the "Send to phone" link.
$this
->clickLink('Send to phone');
$this
->assertResponse(200);
$this
->assertText(url('node/' . $node->nid, array(
'absolute' => true,
)));
// Set test gateway.
variable_set('sms_default_gateway', 'test');
// Click the send button there.
$this
->drupalPost('sms/sendtophone/node/1', array(), t('Send'));
$result = sms_test_gateway_result();
$this
->assertEqual($result['number'], $edit['sms_user']['number']);
$this
->assertEqual($result['message'], url('node/' . $node->nid, array(
'absolute' => true,
)));
}