1# Delete Page Guard - Developer Test Suite 2 3This directory contains a standalone test suite for developers to verify the Delete Page Guard plugin's core functionality without requiring a full DokuWiki installation. 4 5## Running Tests 6 7```bash 8# From the plugin root directory 9php tests/test_runner.php 10``` 11 12## Requirements 13 14- PHP 7.4+ (same as the plugin) 15- No external dependencies 16 17## Test Coverage 18 19The test suite covers: 20 21### ✅ Pattern Validation 22- Valid regex syntax validation 23- ReDoS (Regular Expression Denial of Service) protection 24- Pattern length limits (1000 character max) 25- Line number reporting for errors 26 27### ✅ Pattern Matching 28- Simple and complex regex patterns 29- Exact matches and partial matches 30- Case sensitivity 31- Unicode character support 32 33### ✅ File Path Conversion 34- Converting absolute paths to relative paths 35- Windows and Unix path handling 36- Nested directory structures 37- Edge cases with non-standard paths 38 39### ✅ Configuration Parsing 40- Multi-line pattern configuration 41- Empty line handling 42- Different line ending formats (Unix/Windows) 43- Whitespace trimming 44 45### ✅ Security Features 46- Forward slash escaping in patterns 47- Unicode support and safety 48- Special regex character handling 49- Injection attempt protection 50 51### ✅ Edge Cases 52- Empty patterns and targets 53- Very long input strings 54- Whitespace-only content 55- Malformed input handling 56 57### ✅ Real-world Scenarios 58- User page protection patterns 59- Namespace-based protection 60- File extension matching 61- Complex multi-part patterns 62 63## Test Structure 64 65- **`test_runner.php`** - Main test framework and all test cases 66- **`plugin_test_adapter.php`** - Makes plugin methods testable by mocking DokuWiki dependencies 67- **`README.md`** - This documentation 68 69## Adding New Tests 70 71To add a new test, edit `test_runner.php` and add: 72 73```php 74$runner->addTest('Test Description', function() { 75 $plugin = new TestableDeletePageGuard(); 76 // Your test logic here 77 $result = $plugin->someMethod($input); 78 return $result === $expected; // Return true for pass, false/string for fail 79}); 80``` 81 82## Test Output 83 84- ✅ **PASS** - Test succeeded 85- ❌ **FAIL** - Test failed with optional error message 86- ❌ **ERROR** - Test threw an exception 87 88The runner exits with code 0 on success, 1 on failure (suitable for CI/CD). 89 90## Mocked Dependencies 91 92The test adapter mocks these DokuWiki components: 93 94- `dokuwiki\Extension\ActionPlugin` - Base plugin class 95- `dokuwiki\Extension\Event` - Event system 96- `dokuwiki\Extension\EventHandler` - Event registration 97- Plugin configuration (`getConf()`) 98- Language strings (`getLang()`) 99 100## Example Usage 101 102```bash 103# Run tests and see detailed output 104php tests/test_runner.php 105 106# Check if tests pass (for scripts) 107php tests/test_runner.php && echo "All tests passed!" 108 109# Run tests and capture output 110php tests/test_runner.php > test_results.txt 2>&1 111``` 112 113## Integration with Development Workflow 114 115This test suite is designed for: 116 117- **Pre-commit testing** - Verify changes before committing 118- **Continuous Integration** - Automated testing in CI/CD pipelines 119- **Regression testing** - Ensure new features don't break existing functionality 120- **Development confidence** - Rapid feedback during development 121 122## Performance 123 124The test suite typically runs in under 1 second and includes 30+ test cases covering all critical functionality.