Commit dad76002 authored by Jakob P's avatar Jakob P
Browse files

Issue #3287763 by japerry: Provide basic Drupal 10 compatibility.

parent 11e1e577
Loading
Loading
Loading
Loading
+0 −3
Changes for composer.json: 0 added lines, 3 removed lines.
Original line number Diff line number Diff line
@@ -14,9 +14,6 @@
    "source": "https://git.drupal.org/project/google_analytics.git"
  },
  "license": "GPL-2.0-or-later",
  "require": {
    "drupal/core": "^8.8.6|^9.0"
  },
  "require-dev": {
    "drupal/token": "^1.7"
  },
+1 −1
Changes for google_analytics.info.yml: 1 added line, 1 removed line.
Original line number Diff line number Diff line
@@ -2,5 +2,5 @@ name: 'Google Analytics'
type: module
description: 'Allows your site to be tracked by Google Analytics by adding a Javascript tracking code to every page.'
package: Statistics
core_version_requirement: ^8.8.6 || ^9
core_version_requirement: '>=8.9 < 11'
configure: google_analytics.admin_settings_form
+6 −2
Changes for google_analytics.module: 6 added lines, 2 removed lines.
Original line number Diff line number Diff line
@@ -532,7 +532,9 @@ function _google_analytics_cache($location, $synchronize = FALSE) {
          \Drupal::logger('google_analytics')->info('Locally cached tracking code file has been saved.');

          // Return the local JS file path.
          return file_url_transform_relative(file_create_url($file_destination));
          // @todo: Remove conditional after dropping support lower than 9.3.
          // @phpstan-ignore-next-line
          return method_exists('\Drupal\Core\File\FileUrlGenerator', 'generateString') ? \Drupal::service('file_url_generator')->generateString($file_destination) : file_url_transform_relative(file_create_url($file_destination));
        }
      }
    }
@@ -542,7 +544,9 @@ function _google_analytics_cache($location, $synchronize = FALSE) {
  }
  else {
    // Return the local JS file path.
    return file_url_transform_relative(file_create_url($file_destination));
    // @todo: Remove conditional after dropping support lower than 9.3.
    // @phpstan-ignore-next-line
    return method_exists('\Drupal\Core\File\FileUrlGenerator', 'generateString') ? \Drupal::service('file_url_generator')->generateString($file_destination) : file_url_transform_relative(file_create_url($file_destination));
  }
}

