You are here

function SmsActionWebTest::testSmsActionsTriggersIntegration in SMS Framework 7

Tests integration with the trigger module.

File

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

Class

SmsActionWebTest
Provides integration tests for the sms_action module.

Code

function testSmsActionsTriggersIntegration() {
  $user = $this
    ->drupalCreateUser(array(
    'administer smsframework',
    'administer actions',
    'create article content',
  ));
  $this
    ->drupalLogin($user);

  // Add more actions and verify the trigger page integration.
  $discriminators = array(
    'test1',
    'test2',
    'test3',
    'test4',
    'test5',
    'test6',
  );
  foreach ($discriminators as $discriminator) {
    sms_actions_command_save((object) array(
      'discriminator' => $discriminator,
    ));
  }
  $this
    ->drupalGet('admin/smsframework/actions');
  $this
    ->assertRaw('<td>test1</td>');
  $this
    ->assertRaw('<td>test2</td>');
  $this
    ->assertRaw('<td>test3</td>');
  $this
    ->assertRaw('<td>test4</td>');
  $this
    ->assertRaw('<td>test5</td>');
  $this
    ->assertRaw('<td>test6</td>');

  // Trigger page integration.
  $this
    ->drupalGet('admin/structure/trigger/sms_actions');
  $this
    ->assertText('When an SMS message with the test1 discriminator is received');
  $this
    ->assertText('When an SMS message with the test2 discriminator is received');
  $this
    ->assertText('When an SMS message with the test3 discriminator is received');
  $this
    ->assertText('When an SMS message with the test4 discriminator is received');
  $this
    ->assertText('When an SMS message with the test5 discriminator is received');
  $this
    ->assertText('When an SMS message with the test6 discriminator is received');

  // Test actions integration.
  // Create a test node.
  $node = $this
    ->drupalCreateNode(array(
    'title' => 'Test Node',
    'type' => 'article',
    'status' => 0,
    'promote' => 0,
  ));

  // Verify that node is not published.
  $this
    ->drupalLogout();
  $this
    ->drupalGet('node/' . $node->nid);
  $this
    ->assertResponse(403);
  $this
    ->assertNoText('A test article node for testing.');
  $this
    ->assertFalse($node->status, 'Test node not published.');

  // Create action to publish the created node.
  $action = 'node_publish_action';
  $this
    ->drupalLogin($user);
  $hash = drupal_hash_base64($action);
  $edit = array(
    'aid' => $hash,
  );
  $this
    ->drupalPost('admin/structure/trigger/sms_actions', $edit, t('Assign'), array(), array(), 'trigger-sms-actions-test1-assign-form');
  $this
    ->assertResponse(200);

  // Activate action by calling sms_incoming() with "test1" as a discriminator
  // and the node id as the argument.
  sms_incoming('1234567890', 'test1 ' . $node->nid, array());

  // Reload the node.
  $node = node_load($node->nid);
  $this
    ->drupalLogout();
  $this
    ->drupalGet('node/' . $node->nid);
  $this
    ->assertResponse(200);
  $this
    ->assertText($node->body[LANGUAGE_NONE][0]['value']);
  $this
    ->assertTrue($node->status, 'Test node published.');
}