# Plugin Lifecycle Test Cases

## Purpose
Verify activation, deactivation, and removal semantics, including table cleanup behavior controlled from Setup (`uninstall_cleanup_mode`).

## Preconditions
- Run on a disposable/staging WordPress environment.
- Plugin package installed but tests may deactivate/remove plugin.
- Record current value of `calendar_plugin_uninstall_cleanup_mode`.

## LIF-001 First-Time Activation
- Steps:
  1. Ensure plugin is not active.
  2. Activate plugin.
  3. Open Setup page once.
- Assertions:
  - Activation succeeds without fatal errors.
  - Required plugin tables exist (`*_events`, `*_recurrence_exceptions`, `*_users`, `*_user_tokens`, `*_audit_log`).
  - Default setup values exist, including `uninstall_cleanup_mode=keep`.

## LIF-002 Deactivation (No Data Loss)
- Steps:
  1. Seed at least one event and one user.
  2. Deactivate plugin.
  3. Re-activate plugin.
- Assertions:
  - Deactivation does not drop plugin tables.
  - Seeded data remains available after re-activation.

## LIF-003 Removal With Keep Mode
- Steps:
  1. Set Setup -> Uninstall Cleanup = `keep`.
  2. Remove/delete plugin from WordPress.
  3. Re-install and activate plugin.
- Assertions:
  - Plugin-owned tables are preserved.
  - Existing plugin data remains.

## LIF-004 Removal With Remove Mode
- Steps:
  1. Set Setup -> Uninstall Cleanup = `remove`.
  2. Remove/delete plugin from WordPress.
  3. Inspect database.
- Assertions:
  - Plugin-owned tables are dropped.
  - Plugin-owned options are removed.
  - No non-plugin tables are affected.

## LIF-005 Idempotence/Safety
- Steps:
  1. Run remove flow twice in `remove` mode.
- Assertions:
  - No fatal errors on repeated cleanup.
  - Cleanup remains scoped to plugin-owned objects only.
