You are here

function GoogleAnalyticsBasicTest::testGoogleAnalyticsConfiguration in Google Analytics 7.2

Same name and namespace in other branches
  1. 6.4 googleanalytics.test \GoogleAnalyticsBasicTest::testGoogleAnalyticsConfiguration()
  2. 6.3 googleanalytics.test \GoogleAnalyticsBasicTest::testGoogleAnalyticsConfiguration()
  3. 7 googleanalytics.test \GoogleAnalyticsBasicTest::testGoogleAnalyticsConfiguration()

File

./googleanalytics.test, line 41
Test file for Google Analytics module.

Class

GoogleAnalyticsBasicTest
@file Test file for Google Analytics module.

Code

function testGoogleAnalyticsConfiguration() {

  // Check if Configure link is available on 'Modules' page.
  // Requires 'administer modules' permission.
  $this
    ->drupalGet('admin/modules');
  $this
    ->assertRaw('admin/config/system/googleanalytics', '[testGoogleAnalyticsConfiguration]: Configure link from Modules page to Google Analytics Settings page exists.');

  // Check if Configure link is available on 'Status Reports' page. NOTE: Link is only shown without UA code configured.
  // Requires 'administer site configuration' permission.
  $this
    ->drupalGet('admin/reports/status');
  $this
    ->assertRaw('admin/config/system/googleanalytics', '[testGoogleAnalyticsConfiguration]: Configure link from Status Reports page to Google Analytics Settings page exists.');

  // Check for setting page's presence.
  $this
    ->drupalGet('admin/config/system/googleanalytics');
  $this
    ->assertRaw(t('Web Property ID'), '[testGoogleAnalyticsConfiguration]: Settings page displayed.');

  // Check for account code validation.
  $edit['googleanalytics_account'] = $this
    ->randomName(2);
  $this
    ->drupalPost('admin/config/system/googleanalytics', $edit, t('Save configuration'));
  $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.');

  // User should have access to code snippets.
  $this
    ->assertFieldByName('googleanalytics_codesnippet_create');
  $this
    ->assertFieldByName('googleanalytics_codesnippet_before');
  $this
    ->assertFieldByName('googleanalytics_codesnippet_after');
  $this
    ->assertNoFieldByXPath("//textarea[@name='googleanalytics_codesnippet_create' and @disabled='disabled']", NULL, '"Create only fields" is enabled.');
  $this
    ->assertNoFieldByXPath("//textarea[@name='googleanalytics_codesnippet_before' and @disabled='disabled']", NULL, '"Code snippet (before)" is enabled.');
  $this
    ->assertNoFieldByXPath("//textarea[@name='googleanalytics_codesnippet_after' and @disabled='disabled']", NULL, '"Code snippet (after)" is enabled.');

  // Login as user without JS permissions.
  $this
    ->drupalLogin($this->noSnippetUser);
  $this
    ->drupalGet('admin/config/system/googleanalytics');

  // User should *not* have access to snippets, but create fields.
  $this
    ->assertFieldByName('googleanalytics_codesnippet_create');
  $this
    ->assertFieldByName('googleanalytics_codesnippet_before');
  $this
    ->assertFieldByName('googleanalytics_codesnippet_after');
  $this
    ->assertNoFieldByXPath("//textarea[@name='googleanalytics_codesnippet_create' and @disabled='disabled']", NULL, '"Create only fields" is enabled.');
  $this
    ->assertFieldByXPath("//textarea[@name='googleanalytics_codesnippet_before' and @disabled='disabled']", NULL, '"Code snippet (before)" is disabled.');
  $this
    ->assertFieldByXPath("//textarea[@name='googleanalytics_codesnippet_after' and @disabled='disabled']", NULL, '"Code snippet (after)" is disabled.');
}