public function OptimizelyTestIncludeAliasSnippetCase::testSnippet in Optimizely 7.3
Same name and namespace in other branches
- 7.2 optimizely.test \OptimizelyTestIncludeAliasSnippetCase::testSnippet()
File
- ./
optimizely.test, line 1078 - Optimizely Tests
Class
- OptimizelyTestIncludeAliasSnippetCase
- * Test if snippet is included in path when an alias is used.
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 the url alias of the project to be added
$edit_node1 = array();
$edit_node1['source'] = 'node/' . $node1->nid;
$edit_node1['alias'] = $this
->randomName(10);
$alias_details = array(
"source" => $edit_node1['source'],
"alias" => $edit_node1['alias'],
);
path_save($alias_details);
// 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 the url alias of the project to be added
$edit_node2 = array();
$edit_node2['source'] = 'node/' . $node2->nid;
$edit_node2['alias'] = $this
->randomName(10);
$alias_details = array(
"source" => $edit_node2['source'],
"alias" => $edit_node2['alias'],
);
path_save($alias_details);
// 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 the url alias
$edit_node3 = array();
$edit_node3['source'] = 'node/' . $node3->nid;
$edit_node3['alias'] = $this
->randomName(9);
$alias_details = array(
"source" => $edit_node3['source'],
"alias" => $edit_node3['alias'],
);
path_save($alias_details);
// create fourth page
$settings = array(
'type' => 'page',
'title' => $this
->randomName(32),
'body' => array(
LANGUAGE_NONE => array(
array(
$this
->randomName(64),
),
),
),
);
$node4 = $this
->drupalCreateNode($settings);
// Create the url alias
$edit_node4 = array();
$edit_node4['source'] = 'node/' . $node4->nid;
$edit_node4['alias'] = $this
->randomName(10);
$alias_details = array(
"source" => $edit_node4['source'],
"alias" => $edit_node4['alias'],
);
path_save($alias_details);
// array holding project field values
$edit = array(
'optimizely_project_title' => $this
->randomName(8),
'optimizely_project_code' => rand(0, 10000),
'optimizely_path' => $edit_node1['alias'] . "\n" . $edit_node2['alias'],
'optimizely_path' => $edit_node1['alias'],
'optimizely_enabled' => 1,
);
// Snippet to be found on project pages
$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
->assertRaw($snippet, 'Snippet (' . $snippet . ') found in markup of project path page (alias) -> ' . $edit_node1['alias']);
// check if snippet does appears on project path page
$this
->drupalGet($edit_node2['alias']);
$this
->assertRaw($snippet, 'Snippet (' . $snippet . ') found in markup of project path page (alias) -> ' . $edit_node2['alias']);
// check if snippet does not appear on other project path pages
$this
->drupalGet($edit_node3['alias']);
$this
->assertNoRaw($snippet, 'Snippet (' . $snippet . ') <strong>**not**</strong> found in markup of other page -> ' . $edit_node3['alias']);
$this
->drupalGet($edit_node4['alias']);
$this
->assertNoRaw($snippet, 'Snippet (' . $snippet . ') <strong>**not**</strong> found in markup of other page -> ' . $edit_node4['alias']);
}