function GoogleAnalyticsPhpFilterTest::testGoogleAnalyticsPhpFilter in Google Analytics 6.4
Same name and namespace in other branches
- 7.2 googleanalytics.test \GoogleAnalyticsPhpFilterTest::testGoogleAnalyticsPhpFilter()
- 7 googleanalytics.test \GoogleAnalyticsPhpFilterTest::testGoogleAnalyticsPhpFilter()
File
- ./
googleanalytics.test, line 668 - Test file for Google Analytics module.
Class
Code
function testGoogleAnalyticsPhpFilter() {
$ua_code = 'UA-123456-1';
$this
->drupalLogin($this->admin_user);
$edit = array();
$edit['googleanalytics_account'] = $ua_code;
$edit['googleanalytics_visibility'] = 2;
$edit['googleanalytics_pages'] = '<?php return 0; ?>';
$this
->drupalPost('admin/settings/googleanalytics', $edit, t('Save configuration'));
// Compare saved setting with posted setting.
$googleanalytics_pages = variable_get('googleanalytics_pages', $this
->randomName(8));
$this
->assertEqual('<?php return 0; ?>', $googleanalytics_pages, '[testGoogleAnalyticsPhpFilter]: PHP code snippet is intact.');
// Check tracking code visibility.
variable_set('googleanalytics_pages', '<?php return TRUE; ?>');
$this
->drupalGet('');
$this
->assertRaw('//www.google-analytics.com/analytics.js', '[testGoogleAnalyticsPhpFilter]: Tracking is displayed on frontpage page.');
$this
->drupalGet('admin');
$this
->assertRaw('//www.google-analytics.com/analytics.js', '[testGoogleAnalyticsPhpFilter]: Tracking is displayed on admin page.');
variable_set('googleanalytics_pages', '<?php return FALSE; ?>');
$this
->drupalGet('');
$this
->assertNoRaw('//www.google-analytics.com/analytics.js', '[testGoogleAnalyticsPhpFilter]: Tracking is not displayed on frontpage page.');
// Test administration form.
variable_set('googleanalytics_pages', '<?php return TRUE; ?>');
$this
->drupalGet('admin/settings/googleanalytics');
$this
->assertRaw(t('Pages on which this PHP code returns <code>TRUE</code> (experts only)'), '[testGoogleAnalyticsPhpFilter]: Permission to administer PHP for tracking visibility.');
$this
->assertRaw(check_plain('<?php return TRUE; ?>'), '[testGoogleAnalyticsPhpFilter]: PHP code snippted is displayed.');
// Login the delegated user and check if fields are visible.
$this
->drupalLogin($this->delegated_admin_user);
$this
->drupalGet('admin/settings/googleanalytics');
$this
->assertNoRaw(t('Pages on which this PHP code returns <code>TRUE</code> (experts only)'), '[testGoogleAnalyticsPhpFilter]: No permission to administer PHP for tracking visibility.');
$this
->assertNoRaw(check_plain('<?php return TRUE; ?>'), '[testGoogleAnalyticsPhpFilter]: No permission to view PHP code snippted.');
// Set a different value and verify that this is still the same after the post.
variable_set('googleanalytics_pages', '<?php return 0; ?>');
$edit = array();
$edit['googleanalytics_account'] = $ua_code;
$this
->drupalPost('admin/settings/googleanalytics', $edit, t('Save configuration'));
// Compare saved setting with posted setting.
$googleanalytics_visibility_pages = variable_get('googleanalytics_visibility', 0);
$googleanalytics_pages = variable_get('googleanalytics_pages', $this
->randomName(8));
$this
->assertEqual(2, $googleanalytics_visibility_pages, '[testGoogleAnalyticsPhpFilter]: Pages on which this PHP code returns TRUE is selected.');
$this
->assertEqual('<?php return 0; ?>', $googleanalytics_pages, '[testGoogleAnalyticsPhpFilter]: PHP code snippet is intact.');
}