fix: Umschreiber nennt Bibliotheks-IDs globaler Instanzen nur bei sichtbaren Bibliotheks-IDs (P13)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
d7a991d130
commit
65a207488e
@@ -14,6 +14,7 @@ use LIT\MCP\Integrations\Divi\Design\PageRewriter;
|
||||
use LIT\MCP\Integrations\Divi\Library\GlobalUsages;
|
||||
use LIT\MCP\Integrations\Divi\Library\UsageQuery;
|
||||
use LIT\MCP\Integrations\Divi\Library\UsageReport;
|
||||
use LIT\MCP\Integrations\Divi\Pages\DiviPageLoader;
|
||||
use LIT\MCP\Integrations\Divi\Pages\DiviSaver;
|
||||
use LIT\MCP\Integrations\Divi\Pages\SaveScope;
|
||||
use LIT\MCP\Integrations\Divi\Release\DiviLocked;
|
||||
@@ -94,13 +95,18 @@ final class PageRewriterTest extends TestCase
|
||||
|
||||
/**
|
||||
* The rewriter over $posts: they are the candidates (ID order) and what get_post() finds; the caller has every
|
||||
* capability. $report answers reportFor() (default: all posts, nothing blocked), $libraryReports report($id).
|
||||
* capability. $report answers reportFor() (default: all posts, nothing blocked), $libraryReports report($id);
|
||||
* $loader defaults to one whose user may see library IDs.
|
||||
*
|
||||
* @param list<WP_Post> $posts
|
||||
* @param array<int, UsageReport> $libraryReports
|
||||
*/
|
||||
private function rewriter(array $posts, ?UsageReport $report = null, array $libraryReports = []): PageRewriter
|
||||
{
|
||||
private function rewriter(
|
||||
array $posts,
|
||||
?UsageReport $report = null,
|
||||
array $libraryReports = [],
|
||||
?DiviPageLoader $loader = null
|
||||
): PageRewriter {
|
||||
LibraryFixtures::given($posts);
|
||||
$rows = array_map(
|
||||
static fn (WP_Post $post): array => [
|
||||
@@ -117,7 +123,7 @@ final class PageRewriterTest extends TestCase
|
||||
static fn (int $id): UsageReport => $libraryReports[$id] ?? self::report(0)
|
||||
);
|
||||
|
||||
return new PageRewriter($usages, LibraryFixtures::loader(), $this->saver(), $this->log);
|
||||
return new PageRewriter($usages, $loader ?? LibraryFixtures::loader(), $this->saver(), $this->log);
|
||||
}
|
||||
|
||||
/** Records post ID and scope, puts the content on the post and reports revision 900 + n. */
|
||||
@@ -454,6 +460,38 @@ final class PageRewriterTest extends TestCase
|
||||
self::assertStringContainsString('"modulePreset":["p-cta"]', (string) $post->post_content);
|
||||
}
|
||||
|
||||
/** Ruling P13: a user who may see library IDs is told which entry to edit. */
|
||||
public function testGlobalInstanceReasonNamesTheEntryWhenIdsAreVisible(): void
|
||||
{
|
||||
$rewriter = $this->rewriter([self::page(101, self::layout(self::INSTANCE, self::BUTTON))]);
|
||||
|
||||
$preview = $rewriter->preview(self::query(), self::assign(), null);
|
||||
$result = $rewriter->apply(self::ABILITY, self::query(), self::assign(), null, self::SUMMARY);
|
||||
|
||||
self::assertSame(
|
||||
's0.r0.c0.g0: globales Modul – im Bibliothekseintrag 1059 ändern',
|
||||
$preview['skipped'][0]['reason']
|
||||
);
|
||||
self::assertSame($preview['skipped'], $result['skipped']);
|
||||
}
|
||||
|
||||
/** Ruling P13: without the library right the reason names no library ID (dry run and write). */
|
||||
public function testGlobalInstanceReasonHidesTheEntryWithoutLibraryRights(): void
|
||||
{
|
||||
$loader = LibraryFixtures::loader(LibraryFixtures::access(['divi_library']));
|
||||
$rewriter = $this->rewriter([self::page(101, self::layout(self::INSTANCE, self::BUTTON))], null, [], $loader);
|
||||
self::assertFalse($loader->libraryIdsVisible());
|
||||
|
||||
$preview = $rewriter->preview(self::query(), self::assign(), null);
|
||||
$result = $rewriter->apply(self::ABILITY, self::query(), self::assign(), null, self::SUMMARY);
|
||||
|
||||
$expected = [['post_id' => 101, 'reason' => 's0.r0.c0.g0: globales Modul – im Divi-Builder ändern']];
|
||||
self::assertSame($expected, $preview['skipped']);
|
||||
self::assertSame($expected, $result['skipped']);
|
||||
self::assertSame([101], array_column($result['saved'], 'post_id'));
|
||||
self::assertStringNotContainsString('1059', (string) json_encode([$preview, $result]));
|
||||
}
|
||||
|
||||
/** R8: library entries are usages of their own, saved with DiviWriter's scope. */
|
||||
public function testLibraryEntriesAreSavedWithTheirScope(): void
|
||||
{
|
||||
|
||||
@@ -86,7 +86,7 @@ final class TreeRewriteTest extends TestCase
|
||||
);
|
||||
$before = Serializer::document($document);
|
||||
|
||||
$result = (new TreeRewrite(self::touchButtons()))->apply(NodeIndex::build($document));
|
||||
$result = (new TreeRewrite(self::touchButtons(), true))->apply(NodeIndex::build($document));
|
||||
|
||||
self::assertSame([], $result['changed']);
|
||||
self::assertSame(
|
||||
@@ -96,6 +96,21 @@ final class TreeRewriteTest extends TestCase
|
||||
self::assertSame($before, Serializer::document($document), 'instances are never rewritten');
|
||||
}
|
||||
|
||||
/** Ruling P13, fail closed: without $revealLibraryIds the reason names no library ID. */
|
||||
public function testGlobalInstanceReasonHidesTheLibraryIdByDefault(): void
|
||||
{
|
||||
$document = self::document(
|
||||
'<!-- wp:divi/global-layout {"globalModule":"1058","blockName":"divi/button"} /-->'
|
||||
);
|
||||
|
||||
$result = (new TreeRewrite(self::touchButtons()))->apply(NodeIndex::build($document));
|
||||
|
||||
self::assertSame(
|
||||
[['id' => 's0.r0.c0.g0', 'reason' => 'globales Modul – im Divi-Builder ändern']],
|
||||
$result['skipped']
|
||||
);
|
||||
}
|
||||
|
||||
public function testBlocksWithUnreadableAttributesAreSkippedToo(): void
|
||||
{
|
||||
$document = self::document('<!-- wp:divi/button {"a":1,} /-->');
|
||||
|
||||
Reference in New Issue
Block a user