You are here

function AcquiaLiftWebTestCampaignWizardVariations::testVariationTypeSelect in Acquia Lift Connector 7.2

File

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

Class

AcquiaLiftWebTestCampaignWizardVariations

Code

function testVariationTypeSelect() {
  $variation_input_name = key($this->addVariationSetElement);
  $variation_input_value = reset($this->addVariationSetElement);
  $block_title_name = 'variations[editing][new][0][block][content][title]';
  $element_url_name = 'variations[editing][new][0][element][content][url]';
  $option_set_type_name = 'variations[editing][new][0][option_set_type]';
  $block_type_id = 'edit-variations-editing-new-0-option-set-type-block';
  $element_type_id = 'edit-variations-editing-new-0-option-set-type-element';
  $this
    ->drupalLogin($this->managerUser);
  $agent = $this
    ->createTargetingAgent();
  $this
    ->drupalGet('admin/structure/personalize/manage/' . $agent->machine_name . '/variations');
  $this
    ->drupalPostAJAX(NULL, array(), $this->addVariationSetElement);

  // Make sure the type selection is shown by default without any selections.
  $this
    ->assertFieldByName($option_set_type_name);
  $this
    ->assertNoFieldChecked($block_type_id);
  $this
    ->assertNoFieldChecked($element_type_id);

  // Actual forms should not be shown yet.
  $this
    ->assertNoFieldByName($block_title_name);
  $this
    ->assertNoFieldByName($element_url_name);

  // Button to add a new variation set should still be available.
  $this
    ->assertFieldByName($variation_input_name, $variation_input_value);

  // Cancel variation set creation.
  $this
    ->drupalPostAJAX(NULL, array(), array(
    'cancel_option_set_0' => t('Cancel'),
  ));
  $this
    ->assertFieldByName($variation_input_name, $variation_input_value);
  $this
    ->assertNoFieldByName($option_set_type_name);
  $this
    ->assertNoFieldByName($block_title_name);
  $this
    ->assertNoFieldByName($element_url_name);

  // Select a block variation set.
  $this
    ->drupalPostAJAX(NULL, array(), $this->addVariationSetElement);
  $this
    ->assertFieldByName($option_set_type_name);
  $this
    ->assertNoFieldChecked($block_type_id);
  $this
    ->assertNoFieldChecked($element_type_id);
  $this
    ->assertNoFieldByName($block_title_name);
  $this
    ->assertNoFieldByName($element_url_name);
  $this
    ->assertFieldByName($variation_input_name, $variation_input_value);
  $edit = array(
    $option_set_type_name => 'block',
  );
  $this
    ->drupalPostAJAX(NULL, $edit, $option_set_type_name);
  $this
    ->assertFieldByName($variation_input_name, $variation_input_value);
  $this
    ->assertNoFieldByName($option_set_type_name);
  $this
    ->assertFieldByName($block_title_name);
  $this
    ->assertNoFieldByName($element_url_name);

  // Change the type
  $this
    ->drupalPostAJAX(NULL, array(), $this->changeTypeElement);
  $this
    ->assertFieldByName($option_set_type_name);
  $this
    ->assertNoFieldChecked($block_type_id);
  $this
    ->assertNoFieldChecked($element_type_id);
  $this
    ->assertNoFieldByName($block_title_name);
  $this
    ->assertNoFieldByName($element_url_name);
  $this
    ->assertFieldByName($variation_input_name, $variation_input_value);

  // Select block again.
  $edit = array(
    $option_set_type_name => 'block',
  );
  $this
    ->drupalPostAJAX(NULL, $edit, $option_set_type_name);
  $this
    ->assertFieldByName($variation_input_name, $variation_input_value);
  $this
    ->assertNoFieldByName($option_set_type_name);
  $this
    ->assertFieldByName($block_title_name);
  $this
    ->assertNoFieldByName($element_url_name);

  // Cancel the creation of the variation set.
  $this
    ->drupalPostAJAX(NULL, array(), array(
    'cancel_block_option_set_0' => t('Cancel'),
  ));
  $this
    ->assertFieldByname($variation_input_name, $variation_input_value);
  $this
    ->assertNoFieldByName($option_set_type_name);
  $this
    ->assertNoFieldByName($block_title_name);
  $this
    ->assertNoFieldByName($element_url_name);

  // Select an element variation set.
  $this
    ->drupalPostAJAX(NULL, array(), $this->addVariationSetElement);
  $this
    ->assertFieldByName($option_set_type_name);
  $this
    ->assertNoFieldChecked($block_type_id);
  $this
    ->assertNoFieldChecked($element_type_id);
  $this
    ->assertNoFieldByName($block_title_name);
  $this
    ->assertNoFieldByName($element_url_name);
  $this
    ->assertFieldByName($variation_input_name, $variation_input_value);
  $edit = array(
    $option_set_type_name => 'element',
  );
  $this
    ->drupalPostAJAX(NULL, $edit, $option_set_type_name);
  $this
    ->assertFieldByName($variation_input_name, $variation_input_value);
  $this
    ->assertNoFieldByName($option_set_type_name);
  $this
    ->assertNoFieldByName($block_title_name);
  $this
    ->assertFieldByName($element_url_name);

  // Change the type.
  $this
    ->drupalPostAJAX(NULL, array(), $this->changeTypeElement);
  $this
    ->assertFieldByName($option_set_type_name);
  $this
    ->assertNoFieldChecked($block_type_id);
  $this
    ->assertNoFieldChecked($element_type_id);
  $this
    ->assertNoFieldByName($block_title_name);
  $this
    ->assertNoFieldByName($element_url_name);
  $this
    ->assertFieldByName($variation_input_name, $variation_input_value);

  // Select element again.
  $edit = array(
    $option_set_type_name => 'element',
  );
  $this
    ->drupalPostAJAX(NULL, $edit, $option_set_type_name);
  $this
    ->assertFieldByName($variation_input_name, $variation_input_value);
  $this
    ->assertNoFieldByName($option_set_type_name);
  $this
    ->assertNoFieldByName($block_title_name);
  $this
    ->assertFieldByName($element_url_name);

  // Cancel the creation of the variation set.
  $this
    ->drupalPostAJAX(NULL, array(), array(
    'cancel_element_option_set_0' => t('Cancel'),
  ));
  $this
    ->assertFieldByname($variation_input_name, $variation_input_value);
  $this
    ->assertNoFieldByName($option_set_type_name);
  $this
    ->assertNoFieldByName($block_title_name);
  $this
    ->assertNoFieldByName($element_url_name);

  // Now test the selection process when there is an existing option set.

  /* Temporarily removed: https://www.drupal.org/node/2505247
      $this->createPersonalizedBlock(1, $agent);

      // Set the variation set handling
      $this->drupalget('admin/structure/personalize/manage/' . $agent->machine_name . '/variations');
      $this->assertNoFieldByName($block_title_name);
      $this->assertNoFieldByName($element_url_name);
      $this->assertNoFieldByName('variations[add_variation][option_set_type]');
      $this->assertFieldByName('variations[add_variation][variation_set_handling]');
      $edit = array(
        'variations[add_variation][variation_set_handling]' => ACQUIA_LIFT_DECISION_LOCKSTEP,
      );
      $this->drupalPostAJAX(NULL, $edit, 'variations[add_variation][variation_set_handling]');
      // Now we can set the type of option set to create.
      $edit = array(
        'variations[add_variation][option_set_type]' => 'block',
      );
      $this->drupalPostAJAX(NULL, $edit, 'variations[add_variation][option_set_type]');
      // And finally there should be the new block form.
      $this->assertFieldByName($block_title_name);

      // Finally test adding option sets once they are already multiple.
      $this->createPersonalizedBlock(2, $agent);
      $agent->data['variation_set_handling'] = ACQUIA_LIFT_DECISION_LOCKSTEP;
      personalize_agent_save($agent);

      $this->drupalget('admin/structure/personalize/manage/' . $agent->machine_name . '/variations');
      $this->assertText('Variation sets (Lock step)');
      $this->assertFieldByName('variations[add_variation][option_set_type]');
      $this->assertNoFieldByName('variations[add_variation][variation_set_handling]');
      $this->assertNoFieldByName($block_title_name);
      $this->assertNoFieldByName($element_url_name);
      $edit = array(
        'variations[add_variation][option_set_type]' => 'block',
      );
      $this->drupalPostAJAX(NULL, $edit, 'variations[add_variation][option_set_type]');
      // The new block form should display without selecting variation handling.
      $this->assertFieldByName($block_title_name);
      */
}