# Comprehensive Software Testing Plan (QA Strategy)
## Kampong Speu Provincial Demographic Management System (KSP-DMS)

**Document Code:** KSP-DMS-DOC-TEST-01  
**Standard:** ISO/IEC/IEEE 29119 Software Testing Standard  
**Version:** 1.0 (Draft Proposal)  

---

## 1. Testing Strategy and Objectives

The primary objective of the KSP-DMS quality assurance program is to verify that the application satisfies all functional requirements, enforces strict geographic and role-based security boundaries, guarantees data integrity during vital event mutations, and delivers high-performance responsiveness on local hardware.

```
       [Unit Tests]            --> Service domain logic, calculations, anomaly algorithms
            +
     [Feature Tests]           --> HTTP controllers, form requests, validation rules
            +
     [Security Tests]          --> Geographic isolation, IDOR, CSRF, SQLi immunity
            +
    [Integration Tests]        --> Full multi-tier submission & approval workflows
            +
   [Bilingual UI Tests]        --> Khmer font rendering, UTF8mb4 character preservation
```

---

## 2. Test Suites and Automated Execution Scope

### 2.1 Authentication & Role Permissions
- Test `UserAuthenticationTest`: Valid login, invalid credentials, rate-limiting lockout after 5 failures.
- Test `RoleAuthorizationTest`: Verifies that only Super Admin can manage users; collectors cannot access review dashboards.

### 2.2 Geographic Isolation (Critical Security Suite)
- Test `GeographicScopeTest`:
  - Scenario A (Positive): Commune Reviewer queries households within their assigned commune -> Expect HTTP 200 and correct records.
  - Scenario B (Negative / IDOR): Commune Reviewer modifies URL to target another commune's ID -> Expect HTTP 403 Forbidden and audit log intrusion flag.
  - Scenario C: District Reviewer queries records across all communes within their district -> Expect HTTP 200.

### 2.3 Household & Person Lifecycle (CRUD)
- Test `HouseholdManagementTest`: Unique code generation, single Head of Household validation, soft deletion.
- Test `PersonManagementTest`: Khmer Unicode name persistence, age validation, relational binding to household.

### 2.4 Vital Events & Submission Workflow
- Test `BirthEventTest`: Child registration, parental linkage, automatic draft addition.
- Test `DeathEventTest`: Death registration, approval transitions person to `deceased`, closes household membership.
- Test `SubmissionWorkflowTest`: `draft` -> `submitted` -> `verified` -> `approved` state transitions; verification that unapproved changes do not pollute the active population baseline.

### 2.5 Data Quality Engine
- Test `DataQualityEngineTest`: Verification that anomalous records (e.g. parent younger than child, multiple active heads) trigger automated warning flags in `data_quality_issues`.

### 2.6 REST API v1 Suite
- Test `ApiSanctumAuthTest`: Bearer token issuance, revocation, and protected route access.
- Test `ApiHouseholdSyncTest`: Idempotent batch synchronization using `mutation_id`.

---

## 3. Test Execution Reporting Template

Every executed automated test must be recorded in the test log using the standardized structure:

| Test Identifier | Category | Expected Outcome | Actual Result | Status | Corrective Action |
| :--- | :--- | :--- | :--- | :---: | :--- |
| `TC-AUTH-01` | Authentication | Rejection of bad credentials | HTTP 422 returned | `PASS` | None required |
| `TC-GEO-02` | Security / Scope | 403 Forbidden on foreign commune | HTTP 403 returned | `PASS` | None required |
| `TC-EVT-03` | Vital Events | Death marks person deceased | Person status = deceased | `PASS` | None required |
