You are here

protected function AcquiaLiftWebTestBase::createPersonalizedBlock in Acquia Lift Connector 7

Same name and namespace in other branches
  1. 7.2 tests/acquia_lift.test \AcquiaLiftWebTestBase::createPersonalizedBlock()

Creates the required number of custom blocks.

Parameters

int $num: The number of blocks to create.

Return value

array An array of block deltas for use in personalized blocks.

1 call to AcquiaLiftWebTestBase::createPersonalizedBlock()
AcquiaLiftWebTestTarget::testImplementTargetingStructure in tests/acquia_lift.test

File

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

Class

AcquiaLiftWebTestBase
@file Integration tests for Acquia Lift module.

Code

protected function createPersonalizedBlock($index, $agent, $num_options = 2) {
  $option_set = array(
    'plugin' => 'block',
    'label' => 'Option Set ' . ($index + 1),
    'agent' => $agent->machine_name,
    'data' => array(
      'block_title' => 'Personalized Block ' . ($index + 1),
    ),
  );
  $options = array();
  module_load_include('inc', 'personalize_blocks', 'personalize_blocks.admin');
  for ($i = 1; $i <= $num_options; $i++) {
    $title = t('Custom block @num', array(
      '@num' => $i,
    ));
    $values = array(
      'title' => $title,
      'info' => $title,
      'body' => array(
        'format' => 'filtered_html',
        'value' => 'Some value',
      ),
    );
    $option = array(
      'option_label' => 'Option ' . $i,
      'option_id' => 'option-' . $i,
      'bid' => _personalize_blocks_add_custom_block($values),
    );
    $options[] = $option;
  }
  $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());
    return NULL;
  }
  return $option_set;
}