You are here

public function AcquiaLiftWebTestReports::testReportPage in Acquia Lift Connector 7.2

File

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

Class

AcquiaLiftWebTestReports

Code

public function testReportPage() {

  // Test that a report page shows up for a personalization with a single test.
  $this
    ->drupalLogin($this->managerUser);
  $agent = $this
    ->createTargetingAgent();
  $option_set = $this
    ->createPersonalizedBlock(0, $agent, 3);
  $option_ids = array();
  foreach ($option_set->options as $option) {
    $option_ids[] = $option['option_id'];
  }
  $targeting = array(
    ACQUIA_LIFT_TARGETING_EVERYONE_ELSE => array(
      $option_ids[0],
      $option_ids[1],
      $option_ids[2],
    ),
  );
  try {
    acquia_lift_save_targeting_structure($agent, $targeting);
  } catch (AcquiaLiftException $e) {
    $this
      ->fail('Exception thrown when none expected.');
  }

  // Now implement the targeting structure and set the agent to running.
  AcquiaLiftAPI::setTestInstance();
  acquia_lift_implement_targeting($agent);
  personalize_agent_set_status($agent->machine_name, PERSONALIZE_STATUS_RUNNING);
  $this
    ->resetAll();
  $this
    ->drupalGet('admin/structure/personalize/manage/' . $agent->machine_name . '/results');
  $this
    ->assertText('Everyone audience');
  $this
    ->assertNoFieldByName('audience_filter');
  $this
    ->assertLinkByHref('admin/structure/personalize/manage/' . $agent->machine_name . '/audience/everyone-else/complete');

  // Pause the agent and change it so that it has another test.
  personalize_agent_set_status($agent->machine_name, PERSONALIZE_STATUS_PAUSED);
  $this
    ->resetAll();
  $contexts = array(
    array(
      'context' => implode(PERSONALIZE_TARGETING_ADMIN_SEPARATOR, array(
        'some_plugin',
        'some_context',
      )),
      'operator' => 'contains',
      'match' => 'ohai',
    ),
  );
  acquia_lift_target_audience_save('My First Audience', $agent->machine_name, $contexts, 'OR', 50, 'my-first-audience');
  $targeting['my-first-audience'] = array(
    $option_ids[1],
    $option_ids[2],
  );
  acquia_lift_save_targeting_structure($agent, $targeting);

  // Now implement the targeting structure and set the agent to running.
  AcquiaLiftAPI::setTestInstance();
  acquia_lift_implement_targeting($agent);
  personalize_agent_set_status($agent->machine_name, PERSONALIZE_STATUS_RUNNING);
  $this
    ->resetAll();
  $this
    ->drupalGet('admin/structure/personalize/manage/' . $agent->machine_name . '/results');
  $this
    ->assertNoText('Test for Everyone else audience');
  $this
    ->assertFieldByName('audience_filter');
  $this
    ->assertOptionSelected('acquia-lift-report-audience-filter', 'active|everyone-else');
  $this
    ->assertLinkByHref('admin/structure/personalize/manage/' . $agent->machine_name . '/audience/everyone-else/complete');
  $this
    ->assertNoLinkByHref('admin/structure/personalize/manage/' . $agent->machine_name . '/audience/my-first-audience/complete');

  // Now change the audience and verify that the complete button changes
  $edit = array(
    'audience_filter' => 'active|my-first-audience',
  );
  $this
    ->drupalPostAJAX(NULL, $edit, 'audience_filter');
  $this
    ->assertFieldByName('audience_filter');
  $this
    ->assertOptionSelected('acquia-lift-report-audience-filter', 'active|my-first-audience');
  $this
    ->assertNoLinkByHref('admin/structure/personalize/manage/' . $agent->machine_name . '/audience/everyone-else/complete');
  $this
    ->assertLinkByHref('admin/structure/personalize/manage/' . $agent->machine_name . '/audience/my-first-audience/complete');

  // Change it again so that it has no tests.
  personalize_agent_set_status($agent->machine_name, PERSONALIZE_STATUS_PAUSED);
  $this
    ->resetAll();
  $contexts = array(
    array(
      'context' => implode(PERSONALIZE_TARGETING_ADMIN_SEPARATOR, array(
        'some_plugin',
        'some_context',
      )),
      'operator' => 'contains',
      'match' => 'kthxbai',
    ),
  );
  acquia_lift_target_audience_save('My Second Audience', $agent->machine_name, $contexts, 'OR', 10, 'my-second-audience');
  $targeting = array(
    ACQUIA_LIFT_TARGETING_EVERYONE_ELSE => array(
      $option_ids[0],
    ),
    'my-first-audience' => array(
      $option_ids[1],
    ),
    'my-second-audience' => array(
      $option_ids[2],
    ),
  );
  acquia_lift_save_targeting_structure($agent, $targeting);

  // Now implement the targeting structure and set the agent to running.
  AcquiaLiftAPI::setTestInstance();
  acquia_lift_implement_targeting($agent);
  personalize_agent_set_status($agent->machine_name, PERSONALIZE_STATUS_RUNNING);
  $this
    ->resetAll();
  $this
    ->drupalGet('admin/structure/personalize/manage/' . $agent->machine_name . '/results');
  $this
    ->assertFieldByName('audience_filter');
  $targeting_option_set = acquia_lift_get_option_set_for_targeting($agent->machine_name);
  $fallback_audience = acquia_lift_get_fallback_audience_name(array_keys($targeting_option_set->targeting));

  // Only retired tests shown in the filter.
  $retired = acquia_lift_get_retired_tests($agent->machine_name);
  $this
    ->assertEqual(count($retired), 2);
  $this
    ->assertOptionSelected('acquia-lift-report-audience-filter', 'active|' . $fallback_audience);
  $this
    ->assertNoOptionSelected('acquia-lift-report-audience-filter', 'retired|' . $retired[0]->machine_name);
  $this
    ->assertNoOptionSelected('acquia-lift-report-audience-filter', 'retired|' . $retired[1]->machine_name);

  // No link to complete test.
  $this
    ->assertNoLinkByHref('admin/structure/personalize/manage/' . $agent->machine_name . '/audience/everyone-else/complete');
  $this
    ->assertNoLinkByHref('admin/structure/personalize/manage/' . $agent->machine_name . '/audience/my-first-audience/complete');
  $this
    ->assertNoLinkByHref('admin/structure/personalize/manage/' . $agent->machine_name . '/audience/my-second-audience/complete');
}