You are here

public function MatomoUserFieldsTest::testMatomoUserFields in Matomo Analytics 8

Tests if "allow users to customize tracking on their account page" works.

File

tests/src/Functional/MatomoUserFieldsTest.php, line 48

Class

MatomoUserFieldsTest
Test user fields functionality of Matomo module.

Namespace

Drupal\Tests\matomo\Functional

Code

public function testMatomoUserFields() {
  $site_id = '1';
  $this
    ->config('matomo.settings')
    ->set('site_id', $site_id)
    ->save();
  $this
    ->config('matomo.settings')
    ->set('url_http', 'http://www.example.com/matomo/')
    ->save();
  $this
    ->config('matomo.settings')
    ->set('url_https', 'https://www.example.com/matomo/')
    ->save();

  // Check if the pseudo field is shown on account forms.
  $this
    ->drupalGet('admin/config/people/accounts/form-display');
  $this
    ->assertResponse(200);
  $this
    ->assertRaw('Matomo settings', '[testMatomoUserFields]: Matomo settings field exists on Manage form display.');

  // No customization allowed.
  $this
    ->config('matomo.settings')
    ->set('visibility.user_account_mode', 0)
    ->save();
  $this
    ->drupalGet('user/' . $this->admin_user
    ->id() . '/edit');
  $this
    ->assertResponse(200);
  $this
    ->assertNoRaw('Matomo settings', '[testMatomoUserFields]: Matomo settings field does not exist on user edit page.');

  // Tracking on by default, users with opt-in or out of matomo tracking
  // permission can opt out.
  $this
    ->config('matomo.settings')
    ->set('visibility.user_account_mode', 1)
    ->save();
  $this
    ->drupalGet('user/' . $this->admin_user
    ->id() . '/edit');
  $this
    ->assertResponse(200);
  $this
    ->assertRaw('Users are tracked by default, but you are able to opt out.', '[testMatomoUserFields]: Matomo settings field exists on on user edit page');

  // Tracking off by default, users with opt-in or out of matomo tracking
  // permission can opt in.
  $this
    ->config('matomo.settings')
    ->set('visibility.user_account_mode', 2)
    ->save();
  $this
    ->drupalGet('user/' . $this->admin_user
    ->id() . '/edit');
  $this
    ->assertResponse(200);
  $this
    ->assertRaw('Users are <em>not</em> tracked by default, but you are able to opt in.', '[testMatomoUserFields]: Matomo settings field exists on on user edit page.');
}