Skip to content

Commit 19dc63f

Browse files
committed
Add migration CLI, test suite, and comment support
Features: - WP-CLI migration commands for posts/pages/comments - wp djot analyze/migrate/rollback - wp djot analyze-comments/migrate-comments/rollback-comments - Full test suite (42 tests, 119 assertions) - HTMLPurifier integration for extra XSS protection (optional) - Comment Djot processing with process_full_comments option Changes: - Add phpstan/phpcs to require-dev with PhpCollective standard - Add phpunit with WordPress function mocks - Fix mixed HTML/Markdown migration (process Markdown first) - CI uses composer scripts instead of runtime tool install
1 parent 6cb5b2a commit 19dc63f

File tree

13 files changed

+2176
-26
lines changed

13 files changed

+2176
-26
lines changed

.github/workflows/ci.yml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@ jobs:
1313
strategy:
1414
fail-fast: false
1515
matrix:
16-
php-version: ['8.2', '8.3', '8.4']
16+
php-version: ['8.2', '8.5']
1717

1818
steps:
19-
- uses: actions/checkout@v4
19+
- uses: actions/checkout@v6
2020

2121
- name: Setup PHP
2222
uses: shivammathur/setup-php@v2
@@ -38,35 +38,35 @@ jobs:
3838
runs-on: ubuntu-latest
3939

4040
steps:
41-
- uses: actions/checkout@v4
41+
- uses: actions/checkout@v6
4242

4343
- name: Setup PHP
4444
uses: shivammathur/setup-php@v2
4545
with:
4646
php-version: '8.2'
47-
tools: composer:v2, phpstan
47+
tools: composer:v2
4848

4949
- name: Install dependencies
5050
run: composer install --prefer-dist --no-progress
5151

5252
- name: Run PHPStan
53-
run: phpstan analyse --configuration=phpstan.neon || true
53+
run: composer stan
5454

5555
coding-standards:
5656
name: Coding Standards
5757
runs-on: ubuntu-latest
5858

5959
steps:
60-
- uses: actions/checkout@v4
60+
- uses: actions/checkout@v6
6161

6262
- name: Setup PHP
6363
uses: shivammathur/setup-php@v2
6464
with:
6565
php-version: '8.2'
66-
tools: composer:v2, phpcs
66+
tools: composer:v2
6767

6868
- name: Install dependencies
6969
run: composer install --prefer-dist --no-progress
7070

7171
- name: Check coding standards
72-
run: phpcs --standard=phpcs.xml || true
72+
run: composer cs-check

CONTRIBUTING.md

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
# Contributing to WP Djot
2+
3+
Contributions are welcome! Please feel free to submit a Pull Request.
4+
5+
## How to Contribute
6+
7+
1. Fork the repository
8+
2. Create your feature branch (`git checkout -b feature/amazing-feature`)
9+
3. Commit your changes (`git commit -m 'Add some amazing feature'`)
10+
4. Push to the branch (`git push origin feature/amazing-feature`)
11+
5. Open a Pull Request
12+
13+
## Development Setup
14+
15+
### Requirements
16+
17+
- PHP 8.2 or higher
18+
- Composer
19+
- WordPress 6.0+ (for testing)
20+
- WP-CLI (optional, for CLI command testing)
21+
22+
### Installation
23+
24+
```bash
25+
git clone https://github.com/php-collective/wp-djot.git
26+
cd wp-djot
27+
composer install
28+
```
29+
30+
### Running Tests
31+
32+
```bash
33+
composer test
34+
```
35+
36+
### Code Style
37+
38+
This project follows PSR-12 coding standards.
39+
40+
```bash
41+
# Check code style
42+
composer cs-check
43+
44+
# Fix code style automatically
45+
composer cs-fix
46+
```
47+
48+
### Static Analysis
49+
50+
```bash
51+
composer stan
52+
```
53+
54+
## Pull Request Guidelines
55+
56+
- Follow the existing code style
57+
- Add tests for new features
58+
- Update documentation as needed
59+
- Keep commits focused and atomic
60+
- Write clear commit messages
61+
62+
## Reporting Issues
63+
64+
- Use the GitHub issue tracker
65+
- Include WordPress and PHP version
66+
- Provide steps to reproduce the issue
67+
- Include any error messages
68+
69+
## License
70+
71+
By contributing, you agree that your contributions will be licensed under the MIT License.

composer.json

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,14 @@
1313
"php": ">=8.2",
1414
"php-collective/djot": "^0.1"
1515
},
16+
"require-dev": {
17+
"phpunit/phpunit": "^11.4 || ^12.3",
18+
"php-collective/code-sniffer": "dev-master",
19+
"phpstan/phpstan": "^2.0"
20+
},
21+
"suggest": {
22+
"ezyang/htmlpurifier": "For additional XSS protection on comments (^4.18)"
23+
},
1624
"autoload": {
1725
"psr-4": {
1826
"WpDjot\\": "src/"
@@ -21,8 +29,22 @@
2129
"src/functions.php"
2230
]
2331
},
32+
"autoload-dev": {
33+
"psr-4": {
34+
"WpDjot\\Test\\": "tests/"
35+
}
36+
},
2437
"config": {
38+
"allow-plugins": {
39+
"dealerdirect/phpcodesniffer-composer-installer": true
40+
},
2541
"optimize-autoloader": true,
2642
"sort-packages": true
43+
},
44+
"scripts": {
45+
"cs-check": "phpcs --colors --parallel=16",
46+
"cs-fix": "phpcbf --colors --parallel=16",
47+
"stan": "phpstan analyze",
48+
"test": "phpunit"
2749
}
2850
}

