public function GoogleAnalyticsBasicTest::testGoogleAnalyticsConfiguration in Google Analytics 8.2
Same name and namespace in other branches
- 8.3 tests/src/Functional/GoogleAnalyticsBasicTest.php \Drupal\Tests\google_analytics\Functional\GoogleAnalyticsBasicTest::testGoogleAnalyticsConfiguration()
- 4.x tests/src/Functional/GoogleAnalyticsBasicTest.php \Drupal\Tests\google_analytics\Functional\GoogleAnalyticsBasicTest::testGoogleAnalyticsConfiguration()
Tests if configuration is possible.
File
- tests/
src/ Functional/ GoogleAnalyticsBasicTest.php, line 65
Class
- GoogleAnalyticsBasicTest
- Test basic functionality of Google Analytics module.
Namespace
Drupal\Tests\google_analytics\FunctionalCode
public function testGoogleAnalyticsConfiguration() {
// Check if Configure link is available on 'Extend' page.
// Requires 'administer modules' permission.
$this
->drupalGet('admin/modules');
$this
->assertSession()
->responseContains('admin/config/system/google-analytics');
// 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
->assertSession()
->responseContains('admin/config/system/google-analytics');
// Check for setting page's presence.
$this
->drupalGet('admin/config/system/google-analytics');
$this
->assertSession()
->responseContains(t('Web Property ID'));
// Check for account code validation.
$edit['google_analytics_account'] = $this
->randomMachineName(2);
$this
->drupalPostForm('admin/config/system/google-analytics', $edit, t('Save configuration'));
$this
->assertSession()
->responseContains(t('A valid Google Analytics Web Property ID is case sensitive and formatted like UA-xxxxxxx-yy.'));
// User should have access to code snippets.
$this
->assertFieldByName('google_analytics_codesnippet_create');
$this
->assertFieldByName('google_analytics_codesnippet_before');
$this
->assertFieldByName('google_analytics_codesnippet_after');
$this
->assertNoFieldByXPath("//textarea[@name='google_analytics_codesnippet_create' and @disabled='disabled']", NULL, '"Create only fields" is enabled.');
$this
->assertNoFieldByXPath("//textarea[@name='google_analytics_codesnippet_before' and @disabled='disabled']", NULL, '"Code snippet (before)" is enabled.');
$this
->assertNoFieldByXPath("//textarea[@name='google_analytics_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/google-analytics');
// User should *not* have access to snippets, but create fields.
$this
->assertFieldByName('google_analytics_codesnippet_create');
$this
->assertFieldByName('google_analytics_codesnippet_before');
$this
->assertFieldByName('google_analytics_codesnippet_after');
$this
->assertNoFieldByXPath("//textarea[@name='google_analytics_codesnippet_create' and @disabled='disabled']", NULL, '"Create only fields" is enabled.');
$this
->assertFieldByXPath("//textarea[@name='google_analytics_codesnippet_before' and @disabled='disabled']", NULL, '"Code snippet (before)" is disabled.');
$this
->assertFieldByXPath("//textarea[@name='google_analytics_codesnippet_after' and @disabled='disabled']", NULL, '"Code snippet (after)" is disabled.');
}