From 33963a467a5f5e52cdc4ce97ae2e62b5ce7fba28 Mon Sep 17 00:00:00 2001 From: diosmosis Date: Wed, 27 Nov 2024 06:31:16 -0800 Subject: [PATCH] improve test again and remove some unneeded code --- app/bootstrap.php | 2 -- tests/e2e-uninstall/uninstall.e2e.ts | 23 ++++++++++++++++------- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/app/bootstrap.php b/app/bootstrap.php index f6cec6df9..d6461db07 100644 --- a/app/bootstrap.php +++ b/app/bootstrap.php @@ -160,8 +160,6 @@ function matomo_log_message_no_display($message) if ( !is_plugin_active('matomo/matomo.php') // during tests the plugin may temporarily not be active && (!defined( 'MATOMO_PHPUNIT_TEST' ) || !MATOMO_PHPUNIT_TEST) - // when uninstalling the plugin may not be active - && empty( $GLOBALS['MATOMO_UNINSTALLING'] ) ) { exit; } diff --git a/tests/e2e-uninstall/uninstall.e2e.ts b/tests/e2e-uninstall/uninstall.e2e.ts index c1801e2bf..bb6be2357 100644 --- a/tests/e2e-uninstall/uninstall.e2e.ts +++ b/tests/e2e-uninstall/uninstall.e2e.ts @@ -15,7 +15,22 @@ describe('MWP Uninstall', () => { await Website.login(); }); + async function getTablesInstalled(): Promise { + let result: any = await fetch(`${await Website.rootUrl()}/matomo-for-wordpress/tests/e2e-uninstall/get-matomo-tables.php`); + result = await result.text(); + try { + result = JSON.parse(result); + } catch (e) { + throw new Error(`Failed to parse get-matomo-tables.php response: ${result}`); + } + return result; + } + it('should uninstall and remove all data when the "remove all data" option is enabled', async () => { + let tablesBeforeUninstall = await getTablesInstalled(); + tablesBeforeUninstall = tablesBeforeUninstall.filter((t: string) => t.includes('matomo')); + expect(tablesBeforeUninstall.length).toBeGreaterThan(0); // before uninstalling, check there are tables with "matomo" in the name + await browser.url(`${await Website.baseUrl()}/wp-admin/plugins.php`); await $('#deactivate-matomo').waitForExist({ timeout: 60000 }); @@ -46,13 +61,7 @@ describe('MWP Uninstall', () => { } // check that no matomo table exists in the database - let result: any = await fetch(`${await Website.rootUrl()}/matomo-for-wordpress/tests/e2e-uninstall/get-matomo-tables.php`); - result = await result.text(); - try { - result = JSON.parse(result); - } catch (e) { - throw new Error(`Failed to parse get-matomo-tables.php response: ${result}`); - } + let result = await getTablesInstalled(); expect(result.length).toBeGreaterThan(0); // sanity check