phpcs.xml

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,20 @@
11
<?xml version="1.0"?>
2-
<ruleset name="WP Djot Coding Standards">
3-
<description>PHP CodeSniffer configuration for WP Djot</description>
2+
<ruleset name="wp-djot">
3+
<arg value="nps"/>
44

5-
<!-- Scan these files -->
6-
<file>./src</file>
7-
<file>./wp-djot.php</file>
8-
<file>./uninstall.php</file>
5+
<file>src/</file>
96

10-
<!-- Exclude vendor directory -->
117
<exclude-pattern>*/vendor/*</exclude-pattern>
12-
<exclude-pattern>*/node_modules/*</exclude-pattern>
138

14-
<!-- Use PSR-12 as base -->
15-
<rule ref="PSR12"/>
9+
<rule ref="PhpCollective"/>
1610

17-
<!-- Additional rules -->
18-
<rule ref="Generic.Arrays.DisallowLongArraySyntax"/>
19-
<rule ref="Generic.PHP.RequireStrictTypes"/>
11+
<rule ref="SlevomatCodingStandard.Functions.RequireTrailingCommaInDeclaration"/>
12+
<rule ref="SlevomatCodingStandard.Functions.RequireTrailingCommaInClosureUse"/>
2013

21-
<!-- Allow WordPress functions -->
14+
<!-- WordPress plugin files have side effects by design -->
2215
<rule ref="PSR1.Files.SideEffects.FoundWithSymbols">
2316
<exclude-pattern>wp-djot.php</exclude-pattern>
17+
<exclude-pattern>uninstall.php</exclude-pattern>
2418
</rule>
19+
2520
</ruleset>

phpunit.xml.dist

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<phpunit
3+
bootstrap="tests/bootstrap.php"
4+
colors="true"
5+
stopOnFailure="false"
6+
cacheDirectory=".phpunit.cache"
7+
>
8+
<testsuites>
9+
<testsuite name="WP Djot Test Suite">
10+
<directory>tests/TestCase</directory>
11+
</testsuite>
12+
</testsuites>
13+
<source>
14+
<include>
15+
<directory suffix=".php">src</directory>
16+
</include>
17+
</source>
18+
</phpunit>

src/Admin/Settings.php

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,14 @@
99
*/
1010
class Settings
1111
{
12+
/**
13+
* @var string
14+
*/
1215
private const OPTION_GROUP = 'wp_djot_settings';
1316

17+
/**
18+
* @var string
19+
*/
1420
private const PAGE_SLUG = 'wp-djot-settings';
1521

1622
/**
@@ -41,6 +47,7 @@ public function addMenuPage(): void
4147
* Add settings link to plugin list.
4248
*
4349
* @param array<string> $links
50+
*
4451
* @return array<string>
4552
*/
4653
public function addSettingsLink(array $links): array
@@ -111,7 +118,16 @@ public function registerSettings(): void
111118
[$this, 'renderCheckboxField'],
112119
self::PAGE_SLUG,
113120
'wp_djot_content',
114-
['field' => 'process_full_content', 'description' => __('Process entire post/page content as Djot. When disabled, only [djot]...[/djot] blocks are processed.', 'wp-djot')],
121+
['field' => 'process_full_content', 'description' => __('Process entire post/page content as Djot. When disabled, only {djot}...{/djot} blocks are processed.', 'wp-djot')],
122+
);
123+
124+
add_settings_field(
125+
'process_full_comments',
126+
__('Process Full Comments', 'wp-djot'),
127+
[$this, 'renderCheckboxField'],
128+
self::PAGE_SLUG,
129+
'wp_djot_content',
130+
['field' => 'process_full_comments', 'description' => __('Process entire comment content as Djot. When disabled, only {djot}...{/djot} blocks are processed.', 'wp-djot')],
115131
);
116132

117133
// Security Settings Section
@@ -188,6 +204,7 @@ public function registerSettings(): void
188204
* Sanitize settings before saving.
189205
*
190206
* @param array<string, mixed> $input
207+
*
191208
* @return array<string, mixed>
192209
*/
193210
public function sanitizeSettings(array $input): array
@@ -197,6 +214,7 @@ public function sanitizeSettings(array $input): array
197214
'enable_pages' => !empty($input['enable_pages']),
198215
'enable_comments' => !empty($input['enable_comments']),
199216
'process_full_content' => !empty($input['process_full_content']),
217+
'process_full_comments' => !empty($input['process_full_comments']),
200218
'safe_mode' => !empty($input['safe_mode']),
201219
'highlight_code' => !empty($input['highlight_code']),
202220
'highlight_theme' => sanitize_text_field($input['highlight_theme'] ?? 'github'),

0 commit comments

Comments
 (0)