You are here

public function AcquiaLiftTest::testGetConfidenceReport in Acquia Lift Connector 7

Test AcquiaLiftAPI->getConfidenceReport()

File

tests/AcquiaLiftAPI.test, line 1358
Unit tests for Acquia Lift module.

Class

AcquiaLiftTest
@file Unit tests for Acquia Lift module.

Code

public function testGetConfidenceReport() {
  $default_confidence = 0.95;
  $lift_api = $this
    ->getAcquiaLiftAPI();
  $test_request = array(
    'type' => 'get',
    'headers' => array(
      'Accept' => 'application/json',
    ),
    'options' => array(),
    'body' => NULL,
  );
  $agentName = 'some-agent-name';
  $params = array();
  $params[] = $agentName;

  // Confirm the expected requests were made.
  $dateStr = date('Y-m-d');
  $test_request['uri'] = "{$lift_api->getApiUrl()}/{$lift_api->getOwnerCode()}/{$agentName}/report/confidence/{$dateStr}?features=(none)&apikey={$lift_api->getAdminKey()}&confidence-measure={$default_confidence}&aggregated-over-dates=true";
  $this
    ->assertConfidenceReportAPI($params, $test_request, $lift_api);

  // Test date range.
  $startDate = '2014-01-01';
  $endDate = '2014-01-02';
  $params[] = $startDate;
  $params[] = $endDate;
  $test_request['uri'] = "{$lift_api->getApiUrl()}/{$lift_api->getOwnerCode()}/{$agentName}/report/confidence/{$startDate}/{$endDate}?features=(none)&apikey={$lift_api->getAdminKey()}&confidence-measure={$default_confidence}&aggregated-over-dates=true";
  $this
    ->assertConfidenceReportAPI($params, $test_request, $lift_api);

  // Test sending point name.
  $point_name = 'decision_point';
  $test_request['headers']['x-mpath-point'] = $point_name;
  $params[] = $point_name;
  $this
    ->assertConfidenceReportAPI($params, $test_request, $lift_api);

  // Send features.
  $features = array(
    'feature1',
    'feature2',
  );
  $features_str = implode(',', $features);
  $params[] = array(
    'features' => $features,
  );
  $test_request['uri'] = "{$lift_api->getApiUrl()}/{$lift_api->getOwnerCode()}/{$agentName}/report/confidence/{$startDate}/{$endDate}?features={$features_str}&apikey={$lift_api->getAdminKey()}&confidence-measure={$default_confidence}&aggregated-over-dates=true";
  $this
    ->assertConfidenceReportAPI($params, $test_request, $lift_api);

  // Send confidence measure.
  $confidence_measure = 0.99;
  $params[4]['confidence-measure'] = $confidence_measure;
  $test_request['uri'] = "{$lift_api->getApiUrl()}/{$lift_api->getOwnerCode()}/{$agentName}/report/confidence/{$startDate}/{$endDate}?features={$features_str}&apikey={$lift_api->getAdminKey()}&confidence-measure={$confidence_measure}&aggregated-over-dates=true";
  $this
    ->assertConfidenceReportAPI($params, $test_request, $lift_api);

  // Get detail report.
  $params[4]['aggregated-over-dates'] = FALSE;
  $test_request['uri'] = "{$lift_api->getApiUrl()}/{$lift_api->getOwnerCode()}/{$agentName}/report/confidence/{$startDate}/{$endDate}?features={$features_str}&apikey={$lift_api->getAdminKey()}&confidence-measure={$confidence_measure}&aggregated-over-dates=false";
  $this
    ->assertConfidenceReportAPI($params, $test_request, $lift_api);

  // Get a detail report with a specific goal.
  $params[4]['goal'] = 'some_goal';
  $test_request['uri'] = "{$lift_api->getApiUrl()}/{$lift_api->getOwnerCode()}/{$agentName}/report/confidence/{$startDate}/{$endDate}?features={$features_str}&apikey={$lift_api->getAdminKey()}&confidence-measure={$confidence_measure}&aggregated-over-dates=false&goal=some_goal";
  $this
    ->assertConfidenceReportAPI($params, $test_request, $lift_api);
  $lift_api = $this
    ->getAcquiaLiftAPI(TRUE);
  $this
    ->assertConfidenceReportAPI($params, $test_request, $lift_api);
}