Files
WP-LIT-MCP/tests/Integration/pods-fixture.php
T
janniclas.loosenandClaude Opus 5.5 c615522cf6 test: Theme Builder fixtures with Pods fields from the real builder (stage3b)
Own fixture pod lit_fixture_person (ruling Q1), template and body layout
built through Divi's Theme Builder and Visual Builder UI, brief render with
the template limited to one person (Q5), findings 10-12 in the README.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-09-27 14:51:19 +02:00

136 lines
4.3 KiB
PHP

<?php
/**
* Creates or removes the Pods test content type "lit_person" for integration tests, or creates the
* permanent Etappe 3b fixture pod "lit_fixture_person" with two persons (tests/Fixtures/divi/stage3b).
*
* Usage (inside DDEV, Pods must be active):
* wp eval-file wp-content/plugins/WP-LIT-MCP/tests/Integration/pods-fixture.php create
* wp eval-file wp-content/plugins/WP-LIT-MCP/tests/Integration/pods-fixture.php delete
* wp eval-file wp-content/plugins/WP-LIT-MCP/tests/Integration/pods-fixture.php fixture
*
* "delete" only removes "lit_person"; the fixture pod is kept (smokes never touch it).
*
* No strict_types: wp eval-file runs this through eval().
*/
defined('WP_CLI') && WP_CLI || exit;
if (! function_exists('pods_api')) {
fwrite(STDERR, "Pods is not active\n");
exit(1);
}
$action = $args[0] ?? 'create';
$api = pods_api();
if ($action === 'delete') {
if ($api->load_pod(['name' => 'lit_person'])) {
$api->delete_pod(['name' => 'lit_person'], false, true);
}
echo "deleted\n";
return;
}
if ($action === 'fixture') {
// Etappe 3b fixture pod (ruling Q1): its own type, so no smoke deletes the fixture persons.
if (! $api->load_pod(['name' => 'lit_fixture_person'])) {
$api->save_pod([
'name' => 'lit_fixture_person',
'label' => '[Fixture] Personen',
'label_singular' => '[Fixture] Person',
'type' => 'post_type',
'storage' => 'meta',
'public' => 1,
'show_ui' => 1,
]);
}
$fixtureFields = [
['name' => 'role', 'label' => 'Funktion', 'type' => 'text'],
[
'name' => 'level',
'label' => 'Stufe',
'type' => 'pick',
'pick_object' => 'custom-simple',
'pick_custom' => "junior|Junior\nsenior|Senior",
],
[
'name' => 'mentor',
'label' => 'Mentor',
'type' => 'pick',
'pick_object' => 'post_type',
'pick_val' => 'lit_fixture_person',
'pick_format_type' => 'single',
],
];
foreach ($fixtureFields as $field) {
if (! $api->load_field(['pod' => 'lit_fixture_person', 'name' => $field['name']])) {
$api->save_field(array_merge(['pod' => 'lit_fixture_person'], $field));
}
}
$existing = static function (string $title): int {
$found = get_posts([
'post_type' => 'lit_fixture_person',
'post_status' => 'any',
'title' => $title,
'fields' => 'ids',
'numberposts' => 1,
]);
return (int) ($found[0] ?? 0);
};
$erika = $existing('[Fixture 3b] Erika Muster') ?: (int) pods('lit_fixture_person')->add([
'post_title' => '[Fixture 3b] Erika Muster',
'post_content' => '<p>Beitragsinhalt der Fixture-Person Erika Muster.</p>',
'post_status' => 'publish',
'role' => 'Geschäftsführung',
'level' => 'senior',
]);
$max = $existing('[Fixture 3b] Max Beispiel') ?: (int) pods('lit_fixture_person')->add([
'post_title' => '[Fixture 3b] Max Beispiel',
'post_content' => '<p>Beitragsinhalt der Fixture-Person Max Beispiel.</p>',
'post_status' => 'publish',
'role' => 'Entwicklung',
'level' => 'junior',
'mentor' => $erika,
]);
echo "persons {$erika} {$max}\n";
return;
}
if (! $api->load_pod(['name' => 'lit_person'])) {
$api->save_pod([
'name' => 'lit_person',
'label' => 'Personen',
'label_singular' => 'Person',
'type' => 'post_type',
'storage' => 'meta',
'public' => 1,
'show_ui' => 1,
]);
}
$fields = [
['name' => 'role', 'label' => 'Funktion', 'type' => 'text', 'required' => 1],
[
'name' => 'level',
'label' => 'Stufe',
'type' => 'pick',
'pick_object' => 'custom-simple',
'pick_custom' => "junior|Junior\nsenior|Senior",
],
[
'name' => 'mentor',
'label' => 'Mentor',
'type' => 'pick',
'pick_object' => 'post_type',
'pick_val' => 'lit_person',
'pick_format_type' => 'single',
],
];
foreach ($fields as $field) {
$api->save_field(array_merge(['pod' => 'lit_person'], $field));
}
echo "created\n";