| 1 |
<?php |
| 2 |
|
| 3 |
require __DIR__ . '/../Support/isolated-options.php'; |
| 4 |
|
| 5 |
sa_with_isolated_options(static function () { |
| 6 |
$plugin = SimpleAnalytics\PLUGIN_BASENAME; |
| 7 |
$values = [ |
| 8 |
SimpleAnalytics\SettingName::CUSTOM_DOMAIN => 'stats.example.test', |
| 9 |
SimpleAnalytics\SettingName::EXCLUDED_IP_ADDRESSES => ['203.0.113.10'], |
| 10 |
SimpleAnalytics\SettingName::EXCLUDED_ROLES => ['administrator'], |
| 11 |
SimpleAnalytics\SettingName::MANUAL_COLLECT => '1', |
| 12 |
]; |
| 13 |
foreach ($values as $key => $value) update_option($key, $value); |
| 14 |
|
| 15 |
deactivate_plugins($plugin, false, false); |
| 16 |
sa_assert(! is_plugin_active($plugin), 'The plugin must be deactivated for this test.'); |
| 17 |
foreach ($values as $key => $value) { |
| 18 |
sa_assert(get_option($key) === $value, 'Deactivation deleted ' . $key); |
| 19 |
} |
| 20 |
|
| 21 |
// The plugin is already loaded in this process; fire WordPress's activation |
| 22 |
// hook directly to verify that activation retains the existing options. |
| 23 |
do_action('activate_' . $plugin, false); |
| 24 |
foreach ($values as $key => $value) { |
| 25 |
sa_assert(get_option($key) === $value, 'Reactivation changed ' . $key); |
| 26 |
} |
| 27 |
|
| 28 |
update_option('sa_unrelated_test_option', 'keep'); |
| 29 |
uninstall_plugin($plugin); |
| 30 |
foreach (SimpleAnalytics\SettingName::cases() as $key) { |
| 31 |
sa_assert(get_option($key, 'missing') === 'missing', 'Uninstall did not remove ' . $key); |
| 32 |
} |
| 33 |
sa_assert(get_option('sa_unrelated_test_option') === 'keep', 'Uninstall must retain unrelated options.'); |
| 34 |
}); |
| 35 |
|