You are here

public function AcquiaLiftWebTestTarget::testAgentEditableMessaging in Acquia Lift Connector 7.2

Tests messaging for available operations based on agent status.

File

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

Class

AcquiaLiftWebTestTarget

Code

public function testAgentEditableMessaging() {
  module_enable(array(
    'personalize_blocks',
    'personalize_elements',
    'personalize_fields',
  ));
  $this
    ->resetAll();
  $admin_user = $this
    ->drupalCreateUser(array(
    'access administration pages',
    'administer site configuration',
    'access content',
    'administer content types',
    'administer nodes',
    'bypass node access',
    'manage personalized content',
  ));
  $this
    ->drupalLogin($admin_user);

  // Set the test classes for working with option set manipulation.
  AcquiaLiftAPI::setTestInstance();
  $agent = $this
    ->createTargetingAgent();

  // Personalize blocks.
  $option_set = $this
    ->createPersonalizedBlock(1, $agent, 2);

  // Add targeting so that the agent meets requirements.
  $this
    ->createTestFromOptionSet($agent, $option_set);
  $pb_message = 'Variations in use cannot be removed from Personalized Block 2 until the ' . $agent->label . ' personalization is paused.';
  $this
    ->drupalGet('admin/structure/personalize/variations/personalize-blocks/manage/1/edit');
  $this
    ->assertNoText($pb_message);

  // Start the agent via the UI in order to implement targeting and nested agents.
  $this
    ->drupalPost('admin/structure/personalize/manage/' . $agent->machine_name . '/review', array(), $this
    ->getButton('wizard_start'));
  $this
    ->drupalGet('admin/structure/personalize/variations/personalize-blocks/manage/1/edit');
  $this
    ->assertText($pb_message);

  // Reset the agent.
  personalize_agent_set_status($agent->machine_name, PERSONALIZE_STATUS_NOT_STARTED);
  personalize_option_set_delete($option_set->osid);

  // Personalize elements.
  $option_set = $this
    ->createPersonalizeElementsOptionSet($agent->machine_name, array(
    'num_options' => 4,
  ));
  $pe_message = 'Variations that are in use cannot be removed until the ' . $agent->label . ' personalization is paused.';
  $this
    ->drupalGet('admin/structure/personalize/variations/personalize-elements/manage/' . $option_set->osid . '/edit');
  $this
    ->assertNoText($pe_message);
  $edit = array(
    'options[1][personalize_elements_content]' => 'Mahna mahna',
    'options[2][personalize_elements_content]' => 'Do doo do do do',
    'options[3][personalize_elements_content]' => 'Mahna mahna',
    'options[4][personalize_elements_content]' => '',
  );
  $this
    ->drupalPost(NULL, $edit, 'Save');
  $this
    ->resetAll();

  // Verify that one option was removed.
  $option_set = personalize_option_set_load($option_set->osid);
  $this
    ->assertEqual(count($option_set->options), 3);
  $this
    ->createTestFromOptionSet($agent, $option_set);

  // Start the agent via the UI in order to implement targeting and nested agents.
  $this
    ->drupalPost('admin/structure/personalize/manage/' . $agent->machine_name . '/review', array(), $this
    ->getButton('wizard_start'));
  $this
    ->drupalGet('admin/structure/personalize/variations/personalize-elements/manage/' . $option_set->osid . '/edit');
  $this
    ->assertText($pe_message);
  $edit = array(
    'options[1][personalize_elements_content]' => 'Mahna mahna',
    'options[2][personalize_elements_content]' => 'Do doo do do do',
    'options[3][personalize_elements_content]' => '',
  );
  $this
    ->drupalPost(NULL, $edit, 'Save');
  $this
    ->resetAll();
  $this
    ->assertText('Variations cannot be removed until the ' . $agent->label . ' personalization is paused.');
  $option_set = personalize_option_set_load($option_set->osid);
  $this
    ->assertEqual(count($option_set->options), 3);

  // Personalize fields.
  $this
    ->createPersonalizedArticleField();
  list($node, $os, $agent_name) = $this
    ->createPersonalizedField();

  // Start the agent via the UI in order to implement targeting and nested agents.
  $field_agent = personalize_agent_load($agent_name);
  $this
    ->createTestFromOptionSet($field_agent, $os);
  $this
    ->drupalPost('admin/structure/personalize/manage/' . $agent_name . '/review', array(), $this
    ->getButton('wizard_start'));

  // Verify you can't remove from a running agent.
  $pf_message = 'The Personalizable Headline field cannot be removed until the personalization is paused.';
  $this
    ->drupalGet('node/1/edit');
  $edit = array(
    'article_headline[und][0][value]' => '',
  );
  $this
    ->drupalPost(NULL, $edit, 'Save');
  $this
    ->assertText($pf_message);
  personalize_agent_set_status($agent_name, PERSONALIZE_STATUS_PAUSED);
  $this
    ->drupalGet('node/1/edit');
  $edit = array(
    'article_headline[und][0][value]' => '',
  );
  $this
    ->drupalPost(NULL, $edit, 'Save');
  $this
    ->assertNoText($pf_message);
}