You are here

function ALProfilesWebTest::testSyncEvents in Acquia Lift Connector 7

Same name and namespace in other branches
  1. 7.2 acquia_lift_profiles/tests/acquia_lift_profiles.test \ALProfilesWebTest::testSyncEvents()

File

acquia_lift_profiles/tests/acquia_lift_profiles.test, line 291
Tests for Acquia Lift Profiles module.

Class

ALProfilesWebTest
Tests Acquia Lift Profiles functionality.

Code

function testSyncEvents() {
  $this
    ->configureALProfiles();
  $this
    ->drupalLogin($this->admin_user);
  ALProfilesAPI::setTestInstance();

  // Create a custom action with a label.
  $action_name = 'my_action_with_label';
  $action_label = 'My Friendly Event';
  $action = array(
    'machine_name' => $action_name,
    'label' => $action_label,
    'plugin' => 'link',
    'client_side' => 1,
    'module' => 'visitor_actions',
    'identifier' => '#some-id',
    'event' => 'click',
    'pages' => '',
    'data' => array(),
    'limited_use' => 1,
  );
  visitor_actions_save_action($action);

  // An action with no label should send the machine name as the label to
  // Lift Web.
  $new_action_name = 'my_action_without_label';
  $new_action = $action;
  unset($new_action['label']);
  $new_action['machine_name'] = $new_action_name;
  visitor_actions_save_action($new_action);

  // Check that the expected requests have been made to the Event CRUD API.
  $requests = DummyALProfilesHttpClient::getLoggedRequests();
  $this
    ->assertEqual('http://api.example.com/dashboard/rest/TESTACCOUNT/events/my_action_with_label?customerSite=TESTSITE&label=' . rawurlencode($action_label) . '&type=OTHER', $requests[0]['uri']);
  $this
    ->assertEqual('http://api.example.com/dashboard/rest/TESTACCOUNT/events/my_action_without_label?customerSite=TESTSITE&label=' . $new_action_name . '&type=OTHER', $requests[1]['uri']);
  DummyALProfilesHttpClient::clearLoggedRequests();

  // Now delete the actions.
  visitor_actions_delete_action($action_name);

  // Check that the DELETE request has been made to the API.
  $requests = DummyALProfilesHttpClient::getLoggedRequests();
  $this
    ->assertEqual('http://api.example.com/dashboard/rest/TESTACCOUNT/events/my_action_with_label?customerSite=TESTSITE', $requests[0]['uri']);
  $this
    ->assertEqual('delete', $requests[0]['type']);
}