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' + ); + } +}