You are here

protected function AcquiaLiftWebTestBase::createOptionSet in Acquia Lift Connector 7

Same name and namespace in other branches
  1. 7.2 tests/acquia_lift.test \AcquiaLiftWebTestBase::createOptionSet()
10 calls to AcquiaLiftWebTestBase::createOptionSet()
AcquiaLiftWebTestAgentAdmin::testPauseAgents in tests/acquia_lift.test
Tests that agents are paused when they need to be paused.
AcquiaLiftWebTestAgentAdmin::testSaveAgent in tests/acquia_lift.test
AcquiaLiftWebTestFundamentals::testBatchSyncOperations in tests/acquia_lift.test
Tests the function that gathers operations for syncing of agents and their components to Lift.
AcquiaLiftWebTestReports::testReadReportsFromFile in tests/acquia_lift.test
AcquiaLiftWebTestReports::testReportDates in tests/acquia_lift.test

... See full list

File

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

Class

AcquiaLiftWebTestBase
@file Integration tests for Acquia Lift module.

Code

protected function createOptionSet($index, $optionData, $withQueueItems = TRUE) {
  $option_set = array(
    'plugin' => $optionData['plugin'],
    'label' => 'Option Set ' . ($index + 1),
    'agent' => $optionData['agent'],
  );
  $options = array();
  $choice_ids = array();
  if (!isset($optionData['option_ids'])) {
    for ($j = 0; $j < $optionData['num_options']; $j++) {
      $option_id = personalize_generate_option_id($j);
      $choice_ids[] = $option_id;
      $options[$j] = array(
        'option_id' => $option_id,
        'option_label' => personalize_generate_option_label($j),
      );
    }
  }
  else {
    foreach ($optionData['option_ids'] as $i => $option_id) {
      $choice_ids[] = $option_id;
      $options[$i] = array(
        'option_id' => $option_id,
        'option_label' => personalize_generate_option_label($i),
      );
    }
  }
  $option_set['options'] = $options;
  $option_set = (object) $option_set;
  try {
    personalize_option_set_save($option_set);
  } catch (PersonalizeException $e) {
    $this
      ->fail('Exception thrown with message: . ' . $e
      ->getMessage());
  }
  $expected_queue_items = array();
  if ($withQueueItems) {
    $expected_queue_items[] = array(
      'method' => 'savePoint',
      'args' => array(
        $optionData['agent'],
        personalize_get_decision_point_name_for_option_set($option_set),
      ),
      'agent' => $optionData['agent'],
    );

    // An item will be added to the queue to save the decision.
    $expected_queue_items[] = array(
      'method' => 'saveDecision',
      'args' => array(
        $optionData['agent'],
        personalize_get_decision_point_name_for_option_set($option_set),
        personalize_get_decision_name_for_option_set($option_set),
      ),
      'agent' => $optionData['agent'],
    );

    // An item will be added to teh queue to save each option.
    foreach ($choice_ids as $choice) {
      $expected_queue_items[] = array(
        'method' => 'saveChoice',
        'args' => array(
          $optionData['agent'],
          personalize_get_decision_point_name_for_option_set($option_set),
          personalize_get_decision_name_for_option_set($option_set),
          $choice,
        ),
        'agent' => $optionData['agent'],
      );
    }
  }
  return array(
    $option_set,
    $expected_queue_items,
  );
}