Skip to content

Commit 97276af

Browse files
committed
Fix test isolation by ensuring plugin is activated before configuring settings
The `test_adds_script_with_ignored_pages` test assumed the plugin was already active from a previous test, but PHPUnit tests run in isolation and execution order isn't guaranteed. - Add `activatePluginIfNeeded()` helper to BrowserTestCase that conditionally activates the plugin only if not already active - Update `test_adds_script_with_ignored_pages` to use the helper This ensures the test works regardless of execution order or whether the plugin is already activated.
1 parent f9d12c6 commit 97276af

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

tests/Browser/BrowserTestCase.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,4 +45,17 @@ protected function asEditor()
4545
{
4646
return $this->asUser('editor', 'editor');
4747
}
48+
49+
protected function activatePluginIfNeeded(PantherBrowser $browser): PantherBrowser
50+
{
51+
$browser->visit('/wp-admin/plugins.php');
52+
53+
$activateButton = $browser->crawler()->filter('#activate-simpleanalytics');
54+
55+
if ($activateButton->count() > 0) {
56+
$browser->click('#activate-simpleanalytics');
57+
}
58+
59+
return $browser;
60+
}
4861
}

tests/Browser/PluginSettingsTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@ public function test_activation_and_presence_of_default_scripts(): void
2020

2121
public function test_adds_script_with_ignored_pages(): void
2222
{
23-
$this->asAdmin()
24-
->visit('/wp-admin/plugins.php')
25-
->click('#activate-simpleanalytics')
26-
->visit('/wp-admin/options-general.php?page=simpleanalytics&tab=ignore-rules')
23+
$browser = $this->asAdmin();
24+
$this->activatePluginIfNeeded($browser);
25+
26+
$browser->visit('/wp-admin/options-general.php?page=simpleanalytics&tab=ignore-rules')
2727
->fillField('simpleanalytics_ignore_pages', '/vouchers')
2828
->click('Save Changes')
2929
->visit('/wp-admin/options-general.php?page=simpleanalytics&tab=ignore-rules')

0 commit comments

Comments
 (0)