MatomoUserFieldsTest.php in Matomo Analytics 8
File
tests/src/Functional/MatomoUserFieldsTest.php
View source
<?php
namespace Drupal\Tests\matomo\Functional;
use Drupal\Tests\BrowserTestBase;
class MatomoUserFieldsTest extends BrowserTestBase {
public static $modules = [
'matomo',
'field_ui',
];
protected $defaultTheme = 'stark';
protected function setUp() {
parent::setUp();
$permissions = [
'access administration pages',
'administer user form display',
'opt-in or out of matomo tracking',
];
$this->admin_user = $this
->drupalCreateUser($permissions);
$this
->drupalLogin($this->admin_user);
}
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();
$this
->drupalGet('admin/config/people/accounts/form-display');
$this
->assertResponse(200);
$this
->assertRaw('Matomo settings', '[testMatomoUserFields]: Matomo settings field exists on Manage form display.');
$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.');
$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');
$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.');
}
}