danielebarchiesi@2: t('Google Analytics basic tests'), danielebarchiesi@2: 'description' => t('Test basic functionality of Google Analytics module.'), danielebarchiesi@2: 'group' => 'Google Analytics', danielebarchiesi@2: ); danielebarchiesi@2: } danielebarchiesi@2: danielebarchiesi@2: function setUp() { danielebarchiesi@2: parent::setUp('googleanalytics'); danielebarchiesi@2: danielebarchiesi@2: $permissions = array( danielebarchiesi@2: 'access administration pages', danielebarchiesi@2: 'administer google analytics', danielebarchiesi@2: ); danielebarchiesi@2: danielebarchiesi@2: // User to set up google_analytics. danielebarchiesi@2: $this->admin_user = $this->drupalCreateUser($permissions); danielebarchiesi@2: $this->drupalLogin($this->admin_user); danielebarchiesi@2: } danielebarchiesi@2: danielebarchiesi@2: function testGoogleAnalyticsConfiguration() { danielebarchiesi@2: // Check for setting page's presence. danielebarchiesi@2: $this->drupalGet('admin/config/system/googleanalytics'); danielebarchiesi@2: $this->assertRaw(t('Web Property ID'), '[testGoogleAnalyticsConfiguration]: Settings page displayed.'); danielebarchiesi@2: danielebarchiesi@2: // Check for account code validation. danielebarchiesi@2: $edit['googleanalytics_account'] = $this->randomName(2); danielebarchiesi@2: $this->drupalPost('admin/config/system/googleanalytics', $edit, 'Save configuration'); danielebarchiesi@2: $this->assertRaw(t('A valid Google Analytics Web Property ID is case sensitive and formatted like UA-xxxxxxx-yy.'), '[testGoogleAnalyticsConfiguration]: Invalid Web Property ID number validated.'); danielebarchiesi@2: } danielebarchiesi@2: danielebarchiesi@2: function testGoogleAnalyticsPageVisibility() { danielebarchiesi@2: $ua_code = 'UA-123456-1'; danielebarchiesi@2: variable_set('googleanalytics_account', $ua_code); danielebarchiesi@2: danielebarchiesi@2: // Show tracking on "every page except the listed pages". danielebarchiesi@2: variable_set('googleanalytics_visibility_pages', 0); danielebarchiesi@2: // Disable tracking one "admin*" pages only. danielebarchiesi@2: variable_set('googleanalytics_pages', "admin\nadmin/*"); danielebarchiesi@2: // Enable tracking only for authenticated users only. danielebarchiesi@2: variable_set('googleanalytics_roles', array(DRUPAL_AUTHENTICATED_RID => DRUPAL_AUTHENTICATED_RID)); danielebarchiesi@2: danielebarchiesi@2: // Check tracking code visibility. danielebarchiesi@2: $this->drupalGet(''); danielebarchiesi@2: $this->assertRaw($ua_code, '[testGoogleAnalyticsPageVisibility]: Tracking code is displayed for authenticated users.'); danielebarchiesi@2: danielebarchiesi@2: // Test whether tracking code is not included on pages to omit. danielebarchiesi@2: $this->drupalGet('admin'); danielebarchiesi@2: $this->assertNoRaw($ua_code, '[testGoogleAnalyticsPageVisibility]: Tracking code is not displayed on admin page.'); danielebarchiesi@2: $this->drupalGet('admin/config/system/googleanalytics'); danielebarchiesi@2: // Checking for tracking code URI here, as $ua_code is displayed in the form. danielebarchiesi@2: $this->assertNoRaw('google-analytics.com/ga.js', '[testGoogleAnalyticsPageVisibility]: Tracking code is not displayed on admin subpage.'); danielebarchiesi@2: danielebarchiesi@2: // Test whether tracking code display is properly flipped. danielebarchiesi@2: variable_set('googleanalytics_visibility_pages', 1); danielebarchiesi@2: $this->drupalGet('admin'); danielebarchiesi@2: $this->assertRaw($ua_code, '[testGoogleAnalyticsPageVisibility]: Tracking code is displayed on admin page.'); danielebarchiesi@2: $this->drupalGet('admin/config/system/googleanalytics'); danielebarchiesi@2: // Checking for tracking code URI here, as $ua_code is displayed in the form. danielebarchiesi@2: $this->assertRaw('google-analytics.com/ga.js', '[testGoogleAnalyticsPageVisibility]: Tracking code is displayed on admin subpage.'); danielebarchiesi@2: $this->drupalGet(''); danielebarchiesi@2: $this->assertNoRaw($ua_code, '[testGoogleAnalyticsPageVisibility]: Tracking code is NOT displayed on front page.'); danielebarchiesi@2: danielebarchiesi@2: // Test whether tracking code is not display for anonymous. danielebarchiesi@2: $this->drupalLogout(); danielebarchiesi@2: $this->drupalGet(''); danielebarchiesi@2: $this->assertNoRaw($ua_code, '[testGoogleAnalyticsPageVisibility]: Tracking code is NOT displayed for anonymous.'); danielebarchiesi@2: danielebarchiesi@2: // Switch back to every page except the listed pages. danielebarchiesi@2: variable_set('googleanalytics_visibility_pages', 0); danielebarchiesi@2: // Enable tracking code for all user roles. danielebarchiesi@2: variable_set('googleanalytics_roles', array()); danielebarchiesi@2: danielebarchiesi@2: // Test whether 403 forbidden tracking code is shown if user has no access. danielebarchiesi@2: $this->drupalGet('admin'); danielebarchiesi@2: $this->assertRaw('/403.html', '[testGoogleAnalyticsPageVisibility]: 403 Forbidden tracking code shown if user has no access.'); danielebarchiesi@2: danielebarchiesi@2: // Test whether 404 not found tracking code is shown on non-existent pages. danielebarchiesi@2: $this->drupalGet($this->randomName(64)); danielebarchiesi@2: $this->assertRaw('/404.html', '[testGoogleAnalyticsPageVisibility]: 404 Not Found tracking code shown on non-existent page.'); danielebarchiesi@2: danielebarchiesi@2: // DNT Tests: danielebarchiesi@2: // Enable caching of pages for anonymous users. danielebarchiesi@2: variable_set('cache', 1); danielebarchiesi@2: // Test whether DNT headers will fail to disable embedding of tracking code. danielebarchiesi@2: $this->drupalGet('', array(), array('DNT: 1')); danielebarchiesi@2: $this->assertRaw('_gaq.push(["_trackPageview"]);', '[testGoogleAnalyticsDNTVisibility]: DNT header send from client, but page caching is enabled and tracker cannot removed.'); danielebarchiesi@2: // DNT works only with caching of pages for anonymous users disabled. danielebarchiesi@2: variable_set('cache', 0); danielebarchiesi@2: $this->drupalGet(''); danielebarchiesi@2: $this->assertRaw('_gaq.push(["_trackPageview"]);', '[testGoogleAnalyticsDNTVisibility]: Tracking is enabled without DNT header.'); danielebarchiesi@2: // Test whether DNT header is able to remove the tracking code. danielebarchiesi@2: $this->drupalGet('', array(), array('DNT: 1')); danielebarchiesi@2: $this->assertNoRaw('_gaq.push(["_trackPageview"]);', '[testGoogleAnalyticsDNTVisibility]: DNT header received from client. Tracking has been disabled by browser.'); danielebarchiesi@2: // Disable DNT feature and see if tracker is still embedded. danielebarchiesi@2: variable_set('googleanalytics_privacy_donottrack', 0); danielebarchiesi@2: $this->drupalGet('', array(), array('DNT: 1')); danielebarchiesi@2: $this->assertRaw('_gaq.push(["_trackPageview"]);', '[testGoogleAnalyticsDNTVisibility]: DNT feature is disabled, DNT header from browser has been ignored.'); danielebarchiesi@2: } danielebarchiesi@2: danielebarchiesi@2: function testGoogleAnalyticsTrackingCode() { danielebarchiesi@2: $ua_code = 'UA-123456-2'; danielebarchiesi@2: variable_set('googleanalytics_account', $ua_code); danielebarchiesi@2: danielebarchiesi@2: // Show tracking code on every page except the listed pages. danielebarchiesi@2: variable_set('googleanalytics_visibility_pages', 0); danielebarchiesi@2: // Enable tracking code for all user roles. danielebarchiesi@2: variable_set('googleanalytics_roles', array()); danielebarchiesi@2: danielebarchiesi@2: /* Sample JS code as added to page: danielebarchiesi@2: danielebarchiesi@2: danielebarchiesi@2: */ danielebarchiesi@2: danielebarchiesi@2: // Test whether tracking code uses latest JS. danielebarchiesi@2: variable_set('googleanalytics_cache', 0); danielebarchiesi@2: $this->drupalGet(''); danielebarchiesi@2: $this->assertRaw('google-analytics.com/ga.js', '[testGoogleAnalyticsTrackingCode]: Latest tracking code used.'); danielebarchiesi@2: danielebarchiesi@2: // Test whether the alternate doubleclick library is used danielebarchiesi@2: variable_set('googleanalytics_trackdoubleclick', 1); danielebarchiesi@2: $this->drupalGet(''); danielebarchiesi@2: $this->assertRaw('stats.g.doubleclick.net/dc.js', '[testGoogleAnalyticsTrackingCode]: Doubleclick tracking code used.'); danielebarchiesi@2: danielebarchiesi@2: // Test whether anonymize visitors IP address feature has been enabled. danielebarchiesi@2: $this->drupalGet(''); danielebarchiesi@2: $this->assertNoRaw('_gaq.push(["_gat._anonymizeIp"]);', '[testGoogleAnalyticsTrackingCode]: Anonymize visitors IP address not found on frontpage.'); danielebarchiesi@2: // Enable anonymizing of IP addresses. danielebarchiesi@2: variable_set('googleanalytics_tracker_anonymizeip', 1); danielebarchiesi@2: $this->drupalGet(''); danielebarchiesi@2: $this->assertRaw('_gaq.push(["_gat._anonymizeIp"]);', '[testGoogleAnalyticsTrackingCode]: Anonymize visitors IP address found on frontpage.'); danielebarchiesi@2: danielebarchiesi@2: // Test whether single domain tracking is active. danielebarchiesi@2: $this->drupalGet(''); danielebarchiesi@2: $this->assertNoRaw('_gaq.push(["_setDomainName"', '[testGoogleAnalyticsTrackingCode]: Single domain tracking is active.'); danielebarchiesi@2: danielebarchiesi@2: // Enable "One domain with multiple subdomains". danielebarchiesi@2: variable_set('googleanalytics_domain_mode', 1); danielebarchiesi@2: $this->drupalGet(''); danielebarchiesi@2: danielebarchiesi@2: // Test may run on localhost, an ipaddress or real domain name. danielebarchiesi@2: // TODO: Workaround to run tests successfully. This feature cannot tested reliable. danielebarchiesi@2: global $cookie_domain; danielebarchiesi@2: if (count(explode('.', $cookie_domain)) > 2 && !is_numeric(str_replace('.', '', $cookie_domain))) { danielebarchiesi@2: $this->assertRaw('_gaq.push(["_setDomainName",', '[testGoogleAnalyticsTrackingCode]: One domain with multiple subdomains is active on real host.'); danielebarchiesi@2: } danielebarchiesi@2: else { danielebarchiesi@2: // Special cases, Localhost and IP addresses don't show '_setDomainName'. danielebarchiesi@2: $this->assertNoRaw('_gaq.push(["_setDomainName",', '[testGoogleAnalyticsTrackingCode]: One domain with multiple subdomains may be active on localhost (test result is not reliable).'); danielebarchiesi@2: } danielebarchiesi@2: danielebarchiesi@2: // Enable "Multiple top-level domains" tracking. danielebarchiesi@2: variable_set('googleanalytics_domain_mode', 2); danielebarchiesi@2: variable_set('googleanalytics_cross_domains', "www.example.com\nwww.example.net"); danielebarchiesi@2: $this->drupalGet(''); danielebarchiesi@2: $this->assertRaw('_gaq.push(["_setDomainName", "none"]);', '[testGoogleAnalyticsTrackingCode]: _setDomainName: "none" found. Cross domain tracking is active.'); danielebarchiesi@2: $this->assertRaw('_gaq.push(["_setAllowLinker", true]);', '[testGoogleAnalyticsTrackingCode]: _setAllowLinker: true found. Cross domain tracking is active.'); danielebarchiesi@2: $this->assertRaw('"trackCrossDomains":["www.example.com","www.example.net"]', '[testGoogleAnalyticsTrackingCode]: Cross domain tracking with www.example.com and www.example.net is active.'); danielebarchiesi@2: danielebarchiesi@2: // Test whether the BEFORE and AFTER code is added to the tracker. danielebarchiesi@2: variable_set('googleanalytics_codesnippet_before', '_setDetectFlash(false);'); danielebarchiesi@2: variable_set('googleanalytics_codesnippet_after', '_gaq.push(["t2._setAccount", "UA-123456-3"]);_gaq.push(["t2._trackPageview"]);'); danielebarchiesi@2: $this->drupalGet(''); danielebarchiesi@2: $this->assertRaw('_setDetectFlash(false);', '[testGoogleAnalyticsTrackingCode]: Before codesnippet has been found with "Flash" detection disabled.'); danielebarchiesi@2: $this->assertRaw('t2._setAccount', '[testGoogleAnalyticsTrackingCode]: After codesnippet with "t2" tracker has been found.'); danielebarchiesi@2: } danielebarchiesi@2: } danielebarchiesi@2: danielebarchiesi@2: class GoogleAnalyticsCustomVariablesTest extends DrupalWebTestCase { danielebarchiesi@2: danielebarchiesi@2: public static function getInfo() { danielebarchiesi@2: return array( danielebarchiesi@2: 'name' => t('Google Analytics Custom Variables tests'), danielebarchiesi@2: 'description' => t('Test custom variables functionality of Google Analytics module.'), danielebarchiesi@2: 'group' => 'Google Analytics', danielebarchiesi@2: 'dependencies' => array('token'), danielebarchiesi@2: ); danielebarchiesi@2: } danielebarchiesi@2: danielebarchiesi@2: function setUp() { danielebarchiesi@2: parent::setUp('googleanalytics', 'token'); danielebarchiesi@2: danielebarchiesi@2: $permissions = array( danielebarchiesi@2: 'access administration pages', danielebarchiesi@2: 'administer google analytics', danielebarchiesi@2: ); danielebarchiesi@2: danielebarchiesi@2: // User to set up google_analytics. danielebarchiesi@2: $this->admin_user = $this->drupalCreateUser($permissions); danielebarchiesi@2: } danielebarchiesi@2: danielebarchiesi@2: function testGoogleAnalyticsCustomVariables() { danielebarchiesi@2: $ua_code = 'UA-123456-3'; danielebarchiesi@2: variable_set('googleanalytics_account', $ua_code); danielebarchiesi@2: danielebarchiesi@2: // Basic test if the feature works. danielebarchiesi@2: $custom_vars = array( danielebarchiesi@2: 'slots' => array( danielebarchiesi@2: 1 => array( danielebarchiesi@2: 'slot' => 1, danielebarchiesi@2: 'name' => 'Foo 1', danielebarchiesi@2: 'value' => 'Bar 1', danielebarchiesi@2: 'scope' => 3, danielebarchiesi@2: ), danielebarchiesi@2: 2 => array( danielebarchiesi@2: 'slot' => 2, danielebarchiesi@2: 'name' => 'Foo 2', danielebarchiesi@2: 'value' => 'Bar 2', danielebarchiesi@2: 'scope' => 2, danielebarchiesi@2: ), danielebarchiesi@2: 3 => array( danielebarchiesi@2: 'slot' => 3, danielebarchiesi@2: 'name' => 'Foo 3', danielebarchiesi@2: 'value' => 'Bar 3', danielebarchiesi@2: 'scope' => 3, danielebarchiesi@2: ), danielebarchiesi@2: 4 => array( danielebarchiesi@2: 'slot' => 4, danielebarchiesi@2: 'name' => 'Foo 4', danielebarchiesi@2: 'value' => 'Bar 4', danielebarchiesi@2: 'scope' => 2, danielebarchiesi@2: ), danielebarchiesi@2: 5 => array( danielebarchiesi@2: 'slot' => 5, danielebarchiesi@2: 'name' => 'Foo 5', danielebarchiesi@2: 'value' => 'Bar 5', danielebarchiesi@2: 'scope' => 1, danielebarchiesi@2: ), danielebarchiesi@2: ) danielebarchiesi@2: ); danielebarchiesi@2: variable_set('googleanalytics_custom_var', $custom_vars); danielebarchiesi@2: $this->drupalGet(''); danielebarchiesi@2: danielebarchiesi@2: foreach ($custom_vars['slots'] as $slot) { danielebarchiesi@2: $this->assertRaw("_gaq.push(['_setCustomVar', " . $slot['slot'] . ", \"" . $slot['name'] . "\", \"" . $slot['value'] . "\", " . $slot['scope'] . "]);", '[testGoogleAnalyticsCustomVariables]: _setCustomVar ' . $slot['slot'] . ' is shown.'); danielebarchiesi@2: } danielebarchiesi@2: danielebarchiesi@2: // Test whether tokens are replaced in custom variable names. danielebarchiesi@2: $site_slogan = $this->randomName(16); danielebarchiesi@2: variable_set('site_slogan', $site_slogan); danielebarchiesi@2: danielebarchiesi@2: $custom_vars = array( danielebarchiesi@2: 'slots' => array( danielebarchiesi@2: 1 => array( danielebarchiesi@2: 'slot' => 1, danielebarchiesi@2: 'name' => 'Name: [site:slogan]', danielebarchiesi@2: 'value' => 'Value: [site:slogan]', danielebarchiesi@2: 'scope' => 3, danielebarchiesi@2: ), danielebarchiesi@2: 2 => array( danielebarchiesi@2: 'slot' => 2, danielebarchiesi@2: 'name' => '', danielebarchiesi@2: 'value' => $this->randomName(16), danielebarchiesi@2: 'scope' => 1, danielebarchiesi@2: ), danielebarchiesi@2: 3 => array( danielebarchiesi@2: 'slot' => 3, danielebarchiesi@2: 'name' => $this->randomName(16), danielebarchiesi@2: 'value' => '', danielebarchiesi@2: 'scope' => 2, danielebarchiesi@2: ), danielebarchiesi@2: 4 => array( danielebarchiesi@2: 'slot' => 4, danielebarchiesi@2: 'name' => '', danielebarchiesi@2: 'value' => '', danielebarchiesi@2: 'scope' => 3, danielebarchiesi@2: ), danielebarchiesi@2: 5 => array( danielebarchiesi@2: 'slot' => 5, danielebarchiesi@2: 'name' => '', danielebarchiesi@2: 'value' => '', danielebarchiesi@2: 'scope' => 3, danielebarchiesi@2: ), danielebarchiesi@2: ) danielebarchiesi@2: ); danielebarchiesi@2: variable_set('googleanalytics_custom_var', $custom_vars); danielebarchiesi@2: $this->verbose('
' . print_r($custom_vars, TRUE) . ''); danielebarchiesi@2: danielebarchiesi@2: $this->drupalGet(''); danielebarchiesi@2: $this->assertRaw("_gaq.push(['_setCustomVar', 1, \"Name: $site_slogan\", \"Value: $site_slogan\", 3]", '[testGoogleAnalyticsCustomVariables]: Tokens have been replaced in custom variable.'); danielebarchiesi@2: $this->assertNoRaw("_gaq.push(['_setCustomVar', 2,", '[testGoogleAnalyticsCustomVariables]: Value with empty name is not shown.'); danielebarchiesi@2: $this->assertNoRaw("_gaq.push(['_setCustomVar', 3,", '[testGoogleAnalyticsCustomVariables]: Name with empty value is not shown.'); danielebarchiesi@2: $this->assertNoRaw("_gaq.push(['_setCustomVar', 4,", '[testGoogleAnalyticsCustomVariables]: Empty name and value is not shown.'); danielebarchiesi@2: $this->assertNoRaw("_gaq.push(['_setCustomVar', 5,", '[testGoogleAnalyticsCustomVariables]: Empty name and value is not shown.'); danielebarchiesi@2: } danielebarchiesi@2: } danielebarchiesi@2: danielebarchiesi@2: class GoogleAnalyticsStatusMessagesTest extends DrupalWebTestCase { danielebarchiesi@2: danielebarchiesi@2: public static function getInfo() { danielebarchiesi@2: return array( danielebarchiesi@2: 'name' => t('Google Analytics status messages tests'), danielebarchiesi@2: 'description' => t('Test status messages functionality of Google Analytics module.'), danielebarchiesi@2: 'group' => 'Google Analytics', danielebarchiesi@2: ); danielebarchiesi@2: } danielebarchiesi@2: danielebarchiesi@2: function setUp() { danielebarchiesi@2: parent::setUp('googleanalytics'); danielebarchiesi@2: danielebarchiesi@2: $permissions = array( danielebarchiesi@2: 'access administration pages', danielebarchiesi@2: 'administer google analytics', danielebarchiesi@2: ); danielebarchiesi@2: danielebarchiesi@2: // User to set up google_analytics. danielebarchiesi@2: $this->admin_user = $this->drupalCreateUser($permissions); danielebarchiesi@2: } danielebarchiesi@2: danielebarchiesi@2: function testGoogleAnalyticsStatusMessages() { danielebarchiesi@2: $ua_code = 'UA-123456-4'; danielebarchiesi@2: variable_set('googleanalytics_account', $ua_code); danielebarchiesi@2: danielebarchiesi@2: // Enable logging of errors only. danielebarchiesi@2: variable_set('googleanalytics_trackmessages', array('error' => 'error')); danielebarchiesi@2: danielebarchiesi@2: $this->drupalPost('user/login', array(), 'Log in'); danielebarchiesi@2: $this->assertRaw('_gaq.push(["_trackEvent", "Messages", "Error message", "Username field is required."]);', '[testGoogleAnalyticsStatusMessages]: _trackEvent "Username field is required." is shown.'); danielebarchiesi@2: $this->assertRaw('_gaq.push(["_trackEvent", "Messages", "Error message", "Password field is required."]);', '[testGoogleAnalyticsStatusMessages]: _trackEvent "Password field is required." is shown.'); danielebarchiesi@2: danielebarchiesi@2: // @todo: investigate why drupal_set_message() fails. danielebarchiesi@2: //drupal_set_message('Example status message.', 'status'); danielebarchiesi@2: //drupal_set_message('Example warning message.', 'warning'); danielebarchiesi@2: //drupal_set_message('Example error message.', 'error'); danielebarchiesi@2: //drupal_set_message('Example error message with html tags and link.', 'error'); danielebarchiesi@2: //$this->drupalGet(''); danielebarchiesi@2: //$this->assertNoRaw('_gaq.push(["_trackEvent", "Messages", "Status message", "Example status message."]);', '[testGoogleAnalyticsStatusMessages]: Example status message is not enabled for tracking.'); danielebarchiesi@2: //$this->assertNoRaw('_gaq.push(["_trackEvent", "Messages", "Warning message", "Example warning message."]);', '[testGoogleAnalyticsStatusMessages]: Example warning message is not enabled for tracking.'); danielebarchiesi@2: //$this->assertRaw('_gaq.push(["_trackEvent", "Messages", "Error message", "Example error message."]);', '[testGoogleAnalyticsStatusMessages]: Example error message is shown.'); danielebarchiesi@2: //$this->assertRaw('_gaq.push(["_trackEvent", "Messages", "Error message", "Example error message with html tags and link."]);', '[testGoogleAnalyticsStatusMessages]: HTML has been stripped successful from Example error message with html tags and link.'); danielebarchiesi@2: } danielebarchiesi@2: } danielebarchiesi@2: danielebarchiesi@2: class GoogleAnalyticsRolesTest extends DrupalWebTestCase { danielebarchiesi@2: danielebarchiesi@2: public static function getInfo() { danielebarchiesi@2: return array( danielebarchiesi@2: 'name' => t('Google Analytics role tests'), danielebarchiesi@2: 'description' => t('Test roles functionality of Google Analytics module.'), danielebarchiesi@2: 'group' => 'Google Analytics', danielebarchiesi@2: ); danielebarchiesi@2: } danielebarchiesi@2: danielebarchiesi@2: function setUp() { danielebarchiesi@2: parent::setUp('googleanalytics'); danielebarchiesi@2: danielebarchiesi@2: $permissions = array( danielebarchiesi@2: 'access administration pages', danielebarchiesi@2: 'administer google analytics', danielebarchiesi@2: ); danielebarchiesi@2: danielebarchiesi@2: // User to set up google_analytics. danielebarchiesi@2: $this->admin_user = $this->drupalCreateUser($permissions); danielebarchiesi@2: } danielebarchiesi@2: danielebarchiesi@2: function testGoogleAnalyticsRolesTracking() { danielebarchiesi@2: $ua_code = 'UA-123456-4'; danielebarchiesi@2: variable_set('googleanalytics_account', $ua_code); danielebarchiesi@2: danielebarchiesi@2: // Test if the default settings are working as expected. danielebarchiesi@2: danielebarchiesi@2: // Add to the selected roles only. danielebarchiesi@2: variable_set('googleanalytics_visibility_roles', 0); danielebarchiesi@2: // Enable tracking for all users. danielebarchiesi@2: variable_set('googleanalytics_roles', array()); danielebarchiesi@2: danielebarchiesi@2: // Check tracking code visibility. danielebarchiesi@2: $this->drupalGet(''); danielebarchiesi@2: $this->assertRaw($ua_code, '[testGoogleAnalyticsRoleVisibility]: Tracking code is displayed for anonymous users on frontpage with default settings.'); danielebarchiesi@2: $this->drupalGet('admin'); danielebarchiesi@2: $this->assertRaw('/403.html', '[testGoogleAnalyticsRoleVisibility]: 403 Forbidden tracking code is displayed for anonymous users in admin section with default settings.'); danielebarchiesi@2: danielebarchiesi@2: $this->drupalLogin($this->admin_user); danielebarchiesi@2: danielebarchiesi@2: $this->drupalGet(''); danielebarchiesi@2: $this->assertRaw($ua_code, '[testGoogleAnalyticsRoleVisibility]: Tracking code is displayed for authenticated users on frontpage with default settings.'); danielebarchiesi@2: $this->drupalGet('admin'); danielebarchiesi@2: $this->assertNoRaw($ua_code, '[testGoogleAnalyticsRoleVisibility]: Tracking code is NOT displayed for authenticated users in admin section with default settings.'); danielebarchiesi@2: danielebarchiesi@2: // Test if the non-default settings are working as expected. danielebarchiesi@2: danielebarchiesi@2: // Enable tracking only for authenticated users. danielebarchiesi@2: variable_set('googleanalytics_roles', array(DRUPAL_AUTHENTICATED_RID => DRUPAL_AUTHENTICATED_RID)); danielebarchiesi@2: danielebarchiesi@2: $this->drupalGet(''); danielebarchiesi@2: $this->assertRaw($ua_code, '[testGoogleAnalyticsRoleVisibility]: Tracking code is displayed for authenticated users only on frontpage.'); danielebarchiesi@2: danielebarchiesi@2: $this->drupalLogout(); danielebarchiesi@2: $this->drupalGet(''); danielebarchiesi@2: $this->assertNoRaw($ua_code, '[testGoogleAnalyticsRoleVisibility]: Tracking code is NOT displayed for anonymous users on frontpage.'); danielebarchiesi@2: danielebarchiesi@2: // Add to every role except the selected ones. danielebarchiesi@2: variable_set('googleanalytics_visibility_roles', 1); danielebarchiesi@2: // Enable tracking for all users. danielebarchiesi@2: variable_set('googleanalytics_roles', array()); danielebarchiesi@2: danielebarchiesi@2: // Check tracking code visibility. danielebarchiesi@2: $this->drupalGet(''); danielebarchiesi@2: $this->assertRaw($ua_code, '[testGoogleAnalyticsRoleVisibility]: Tracking code is added to every role and displayed for anonymous users.'); danielebarchiesi@2: $this->drupalGet('admin'); danielebarchiesi@2: $this->assertRaw('/403.html', '[testGoogleAnalyticsRoleVisibility]: 403 Forbidden tracking code is shown for anonymous users if every role except the selected ones is selected.'); danielebarchiesi@2: danielebarchiesi@2: $this->drupalLogin($this->admin_user); danielebarchiesi@2: danielebarchiesi@2: $this->drupalGet(''); danielebarchiesi@2: $this->assertRaw($ua_code, '[testGoogleAnalyticsRoleVisibility]: Tracking code is added to every role and displayed on frontpage for authenticated users.'); danielebarchiesi@2: $this->drupalGet('admin'); danielebarchiesi@2: $this->assertNoRaw($ua_code, '[testGoogleAnalyticsRoleVisibility]: Tracking code is added to every role and NOT displayed in admin section for authenticated users.'); danielebarchiesi@2: danielebarchiesi@2: // Disable tracking for authenticated users. danielebarchiesi@2: variable_set('googleanalytics_roles', array(DRUPAL_AUTHENTICATED_RID => DRUPAL_AUTHENTICATED_RID)); danielebarchiesi@2: danielebarchiesi@2: $this->drupalGet(''); danielebarchiesi@2: $this->assertNoRaw($ua_code, '[testGoogleAnalyticsRoleVisibility]: Tracking code is NOT displayed on frontpage for excluded authenticated users.'); danielebarchiesi@2: $this->drupalGet('admin'); danielebarchiesi@2: $this->assertNoRaw($ua_code, '[testGoogleAnalyticsRoleVisibility]: Tracking code is NOT displayed in admin section for excluded authenticated users.'); danielebarchiesi@2: danielebarchiesi@2: $this->drupalLogout(); danielebarchiesi@2: $this->drupalGet(''); danielebarchiesi@2: $this->assertRaw($ua_code, '[testGoogleAnalyticsRoleVisibility]: Tracking code is displayed on frontpage for included anonymous users.'); danielebarchiesi@2: } danielebarchiesi@2: danielebarchiesi@2: }