You are here

function MatomoBasicTest::testMatomoConfiguration in Matomo Analytics 7.2

File

./matomo.test, line 39
Test file for Matomo module.

Class

MatomoBasicTest
@file Test file for Matomo module.

Code

function testMatomoConfiguration() {

  // Check for setting page's presence.
  $this
    ->drupalGet('admin/config/system/matomo');
  $this
    ->assertRaw(t('Matomo site ID'), '[testMatomoConfiguration]: Settings page displayed.');

  // Check for account code validation.
  $edit['matomo_site_id'] = $this
    ->randomName(2);
  $this
    ->drupalPost('admin/config/system/matomo', $edit, 'Save configuration');
  $this
    ->assertRaw(t('A valid Matomo site ID is an integer only.'), '[testMatomoConfiguration]: Invalid Matomo site ID number validated.');

  // User should have access to code snippets.
  $this
    ->assertFieldByName('matomo_codesnippet_before');
  $this
    ->assertFieldByName('matomo_codesnippet_after');
  $this
    ->assertNoFieldByXPath("//textarea[@name='matomo_codesnippet_before' and @disabled='disabled']", NULL, '"Code snippet (before)" is enabled.');
  $this
    ->assertNoFieldByXPath("//textarea[@name='matomo_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/matomo');

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