You are here

public function OptimizelyTestPageSnippetTestCase::setUp in Optimizely 7.3

Same name and namespace in other branches
  1. 7.2 optimizely.test \OptimizelyTestPageSnippetTestCase::setUp()

OptimizelyTestPageSnippetTestCase setUp().

Overrides DrupalWebTestCase::setUp

File

./optimizely.test, line 381
Optimizely Tests

Class

OptimizelyTestPageSnippetTestCase

Code

public function setUp() {

  // Enable any modules required for the test
  parent::setUp('optimizely');
  $this->anonymous_user = $this
    ->drupalCreateUser(array());
  $this->authenticated_user = $this
    ->drupalCreateUser(array(
    'access content',
  ));

  // Create and log in an admin user. The user will have the privilege
  // 'administer optimizely'. This privaged is need to access all administration
  // functionality of the module.
  $this->privileged_user = $this
    ->drupalCreateUser(array(
    'administer optimizely',
    'create page content',
    'edit own page content',
    'administer url aliases',
    'create url aliases',
  ));

  /*
   * Pages
   * 1. 1 x page (node/x), no alias
   * 2. 1 x page, article
   * 2. 3 x page (node/x), 2 x alias - "article/one, article/two"
   * 3. 2 x sub page (node/x), 2 x alias - "article/one/sub, article/two/sub"
   * 4. <front>, node/x, article/three
   *
   * Projects
   * 1. node/x,
   * 2. article/one
   * 3. node/x, article/one, node/x
   * 4. article/one, node/x, article/two
   * 5. node/*
   * 6. article/* <-- Multi matches: article, article/one, article/two, article/one/sub, article/two/sub
   * 7. <front> (article/one)
   * 8. <front>, article/one <-- non unique path
   * 9. node/*, article/* <-- non unique path
   * 10. article/one/* <-- Multi matches: article/one/sub
   * 11. article, article/one, article/one/*
   * 12. article, node/x, article/one, article/two/*
   * 13. node/x, article/one, article/two/*, user, user/*
   * 14. article/one?param=xx&parm2=xxx
   * 15. node/x, article/one, article/two/*, user/*, article?param=xx&parm2=xxx
   *
   * ++ multi projects enabled
   */

  // Test page creation at base alias path
  $this->project_nodes = array();
  $this->project_aliases = array();
  $this->project_paths = array();
  $subpath = '';

  // Access with privileged user
  $this
    ->drupalLogin($this->privileged_user);
  for ($project_count = 0; $project_count <= 3; $project_count++) {
    $this->project_paths[$project_count] = '';
    for ($page_count = 0; $page_count <= 4; $page_count++) {

      // create page
      $settings = array(
        'type' => 'page',
        'title' => $this
          ->randomName(32),
        'body' => array(
          LANGUAGE_NONE => array(
            array(
              $this
                ->randomName(64),
            ),
          ),
        ),
      );
      $node = $this
        ->drupalCreateNode($settings);

      // Keep track of the nids created
      $this->project_nodes[] = $node->nid;
      $random_alias_node = rand(0, 1);
      if ($random_alias_node) {
        $alias = $this
          ->randomName(10);

        // Random subpath alias
        $random_subalias_node = rand(0, 1);
        if ($random_subalias_node) {
          $subpath = $this
            ->randomName(10);
          $alias = $subpath . '/' . $alias;
        }

        // Create the url alias
        $edit_node = array();
        $edit_node['source'] = 'node/' . $node->nid;
        $edit_node['alias'] = $alias;
        $alias_details = array(
          "source" => $edit_node['source'],
          "alias" => $edit_node['alias'],
        );
        path_save($alias_details);

        // Keep track of alias created
        $this->project_aliases[] = $alias;

        // Randomly create wildcard project path entry
        $random_project_wildcard = rand(0, 1);
        if ($random_project_wildcard && $subpath != '') {
          $edit_node['alias'] = $subpath . '/*';
          $subpath = '';

          // Add alias to project path setting variable
          if (isset($this->project_paths[$project_count])) {
            $this->project_paths[$project_count] = $edit_node['alias'] . "\n" . $this->project_paths[$project_count];
          }
          else {
            $this->project_paths[$project_count] = $edit_node['alias'];
          }
        }
        elseif ($subpath == '') {
          if (isset($this->project_paths[$project_count])) {
            $this->project_paths[$project_count] = $edit_node['alias'] . "\n" . $this->project_paths[$project_count];
          }
          else {
            $this->project_paths[$project_count] = $edit_node['alias'];
          }
        }
      }
      else {
        if (isset($this->project_paths[$project_count])) {
          $this->project_paths[$project_count] = 'node/' . $node->nid . "\n" . $this->project_paths[$project_count];
        }
        else {
          $this->project_paths[$project_count] = 'node/' . $node->nid;
        }
      }
    }

    // Create Projects
    $this->project_code[$project_count] = rand(0, 10000);

    // Add project with path setting to page
    $edit = array(
      'optimizely_project_title' => $this
        ->randomName(8),
      'optimizely_project_code' => $this->project_code[$project_count],
      'optimizely_path' => $this->project_paths[$project_count],
      'optimizely_enabled' => 0,
    );
    $this
      ->drupalPost('admin/config/system/optimizely/add_update', $edit, t('Add'));
  }
}