feat: deferred 1a items - menu_rev lock, lit_mcp_guides filter, warnings, schedule guard precision
Task 14 (rulings P17/P18, Q10): - lit/menu-get returns menu_rev (Rev::ofMenu over id, parent, position, title, url, object, object_id); lit/menu-set-items requires it, refuses a stale one with rev_mismatch (hint: lit/menu-get) and returns the new menu_rev. Errors::revMismatch takes an optional message/hint. - GuideRepository: filter lit_mcp_guides adds/overrides topics; invalid topic names and non-string content are ignored, files stay the default. - lit/post-trash names front page, posts page and linking menus in the confirmation and as warnings; lit/menu-assign-location needs confirm to remove an assigned menu and names it; lit/post-schedule warns that a private entry becomes public; Divi hints no longer point to non-existing lit-divi-* tools. - PostGuard::missedSchedule: 60 s publish window, zero GMT date falls back to get_gmt_from_date(post_date); post-schedule refuses dates within that window. - write_failed after a clean rollback that keeps a revision/backup says "Die Aenderung wurde nicht gespeichert (... bleibt erhalten)" via the new state parameter (Errors::writeFailed / WriteFailed rolledBackState). - wp-basis-smoke: menu_rev flow, unassign confirm, trash/menu and private-schedule 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:
@@ -116,7 +116,9 @@ final class ContentUpdateAbilityTest extends TestCase
|
||||
->execute(['post_id' => 5, 'rev' => Rev::ofPost($this->post), 'content' => '<p>Neu</p>']);
|
||||
|
||||
self::assertSame('lit_unsupported', $result->get_error_code());
|
||||
self::assertStringContainsString('lit-divi-outline', $result->get_error_message());
|
||||
self::assertStringNotContainsString('lit-divi', $result->get_error_message());
|
||||
self::assertStringContainsString('Divi-Werkzeuge folgen in einer späteren Version; bis dahin im Divi-Builder '
|
||||
. 'bearbeiten.', $result->get_error_data()['hint']);
|
||||
}
|
||||
|
||||
public function testNothingToChangeIsAValidationError(): void
|
||||
@@ -231,6 +233,9 @@ final class ContentUpdateAbilityTest extends TestCase
|
||||
|
||||
self::assertTrue($failure->rolledBack);
|
||||
self::assertSame('lit_write_failed', $failure->toError()->get_error_code());
|
||||
$message = $failure->toError()->get_error_message();
|
||||
self::assertStringNotContainsString('Nichts wurde gespeichert', $message);
|
||||
self::assertStringContainsString('Die Änderung wurde nicht gespeichert (Revision 811 bleibt erhalten).', $message);
|
||||
self::assertSame([
|
||||
['post_title' => 'Unser Team', 'post_name' => 'unser-team', 'ID' => 5],
|
||||
['post_name' => 'team', 'ID' => 5],
|
||||
|
||||
@@ -87,7 +87,8 @@ final class PostPresenterTest extends TestCase
|
||||
self::assertTrue($full['divi']);
|
||||
self::assertNull($full['content']);
|
||||
self::assertNull($full['featured_image']);
|
||||
self::assertStringContainsString('lit-divi-outline', $full['hints'][0]);
|
||||
self::assertStringNotContainsString('lit-divi', $full['hints'][0]);
|
||||
self::assertStringContainsString('Divi-Werkzeuge folgen in einer späteren Version', $full['hints'][0]);
|
||||
self::assertInstanceOf(stdClass::class, $full['terms']);
|
||||
self::assertInstanceOf(stdClass::class, $full['fields']);
|
||||
self::assertSame(Rev::ofPost($post), $full['rev']);
|
||||
|
||||
@@ -18,7 +18,11 @@ final class MenuAssignLocationAbilityTest extends TestCase
|
||||
Functions\when('get_registered_nav_menus')->justReturn(['primary-menu' => 'Hauptmenü']);
|
||||
Functions\when('get_nav_menu_locations')->justReturn(['primary-menu' => 3]);
|
||||
Functions\when('wp_get_nav_menu_object')->alias(
|
||||
static fn (int $id) => $id === 8 ? (object) ['term_id' => 8, 'name' => 'Neu'] : false
|
||||
static fn (int $id) => match ($id) {
|
||||
8 => (object) ['term_id' => 8, 'name' => 'Neu'],
|
||||
3 => (object) ['term_id' => 3, 'name' => 'Hauptmenü'],
|
||||
default => false,
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
@@ -42,7 +46,21 @@ final class MenuAssignLocationAbilityTest extends TestCase
|
||||
self::assertSame(6, $result['log_id']);
|
||||
}
|
||||
|
||||
public function testZeroRemovesTheAssignment(): void
|
||||
public function testRemovingAnAssignmentNeedsConfirmation(): void
|
||||
{
|
||||
Functions\expect('set_theme_mod')->never();
|
||||
|
||||
$result = (new MenuAssignLocationAbility(Mockery::mock(ChangeLog::class)))
|
||||
->execute(['location' => 'primary-menu', 'menu_id' => 0]);
|
||||
|
||||
self::assertSame('lit_confirm_required', $result->get_error_code());
|
||||
self::assertStringContainsString(
|
||||
'"Hauptmenü" (ID 3)',
|
||||
json_decode($result->get_error_message(), true)['message']
|
||||
);
|
||||
}
|
||||
|
||||
public function testZeroRemovesTheAssignmentAndNamesTheRemovedMenu(): void
|
||||
{
|
||||
Functions\expect('set_theme_mod')->once()->with('nav_menu_locations', []);
|
||||
$log = Mockery::mock(ChangeLog::class);
|
||||
@@ -51,16 +69,40 @@ final class MenuAssignLocationAbilityTest extends TestCase
|
||||
'lit/menu-assign-location',
|
||||
'menu_location',
|
||||
'primary-menu',
|
||||
'Zuweisung der Position primary-menu entfernt'
|
||||
'Menü "Hauptmenü" (ID 3) von der Position primary-menu entfernt'
|
||||
)
|
||||
->andReturn(7);
|
||||
|
||||
$result = (new MenuAssignLocationAbility($log))->execute(['location' => 'primary-menu', 'menu_id' => 0]);
|
||||
$result = (new MenuAssignLocationAbility($log))
|
||||
->execute(['location' => 'primary-menu', 'menu_id' => 0, 'confirm' => true]);
|
||||
|
||||
self::assertSame('unassigned', $result['changed'][0]['action']);
|
||||
self::assertSame(3, $result['previous_menu_id']);
|
||||
self::assertStringContainsString('"Hauptmenü" (ID 3)', $result['summary']);
|
||||
self::assertSame(7, $result['log_id']);
|
||||
}
|
||||
|
||||
public function testRemovingFromAnEmptyLocationNeedsNoConfirmation(): void
|
||||
{
|
||||
Functions\when('get_nav_menu_locations')->justReturn([]);
|
||||
Functions\expect('set_theme_mod')->once()->with('nav_menu_locations', []);
|
||||
$log = Mockery::mock(ChangeLog::class);
|
||||
$log->allows('record')->andReturn(8);
|
||||
|
||||
$result = (new MenuAssignLocationAbility($log))->execute(['location' => 'primary-menu', 'menu_id' => 0]);
|
||||
|
||||
self::assertTrue($result['ok']);
|
||||
self::assertNull($result['previous_menu_id']);
|
||||
}
|
||||
|
||||
public function testDescribesTheConfirmationForRemoval(): void
|
||||
{
|
||||
$ability = new MenuAssignLocationAbility(Mockery::mock(ChangeLog::class));
|
||||
|
||||
self::assertArrayHasKey('confirm', $ability->inputSchema()['properties']);
|
||||
self::assertStringContainsString('confirm: true', $ability->description());
|
||||
}
|
||||
|
||||
public function testUnknownMenuIsNotFound(): void
|
||||
{
|
||||
Functions\expect('set_theme_mod')->never();
|
||||
|
||||
@@ -5,6 +5,7 @@ declare(strict_types=1);
|
||||
namespace LIT\MCP\Tests\Unit\Integrations\WordPress\Menus;
|
||||
|
||||
use Brain\Monkey\Functions;
|
||||
use LIT\MCP\Abilities\Rev;
|
||||
use LIT\MCP\Integrations\WordPress\Menus\MenuGetAbility;
|
||||
use LIT\MCP\Integrations\WordPress\Menus\MenuListAbility;
|
||||
use LIT\MCP\Tests\Unit\TestCase;
|
||||
@@ -48,6 +49,8 @@ final class MenuReadAbilitiesTest extends TestCase
|
||||
|
||||
self::assertSame('Hauptmenü', $result['name']);
|
||||
self::assertSame('Start', $result['items'][0]['title']);
|
||||
self::assertSame(Rev::ofMenu([self::item(10, 0, 'Start')]), $result['menu_rev']);
|
||||
self::assertContains('menu_rev', $ability->outputSchema()['required']);
|
||||
self::assertSame('lit_not_found', $ability->execute(['menu_id' => 9])->get_error_code());
|
||||
}
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@ declare(strict_types=1);
|
||||
namespace LIT\MCP\Tests\Unit\Integrations\WordPress\Menus;
|
||||
|
||||
use Brain\Monkey\Functions;
|
||||
use LIT\MCP\Abilities\Rev;
|
||||
use LIT\MCP\Abilities\WriteFailed;
|
||||
use LIT\MCP\ChangeLog\ChangeLog;
|
||||
use LIT\MCP\Integrations\WordPress\Menus\MenuOperations;
|
||||
@@ -26,14 +27,52 @@ final class MenuSetItemsAbilityTest extends TestCase
|
||||
Functions\when('wp_get_nav_menu_items')->justReturn([self::item(10, 0, 'Home', 'custom', '/')]);
|
||||
}
|
||||
|
||||
/** The menu_rev of the items wp_get_nav_menu_items() currently returns (what lit/menu-get would show). */
|
||||
private static function rev(): string
|
||||
{
|
||||
return Rev::ofMenu(wp_get_nav_menu_items(3));
|
||||
}
|
||||
|
||||
public function testAStaleOrMissingMenuRevIsRefusedAndNothingIsWritten(): void
|
||||
{
|
||||
$writer = Mockery::mock(MenuWriter::class);
|
||||
$writer->expects('apply')->never();
|
||||
$ability = new MenuSetItemsAbility($writer, new MenuOperations(), Mockery::mock(ChangeLog::class));
|
||||
|
||||
$stale = $ability->execute(['menu_id' => 3, 'menu_rev' => 'abcdefabcdef', 'items' => [['id' => 10]]]);
|
||||
$missing = $ability->execute(['menu_id' => 3, 'items' => [['id' => 10]]]);
|
||||
|
||||
self::assertSame('lit_rev_mismatch', $stale->get_error_code());
|
||||
self::assertStringContainsString('lit/menu-get', $stale->get_error_data()['hint']);
|
||||
self::assertStringContainsString('Menü', $stale->get_error_message());
|
||||
self::assertSame('lit_rev_mismatch', $missing->get_error_code());
|
||||
self::assertContains('menu_rev', $ability->inputSchema()['required']);
|
||||
self::assertStringContainsString('menu_rev', $ability->description());
|
||||
}
|
||||
|
||||
public function testTheResultCarriesTheNewMenuRev(): void
|
||||
{
|
||||
$writer = Mockery::mock(MenuWriter::class);
|
||||
$writer->allows('plan')->andReturn(['errors' => [], 'removals' => [], 'warnings' => []]);
|
||||
$writer->allows('apply')->andReturn(['created' => 0, 'updated' => 1, 'removed' => 0]);
|
||||
$log = Mockery::mock(ChangeLog::class);
|
||||
$log->allows('record')->andReturn(30);
|
||||
|
||||
$result = (new MenuSetItemsAbility($writer, new MenuOperations(), $log))->execute(
|
||||
['menu_id' => 3, 'menu_rev' => self::rev(), 'items' => [['id' => 10]]]
|
||||
);
|
||||
|
||||
self::assertSame(self::rev(), $result['menu_rev']);
|
||||
}
|
||||
|
||||
public function testItemsAndOperationsAreMutuallyExclusive(): void
|
||||
{
|
||||
$ability = new MenuSetItemsAbility(new MenuWriter(), new MenuOperations(), Mockery::mock(ChangeLog::class));
|
||||
|
||||
self::assertSame('lit_validation_failed', $ability->execute(['menu_id' => 3])->get_error_code());
|
||||
self::assertSame('lit_validation_failed', $ability->execute(['menu_id' => 3, 'menu_rev' => self::rev()])->get_error_code());
|
||||
self::assertSame(
|
||||
'lit_validation_failed',
|
||||
$ability->execute(['menu_id' => 3, 'items' => [], 'operations' => [['op' => 'remove', 'id' => 10]]])
|
||||
$ability->execute(['menu_id' => 3, 'menu_rev' => self::rev(), 'items' => [], 'operations' => [['op' => 'remove', 'id' => 10]]])
|
||||
->get_error_code()
|
||||
);
|
||||
}
|
||||
@@ -52,7 +91,7 @@ final class MenuSetItemsAbilityTest extends TestCase
|
||||
Functions\expect('wp_delete_post')->never();
|
||||
$ability = new MenuSetItemsAbility(new MenuWriter(), new MenuOperations(), Mockery::mock(ChangeLog::class));
|
||||
|
||||
$result = $ability->execute(['menu_id' => 3, 'items' => []]);
|
||||
$result = $ability->execute(['menu_id' => 3, 'menu_rev' => self::rev(), 'items' => []]);
|
||||
|
||||
self::assertSame('lit_confirm_required', $result->get_error_code());
|
||||
self::assertSame([['id' => 10, 'title' => 'Home']], $result->get_error_data()['removals']);
|
||||
@@ -66,7 +105,7 @@ final class MenuSetItemsAbilityTest extends TestCase
|
||||
$ability = new MenuSetItemsAbility(new MenuWriter(), new MenuOperations(), Mockery::mock(ChangeLog::class));
|
||||
|
||||
$result = $ability->execute([
|
||||
'menu_id' => 3,
|
||||
'menu_id' => 3, 'menu_rev' => self::rev(),
|
||||
'confirm' => true,
|
||||
'items' => [['id' => 10], ['type' => 'custom', 'url' => 'javascript:alert(1)', 'title' => 'X']],
|
||||
]);
|
||||
@@ -81,7 +120,7 @@ final class MenuSetItemsAbilityTest extends TestCase
|
||||
$writer->expects('apply')->never();
|
||||
$ability = new MenuSetItemsAbility($writer, new MenuOperations(), Mockery::mock(ChangeLog::class));
|
||||
|
||||
$result = $ability->execute(['menu_id' => 3, 'operations' => [['op' => 'move', 'id' => 99]]]);
|
||||
$result = $ability->execute(['menu_id' => 3, 'menu_rev' => self::rev(), 'operations' => [['op' => 'move', 'id' => 99]]]);
|
||||
|
||||
self::assertSame('lit_validation_failed', $result->get_error_code());
|
||||
}
|
||||
@@ -95,7 +134,7 @@ final class MenuSetItemsAbilityTest extends TestCase
|
||||
$log->expects('record')->with('lit/menu-set-items', 'nav_menu', '3', Mockery::type('string'))->andReturn(21);
|
||||
|
||||
$result = (new MenuSetItemsAbility($writer, new MenuOperations(), $log))->execute([
|
||||
'menu_id' => 3,
|
||||
'menu_id' => 3, 'menu_rev' => self::rev(),
|
||||
'operations' => [['op' => 'add', 'item' => ['type' => 'custom', 'url' => '/blog', 'title' => 'Blog']]],
|
||||
]);
|
||||
|
||||
@@ -116,7 +155,7 @@ final class MenuSetItemsAbilityTest extends TestCase
|
||||
$log->allows('record')->andReturn(22);
|
||||
|
||||
$result = (new MenuSetItemsAbility($writer, new MenuOperations(), $log))->execute(
|
||||
['menu_id' => 3, 'items' => [], 'confirm' => true]
|
||||
['menu_id' => 3, 'menu_rev' => self::rev(), 'items' => [], 'confirm' => true]
|
||||
);
|
||||
|
||||
self::assertSame(10, $result['previous_items'][0]['id']);
|
||||
@@ -134,7 +173,7 @@ final class MenuSetItemsAbilityTest extends TestCase
|
||||
$log->expects('record')->never();
|
||||
|
||||
$result = (new MenuSetItemsAbility(new MenuWriter(), new MenuOperations(), $log))->execute(
|
||||
['menu_id' => 3, 'items' => MenuTree::build($items)]
|
||||
['menu_id' => 3, 'menu_rev' => self::rev(), 'items' => MenuTree::build($items)]
|
||||
);
|
||||
|
||||
self::assertSame('Menü "Hauptmenü": keine Änderung.', $result['summary']);
|
||||
@@ -151,7 +190,7 @@ final class MenuSetItemsAbilityTest extends TestCase
|
||||
$ability = new MenuSetItemsAbility($writer, new MenuOperations(), Mockery::mock(ChangeLog::class));
|
||||
|
||||
$result = $ability->execute(
|
||||
['menu_id' => 3, 'items' => [['type' => 'post', 'object_id' => 7]], 'allow_unpublished' => true]
|
||||
['menu_id' => 3, 'menu_rev' => self::rev(), 'items' => [['type' => 'post', 'object_id' => 7]], 'allow_unpublished' => true]
|
||||
);
|
||||
|
||||
self::assertSame('lit_validation_failed', $result->get_error_code());
|
||||
@@ -169,7 +208,7 @@ final class MenuSetItemsAbilityTest extends TestCase
|
||||
$log = Mockery::mock(ChangeLog::class);
|
||||
$log->allows('record')->andReturn(24);
|
||||
$ability = new MenuSetItemsAbility(new MenuWriter(), new MenuOperations(), $log);
|
||||
$input = ['menu_id' => 3, 'operations' => [['op' => 'add', 'item' => ['type' => 'post', 'object_id' => 7]]]];
|
||||
$input = ['menu_id' => 3, 'menu_rev' => self::rev(), 'operations' => [['op' => 'add', 'item' => ['type' => 'post', 'object_id' => 7]]]];
|
||||
|
||||
$refused = $ability->execute($input);
|
||||
$allowed = $ability->execute($input + ['allow_unpublished' => true]);
|
||||
@@ -190,7 +229,7 @@ final class MenuSetItemsAbilityTest extends TestCase
|
||||
$ability = new MenuSetItemsAbility(new MenuWriter(), new MenuOperations(), Mockery::mock(ChangeLog::class));
|
||||
|
||||
$result = $ability->execute([
|
||||
'menu_id' => 3,
|
||||
'menu_id' => 3, 'menu_rev' => self::rev(),
|
||||
'allow_unpublished' => true,
|
||||
'operations' => [['op' => 'add', 'item' => ['type' => 'post', 'object_id' => 7]]],
|
||||
]);
|
||||
@@ -209,7 +248,7 @@ final class MenuSetItemsAbilityTest extends TestCase
|
||||
$ability = new MenuSetItemsAbility($writer, new MenuOperations(), $log);
|
||||
|
||||
$this->expectException(WriteFailed::class);
|
||||
$ability->execute(['menu_id' => 3, 'items' => [['id' => 10]]]);
|
||||
$ability->execute(['menu_id' => 3, 'menu_rev' => self::rev(), 'items' => [['id' => 10]]]);
|
||||
}
|
||||
|
||||
public function testAPartialWriteIsLoggedAsPartial(): void
|
||||
@@ -222,7 +261,7 @@ final class MenuSetItemsAbilityTest extends TestCase
|
||||
$ability = new MenuSetItemsAbility($writer, new MenuOperations(), $log);
|
||||
|
||||
$this->expectException(WriteFailed::class);
|
||||
$ability->execute(['menu_id' => 3, 'items' => [['id' => 10]]]);
|
||||
$ability->execute(['menu_id' => 3, 'menu_rev' => self::rev(), 'items' => [['id' => 10]]]);
|
||||
}
|
||||
|
||||
public function testAChangeLogFailureIsOnlyAWarning(): void
|
||||
@@ -237,7 +276,7 @@ final class MenuSetItemsAbilityTest extends TestCase
|
||||
|
||||
try {
|
||||
$result = (new MenuSetItemsAbility($writer, new MenuOperations(), $log))->execute(
|
||||
['menu_id' => 3, 'items' => [['id' => 10]]]
|
||||
['menu_id' => 3, 'menu_rev' => self::rev(), 'items' => [['id' => 10]]]
|
||||
);
|
||||
} finally {
|
||||
ini_set('error_log', (string) $errorLog);
|
||||
@@ -253,7 +292,7 @@ final class MenuSetItemsAbilityTest extends TestCase
|
||||
Functions\when('current_user_can')->justReturn(false);
|
||||
$ability = new MenuSetItemsAbility(new MenuWriter(), new MenuOperations(), Mockery::mock(ChangeLog::class));
|
||||
|
||||
self::assertSame('lit_forbidden', $ability->permission(['menu_id' => 3])->get_error_code());
|
||||
self::assertSame('lit_forbidden', $ability->permission(['menu_id' => 3, 'menu_rev' => self::rev()])->get_error_code());
|
||||
}
|
||||
|
||||
public function testIsDestructiveAndDescribesWhenConfirmIsNeeded(): void
|
||||
|
||||
@@ -67,11 +67,40 @@ final class PostGuardTest extends TestCase
|
||||
self::assertTrue(PostGuard::missedSchedule(new WP_Post(['post_status' => 'future', 'post_date_gmt' => $past])));
|
||||
self::assertFalse(PostGuard::missedSchedule(new WP_Post(['post_status' => 'future', 'post_date_gmt' => $future])));
|
||||
self::assertFalse(PostGuard::missedSchedule(new WP_Post(['post_status' => 'draft', 'post_date_gmt' => $past])));
|
||||
Functions\when('get_gmt_from_date')->justReturn('');
|
||||
self::assertFalse(PostGuard::missedSchedule(
|
||||
new WP_Post(['post_status' => 'future', 'post_date_gmt' => '0000-00-00 00:00:00'])
|
||||
));
|
||||
}
|
||||
|
||||
public function testMissedScheduleIncludesTheLastMinuteBeforePublication(): void
|
||||
{
|
||||
// wp_update_post() publishes a future post on save when its date is within the next 60 seconds.
|
||||
$in30s = gmdate('Y-m-d H:i:s', time() + 30);
|
||||
$in5min = gmdate('Y-m-d H:i:s', time() + 300);
|
||||
|
||||
self::assertTrue(PostGuard::missedSchedule(new WP_Post(['post_status' => 'future', 'post_date_gmt' => $in30s])));
|
||||
self::assertFalse(PostGuard::missedSchedule(new WP_Post(['post_status' => 'future', 'post_date_gmt' => $in5min])));
|
||||
}
|
||||
|
||||
public function testMissedScheduleFallsBackToTheLocalDateWhenTheGmtDateIsZero(): void
|
||||
{
|
||||
Functions\when('get_gmt_from_date')->alias(
|
||||
static fn (string $local): string => $local === '2020-01-01 10:00:00' ? '2020-01-01 09:00:00' : $local
|
||||
);
|
||||
|
||||
self::assertTrue(PostGuard::missedSchedule(new WP_Post([
|
||||
'post_status' => 'future',
|
||||
'post_date_gmt' => '0000-00-00 00:00:00',
|
||||
'post_date' => '2020-01-01 10:00:00',
|
||||
])));
|
||||
self::assertFalse(PostGuard::missedSchedule(new WP_Post([
|
||||
'post_status' => 'future',
|
||||
'post_date_gmt' => '0000-00-00 00:00:00',
|
||||
'post_date' => '2099-01-01 10:00:00',
|
||||
])));
|
||||
}
|
||||
|
||||
public function testStatusStableRefusesAMissedScheduleWithAHint(): void
|
||||
{
|
||||
$post = new WP_Post(['ID' => 5, 'post_status' => 'future', 'post_date_gmt' => gmdate('Y-m-d H:i:s', time() - 60)]);
|
||||
|
||||
@@ -171,6 +171,11 @@ final class RevisionRestoreAbilityTest extends TestCase
|
||||
]);
|
||||
|
||||
self::assertSame('lit_write_failed', $result->get_error_code());
|
||||
self::assertStringNotContainsString('Nichts wurde gespeichert', $result->get_error_message());
|
||||
self::assertStringContainsString(
|
||||
'Die Änderung wurde nicht gespeichert (Revision 813 bleibt erhalten).',
|
||||
$result->get_error_message()
|
||||
);
|
||||
}
|
||||
|
||||
public function testFailuresAfterTheWriteOnlyAddWarnings(): void
|
||||
|
||||
@@ -231,6 +231,9 @@ final class PostReplaceWithCopyAbilityTest extends TestCase
|
||||
self::assertTrue($e->rolledBack);
|
||||
self::assertSame('lit_write_failed', $e->toError()->get_error_code());
|
||||
self::assertSame(88, $e->toError()->get_error_data()['backup_id']);
|
||||
$message = $e->toError()->get_error_message();
|
||||
self::assertStringNotContainsString('Nichts wurde gespeichert', $message);
|
||||
self::assertStringContainsString('Die Änderung wurde nicht gespeichert (Sicherung 88', $message);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -54,6 +54,33 @@ final class PostScheduleAbilityTest extends TestCase
|
||||
self::assertStringContainsString('2099-06-01 09:30', $result['summary']);
|
||||
}
|
||||
|
||||
public function testWarnsThatAPrivatePostBecomesPublic(): void
|
||||
{
|
||||
Functions\when('get_post')->justReturn(new WP_Post(['ID' => 5, 'post_type' => 'post', 'post_title' => 'Intern', 'post_status' => 'private']));
|
||||
Functions\when('wp_update_post')->justReturn(5);
|
||||
Functions\when('get_post_status')->justReturn('future');
|
||||
$log = Mockery::mock(ChangeLog::class);
|
||||
$log->allows('record')->andReturn(4);
|
||||
|
||||
$result = $this->ability($log)->execute(['post_id' => 5, 'date' => '2099-06-01 09:30']);
|
||||
|
||||
self::assertCount(1, $result['warnings']);
|
||||
self::assertStringContainsString('öffentlich', $result['warnings'][0]);
|
||||
self::assertStringContainsString('2099-06-01 09:30', $result['warnings'][0]);
|
||||
}
|
||||
|
||||
public function testADraftGetsNoPrivacyWarning(): void
|
||||
{
|
||||
Functions\when('wp_update_post')->justReturn(5);
|
||||
Functions\when('get_post_status')->justReturn('future');
|
||||
$log = Mockery::mock(ChangeLog::class);
|
||||
$log->allows('record')->andReturn(4);
|
||||
|
||||
$result = $this->ability($log)->execute(['post_id' => 5, 'date' => '2099-06-01 09:30']);
|
||||
|
||||
self::assertSame([], $result['warnings']);
|
||||
}
|
||||
|
||||
public function testAHookThrowingDuringTheWriteIsAPartialWrite(): void
|
||||
{
|
||||
Functions\when('wp_update_post')->alias(static function (): void {
|
||||
@@ -95,4 +122,18 @@ final class PostScheduleAbilityTest extends TestCase
|
||||
self::assertStringContainsString('Zukunft', $past->get_error_message());
|
||||
self::assertSame('lit_validation_failed', $impossible->get_error_code());
|
||||
}
|
||||
|
||||
public function testADateWithinTheNextMinuteIsRejectedBecauseWordPressWouldPublishAtOnce(): void
|
||||
{
|
||||
Functions\expect('wp_update_post')->never();
|
||||
// The start of the next minute: always in the future, but at most 60 seconds away.
|
||||
$soon = (new \DateTimeImmutable('@' . (intdiv(time(), 60) * 60 + 60)))
|
||||
->setTimezone(new DateTimeZone('Europe/Berlin'));
|
||||
Functions\when('get_post_status')->justReturn('future');
|
||||
|
||||
$result = $this->ability(Mockery::mock(ChangeLog::class))
|
||||
->execute(['post_id' => 5, 'date' => $soon->format('Y-m-d H:i')]);
|
||||
|
||||
self::assertSame('lit_validation_failed', $result->get_error_code());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,6 +16,19 @@ use WP_Post;
|
||||
|
||||
final class PostTrashAbilityTest extends TestCase
|
||||
{
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
$this->options([]);
|
||||
Functions\when('wp_get_associated_nav_menu_items')->justReturn([]);
|
||||
}
|
||||
|
||||
/** @param array<string, mixed> $options */
|
||||
private function options(array $options): void
|
||||
{
|
||||
Functions\when('get_option')->alias(static fn (string $name, mixed $default = false) => $options[$name] ?? $default);
|
||||
}
|
||||
|
||||
private function ability(ChangeLog $log): PostTrashAbility
|
||||
{
|
||||
Functions\when('get_post')->justReturn(new WP_Post(['ID' => 5, 'post_type' => 'page', 'post_title' => 'Alt', 'post_status' => 'publish']));
|
||||
@@ -93,6 +106,51 @@ final class PostTrashAbilityTest extends TestCase
|
||||
self::assertStringContainsString('bereits im Papierkorb', $result['summary']);
|
||||
}
|
||||
|
||||
public function testWarnsWhenTrashingTheFrontPageOrThePostsPage(): void
|
||||
{
|
||||
$this->options(['show_on_front' => 'page', 'page_on_front' => '5', 'page_for_posts' => '9']);
|
||||
Functions\when('wp_trash_post')->justReturn(new WP_Post(['ID' => 5]));
|
||||
$log = Mockery::mock(ChangeLog::class);
|
||||
$log->allows('record')->andReturn(3);
|
||||
$ability = $this->ability($log);
|
||||
|
||||
$confirm = $ability->execute(['post_id' => 5]);
|
||||
$result = $ability->execute(['post_id' => 5, 'confirm' => true]);
|
||||
|
||||
self::assertStringContainsString('Startseite', $confirm->get_error_message());
|
||||
self::assertCount(1, $result['warnings']);
|
||||
self::assertStringContainsString('Startseite', $result['warnings'][0]);
|
||||
self::assertTrue($result['ok']);
|
||||
|
||||
$this->options(['show_on_front' => 'page', 'page_on_front' => '9', 'page_for_posts' => '5']);
|
||||
self::assertStringContainsString('Beitragsseite', $ability->execute(['post_id' => 5, 'confirm' => true])['warnings'][0]);
|
||||
|
||||
$this->options(['show_on_front' => 'posts', 'page_on_front' => '5']);
|
||||
self::assertSame([], $ability->execute(['post_id' => 5, 'confirm' => true])['warnings']);
|
||||
}
|
||||
|
||||
public function testWarnsAndNamesTheMenusThatLinkThePost(): void
|
||||
{
|
||||
Functions\when('wp_get_associated_nav_menu_items')->alias(
|
||||
static fn (int $id, string $type): array => $id === 5 && $type === 'post_type' ? [40, 41] : []
|
||||
);
|
||||
Functions\when('wp_get_object_terms')->alias(
|
||||
static fn (array $ids, string $taxonomy, array $args): array =>
|
||||
$ids === [40, 41] && $taxonomy === 'nav_menu' && $args === ['fields' => 'names']
|
||||
? ['Hauptmenü', 'Footer', 'Hauptmenü']
|
||||
: []
|
||||
);
|
||||
Functions\when('wp_trash_post')->justReturn(new WP_Post(['ID' => 5]));
|
||||
$log = Mockery::mock(ChangeLog::class);
|
||||
$log->allows('record')->andReturn(3);
|
||||
|
||||
$result = $this->ability($log)->execute(['post_id' => 5, 'confirm' => true]);
|
||||
|
||||
self::assertCount(1, $result['warnings']);
|
||||
self::assertStringContainsString('"Hauptmenü", "Footer"', $result['warnings'][0]);
|
||||
self::assertSame(1, substr_count($result['warnings'][0], 'Hauptmenü'));
|
||||
}
|
||||
|
||||
public function testIsDestructiveAndIndirect(): void
|
||||
{
|
||||
$ability = $this->ability(Mockery::mock(ChangeLog::class));
|
||||
|
||||
Reference in New Issue
Block a user