You are here

function AcquiaLiftWebTestCampaignWizard::testGoalTypeSelect in Acquia Lift Connector 7.2

Test goals type form.

File

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

Class

AcquiaLiftWebTestCampaignWizard

Code

function testGoalTypeSelect() {
  $goal_input_name = key($this->addGoalElement);
  $goal_input_value = reset($this->addGoalElement);
  $existing_action = 'goals[new][0][details][action_name]';
  $page_event = 'goals[new][0][details][event][page]';
  $element_url = 'goals[new][0][details][url]';
  $goal_type_name = 'goals[new][0][goal_type]';
  $cancel_element = array(
    'cancel_goal_0' => t('Cancel'),
  );
  $agent = $this
    ->createTargetingAgent();
  $this
    ->drupalGet('admin/structure/personalize/manage/' . $agent->machine_name . '/goals');

  // Only a button to add a new goal shown by default
  $this
    ->assertFieldByName($goal_input_name, $goal_input_value);
  $this
    ->assertNoFieldByName($goal_type_name);
  $this
    ->assertNoFieldByName($existing_action);
  $this
    ->assertNoFieldByName($page_event);
  $this
    ->assertNoFieldByname($element_url);
  $this
    ->drupalPostAJAX(NULL, array(), $this->addGoalElement);

  // Make sure the type selection is shown by default without any selections.
  $this
    ->assertFieldByName($goal_type_name);
  $this
    ->assertNoFieldChecked('edit-goals-new-0-goal-type-existing');
  $this
    ->assertNoFieldChecked('edit-goals-new-0-goal-type-page');
  $this
    ->assertNoFieldChecked('edit-goals-new-0-goal-type-element');

  // Actual forms should not be shown yet.
  $this
    ->assertNoFieldByName($existing_action);
  $this
    ->assertNoFieldByName($page_event);
  $this
    ->assertNoFieldByname($element_url);

  // Button to add a new goal should still be available.
  $this
    ->assertFieldByName($goal_input_name, $goal_input_value);

  // Cancel goal creation.
  $this
    ->drupalPostAJAX(NULL, array(), $cancel_element);
  $this
    ->assertFieldByName($goal_input_name, $goal_input_value);
  $this
    ->assertNoFieldByName($goal_type_name);
  $this
    ->assertNoFieldByName($existing_action);
  $this
    ->assertNoFieldByName($page_event);
  $this
    ->assertNoFieldByname($element_url);

  // Select an existing goal.
  $this
    ->drupalPostAJAX(NULL, array(), $this->addGoalElement);
  $this
    ->assertFieldByName($goal_type_name);
  $this
    ->assertNoFieldChecked('edit-goals-new-0-goal-type-existing');
  $this
    ->assertNoFieldChecked('edit-goals-new-0-goal-type-page');
  $this
    ->assertNoFieldChecked('edit-goals-new-0-goal-type-element');
  $this
    ->assertNoFieldByName($existing_action);
  $this
    ->assertNoFieldByName($page_event);
  $this
    ->assertNoFieldByname($element_url);
  $this
    ->assertFieldByName($goal_input_name, $goal_input_value);
  $edit = array(
    $goal_type_name => 'existing',
  );
  $this
    ->drupalPostAJAX(NULL, $edit, $goal_type_name);
  $this
    ->assertFieldByName($goal_input_name, $goal_input_value);
  $this
    ->assertNoFieldByName($goal_type_name);
  $this
    ->assertFieldByName($existing_action);
  $this
    ->assertNoFieldByName($page_event);
  $this
    ->assertNoFieldByname($element_url);

  // Change the type
  $this
    ->drupalPostAJAX(NULL, array(), $this->changeTypeElement);
  $this
    ->assertFieldByName($goal_type_name);
  $this
    ->assertNoFieldChecked('edit-goals-new-0-goal-type-existing');
  $this
    ->assertNoFieldChecked('edit-goals-new-0-goal-type-page');
  $this
    ->assertNoFieldChecked('edit-goals-new-0-goal-type-element');
  $this
    ->assertNoFieldByName($existing_action);
  $this
    ->assertNoFieldByName($page_event);
  $this
    ->assertNoFieldByname($element_url);
  $this
    ->assertFieldByName($goal_input_name, $goal_input_value);

  // Select existing again.
  $edit = array(
    $goal_type_name => 'existing',
  );
  $this
    ->drupalPostAJAX(NULL, $edit, $goal_type_name);
  $this
    ->assertFieldByName($goal_input_name, $goal_input_value);
  $this
    ->assertNoFieldByName($goal_type_name);
  $this
    ->assertFieldByName($existing_action);
  $this
    ->assertNoFieldByName($page_event);
  $this
    ->assertNoFieldByname($element_url);

  // Cancel the creation of the goal.
  $this
    ->drupalPostAJAX(NULL, array(), $cancel_element);
  $this
    ->assertFieldByName($goal_input_name, $goal_input_value);
  $this
    ->assertNoFieldByName($goal_type_name);
  $this
    ->assertNoFieldByName($existing_action);
  $this
    ->assertNoFieldByName($page_event);
  $this
    ->assertNoFieldByname($element_url);

  // Select a page goal
  $this
    ->drupalPostAJAX(NULL, array(), $this->addGoalElement);
  $this
    ->assertFieldByName($goal_type_name);
  $this
    ->assertNoFieldChecked('edit-goals-new-0-goal-type-existing');
  $this
    ->assertNoFieldChecked('edit-goals-new-0-goal-type-page');
  $this
    ->assertNoFieldChecked('edit-goals-new-0-goal-type-element');
  $this
    ->assertNoFieldByName($existing_action);
  $this
    ->assertNoFieldByName($page_event);
  $this
    ->assertNoFieldByname($element_url);
  $this
    ->assertFieldByName($goal_input_name, $goal_input_value);
  $edit = array(
    $goal_type_name => 'page',
  );
  $this
    ->drupalPostAJAX(NULL, $edit, $goal_type_name);
  $this
    ->assertFieldByName($goal_input_name, $goal_input_value);
  $this
    ->assertNoFieldByName($goal_type_name);
  $this
    ->assertNoFieldByName($existing_action);
  $this
    ->assertFieldByName($page_event);
  $this
    ->assertNoFieldByname($element_url);

  // Change the type
  $this
    ->drupalPostAJAX(NULL, array(), $this->changeTypeElement);
  $this
    ->assertFieldByName($goal_type_name);
  $this
    ->assertNoFieldChecked('edit-goals-new-0-goal-type-existing');
  $this
    ->assertNoFieldChecked('edit-goals-new-0-goal-type-page');
  $this
    ->assertNoFieldChecked('edit-goals-new-0-goal-type-element');
  $this
    ->assertNoFieldByName($existing_action);
  $this
    ->assertNoFieldByName($page_event);
  $this
    ->assertNoFieldByname($element_url);
  $this
    ->assertFieldByName($goal_input_name, $goal_input_value);

  // Select page again.
  $edit = array(
    $goal_type_name => 'page',
  );
  $this
    ->drupalPostAJAX(NULL, $edit, $goal_type_name);
  $this
    ->assertFieldByName($goal_input_name, $goal_input_value);
  $this
    ->assertNoFieldByName($goal_type_name);
  $this
    ->assertNoFieldByName($existing_action);
  $this
    ->assertFieldByName($page_event);
  $this
    ->assertNoFieldByname($element_url);

  // Cancel the creation of the goal.
  $this
    ->drupalPostAJAX(NULL, array(), $cancel_element);
  $this
    ->assertFieldByName($goal_input_name, $goal_input_value);
  $this
    ->assertNoFieldByName($goal_type_name);
  $this
    ->assertNoFieldByName($existing_action);
  $this
    ->assertNoFieldByName($page_event);
  $this
    ->assertNoFieldByname($element_url);

  // Select an element goal.
  $this
    ->drupalPostAJAX(NULL, array(), $this->addGoalElement);
  $this
    ->assertFieldByName($goal_type_name);
  $this
    ->assertNoFieldChecked('edit-goals-new-0-goal-type-existing');
  $this
    ->assertNoFieldChecked('edit-goals-new-0-goal-type-page');
  $this
    ->assertNoFieldChecked('edit-goals-new-0-goal-type-element');
  $this
    ->assertNoFieldByName($existing_action);
  $this
    ->assertNoFieldByName($page_event);
  $this
    ->assertNoFieldByname($element_url);
  $this
    ->assertFieldByName($goal_input_name, $goal_input_value);
  $edit = array(
    $goal_type_name => 'element',
  );
  $this
    ->drupalPostAJAX(NULL, $edit, $goal_type_name);
  $this
    ->assertFieldByName($goal_input_name, $goal_input_value);
  $this
    ->assertNoFieldByName($goal_type_name);
  $this
    ->assertNoFieldByName($existing_action);
  $this
    ->assertNoFieldByName($page_event);
  $this
    ->assertFieldByname($element_url);

  // Change the type
  $this
    ->drupalPostAJAX(NULL, array(), $this->changeTypeElement);
  $this
    ->assertFieldByName($goal_type_name);
  $this
    ->assertNoFieldChecked('edit-goals-new-0-goal-type-existing');
  $this
    ->assertNoFieldChecked('edit-goals-new-0-goal-type-page');
  $this
    ->assertNoFieldChecked('edit-goals-new-0-goal-type-element');
  $this
    ->assertNoFieldByName($existing_action);
  $this
    ->assertNoFieldByName($page_event);
  $this
    ->assertNoFieldByname($element_url);
  $this
    ->assertFieldByName($goal_input_name, $goal_input_value);

  // Select existing again.
  $edit = array(
    $goal_type_name => 'element',
  );
  $this
    ->drupalPostAJAX(NULL, $edit, $goal_type_name);
  $this
    ->assertFieldByName($goal_input_name, $goal_input_value);
  $this
    ->assertNoFieldByName($goal_type_name);
  $this
    ->assertNoFieldByName($existing_action);
  $this
    ->assertNoFieldByName($page_event);
  $this
    ->assertFieldByname($element_url);

  // Cancel the creation of the goal.
  $this
    ->drupalPostAJAX(NULL, array(), $cancel_element);
  $this
    ->assertFieldByName($goal_input_name, $goal_input_value);
  $this
    ->assertNoFieldByName($goal_type_name);
  $this
    ->assertNoFieldByName($existing_action);
  $this
    ->assertNoFieldByName($page_event);
  $this
    ->assertNoFieldByname($element_url);
}