You are here

function AcquiaLiftWebTestWorkflow::testAutoStopMultiplePoints in Acquia Lift Connector 7

Tests the logic of AcquiaLiftAgent's stopNow() implementation when the agent has mulitple decision points including an MVT.

File

tests/acquia_lift.test, line 2869
Integration tests for Acquia Lift module.

Class

AcquiaLiftWebTestWorkflow

Code

function testAutoStopMultiplePoints() {

  // Create a new agent.
  $agent = $this
    ->createTestAgent(array(
    'control_rate' => 10,
    'explore_rate' => 30,
    'auto_stop' => 1,
  ), TRUE, FALSE);
  $machine_name = $agent
    ->getMachineName();

  // This time we'll add 3 option sets.
  $option_set_values = array(
    array(
      'agent' => $machine_name,
      'plugin' => 'type1',
      'num_options' => 3,
    ),
    array(
      'agent' => $machine_name,
      'plugin' => 'type2',
      'num_options' => 2,
    ),
    array(
      'agent' => $machine_name,
      'plugin' => 'type2',
      'num_options' => 3,
    ),
  );
  $option_sets = array();
  foreach ($option_set_values as $i => $values) {
    list($option_set, $new_queue_items) = $this
      ->createOptionSet($i, $values);
    $option_sets[] = $option_set;
  }
  $first_osid = 'osid-' . $option_sets[0]->osid;
  $second_osid = 'osid-' . $option_sets[1]->osid;
  $third_osid = 'osid-' . $option_sets[2]->osid;

  // Create an MVT and add two of the option sets to it.
  $mvt_label = $this
    ->randomName();
  $mvt_machine_name = personalize_generate_machine_name($mvt_label, 'personalize_mvt_machine_name_exists');
  $edit = array(
    'mvt[add][mvt_basic_info][label]' => $mvt_machine_name,
    'mvt[add][mvt_basic_info][option_sets][]' => array(
      $option_sets[1]->osid,
      $option_sets[2]->osid,
    ),
  );
  $this
    ->drupalPost("admin/structure/personalize/manage/{$machine_name}/edit", $edit, $this
    ->getButton('mvt'));

  // Generate the reporting data to be returned by the dummy http client for this
  // agent. All possible choices at each decision point need to be accounted for in
  // the report.
  $points = array(
    $first_osid => array(
      $first_osid . ':option-A',
      $first_osid . ':option-B',
      $first_osid . ':option-C',
    ),
    $mvt_machine_name => array(
      $second_osid . ':option-A,' . $third_osid . ':option-A',
      $second_osid . ':option-A,' . $third_osid . ':option-B',
      $second_osid . ':option-A,' . $third_osid . ':option-C',
      $second_osid . ':option-B,' . $third_osid . ':option-A',
      $second_osid . ':option-B,' . $third_osid . ':option-B',
      $second_osid . ':option-B,' . $third_osid . ':option-C',
    ),
  );
  $test_data = array(
    'reports' => array(
      $machine_name => array(
        // We'll specify a winner at each decision point - for option set 1 it will be
        // Option B and for the MVT it will be the combination of Option A and Option C
        // in Option Sets 2 and 3 respectively.
        'confidence' => AcquiaLiftTestReports::generateConfidenceReportWithWinners($machine_name, $points, array(
          $first_osid => $first_osid . ':option-B',
          $mvt_machine_name => $second_osid . ':option-A,' . $third_osid . ':option-C',
        )),
      ),
    ),
  );
  variable_set('acquia_lift_web_test_data', $test_data);
  $this
    ->resetAll();
  $agent_instance = personalize_agent_load_agent($machine_name, TRUE);
  AcquiaLiftAPI::setTestInstance();

  // Set the minimum number of decisions to 30, and the minium runtime to 0 so
  // that we know we'll get passed these two checks.
  variable_set('acquia_lift_min_decisions', 30);
  variable_set('acquia_lift_min_runtime_num', 0);
  $this
    ->resetAll();
  $agent_instance = personalize_agent_load_agent($machine_name, TRUE);
  AcquiaLiftAPI::setTestInstance();
  $stop = $agent_instance
    ->stopNow();
  $this
    ->assertTrue($stop);

  // CHeck that the winner has been set on each option set.
  $option_sets = personalize_option_set_load_by_agent($machine_name, TRUE);
  $osids = array_keys($option_sets);
  $this
    ->assertEqual('option-B', $option_sets[$osids[0]]->winner);
  $this
    ->assertEqual('option-A', $option_sets[$osids[1]]->winner);
  $this
    ->assertEqual('option-C', $option_sets[$osids[2]]->winner);

  // Setting the minimum number of decisions to 70 will mean the first decision point
  // won't satisfy this so we should get FALSE from teh stopNow() call.
  variable_set('acquia_lift_min_decisions', 70);
  $this
    ->resetAll();
  $agent_instance = personalize_agent_load_agent($machine_name, TRUE);
  AcquiaLiftAPI::setTestInstance();
  $stop = $agent_instance
    ->stopNow();
  $this
    ->assertFalse($stop);

  // Setting it to 60 should get TRUE again.
  variable_set('acquia_lift_min_decisions', 60);
  $this
    ->resetAll();
  $agent_instance = personalize_agent_load_agent($machine_name, TRUE);
  AcquiaLiftAPI::setTestInstance();
  $stop = $agent_instance
    ->stopNow();
  $this
    ->assertTrue($stop);
}