You are here

public function OptimizelyTestIncludeSnippetCase::testSnippet in Optimizely 7.2

Same name and namespace in other branches
  1. 7.3 optimizely.test \OptimizelyTestIncludeSnippetCase::testSnippet()

File

./optimizely.test, line 978
Optimizely Tests

Class

OptimizelyTestIncludeSnippetCase
* Test if snippet is included in path when not using aliases.

Code

public function testSnippet() {

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

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

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

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

  //array holding project field values
  $edit = array(
    'optimizely_project_title' => $this
      ->randomName(8),
    'optimizely_project_code' => rand(0, 10000),
    'optimizely_path' => "node/" . $node1->nid . "\n" . "node/" . $node2->nid,
    'optimizely_enabled' => 1,
  );

  // create snippet
  $snippet = 'http://cdn.optimizely.com/js/' . $edit['optimizely_project_code'] . '.js';

  //create the project
  $this
    ->drupalPost('admin/config/system/optimizely/add_update', $edit, t('Add'));

  //log out to make sure optimizely_refresh_cache() works
  $this
    ->drupalLogout();

  // @todo check how to turn "cache pages for anonymous users" and "Aggregate JavaScript files" to on on Performance page
  // check if snippet does appears on project path page

  //$this->drupalGet($edit_node1['alias']);
  $this
    ->drupalGet("node/" . $node1->nid);
  $this
    ->drupalGetContent();
  $this
    ->assertRaw($snippet, 'snippet found in markup of project path page -> node/' . $node1->nid);
  $this
    ->drupalGet("node/" . $node2->nid);
  $this
    ->drupalGetContent();
  $this
    ->assertRaw($snippet, 'snippet found in markup of project path page -> node2/' . $node1->nid);

  // check if snippet does not appear on other project path pages
  $this
    ->drupalGet("node/" . $node3->nid);
  $this
    ->drupalGetContent();

  // @todo check if drupalGetContent() is necessary
  $this
    ->assertNoRaw($snippet, 'snippet not found in markup of other page');
  $this
    ->drupalGet("node/" . $node4->nid);
  $this
    ->drupalGetContent();
  $this
    ->assertNoRaw($snippet, 'snippet not found in markup of other page');
}