Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01At3V6SjwbMe6eMzVGW3Hs7
46 lines
1.7 KiB
PHP
46 lines
1.7 KiB
PHP
<?php
|
||
|
||
/**
|
||
* Exports the post_content of a page built in the Divi Visual Builder byte-exact into
|
||
* tests/Fixtures/divi/builder-<name>.html. Every file there is part of the parse → serialize
|
||
* round-trip test (tests/Unit/Integrations/Divi/BlockTree/ParserTest.php).
|
||
* Usage (DDEV, WordPress root):
|
||
* wp eval-file wp-content/plugins/WP-LIT-MCP/tests/Integration/divi-export-page.php <post_id> <name>
|
||
* <name>: lowercase letters, digits and dashes, e.g. "startseite-mit-global".
|
||
* Only use pages without personal data – fixtures are committed.
|
||
* No `declare(strict_types=1);` – wp eval-file runs the file through eval().
|
||
*/
|
||
|
||
defined('WP_CLI') && WP_CLI || exit;
|
||
|
||
$args = $args ?? [];
|
||
$postId = (int) ($args[0] ?? 0);
|
||
$name = (string) ($args[1] ?? '');
|
||
if ($postId <= 0 || preg_match('/^[a-z0-9]+(-[a-z0-9]+)*$/', $name) !== 1) {
|
||
WP_CLI::error('Usage: divi-export-page.php <post_id> <name>');
|
||
}
|
||
|
||
$post = get_post($postId);
|
||
if (! $post instanceof WP_Post) {
|
||
WP_CLI::error('No post ' . $postId);
|
||
}
|
||
|
||
$content = (string) $post->post_content;
|
||
if (! str_contains($content, '<!-- wp:divi/')) {
|
||
WP_CLI::error('Post ' . $postId . ' has no Divi 5 content (open and save it in the Divi builder first).');
|
||
}
|
||
|
||
$file = dirname(__DIR__) . '/Fixtures/divi/builder-' . $name . '.html';
|
||
if (file_put_contents($file, $content) === false) {
|
||
WP_CLI::error('Cannot write ' . $file);
|
||
}
|
||
|
||
WP_CLI::success(sprintf(
|
||
'%s: %d bytes, %d blocks, globalModule: %s, tree_rev %s. Now run composer test.',
|
||
basename($file),
|
||
strlen($content),
|
||
substr_count($content, '<!-- wp:'),
|
||
str_contains($content, 'globalModule') ? 'yes' : 'no',
|
||
substr(hash('sha256', $content), 0, 12)
|
||
));
|