feat(pods): Verhaltensprobe als Prüfschritt
Beim Prüfen schreibt und liest PodsProbe auf einem Wegwerf-Entwurf ein Textfeld genau so, wie LIT MCP es tut, vergleicht die Werte und löscht den Entwurf wieder. Bevorzugt von Pods angelegte Typen; ohne Pod mit Textfeld gilt der Schritt als grün mit Hinweis „nicht geprüft“. Ein roter Schritt sperrt Pods über die Berichtssperre. Liegengebliebene Probe-Einträge räumt der Load-Hook des Reiters auf. Pods-Smoke um Probe und Bereinigung erweitert. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
42aa4f8dc9
commit
1a294b7881
@@ -62,9 +62,16 @@ REPORT=$(stored_option lit_mcp_pods_check_report)
|
||||
echo "$REPORT" | jq -e '(.steps | length) >= 1 and all(.steps[]; .problems == [] and .skipped == false)
|
||||
and .version == "3.3.9.2" and (has("divi_version") | not)' >/dev/null || fail "the stored report must be green with key version: $REPORT"
|
||||
[ -z "$(stored_option lit_mcp_pods_check_lock)" ] || fail "the check lock must be released"
|
||||
# The behaviour probe is part of the report (green, not skipped, its label is the real probe, not "not probed") ...
|
||||
echo "$REPORT" | jq -e '[.steps[] | select(.key == "probe")] | length == 1 and (.[0] | .problems == [] and .skipped == false
|
||||
and (.label | contains("nicht geprüft") | not))' >/dev/null || fail "the report must contain the green probe step: $REPORT"
|
||||
# ... and leaves no entry behind (it ran on lit_person; any status, any marked entry).
|
||||
LEFT=$(wp post list --post_type=any --post_status=any --meta_key=_lit_mcp_check_entry --format=count)
|
||||
[ "$LEFT" = "0" ] || fail "the probe left $LEFT entries behind"
|
||||
[ "$(wp post list --post_type=lit_person --post_status=any --format=count)" = "0" ] || fail "the probe left a lit_person entry"
|
||||
UNAUTH=$(curl -s -o /dev/null -w '%{http_code}' -X POST -H "Host: $HOST" -H 'X-Forwarded-Proto: https' "$BASE/wp-json/lit-mcp/v1/pods-check")
|
||||
[ "$UNAUTH" = "401" ] || [ "$UNAUTH" = "403" ] || fail "anonymous check must be refused, got $UNAUTH"
|
||||
pass "/pods-check: 303 to the tab, green report with key version, lock released, anonymous refused"
|
||||
pass "/pods-check: 303 to the tab, green report with key version and probe step, no probe entry left, lock released, anonymous refused"
|
||||
|
||||
# 3. The tab renders the Pods section and, as 3.3.9.2 is tested, offers no release
|
||||
TAB=$(wp --user="$ADMIN_LOGIN" eval '
|
||||
@@ -78,6 +85,25 @@ echo "$TAB" | grep -q 'lit-mcp-compat-check-pods' || fail "the Pods section must
|
||||
echo "$TAB" | grep -q 'lit-mcp-compat-release-pods' && fail "no release button for a tested version"
|
||||
pass "tab Compatibility: Pods section with version and state, check button, no release button"
|
||||
|
||||
# 3b. Orphan cleanup: an old marked probe entry (a dead check) is deleted on the tab's profile-load hook, a young one and
|
||||
# an unmarked entry with the same title are not.
|
||||
ORPHANS=$(wp --user="$ADMIN_LOGIN" eval '
|
||||
$make = static fn (string $date, bool $marked): int => (int) wp_insert_post([
|
||||
"post_type" => "lit_person", "post_status" => "draft", "post_title" => LIT\MCP\Integrations\Pods\PodsProbe::TITLE . " smoke",
|
||||
"post_date" => get_date_from_gmt($date), "post_date_gmt" => $date,
|
||||
"meta_input" => $marked ? [LIT\MCP\Integrations\Pods\PodsProbe::MARKER => "1"] : [],
|
||||
]);
|
||||
$old = $make(gmdate("Y-m-d H:i:s", time() - 3600), true);
|
||||
$young = $make(gmdate("Y-m-d H:i:s"), true);
|
||||
$unmarked = $make(gmdate("Y-m-d H:i:s", time() - 3600), false);
|
||||
do_action(LIT\MCP\Admin\CompatibilityTab::LOAD_ACTION, "pods");
|
||||
echo json_encode([$old, $young, $unmarked, get_post_status($old), get_post_status($young), get_post_status($unmarked)]);')
|
||||
OLD_ID=$(echo "$ORPHANS" | jq -r '.[0]'); YOUNG_ID=$(echo "$ORPHANS" | jq -r '.[1]'); UNMARKED_ID=$(echo "$ORPHANS" | jq -r '.[2]')
|
||||
CREATED_POSTS+=("$OLD_ID" "$YOUNG_ID" "$UNMARKED_ID")
|
||||
echo "$ORPHANS" | jq -e '.[3] == false and .[4] == "draft" and .[5] == "draft"' >/dev/null \
|
||||
|| fail "orphan cleanup must delete only the old marked entry: $ORPHANS"
|
||||
pass "orphan cleanup: old marked probe entry deleted, young and unmarked ones kept"
|
||||
|
||||
# 4. Release: refused for the tested version; for an untested one (simulated profile) it is only documented
|
||||
[ "$(handler release real)" = "compat_release_refused" ] || fail "releasing a tested version must be refused"
|
||||
[ -z "$(stored_option lit_mcp_pods_releases)" ] || fail "a refused release must write nothing"
|
||||
|
||||
+85
@@ -0,0 +1,85 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace LIT\MCP\Tests\Unit\Integrations\Pods;
|
||||
|
||||
use Closure;
|
||||
use LIT\MCP\Compatibility\CheckStep;
|
||||
use LIT\MCP\Integrations\Pods\PodsCheckSteps;
|
||||
use LIT\MCP\Tests\Unit\TestCase;
|
||||
use RuntimeException;
|
||||
|
||||
final class PodsCheckStepsTest extends TestCase
|
||||
{
|
||||
/** Captures what Log::failure writes to the PHP error log while $run runs. */
|
||||
private function logged(Closure $run): string
|
||||
{
|
||||
$log = (string) tempnam(sys_get_temp_dir(), 'lit-mcp-log');
|
||||
$previous = ini_set('error_log', $log);
|
||||
try {
|
||||
$run();
|
||||
|
||||
return (string) file_get_contents($log);
|
||||
} finally {
|
||||
ini_set('error_log', (string) $previous);
|
||||
unlink($log);
|
||||
}
|
||||
}
|
||||
|
||||
public function testStepsAreSkippedWithARedManifestAndTheProbeIsNotRun(): void
|
||||
{
|
||||
$ran = false;
|
||||
$steps = (PodsCheckSteps::extra(static function () use (&$ran): array {
|
||||
$ran = true;
|
||||
|
||||
return [];
|
||||
}))(false);
|
||||
|
||||
self::assertCount(1, $steps);
|
||||
self::assertSame(PodsCheckSteps::PROBE, $steps[0]->key);
|
||||
self::assertTrue($steps[0]->skipped);
|
||||
self::assertFalse($ran);
|
||||
}
|
||||
|
||||
public function testTheStepCarriesTheProbeProblems(): void
|
||||
{
|
||||
$steps = (PodsCheckSteps::extra(static fn (): array => ['rot']))(true);
|
||||
|
||||
self::assertSame(['rot'], $steps[0]->problems);
|
||||
self::assertFalse($steps[0]->skipped);
|
||||
self::assertSame('Lese- und Schreibtest an einem Wegwerf-Eintrag', $steps[0]->label());
|
||||
}
|
||||
|
||||
/** No target is no red step: a skipped one would lock Pods on a site that has no pod yet (CheckReport::green()). */
|
||||
public function testWithoutATargetTheStepIsGreenAndSaysSo(): void
|
||||
{
|
||||
$steps = (PodsCheckSteps::extra(static fn (): ?array => null))(true);
|
||||
|
||||
self::assertTrue($steps[0]->green());
|
||||
self::assertStringContainsString('nicht geprüft', $steps[0]->label());
|
||||
}
|
||||
|
||||
public function testALateExceptionOfTheClosureIsStillGuarded(): void
|
||||
{
|
||||
$logged = $this->logged(function (): void {
|
||||
$steps = (PodsCheckSteps::extra(static fn (): never => throw new RuntimeException('boom')))(true);
|
||||
self::assertSame(['Prüfschritt abgebrochen (Details im PHP-Error-Log).'], $steps[0]->problems);
|
||||
});
|
||||
|
||||
self::assertStringContainsString('boom', $logged);
|
||||
}
|
||||
|
||||
public function testTheLabelOfAnOldStepComesFromTheKey(): void
|
||||
{
|
||||
self::assertSame(
|
||||
'Lese- und Schreibtest an einem Wegwerf-Eintrag',
|
||||
PodsCheckSteps::label(new CheckStep(PodsCheckSteps::PROBE, []))
|
||||
);
|
||||
self::assertSame(
|
||||
'Pods-Funktionen, Klassen und Registrierungen',
|
||||
PodsCheckSteps::label(new CheckStep(CheckStep::MANIFEST, []))
|
||||
);
|
||||
self::assertSame('other', PodsCheckSteps::label(new CheckStep('other', [])));
|
||||
}
|
||||
}
|
||||
@@ -5,9 +5,11 @@ declare(strict_types=1);
|
||||
namespace LIT\MCP\Tests\Unit\Integrations\Pods;
|
||||
|
||||
use LIT\MCP\Compatibility\Call;
|
||||
use LIT\MCP\Compatibility\CheckStep;
|
||||
use LIT\MCP\Compatibility\Compatibility;
|
||||
use LIT\MCP\Compatibility\Tier;
|
||||
use LIT\MCP\Integrations\Divi\Release\DiviProfile;
|
||||
use LIT\MCP\Integrations\Pods\PodsCheckSteps;
|
||||
use LIT\MCP\Integrations\Pods\PodsCompatibility;
|
||||
use LIT\MCP\Integrations\Pods\PodsFeature;
|
||||
use LIT\MCP\Tests\Unit\TestCase;
|
||||
@@ -39,6 +41,21 @@ final class PodsCompatibilityTest extends TestCase
|
||||
self::assertSame(PodsFeature::cases(), $profile->capabilities);
|
||||
}
|
||||
|
||||
public function testTheCheckHasTheProbeAsExtraStep(): void
|
||||
{
|
||||
$profile = PodsCompatibility::profile();
|
||||
|
||||
self::assertNotNull($profile->extraSteps);
|
||||
$steps = ($profile->extraSteps)(false);
|
||||
self::assertSame([PodsCheckSteps::PROBE], array_map(static fn ($step): string => $step->key, $steps));
|
||||
self::assertTrue($steps[0]->skipped);
|
||||
self::assertNotNull($profile->stepLabel);
|
||||
self::assertSame(
|
||||
'Lese- und Schreibtest an einem Wegwerf-Eintrag',
|
||||
($profile->stepLabel)(new CheckStep(PodsCheckSteps::PROBE, []))
|
||||
);
|
||||
}
|
||||
|
||||
/** @runInSeparateProcess
|
||||
* @preserveGlobalState disabled
|
||||
*/
|
||||
|
||||
@@ -4,6 +4,8 @@ declare(strict_types=1);
|
||||
|
||||
namespace LIT\MCP\Tests\Unit\Integrations\Pods;
|
||||
|
||||
use Brain\Monkey\Functions;
|
||||
use LIT\MCP\Admin\CompatibilityTab;
|
||||
use LIT\MCP\Compatibility\ProvidesCompatibility;
|
||||
use LIT\MCP\Guides\InstructionsBuilder;
|
||||
use LIT\MCP\Integrations\Integration;
|
||||
@@ -26,6 +28,50 @@ final class PodsIntegrationTest extends TestCase
|
||||
self::assertEquals([PodsCompatibility::profile()], $integration->compatibilities());
|
||||
}
|
||||
|
||||
public function testBootHooksTheOrphanCleanupIntoTheProfileLoad(): void
|
||||
{
|
||||
$integration = new PodsIntegration();
|
||||
$integration->boot();
|
||||
|
||||
self::assertNotFalse(has_action(CompatibilityTab::LOAD_ACTION, [$integration, 'removeOrphans']));
|
||||
}
|
||||
|
||||
public function testNoCleanupForAnotherProfile(): void
|
||||
{
|
||||
Functions\expect('get_posts')->never();
|
||||
Functions\when('current_user_can')->justReturn(true);
|
||||
|
||||
(new PodsIntegration(static fn (): bool => true))->removeOrphans('divi');
|
||||
$this->addToAssertionCount(1);
|
||||
}
|
||||
|
||||
public function testNoCleanupWithoutPods(): void
|
||||
{
|
||||
Functions\expect('get_posts')->never();
|
||||
Functions\when('current_user_can')->justReturn(true);
|
||||
|
||||
(new PodsIntegration(static fn (): bool => false))->removeOrphans('pods');
|
||||
$this->addToAssertionCount(1);
|
||||
}
|
||||
|
||||
public function testNoCleanupWithoutTheCapability(): void
|
||||
{
|
||||
Functions\expect('get_posts')->never();
|
||||
Functions\when('current_user_can')->justReturn(false);
|
||||
|
||||
(new PodsIntegration(static fn (): bool => true))->removeOrphans('pods');
|
||||
$this->addToAssertionCount(1);
|
||||
}
|
||||
|
||||
public function testCleansUpForTheAdministratorWithPods(): void
|
||||
{
|
||||
Functions\when('current_user_can')->justReturn(true);
|
||||
Functions\when('get_post_types')->justReturn(['post' => 'post']);
|
||||
Functions\expect('get_posts')->once()->andReturn([]);
|
||||
|
||||
(new PodsIntegration(static fn (): bool => true))->removeOrphans('pods');
|
||||
}
|
||||
|
||||
public function testIsAvailableOnlyWithPods(): void
|
||||
{
|
||||
self::assertSame(defined('PODS_VERSION'), (new PodsIntegration())->isAvailable());
|
||||
|
||||
+353
@@ -0,0 +1,353 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace LIT\MCP\Tests\Unit\Integrations\Pods;
|
||||
|
||||
use Brain\Monkey\Functions;
|
||||
use Closure;
|
||||
use LIT\MCP\Integrations\Pods\PodsFieldSource;
|
||||
use LIT\MCP\Integrations\Pods\PodsProbe;
|
||||
use LIT\MCP\Tests\Unit\TestCase;
|
||||
use Mockery;
|
||||
use RuntimeException;
|
||||
use WP_Error;
|
||||
use WP_Post;
|
||||
|
||||
final class PodsProbeTest extends TestCase
|
||||
{
|
||||
/** @var list<int> */
|
||||
private array $deleted = [];
|
||||
|
||||
/** @var array<string, mixed> What the fake Pods object holds. */
|
||||
private array $stored = [];
|
||||
|
||||
/** @var array<string, mixed>|null The wp_insert_post arguments. */
|
||||
private ?array $inserted = null;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
$this->deleted = [];
|
||||
$this->stored = [];
|
||||
$this->inserted = null;
|
||||
Functions\when('wp_insert_post')->alias(function (array $post): int {
|
||||
$this->inserted = $post;
|
||||
|
||||
return 77;
|
||||
});
|
||||
Functions\when('get_post_type')->justReturn('lit_person');
|
||||
Functions\when('is_wp_error')->alias(static fn ($value): bool => $value instanceof WP_Error);
|
||||
Functions\when('wp_delete_post')->alias(function (int $id, bool $force): WP_Post {
|
||||
self::assertTrue($force, 'never to the trash');
|
||||
$this->deleted[] = $id;
|
||||
|
||||
return new WP_Post(['ID' => $id]);
|
||||
});
|
||||
}
|
||||
|
||||
/** @param array<string, mixed> $args */
|
||||
private function field(
|
||||
string $name,
|
||||
string $type,
|
||||
bool $required = false,
|
||||
array $args = [],
|
||||
bool $multiple = false
|
||||
): object {
|
||||
$field = Mockery::mock();
|
||||
$field->allows('get_name')->andReturn($name);
|
||||
$field->allows('get_label')->andReturn(ucfirst($name));
|
||||
$field->allows('get_type')->andReturn($type);
|
||||
$field->allows('is_required')->andReturn($required);
|
||||
$field->allows('is_multi_value')->andReturn($multiple);
|
||||
$field->allows('get_arg')->andReturnUsing(static fn (string $key, $default = null) => $args[$key] ?? $default);
|
||||
|
||||
return $field;
|
||||
}
|
||||
|
||||
/** @param list<object> $fields */
|
||||
private function schema(array $fields, string $object = ''): object
|
||||
{
|
||||
$pod = Mockery::mock();
|
||||
$pod->allows('get_type')->andReturn('post_type');
|
||||
$pod->allows('get_arg')->andReturnUsing(
|
||||
static fn (string $key, $default = null) => $key === 'object' ? $object : $default
|
||||
);
|
||||
$pod->allows('get_fields')->andReturn($fields);
|
||||
|
||||
return $pod;
|
||||
}
|
||||
|
||||
/** @param (Closure(array<string, mixed>): mixed)|null $save */
|
||||
private function entry(?Closure $save = null, ?string $readBack = null): object
|
||||
{
|
||||
$entry = Mockery::mock();
|
||||
$entry->allows('save')->andReturnUsing(function (array $data) use ($save) {
|
||||
if ($save !== null) {
|
||||
return $save($data);
|
||||
}
|
||||
$this->stored = $data;
|
||||
|
||||
return 77;
|
||||
});
|
||||
$entry->allows('field')->andReturnUsing(
|
||||
fn (array $args) => $readBack ?? $this->stored[$args['name']] ?? ''
|
||||
);
|
||||
|
||||
return $entry;
|
||||
}
|
||||
|
||||
/** @param list<object>|null $fields */
|
||||
private function probe(?array $fields = null, ?object $entry = null): PodsProbe
|
||||
{
|
||||
$pod = $this->schema($fields ?? [$this->field('role', 'text')]);
|
||||
$entry ??= $this->entry();
|
||||
$source = new PodsFieldSource(
|
||||
static fn (): bool => true,
|
||||
static fn (string $name) => $name === 'lit_person' ? $pod : false,
|
||||
static fn () => $entry,
|
||||
static fn (object $field): ?bool => null
|
||||
);
|
||||
|
||||
return new PodsProbe(
|
||||
$source,
|
||||
static fn (string $name) => $name === 'lit_person' ? $pod : false,
|
||||
static fn (): array => ['post', 'lit_person']
|
||||
);
|
||||
}
|
||||
|
||||
/** Captures what Log::failure writes to the PHP error log while $run runs. */
|
||||
private function logged(Closure $run): string
|
||||
{
|
||||
$log = (string) tempnam(sys_get_temp_dir(), 'lit-mcp-log');
|
||||
$previous = ini_set('error_log', $log);
|
||||
try {
|
||||
$run();
|
||||
|
||||
return (string) file_get_contents($log);
|
||||
} finally {
|
||||
ini_set('error_log', (string) $previous);
|
||||
unlink($log);
|
||||
}
|
||||
}
|
||||
|
||||
public function testGreenWhenTheWrittenValueIsReadBackAndTheEntryIsGone(): void
|
||||
{
|
||||
self::assertSame([], $this->probe()->run());
|
||||
self::assertSame(['role' => PodsProbe::VALUE], $this->stored);
|
||||
self::assertSame([77], $this->deleted);
|
||||
}
|
||||
|
||||
public function testCreatesAMarkedDraftWithThePrefixedTitleInThePodsPostType(): void
|
||||
{
|
||||
$this->probe()->run();
|
||||
|
||||
self::assertSame('lit_person', $this->inserted['post_type']);
|
||||
self::assertSame('draft', $this->inserted['post_status']);
|
||||
self::assertStringStartsWith(PodsProbe::TITLE, $this->inserted['post_title']);
|
||||
self::assertSame(['_lit_mcp_check_entry' => '1'], $this->inserted['meta_input']);
|
||||
}
|
||||
|
||||
public function testADifferingValueIsAFixedTextAndTheValueGoesToTheLogOnly(): void
|
||||
{
|
||||
$problems = [];
|
||||
$logged = $this->logged(function () use (&$problems): void {
|
||||
$problems = $this->probe(null, $this->entry(null, 'etwas anderes'))->run();
|
||||
});
|
||||
|
||||
self::assertSame(['Gelesener Wert weicht vom geschriebenen ab.'], $problems);
|
||||
self::assertStringContainsString('role', $logged);
|
||||
self::assertStringContainsString('etwas anderes', $logged);
|
||||
self::assertSame([77], $this->deleted);
|
||||
}
|
||||
|
||||
public function testAnExceptionBecomesTheFixedTextAndALogLineAndTheEntryIsDeleted(): void
|
||||
{
|
||||
$entry = $this->entry(static function (): never {
|
||||
throw new RuntimeException('Pods kaputt');
|
||||
});
|
||||
$problems = [];
|
||||
$logged = $this->logged(function () use (&$problems, $entry): void {
|
||||
$problems = $this->probe(null, $entry)->run();
|
||||
});
|
||||
|
||||
self::assertSame(['Pods-Probe abgebrochen (Details im PHP-Error-Log).'], $problems);
|
||||
self::assertStringContainsString('Pods kaputt', $logged);
|
||||
self::assertSame([77], $this->deleted);
|
||||
}
|
||||
|
||||
public function testAFailingSchemaLookupIsTheFixedTextToo(): void
|
||||
{
|
||||
$broken = static fn () => throw new RuntimeException('Schema kaputt');
|
||||
$probe = new PodsProbe(
|
||||
new PodsFieldSource(static fn (): bool => true, $broken),
|
||||
$broken,
|
||||
static fn (): array => ['lit_person']
|
||||
);
|
||||
$problems = [];
|
||||
$logged = $this->logged(function () use (&$problems, $probe): void {
|
||||
$problems = $probe->run();
|
||||
});
|
||||
|
||||
self::assertSame(['Pods-Probe abgebrochen (Details im PHP-Error-Log).'], $problems);
|
||||
self::assertStringContainsString('Schema kaputt', $logged);
|
||||
self::assertNull($this->inserted);
|
||||
}
|
||||
|
||||
public function testNothingToProbeWithoutAPodWithAPlainWritableTextField(): void
|
||||
{
|
||||
$fields = [$this->field('mail', 'email'), $this->field('intro', 'wysiwyg')];
|
||||
|
||||
self::assertNull($this->probe($fields)->run());
|
||||
self::assertNull($this->probe([])->run());
|
||||
self::assertNull($this->inserted, 'nothing is created without a target');
|
||||
self::assertSame([], $this->deleted);
|
||||
}
|
||||
|
||||
public function testARequiredTextFieldIsFineBecauseTheProbeWritesAValue(): void
|
||||
{
|
||||
self::assertSame([], $this->probe([$this->field('role', 'text', true)])->run());
|
||||
self::assertSame(['role' => PodsProbe::VALUE], $this->stored);
|
||||
}
|
||||
|
||||
public function testPicksThePlainTextFieldAmongOthers(): void
|
||||
{
|
||||
$this->probe([$this->field('mail', 'email'), $this->field('title2', 'text')])->run();
|
||||
|
||||
self::assertSame(['title2' => PodsProbe::VALUE], $this->stored);
|
||||
}
|
||||
|
||||
public function testAnEntryThatCannotBeCreatedIsAFixedTextAndNothingIsDeleted(): void
|
||||
{
|
||||
Functions\when('wp_insert_post')->justReturn(new WP_Error('x', 'Datenbank voll'));
|
||||
$problems = [];
|
||||
$logged = $this->logged(function () use (&$problems): void {
|
||||
$problems = $this->probe()->run();
|
||||
});
|
||||
|
||||
self::assertSame(['Der Probe-Eintrag konnte nicht angelegt werden (Details im PHP-Error-Log).'], $problems);
|
||||
self::assertStringContainsString('Datenbank voll', $logged);
|
||||
self::assertSame([], $this->deleted);
|
||||
}
|
||||
|
||||
public function testAnEntryThatCannotBeDeletedIsReported(): void
|
||||
{
|
||||
Functions\when('wp_delete_post')->justReturn(false);
|
||||
|
||||
$problems = $this->probe()->run();
|
||||
|
||||
self::assertCount(1, $problems);
|
||||
self::assertStringContainsString('77', $problems[0]);
|
||||
self::assertStringContainsString('gelöscht', $problems[0]);
|
||||
}
|
||||
|
||||
public function testOrphansAreLookedForInEveryPostTypeWithThePodsMarker(): void
|
||||
{
|
||||
Functions\when('get_post_types')->justReturn(['post' => 'post', 'lit_person' => 'lit_person']);
|
||||
$query = null;
|
||||
Functions\when('get_posts')->alias(static function (array $args) use (&$query): array {
|
||||
$query = $args;
|
||||
|
||||
return [
|
||||
new WP_Post(['ID' => 5, 'post_title' => PodsProbe::TITLE . ' 2026-11-06 10:00']),
|
||||
new WP_Post(['ID' => 6, 'post_title' => 'Echte Person']),
|
||||
];
|
||||
});
|
||||
|
||||
self::assertSame([5], PodsProbe::removeOrphans());
|
||||
self::assertSame([5], $this->deleted);
|
||||
self::assertSame('_lit_mcp_check_entry', $query['meta_key']);
|
||||
self::assertSame(['post', 'lit_person'], $query['post_type']);
|
||||
self::assertSame('post_modified_gmt', $query['date_query'][0]['column']);
|
||||
}
|
||||
|
||||
/** @param array<string, object> $pods */
|
||||
private function probeOver(array $pods, ?callable $postTypes = null): PodsProbe
|
||||
{
|
||||
$load = static fn (string $name) => $pods[$name] ?? false;
|
||||
$source = new PodsFieldSource(
|
||||
static fn (): bool => true,
|
||||
$load,
|
||||
fn () => $this->entry(),
|
||||
static fn (object $field): ?bool => null
|
||||
);
|
||||
|
||||
return new PodsProbe($source, $load, $postTypes);
|
||||
}
|
||||
|
||||
public function testPodsOwnPostTypesComeBeforeExtendedForeignOnesAndPostAndPage(): void
|
||||
{
|
||||
$fields = [$this->field('role', 'text')];
|
||||
$pods = [
|
||||
'post' => $this->schema($fields, 'post'),
|
||||
'event' => $this->schema($fields, 'event'),
|
||||
'lit_person' => $this->schema($fields),
|
||||
];
|
||||
|
||||
$this->probeOver($pods, static fn (): array => ['post', 'event', 'lit_person'])->run();
|
||||
|
||||
self::assertSame('lit_person', $this->inserted['post_type']);
|
||||
}
|
||||
|
||||
public function testAnExtendedForeignTypeComesBeforePostAndPage(): void
|
||||
{
|
||||
$fields = [$this->field('role', 'text')];
|
||||
$pods = ['post' => $this->schema($fields, 'post'), 'event' => $this->schema($fields, 'event')];
|
||||
|
||||
$this->probeOver($pods, static fn (): array => ['post', 'event'])->run();
|
||||
|
||||
self::assertSame('event', $this->inserted['post_type']);
|
||||
}
|
||||
|
||||
public function testPostIsTheLastResort(): void
|
||||
{
|
||||
$pods = ['post' => $this->schema([$this->field('role', 'text')], 'post')];
|
||||
|
||||
$this->probeOver($pods, static fn (): array => ['page', 'post'])->run();
|
||||
|
||||
self::assertSame('post', $this->inserted['post_type']);
|
||||
}
|
||||
|
||||
public function testALowerRankedTypeIsUsedWhenTheBetterOnesHaveNoTextField(): void
|
||||
{
|
||||
$pods = [
|
||||
'lit_person' => $this->schema([$this->field('mail', 'email')]),
|
||||
'post' => $this->schema([$this->field('role', 'text')], 'post'),
|
||||
];
|
||||
|
||||
$this->probeOver($pods, static fn (): array => ['lit_person', 'post'])->run();
|
||||
|
||||
self::assertSame('post', $this->inserted['post_type']);
|
||||
}
|
||||
|
||||
public function testReadOnlyAndMultipleTextFieldsAreNotProbed(): void
|
||||
{
|
||||
$fields = [
|
||||
$this->field('locked', 'text', false, ['read_only' => true]),
|
||||
$this->field('many', 'text', false, [], true),
|
||||
];
|
||||
|
||||
self::assertNull($this->probe($fields)->run());
|
||||
self::assertNull($this->inserted);
|
||||
|
||||
$this->probe([...$fields, $this->field('role', 'text')])->run();
|
||||
self::assertSame(['role' => PodsProbe::VALUE], $this->stored);
|
||||
}
|
||||
|
||||
public function testTheDefaultPostTypesAreCustomTypesThenPostAndPage(): void
|
||||
{
|
||||
Functions\when('get_post_types')->justReturn(['lit_person' => 'lit_person', 'post' => 'post']);
|
||||
$asked = [];
|
||||
$probe = new PodsProbe(
|
||||
new PodsFieldSource(static fn (): bool => true, static fn () => false),
|
||||
static function (string $name) use (&$asked) {
|
||||
$asked[] = $name;
|
||||
|
||||
return false;
|
||||
}
|
||||
);
|
||||
|
||||
self::assertNull($probe->run());
|
||||
self::assertSame(['lit_person', 'post', 'page'], $asked);
|
||||
}
|
||||
}
|
||||
@@ -53,13 +53,13 @@ final class PluginTest extends TestCase
|
||||
);
|
||||
}
|
||||
|
||||
/** Only Divi has boot steps (upgrader hook, compat listener, admin extras); a second boot registers nothing twice. */
|
||||
/** Divi and Pods boot (hooks, orphan cleanup); a second boot registers nothing twice. */
|
||||
public function testTheBootableIntegrationsBootExactlyOnce(): void
|
||||
{
|
||||
Actions\expectAdded('upgrader_process_complete')->once();
|
||||
Actions\expectAdded('lit_mcp_compat_changed')->once();
|
||||
Filters\expectAdded(SettingsPage::TABS_FILTER)->never();
|
||||
Actions\expectAdded(CompatibilityTab::LOAD_ACTION)->once();
|
||||
Actions\expectAdded(CompatibilityTab::LOAD_ACTION)->times(2); // Divi and Pods
|
||||
Actions\expectAdded(CompatibilityTab::EXTRA_ACTION)->once();
|
||||
Filters\expectAdded(CompatibilityTab::COLUMNS_FILTER)->once();
|
||||
$registry = self::registry();
|
||||
|
||||
Reference in New Issue
Block a user