public function MatomoBasicTest::testMatomoConfiguration in Matomo Analytics 8
Tests if configuration is possible.
File
- tests/
src/ Functional/ MatomoBasicTest.php, line 57
Class
- MatomoBasicTest
- Test basic functionality of Matomo module.
Namespace
Drupal\Tests\matomo\FunctionalCode
public function testMatomoConfiguration() {
// Check for setting page's presence.
$this
->drupalGet('admin/config/system/matomo');
$this
->assertRaw('Matomo site ID', '[testMatomoConfiguration]: Settings page displayed.');
// Check for account code validation.
$edit['matomo_site_id'] = $this
->randomMachineName(2);
$edit['matomo_url_http'] = 'http://www.example.com/matomo/';
$this
->drupalPostForm('admin/config/system/matomo', $edit, 'Save configuration');
$this
->assertRaw('A valid Matomo site ID is an integer only.', '[testMatomoConfiguration]: Invalid Matomo site ID number validated.');
// Verify that invalid URLs throw a form error.
$edit = [];
$edit['matomo_site_id'] = 1;
$edit['matomo_url_http'] = 'http://www.example.com/matomo/';
$edit['matomo_url_https'] = 'https://www.example.com/matomo/';
$this
->drupalPostForm('admin/config/system/matomo', $edit, 'Save configuration');
$this
->assertRaw('The validation of "http://www.example.com/matomo/matomo.php" failed with an exception', '[testMatomoConfiguration]: HTTP URL exception shown.');
$this
->assertRaw('The validation of "https://www.example.com/matomo/matomo.php" failed with an exception', '[testMatomoConfiguration]: HTTPS URL exception shown.');
// 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.');
}