fix: typed write failures, template rollback, parent and term cleanup
WriteFailed maps to lit_write_failed / lit_partial_write (partial writes are logged with result partial); old template read before the update; row marker set before wp_update_post; created terms deleted on rollback; parent must be a readable non-descendant of a hierarchical type; featured image must be readable; snapshot keeps empty values; meta comparison after sanitize_meta; follow-up failures (listener, change log) only add warnings. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01At3V6SjwbMe6eMzVGW3Hs7
This commit is contained in:
@@ -94,6 +94,7 @@ final class RegisteredMetaSourceTest extends TestCase
|
||||
public function testUnchangedValueIsNotAFailure(): void
|
||||
{
|
||||
$field = new FieldDefinition('count', 'count', 'integer', 'meta', 'writable');
|
||||
Functions\when('sanitize_meta')->returnArg(2);
|
||||
Functions\expect('update_post_meta')->once()->with(5, 'count', 3)->andReturn(false);
|
||||
Functions\expect('get_post_meta')->once()->with(5, 'count', false)->andReturn(['3']);
|
||||
|
||||
@@ -101,9 +102,21 @@ final class RegisteredMetaSourceTest extends TestCase
|
||||
self::addToAssertionCount(1);
|
||||
}
|
||||
|
||||
public function testTheComparisonUsesTheSanitizedValue(): void
|
||||
{
|
||||
$field = new FieldDefinition('slug_meta', 'slug_meta', 'string', 'meta', 'writable');
|
||||
Functions\expect('sanitize_meta')->once()->with('slug_meta', ' Trier ', 'post', 'event')->andReturn('trier');
|
||||
Functions\when('update_post_meta')->justReturn(false);
|
||||
Functions\when('get_post_meta')->justReturn(['trier']);
|
||||
|
||||
(new RegisteredMetaSource())->write(5, 'event', ['slug_meta' => ' Trier '], ['slug_meta' => $field]);
|
||||
self::addToAssertionCount(1);
|
||||
}
|
||||
|
||||
public function testFailedUpdateThrows(): void
|
||||
{
|
||||
$field = new FieldDefinition('count', 'count', 'integer', 'meta', 'writable');
|
||||
Functions\when('sanitize_meta')->returnArg(2);
|
||||
Functions\when('update_post_meta')->justReturn(false);
|
||||
Functions\when('get_post_meta')->justReturn(['2']);
|
||||
|
||||
|
||||
@@ -69,7 +69,33 @@ final class TermAssignerTest extends TestCase
|
||||
Functions\expect('wp_insert_term')->once()->with('Neu', 'category')->andReturn(['term_id' => 15]);
|
||||
Functions\expect('wp_set_object_terms')->once()->with(5, [4, 15], 'category', false)->andReturn([4, 15]);
|
||||
|
||||
(new TermAssigner())->assign(5, ['category' => [4, 'Neu']]);
|
||||
self::assertSame([15 => 'category'], (new TermAssigner())->assign(5, ['category' => [4, 'Neu']]));
|
||||
}
|
||||
|
||||
public function testAFailedAssignmentDeletesTheTermsItCreated(): void
|
||||
{
|
||||
Functions\when('wp_insert_term')->justReturn(['term_id' => 15]);
|
||||
Functions\when('wp_set_object_terms')->justReturn(new WP_Error('x', 'kaputt'));
|
||||
Functions\expect('wp_delete_term')->once()->with(15, 'category')->andReturn(true);
|
||||
|
||||
$this->expectException(RuntimeException::class);
|
||||
|
||||
(new TermAssigner())->assign(5, ['category' => ['Neu']]);
|
||||
}
|
||||
|
||||
public function testDeleteTermsAcceptsAlreadyMissingTermsAndThrowsOnRealFailures(): void
|
||||
{
|
||||
Functions\when('wp_delete_term')->alias(static fn (int $id): mixed => match ($id) {
|
||||
15 => true,
|
||||
16 => false,
|
||||
default => new WP_Error('x', 'kaputt'),
|
||||
});
|
||||
$assigner = new TermAssigner();
|
||||
|
||||
$assigner->deleteTerms([15 => 'category', 16 => 'category']);
|
||||
|
||||
$this->expectException(RuntimeException::class);
|
||||
$assigner->deleteTerms([15 => 'category', 17 => 'post_tag']);
|
||||
}
|
||||
|
||||
public function testAssignFailureThrows(): void
|
||||
|
||||
Reference in New Issue
Block a user