public function SmsUserWebTest::testSmsUserOptions in SMS Framework 7
Tests sms_user admin options.
File
- modules/
sms_user/ tests/ sms_user.test, line 95 - Contains tests for the functions in sms_user.module and user integration.
Class
- SmsUserWebTest
- Provides integration tests for the sms_user module.
Code
public function testSmsUserOptions() {
$user = $this
->drupalCreateUser(array(
'administer smsframework',
'receive sms',
'edit own sms number',
));
$this
->drupalLogin($user);
// Set the sms_user admin options.
$edit = array(
'sms_user_registration_form' => 0,
'sms_user_confirmation_message' => $this
->randomString(20),
'sms_user_sleep' => 1,
'sms_user_sleep_start_time' => 1,
'sms_user_sleep_end_time' => 1,
'sms_user_registration_enabled' => 1,
'sms_user_allow_password' => 1,
'sms_user_new_account_message' => $this
->randomString(30),
'sms_user_max_chars' => 160,
);
$this
->drupalPost('admin/smsframework/sms_user_options', $edit, t('Save configuration'));
$this
->assertResponse(200);
// Verify that the variables are set.
foreach ($edit as $name => $value) {
$this
->assertEqual($value, variable_get($name), sprintf('Variable %s has been set.', $name));
}
// Check that the user registration page honors the mobile number field
// visibility and required options.
$this
->drupalLogout();
// Mobile fields disabled.
variable_set('sms_user_registration_form', 0);
$this
->drupalGet('user/register');
$this
->assertNoField('sms_user[number]', 'No number field in registration form.');
// Mobile fields optional.
variable_set('sms_user_registration_form', 1);
$this
->drupalGet('user/register');
$this
->assertField('sms_user[number]', 'Number field in registration form.');
// Post without the mobile number and confirm success.
$edit = array(
'name' => $this
->randomName(),
'mail' => $this
->randomName() . '@example.com',
);
$this
->drupalPost(NULL, $edit, 'Create new account');
$this
->assertUrl('<front>');
$this
->assertText('Thank you for applying for an account.', 'Successfully posted registration form without optional mobile number.');
// Mobile fields required.
variable_set('sms_user_registration_form', 2);
$this
->drupalGet('user/register');
$this
->assertField('sms_user[number]', 'Number field in registration form.');
$this
->assertText('Phone number *', 'Number field is required.');
// Post without the mobile number and confirm validation failure.
$edit = array(
'name' => $this
->randomName(),
'mail' => $this
->randomName() . '@example.com',
);
$this
->drupalPost(NULL, $edit, 'Create new account');
$this
->assertUrl('user/register');
$this
->assertText('Phone number field is required.', 'Failed to post registration form without required mobile number.');
}