archive-casino-wp-builder / test-full-html-editor.mjs
coingimp's picture
Release ReVault menu-cleanroom-3.2.0
4818f8a verified
Raw
History Blame Contribute Delete
2.2 kB
import assert from "node:assert/strict";
import { readFile } from "node:fs/promises";
import { validateFullDocumentEdit } from "./server.mjs";
const original = `<!doctype html>
<html lang="de-DE"><head><title>Stagewar</title><script src="{{ACI_ASSET_URL}}/site.js"></script></head>
<body><header><ul><li id="menu-item-126"><a href="/page-id-639/">Extras</a><ul><li>Wallpaper</li></ul></li><li><a href="/">Home</a></li></ul></header><main class="entry-content"><p>Text</p></main><footer>Footer</footer></body></html>`;
const removedMenuItem = original.replace(/<li id="menu-item-126">[\s\S]*?<\/li><li>/, "<li>");
assert.equal(validateFullDocumentEdit(original, removedMenuItem), "");
assert.match(validateFullDocumentEdit(original, "<main>fragment</main>"), /full HTML document/i);
assert.match(
validateFullDocumentEdit(original, original.replace("</body>", '<script>alert(1)</script></body>')),
/cannot add or modify executable scripts/i
);
assert.match(
validateFullDocumentEdit(original, original.replace("site.js", "changed.js")),
/cannot add or modify executable scripts/i
);
assert.match(
validateFullDocumentEdit(original, original.replace("<p>Text</p>", "<p onmouseover=alert(1)>Text</p>")),
/cannot add or modify executable scripts/i
);
assert.equal(validateFullDocumentEdit(original, original.replace("<title>Stagewar</title>", "<title>Edited</title>")), "");
const [serverSource, appSource, htmlSource] = await Promise.all([
readFile(new URL("./server.mjs", import.meta.url), "utf8"),
readFile(new URL("./public/app.js", import.meta.url), "utf8"),
readFile(new URL("./public/index.html", import.meta.url), "utf8")
]);
assert.match(serverSource, /scope === "document"/);
assert.match(serverSource, /manualFullHtmlEdit: true/);
assert.match(serverSource, /acwpb_theme_validate_full_document_edit/);
assert.match(serverSource, /_acwpb_recovered_full_html_enabled/);
assert.match(serverSource, /Save full HTML/);
assert.match(serverSource, /acwpb-full-html-source/);
assert.match(appSource, /currentEditScope/);
assert.match(htmlSource, /id="codeEditorScope"/);
assert.match(htmlSource, /id="fullHtmlConfirmCheckbox"/);
console.log("Full HTML editor tests passed: 15/15");