View source
<?php
class SmsTrackWebTestCase extends DrupalWebTestCase {
public function drupalCreateAdminUser(array $permissions = array(
'receive sms',
'edit own sms number',
)) {
$roles = user_roles();
$index = array_search('administrator', $roles);
$user = $this
->drupalCreateUser($permissions);
$user->roles[$index] = 'administrator';
return user_save($user);
}
}
class SmsTrackArchiveTestCase extends SmsTrackWebTestCase {
public static function getInfo() {
return array(
'name' => 'SMS Track Integration Test',
'description' => 'Integration tests for the SMS Framework Track Module.',
'group' => 'SMS Framework',
);
}
public function setUp() {
parent::setUp('sms', 'sms_test_gateway', 'sms_track', 'sms_user', 'sms_devel');
}
public function testArchiveWriteForSentMessages() {
$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'));
$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();
$recipient = $this
->drupalCreateAdminUser();
$this
->drupalLogin($recipient);
$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);
$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');
$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);
$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_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_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.');
$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.');
$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');
}
protected function assertTextInXPath($xpath, $text, $message = NULL, $group = 'Other') {
if (!$message) {
$message = t('"@text" found', array(
'@text' => $text,
));
}
foreach ($this
->xpath($xpath) as $xml_node) {
$xml = filter_xss($xml_node
->asXML(), array());
if (strpos($xml, $text) !== FALSE) {
return $this
->pass($message, $group);
}
}
return $this
->fail($message, $group);
}
}