public function GoogleAnalyticsUninstallTest::testGoogleAnalyticsUninstall in Google Analytics 8.2
Same name and namespace in other branches
- 8.3 tests/src/Functional/GoogleAnalyticsUninstallTest.php \Drupal\Tests\google_analytics\Functional\GoogleAnalyticsUninstallTest::testGoogleAnalyticsUninstall()
- 4.x tests/src/Functional/GoogleAnalyticsUninstallTest.php \Drupal\Tests\google_analytics\Functional\GoogleAnalyticsUninstallTest::testGoogleAnalyticsUninstall()
Tests if the module cleans up the disk on uninstall.
File
- tests/
src/ Functional/ GoogleAnalyticsUninstallTest.php, line 46
Class
- GoogleAnalyticsUninstallTest
- Test uninstall functionality of Google Analytics module.
Namespace
Drupal\Tests\google_analytics\FunctionalCode
public function testGoogleAnalyticsUninstall() {
$cache_path = 'public://google_analytics';
$ua_code = 'UA-123456-1';
// Show tracker in pages.
$this
->config('google_analytics.settings')
->set('account', $ua_code)
->save();
// Enable local caching of analytics.js.
$this
->config('google_analytics.settings')
->set('cache', 1)
->save();
// Load page to get the analytics.js downloaded into local cache.
$this
->drupalGet('');
// Test if the directory and analytics.js exists.
$this
->assertDirectoryExists($cache_path, 'Cache directory "public://google_analytics" has been found.');
$this
->assertFileExists($cache_path . '/analytics.js', 'Cached analytics.js tracking file has been found.');
$this
->assertFileExists($cache_path . '/analytics.js.gz', 'Cached analytics.js.gz tracking file has been found.');
// Uninstall the module.
$edit = [];
$edit['uninstall[google_analytics]'] = TRUE;
$this
->drupalPostForm('admin/modules/uninstall', $edit, t('Uninstall'));
$this
->assertSession()
->pageTextNotContains(\Drupal::translation()
->translate('Configuration deletions'));
$this
->drupalPostForm(NULL, NULL, t('Uninstall'));
$this
->assertSession()
->pageTextContains(t('The selected modules have been uninstalled.'));
// Test if the directory and all files have been removed.
$this
->assertDirectoryNotExists($cache_path);
}