public function SmsTrackArchiveTestCase::testArchiveWriteForSentMessages in SMS Framework 7
Tests recording a message sent from one site user to another.
File
- modules/
sms_track/ tests/ sms_track.test, line 39
Class
- SmsTrackArchiveTestCase
- Provides integration tests for the SMS Framework.
Code
public function testArchiveWriteForSentMessages() {
// Create Author User
$author = $this
->drupalCreateAdminUser();
$this
->drupalLogin($author);
$archiving_settings = array(
'archive_dir' => '4',
);
$this
->drupalPost('admin/smsframework/sms_track', $archiving_settings, t('Save'));
$sms_user_settings = array(
'sms_user_registration_enabled' => FALSE,
'sms_user_allow_password' => FALSE,
);
$this
->drupalPost('admin/smsframework/sms_user_options', $sms_user_settings, t('Save configuration'));
// Confirm author number.
$edit = array(
'number' => '1234567890',
);
$this
->drupalPost('user/' . $author->uid . '/edit/mobile', $edit, t('Confirm number'));
$this
->drupalPost(NULL, NULL, t('Confirm without code'));
$this
->assertText('Your mobile phone number has been confirmed.', 'Authors number is confirmed');
$this
->drupalLogout();
// Create Recipient User
$recipient = $this
->drupalCreateAdminUser();
$this
->drupalLogin($recipient);
// Confirm recipient number.
$edit = array(
'number' => '0987654321',
);
$this
->drupalPost('user/' . $recipient->uid . '/edit/mobile', $edit, t('Confirm number'));
$this
->drupalPost(NULL, NULL, t('Confirm without code'));
$this
->assertText('Your mobile phone number has been confirmed.', 'Recipients number is confirmed');
$this
->drupalLogout();
$this
->drupalLogin($author);
// Send messages to registered users and confirm they are recorded properly.
$test_message = array(
'number' => '0987654321',
'message' => 'Test archiving messages from one registered number to another',
);
$this
->drupalPost('admin/smsframework/devel', $test_message, t('Send Message'));
$this
->assertResponse(200);
$this
->assertText('Form submitted ok for number ' . $test_message['number'] . ' and message: ' . $test_message['message'], 'Successfully sent message to recipient with registered number');
// Test whether author and recipient uids were recorded properly.
$this
->drupalGet('user/' . $author->uid . '/my-messages');
$this
->assertTextInXPath('//tbody/tr[1]/td[1]', $test_message['message'], 'Message recorded and displayed properly on Author\'s My Messages page.');
$this
->assertTextInXPath('//tbody/tr[1]/td[2]', $author->name, 'Author\'s name recorded and displayed properly on Author\'s My Messages page.');
$this
->assertTextInXPath('//tbody/tr[1]/td[3]', $recipient->name, 'Recipient\'s name recorded and displayed properly on Author\'s My Messages page.');
$this
->drupalLogout();
$this
->drupalLogin($recipient);
// Test whether author and recipient uids were recorded properly.
$this
->drupalGet('user/' . $recipient->uid . '/my-messages');
$this
->assertTextInXPath('//tbody/tr[1]/td[1]', $test_message['message'], 'Message recorded and displayed properly on Recipient\'s My Messages page.');
$this
->assertTextInXPath('//tbody/tr[1]/td[2]', $author->name, 'Author\'s name recorded and displayed properly on Recipient\'s My Messages page.');
$this
->assertTextInXPath('//tbody/tr[1]/td[3]', $recipient->name, 'Recipient\'s name recorded and displayed properly on Recipient\'s My Messages page.');
// Test sending messages to unknown number.
$test_message = array(
'number' => '23456789103',
'message' => 'Test archive of message sent to unknown recipient',
);
$this
->drupalPost('admin/smsframework/devel', $test_message, t('Send Message'));
$this
->assertResponse(200);
$this
->assertText('Form submitted ok for number ' . $test_message['number'] . ' and message: ' . $test_message['message'], 'Successfully sent message to unknown recipient');
$this
->drupalGet('user/' . $recipient->uid . '/my-messages');
$this
->assertTextInXPath('//tbody/tr[1]/td[1]', $test_message['message'], 'Message recorded and displayed properly on Author\'s My Messages page.');
$this
->assertTextInXPath('//tbody/tr[1]/td[2]', $recipient->name, 'Author\'s name recorded and displayed properly on Author\'s My Messages page.');
$this
->assertTextInXPath('//tbody/tr[1]/td[3]', 'Anonymous (not verified)', 'Recipient\'s name recorded and displayed properly on Author\'s My Messages page.');
// Test receiving messages from unknown number.
$test_message = array(
'number' => '23456789103',
'message' => 'Test archive of message received from unknown recipient',
);
$this
->drupalPost('admin/smsframework/devel', $test_message, t('Receive Message'));
$this
->assertResponse(200);
$this
->assertText('Message received from number ' . $test_message['number'] . ' and message: ' . $test_message['message'], 'Successfully received message from unknown sender');
$this
->drupalGet('user/' . $recipient->uid . '/my-messages');
$this
->assertTextInXPath('//tbody/tr[1]/td[1]', $test_message['message'], 'Message recorded and displayed properly on Recipient\'s My Messages page.');
$this
->assertTextInXPath('//tbody/tr[1]/td[2]', 'Anonymous (not verified)', 'Author\'s name recorded and displayed properly on Recipient\'s My Messages page.');
$this
->assertTextInXPath('//tbody/tr[1]/td[3]', $recipient->name, 'Recipient\'s name recorded and displayed properly on Recipient\'s My Messages page.');
// Test that a user can only view their own messages.
$this
->drupalLogout();
$this
->drupalGet('user/' . $author->uid . '/my-messages');
$this
->assertResponse(403, 'Access denied from anonymous user to My Messages page.');
$this
->drupalLogout();
$user = $this
->drupalCreateUser();
$this
->drupalLogin($user);
$this
->drupalGet('user/' . $author->uid . '/my-messages');
$this
->assertResponse(403, 'Access denied from authenticated user to another user\'s My Messages page.');
// Test that all messages are available on administrative interface.
$this
->drupalLogin($author);
$this
->drupalGet('admin/smsframework/sms_track/view');
$this
->assertEqual(count($this
->xpath('//tbody/tr')), 5, 'All messages captured in admin sms_track view');
}