From f1937ca6fffc055214bd1bfff2247e8843fa5da2 Mon Sep 17 00:00:00 2001 From: Jan-Niclas Loosen Date: Sun, 27 Sep 2026 04:25:53 +0200 Subject: [PATCH] test: file-based editor byte-identity regression; filters fixture with JSON escapes (P20) synthetic-divi-filters.html now stores its paragraph as Divi does (unicode escapes, bytes built with chr(92) and checked with od). A data-provider test inserts a section as a user without unfiltered_html into every Divi 5 fixture page read from disk and asserts that every other byte stays. Co-Authored-By: Claude Opus 5.5 (1M context) --- .../Fixtures/divi/synthetic-divi-filters.html | 2 +- .../Divi/Pages/DiviEditorByteIdentityTest.php | 69 +++++++++++++++++++ 2 files changed, 70 insertions(+), 1 deletion(-) create mode 100644 tests/Unit/Integrations/Divi/Pages/DiviEditorByteIdentityTest.php diff --git a/tests/Fixtures/divi/synthetic-divi-filters.html b/tests/Fixtures/divi/synthetic-divi-filters.html index 2103459..e310d16 100644 --- a/tests/Fixtures/divi/synthetic-divi-filters.html +++ b/tests/Fixtures/divi/synthetic-divi-filters.html @@ -1 +1 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/tests/Unit/Integrations/Divi/Pages/DiviEditorByteIdentityTest.php b/tests/Unit/Integrations/Divi/Pages/DiviEditorByteIdentityTest.php new file mode 100644 index 0000000..ab2696e --- /dev/null +++ b/tests/Unit/Integrations/Divi/Pages/DiviEditorByteIdentityTest.php @@ -0,0 +1,69 @@ + */ + public static function pages(): array + { + $pages = []; + foreach (['', 'stage3/'] as $dir) { + foreach (glob(dirname(__DIR__, 4) . '/Fixtures/divi/' . $dir . '*.html') ?: [] as $file) { + $name = $dir . basename($file); + if ($name !== 'divi4-shortcodes.html') { + $pages[$name] = [$name]; + } + } + } + + return $pages; + } + + /** @dataProvider pages */ + public function testAnEditorInsertKeepsEveryOtherByte(string $fixture): void + { + $original = DiviFixtures::markup($fixture); + self::assertNotSame('', $original, $fixture); + DiviFixtures::givenPost($original); + Functions\when('get_preview_post_link')->justReturn('https://kunde.test/?page_id=7&preview=true'); + $saved = []; + + $result = (new DiviInsertAbility(DiviWriterFixture::writer($saved, unfiltered: false)))->execute([ + 'post_id' => 7, + 'tree_rev' => Rev::of($original), + 'nodes' => [['type' => 'section']], + ]); + + self::assertTrue($result['ok'] ?? false, $fixture . ': ' . json_encode($result)); + self::assertCount(1, $saved); + $node = NodeIndex::build((new Parser())->parse($saved[0]))->find($result['changed'][0]['id']); + self::assertNotNull($node, $fixture); + $inserted = Serializer::block($node); + $at = strpos($saved[0], $inserted); + self::assertNotFalse($at, $fixture); + self::assertSame( + $original, + substr($saved[0], 0, (int) $at) . substr($saved[0], (int) $at + strlen($inserted)), + $fixture . ': only the new section was added' + ); + } +}