public function GoogleAnalyticsCustomDimensionsAndMetricsTest::testGoogleAnalyticsCustomDimensionsTokenFormValidation in Google Analytics 4.x
Same name and namespace in other branches
- 8.3 tests/src/Functional/GoogleAnalyticsCustomDimensionsAndMetricsTest.php \Drupal\Tests\google_analytics\Functional\GoogleAnalyticsCustomDimensionsAndMetricsTest::testGoogleAnalyticsCustomDimensionsTokenFormValidation()
- 8.2 tests/src/Functional/GoogleAnalyticsCustomDimensionsAndMetricsTest.php \Drupal\Tests\google_analytics\Functional\GoogleAnalyticsCustomDimensionsAndMetricsTest::testGoogleAnalyticsCustomDimensionsTokenFormValidation()
Tests if Custom Dimensions token form validation works.
File
- tests/
src/ Functional/ GoogleAnalyticsCustomDimensionsAndMetricsTest.php, line 276
Class
- GoogleAnalyticsCustomDimensionsAndMetricsTest
- Test custom dimensions and metrics functionality of Google Analytics module.
Namespace
Drupal\Tests\google_analytics\FunctionalCode
public function testGoogleAnalyticsCustomDimensionsTokenFormValidation() {
$ua_code = 'UA-123456-1';
// Check form validation.
$edit['google_analytics_account'] = $ua_code;
$edit['google_analytics_custom_dimension[indexes][1][name]'] = 'current_user_name';
$edit['google_analytics_custom_dimension[indexes][1][value]'] = '[current-user:name]';
$edit['google_analytics_custom_dimension[indexes][2][name]'] = 'current_user_edit_url';
$edit['google_analytics_custom_dimension[indexes][2][value]'] = '[current-user:edit-url]';
$edit['google_analytics_custom_dimension[indexes][3][name]'] = 'user_name';
$edit['google_analytics_custom_dimension[indexes][3][value]'] = '[user:name]';
$edit['google_analytics_custom_dimension[indexes][4][name]'] = 'term_name';
$edit['google_analytics_custom_dimension[indexes][4][value]'] = '[term:name]';
$edit['google_analytics_custom_dimension[indexes][5][name]'] = 'term_tid';
$edit['google_analytics_custom_dimension[indexes][5][value]'] = '[term:tid]';
$this
->drupalPostForm('admin/config/services/google-analytics', $edit, $this
->t('Save configuration'));
$this
->assertRaw($this
->t('The %element-title is using the following forbidden tokens with personal identifying information: @invalid-tokens.', [
'%element-title' => $this
->t('Custom dimension value #@index', [
'@index' => 1,
]),
'@invalid-tokens' => implode(', ', [
'[current-user:name]',
]),
]));
$this
->assertRaw($this
->t('The %element-title is using the following forbidden tokens with personal identifying information: @invalid-tokens.', [
'%element-title' => $this
->t('Custom dimension value #@index', [
'@index' => 2,
]),
'@invalid-tokens' => implode(', ', [
'[current-user:edit-url]',
]),
]));
$this
->assertRaw($this
->t('The %element-title is using the following forbidden tokens with personal identifying information: @invalid-tokens.', [
'%element-title' => $this
->t('Custom dimension value #@index', [
'@index' => 3,
]),
'@invalid-tokens' => implode(', ', [
'[user:name]',
]),
]));
// BUG #2037595
//$this->assertNoRaw($this->t('The %element-title is using the following forbidden tokens with personal identifying information: @invalid-tokens.', ['%element-title' => t('Custom dimension value #@index', ['@index' => 4]), '@invalid-tokens' => implode(', ', ['[term:name]'])]));
//$this->assertNoRaw($this->t('The %element-title is using the following forbidden tokens with personal identifying information: @invalid-tokens.', ['%element-title' => t('Custom dimension value #@index', ['@index' => 5]), '@invalid-tokens' => implode(', ', ['[term:tid]'])]));
}