You are here

public function OptimizelyTestPageSnippetTestCase::testOptimizelyTestPageSnippetTestForPresence in Optimizely 7.3

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

File

./optimizely.test, line 538
Optimizely Tests

Class

OptimizelyTestPageSnippetTestCase

Code

public function testOptimizelyTestPageSnippetTestForPresence() {
  $project_count = 0;
  while ($project_count < count($this->project_paths)) {
    $target_project = $project_count + 2;

    // Access with privileged user
    $this
      ->drupalLogin($this->privileged_user);

    // Enable project 1
    $edit = array(
      'optimizely_enabled' => 1,
    );
    $this
      ->drupalPost('admin/config/system/optimizely/add_update/' . $target_project, $edit, t('Update'));

    // Test Project was enabled
    $this
      ->drupalGet('admin/config/system/optimizely');
    $this
      ->assertRaw('name="project-' . $target_project . '" checked="checked"', '** <strong>Project ' . $target_project . ' is enabled</strong>, ready to test path settings for presance of snippet.');
    $this
      ->drupalLogout();
    $this
      ->drupalLogin($this->anonymous_user);

    // Test project paths for presence of snippet
    $next_project_paths = $this->project_paths[$project_count];
    if ($next_project_paths) {
      $paths = explode("\n", $next_project_paths);
    }
    else {
      $paths = NULL;
    }
    foreach ($paths as $path) {

      // Only test non wildcard paths
      if (strpos($path, '/*') === FALSE && $path != '') {

        // Look up the page defained in the project
        $this
          ->drupalGet($path);

        // Confirm default project is *enabled*
        $this
          ->assertRaw('http://cdn.optimizely.com/js/' . $this->project_code[$project_count] . '.js', '** <strong>Optimizely snippet call http://cdn.optimizely.com/js/' . $this->project_code[$project_count] . '.js found</strong> at: ' . $path);
      }
    }
    $this
      ->drupalLogout();

    // Disable project
    // Access with privileged user
    $this
      ->drupalLogin($this->privileged_user);
    $edit = array(
      'optimizely_enabled' => 0,
    );
    $this
      ->drupalPost('admin/config/system/optimizely/add_update/' . $target_project, $edit, t('Update'));
    $this
      ->drupalLogout();
    $project_count++;
  }
}