+17 −10
Changes for tests/src/Functional/GoogleAnalyticsBasicTest.php: 17 added lines, 10 removed lines.
Original line number Diff line number Diff line
@@ -39,7 +39,7 @@ class GoogleAnalyticsBasicTest extends BrowserTestBase {
  /**
   * {@inheritdoc}
   */
  protected function setUp() {
  protected function setUp(): void {
    parent::setUp();

    $permissions = [
@@ -80,13 +80,14 @@ class GoogleAnalyticsBasicTest extends BrowserTestBase {

    // Check for account code validation.
    $edit['google_analytics_account'] = $this->randomMachineName(2);
    $this->drupalPostForm('admin/config/system/google-analytics', $edit, t('Save configuration'));
    $this->drupalGet('admin/config/system/google-analytics');
    $this->submitForm($edit, t('Save configuration'));
    $this->assertSession()->responseContains(t('A valid Google Analytics Web Property ID is case sensitive and formatted like UA-xxxxxxx-yy.'));

    // User should have access to code snippets.
    $this->assertFieldByName('google_analytics_codesnippet_create');
    $this->assertFieldByName('google_analytics_codesnippet_before');
    $this->assertFieldByName('google_analytics_codesnippet_after');
    $this->assertSession()->fieldExists('google_analytics_codesnippet_create');
    $this->assertSession()->fieldExists('google_analytics_codesnippet_before');
    $this->assertSession()->fieldExists('google_analytics_codesnippet_after');
    $this->assertNoFieldByXPath("//textarea[@name='google_analytics_codesnippet_create' and @disabled='disabled']", NULL, '"Create only fields" is enabled.');
    $this->assertNoFieldByXPath("//textarea[@name='google_analytics_codesnippet_before' and @disabled='disabled']", NULL, '"Code snippet (before)" is enabled.');
    $this->assertNoFieldByXPath("//textarea[@name='google_analytics_codesnippet_after' and @disabled='disabled']", NULL, '"Code snippet (after)" is enabled.');
@@ -96,9 +97,9 @@ class GoogleAnalyticsBasicTest extends BrowserTestBase {
    $this->drupalGet('admin/config/system/google-analytics');

    // User should *not* have access to snippets, but create fields.
    $this->assertFieldByName('google_analytics_codesnippet_create');
    $this->assertFieldByName('google_analytics_codesnippet_before');
    $this->assertFieldByName('google_analytics_codesnippet_after');
    $this->assertSession()->fieldExists('google_analytics_codesnippet_create');
    $this->assertSession()->fieldExists('google_analytics_codesnippet_before');
    $this->assertSession()->fieldExists('google_analytics_codesnippet_after');
    $this->assertNoFieldByXPath("//textarea[@name='google_analytics_codesnippet_create' and @disabled='disabled']", NULL, '"Create only fields" is enabled.');
    $this->assertFieldByXPath("//textarea[@name='google_analytics_codesnippet_before' and @disabled='disabled']", NULL, '"Code snippet (before)" is disabled.');
    $this->assertFieldByXPath("//textarea[@name='google_analytics_codesnippet_after' and @disabled='disabled']", NULL, '"Code snippet (after)" is disabled.');
@@ -110,11 +111,17 @@ class GoogleAnalyticsBasicTest extends BrowserTestBase {
  public function testGoogleAnalyticsHelp() {
    // Requires help and block module and help block placement.
    $this->drupalGet('admin/config/system/google-analytics');
    $this->assertText('Google Analytics is a free (registration required) website traffic and marketing effectiveness service.');
    // TODO: Drupal Rector Notice: Please delete the following comment after you've made any necessary changes.
    // Verify the assertion: pageTextContains() for HTML responses, responseContains() for non-HTML responses.
    // The passed text should be HTML decoded, exactly as a human sees it in the browser.
    $this->assertSession()->pageTextContains('Google Analytics is a free (registration required) website traffic and marketing effectiveness service.');

    // Requires help.module.
    $this->drupalGet('admin/help/google_analytics');
    $this->assertText('Google Analytics adds a web statistics tracking system to your website.');
    // TODO: Drupal Rector Notice: Please delete the following comment after you've made any necessary changes.
    // Verify the assertion: pageTextContains() for HTML responses, responseContains() for non-HTML responses.
    // The passed text should be HTML decoded, exactly as a human sees it in the browser.
    $this->assertSession()->pageTextContains('Google Analytics adds a web statistics tracking system to your website.');
  }

  /**
+7 −3
Changes for tests/src/Functional/GoogleAnalyticsCustomDimensionsAndMetricsTest.php: 7 added lines, 3 removed lines.
Original line number Diff line number Diff line
@@ -29,7 +29,7 @@ class GoogleAnalyticsCustomDimensionsAndMetricsTest extends BrowserTestBase {
  /**
   * {@inheritdoc}
   */
  protected function setUp() {
  protected function setUp(): void {
    parent::setUp();

    $permissions = [
@@ -142,7 +142,10 @@ class GoogleAnalyticsCustomDimensionsAndMetricsTest extends BrowserTestBase {

    // Test on a node.
    $this->drupalGet('node/' . $node->id());
    $this->assertText($node->getTitle());
    // TODO: Drupal Rector Notice: Please delete the following comment after you've made any necessary changes.
    // Verify the assertion: pageTextContains() for HTML responses, responseContains() for non-HTML responses.
    // The passed text should be HTML decoded, exactly as a human sees it in the browser.
    $this->assertSession()->pageTextContains($node->getTitle());
    $this->assertSession()->responseContains('ga("set", ' . Json::encode('dimension5') . ', ' . Json::encode('article') . ');');
  }

@@ -228,8 +231,9 @@ class GoogleAnalyticsCustomDimensionsAndMetricsTest extends BrowserTestBase {
    $edit['google_analytics_custom_dimension[indexes][3][value]'] = '[user:name]';
    $edit['google_analytics_custom_dimension[indexes][4][value]'] = '[term:name]';
    $edit['google_analytics_custom_dimension[indexes][5][value]'] = '[term:tid]';
    $this->drupalGet('admin/config/system/google-analytics');

    $this->drupalPostForm('admin/config/system/google-analytics', $edit, t('Save configuration'));
    $this->submitForm($edit, t('Save configuration'));

    $this->assertSession()->responseContains(t('The %element-title is using the following forbidden tokens with personal identifying information: @invalid-tokens.', ['%element-title' => t('Custom dimension value #@index', ['@index' => 1]), '@invalid-tokens' => implode(', ', ['[current-user:name]'])]));
    $this->assertSession()->responseContains(t('The %element-title is using the following forbidden tokens with personal identifying information: @invalid-tokens.', ['%element-title' => t('Custom dimension value #@index', ['@index' => 2]), '@invalid-tokens' => implode(', ', ['[current-user:edit-url]'])]));
Loading