You are here

public function SmsActionWebTest::testSmsActionsActionsIntegration in SMS Framework 7

Tests integration with the actions module.

File

modules/sms_actions/sms_actions.test, line 130
Contains tests for the functions in sms_action.module and actions integration.

Class

SmsActionWebTest
Provides integration tests for the sms_action module.

Code

public function testSmsActionsActionsIntegration() {
  $user = $this
    ->drupalCreateUser(array(
    'administer smsframework',
    'administer actions',
  ));
  $this
    ->drupalLogin($user);

  // Enable sms test gateway.
  module_enable(array(
    'sms_test_gateway',
  ));
  variable_set('sms_default_gateway', 'test');

  // Create sms actions discriminator testX.
  sms_actions_command_save((object) array(
    'discriminator' => 'test80',
  ));

  // Create a configurable sms_actions action.
  $action = 'sms_actions_send_action';
  $hash = drupal_hash_base64($action);
  $edit = array(
    'actions_label' => 'Send Test SMS',
    'number' => '6789012345',
    'message' => '!This is a test!',
  );
  $this
    ->drupalPost("admin/config/system/actions/configure/{$hash}", $edit, t('Save'));
  $this
    ->assertText(t('The action has been successfully saved.'));

  // Get the ID of the action just created.
  $aid = db_query('SELECT aid FROM {actions} WHERE callback = :callback AND label = :label', array(
    ':callback' => $action,
    ':label' => $edit['actions_label'],
  ))
    ->fetchField();
  $post = array(
    'aid' => drupal_hash_base64($aid),
  );
  $this
    ->drupalPost('admin/structure/trigger/sms_actions', $post, t('Assign'), array(), array(), 'trigger-sms-actions-test80-assign-form');
  $this
    ->assertResponse(200);

  // Activate action by calling sms_incoming() with "testX" as a discriminator
  // and the node message as the argument.
  sms_incoming('1234567890', 'test80', array());

  // Assert that the configured message '!This is a test!' was sent.
  $result = sms_test_gateway_result();
  $this
    ->assertEqual($edit['message'], $result['message'], 'SMS actions sent as configured');

  // "Any" discriminator test.
  sms_actions_command_save((object) array(
    // Add a new discriminator.
    'discriminator' => 'test23',
  ));
  $this
    ->drupalPost('admin/structure/trigger/sms_actions', $post, t('Assign'), array(), array(), 'trigger-sms-actions-assign-form');
  $this
    ->assertResponse(200);

  // Reset triggered actions so the new ones can reload.
  drupal_static_reset('trigger_get_assigned_actions');
  sms_test_gateway_result(true);
  sms_incoming('6789012345', 'testy', array());
  $this
    ->assertEqual(array(), sms_test_gateway_result(), 'Non-existent discriminator not triggered.');
  sms_incoming('4567123890', 'test23', array());
  $result = sms_test_gateway_result();
  $this
    ->assertEqual($edit['message'], $result['message'], 'Existing discriminator triggered for the "Any" discriminator trigger.');
}