diff --git a/.github/workflows/phpunit-tests.yml b/.github/workflows/phpunit-tests.yml index f46b419656a44..b387ebacd0874 100644 --- a/.github/workflows/phpunit-tests.yml +++ b/.github/workflows/phpunit-tests.yml @@ -252,7 +252,7 @@ jobs: php: [ '7.4', '8.0', '8.4' ] db-type: [ 'mysql' ] db-version: [ '8.4' ] - phpunit-test-groups: [ 'html-api-html5lib-tests' ] + phpunit-test-groups: [ 'html-api-web-platform-tests' ] # A matrix value is needed in the 'name' directive for proper grouping in the GitHub UI. label: [ 'HTML API' ] with: @@ -305,7 +305,7 @@ jobs: - php: '8.4' db-version: '9.7' db-type: 'mysql' - phpunit-test-groups: 'html-api-html5lib-tests' + phpunit-test-groups: 'html-api-web-platform-tests' exclude: # Exclude PHP versions that are not supported by the database versions. diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 4b6c149867c7d..2b1a8c9dab784 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -29,7 +29,7 @@ ms-files ms-required external-http - html-api-html5lib-tests + html-api-web-platform-tests diff --git a/tests/phpunit/data/html5lib-tests/AUTHORS.rst b/tests/phpunit/data/html5lib-tests/AUTHORS.rst deleted file mode 100644 index 4a7de17ad456c..0000000000000 --- a/tests/phpunit/data/html5lib-tests/AUTHORS.rst +++ /dev/null @@ -1,34 +0,0 @@ -Credits -======= - -The ``html5lib`` test data is maintained by: - -- James Graham -- Geoffrey Sneddon - - -Contributors ------------- - -- Adam Barth -- Andi Sidwell -- Anne van Kesteren -- David Flanagan -- Edward Z. Yang -- Geoffrey Sneddon -- Henri Sivonen -- Ian Hickson -- Jacques Distler -- James Graham -- Lachlan Hunt -- lantis63 -- Mark Pilgrim -- Mats Palmgren -- Ms2ger -- Nolan Waite -- Philip Taylor -- Rafael Weinstein -- Ryan King -- Sam Ruby -- Simon Pieters -- Thomas Broyer diff --git a/tests/phpunit/data/html5lib-tests/LICENSE b/tests/phpunit/data/html5lib-tests/LICENSE deleted file mode 100644 index 8812371b41cfc..0000000000000 --- a/tests/phpunit/data/html5lib-tests/LICENSE +++ /dev/null @@ -1,21 +0,0 @@ -Copyright (c) 2006-2013 James Graham, Geoffrey Sneddon, and -other contributors - -Permission is hereby granted, free of charge, to any person obtaining -a copy of this software and associated documentation files (the -"Software"), to deal in the Software without restriction, including -without limitation the rights to use, copy, modify, merge, publish, -distribute, sublicense, and/or sell copies of the Software, and to -permit persons to whom the Software is furnished to do so, subject to -the following conditions: - -The above copyright notice and this permission notice shall be -included in all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/tests/phpunit/data/html5lib-tests/README.md b/tests/phpunit/data/html5lib-tests/README.md deleted file mode 100644 index be775c8b497b5..0000000000000 --- a/tests/phpunit/data/html5lib-tests/README.md +++ /dev/null @@ -1,25 +0,0 @@ -# html5lib-tests - -This directory contains a third-party test suite used for testing the WordPress HTML API. - -`html5lib-tests` can be found on GitHub at [html5lib/html5lib-tests](https://github.com/html5lib/html5lib-tests). - -The necessary files have been copied to this directory: - -- `AUTHORS.rst` -- `LICENSE` -- `README.md` -- `tree-construction/README.md` -- `tree-construction/*.dat` - -The version of these files was taken from the git commit with -SHA [`a9f44960a9fedf265093d22b2aa3c7ca123727b9`](https://github.com/html5lib/html5lib-tests/commit/a9f44960a9fedf265093d22b2aa3c7ca123727b9). - -## Updating - -If there have been changes to the html5lib-tests repository, this test suite can be updated. In -order to update: - -1. Check out the latest version of git repository mentioned above. -1. Copy the files listed above into this directory. -1. Update the SHA mentioned in this README file with the new html5lib-tests SHA. diff --git a/tests/phpunit/data/html5lib-tests/.gitattributes b/tests/phpunit/data/web-platform-tests/.gitattributes similarity index 100% rename from tests/phpunit/data/html5lib-tests/.gitattributes rename to tests/phpunit/data/web-platform-tests/.gitattributes diff --git a/tests/phpunit/data/web-platform-tests/LICENSE.md b/tests/phpunit/data/web-platform-tests/LICENSE.md new file mode 100644 index 0000000000000..39c46d03ac298 --- /dev/null +++ b/tests/phpunit/data/web-platform-tests/LICENSE.md @@ -0,0 +1,11 @@ +# The 3-Clause BSD License + +Copyright © web-platform-tests contributors + +Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: + +1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. +2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. +3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/tests/phpunit/data/web-platform-tests/README.md b/tests/phpunit/data/web-platform-tests/README.md new file mode 100644 index 0000000000000..a111e20b48831 --- /dev/null +++ b/tests/phpunit/data/web-platform-tests/README.md @@ -0,0 +1,19 @@ +# Web Platform Tests + +This directory contains a third-party test suite used for testing the WordPress HTML API. + +The tests are maintained by the Web Platform Tests project. +The current tests can be found on GitHub at +[`web-platform-tests/wpt/html/syntax/parsing/resources`](https://github.com/web-platform-tests/wpt/tree/master/html/syntax/parsing/resources). + +The version of the WPT files was taken from the git commit with +SHA [`1ae157bacf6cb1db64a60875800a30c80a4fc93c`](https://github.com/web-platform-tests/wpt/tree/1ae157bacf6cb1db64a60875800a30c80a4fc93c/html/syntax/parsing/resources). + +## Updating + +If there have been changes to the Web Platform Tests repository, this test suite can be updated. In +order to update: + +1. Check out the latest version of git repository mentioned above. +1. Replace the local `html_syntax_parsing_resources/` directory with the WPT repo's `html/syntax/parsing/resources` directory. +1. Update the SHA mentioned in this README file with the new Web Platform Tests SHA. diff --git a/tests/phpunit/data/html5lib-tests/tree-construction/README.md b/tests/phpunit/data/web-platform-tests/html_syntax_parsing_resources/README.md similarity index 99% rename from tests/phpunit/data/html5lib-tests/tree-construction/README.md rename to tests/phpunit/data/web-platform-tests/html_syntax_parsing_resources/README.md index 4737a3a867e86..5005d4ec99367 100644 --- a/tests/phpunit/data/html5lib-tests/tree-construction/README.md +++ b/tests/phpunit/data/web-platform-tests/html_syntax_parsing_resources/README.md @@ -31,7 +31,7 @@ errors. Then there \*may\* be a line that says "\#document-fragment", which must be followed by a newline (LF), followed by a string of characters that -indicates the context element, followed by a newline (LF). If the string +indicates the context element, followed by a newline (LF). If the string of characters starts with "svg ", the context element is in the SVG namespace and the substring after "svg " is the local name. If the string of characters starts with "math ", the context element is in the diff --git a/tests/phpunit/data/html5lib-tests/tree-construction/adoption01.dat b/tests/phpunit/data/web-platform-tests/html_syntax_parsing_resources/adoption01.dat similarity index 100% rename from tests/phpunit/data/html5lib-tests/tree-construction/adoption01.dat rename to tests/phpunit/data/web-platform-tests/html_syntax_parsing_resources/adoption01.dat diff --git a/tests/phpunit/data/html5lib-tests/tree-construction/adoption02.dat b/tests/phpunit/data/web-platform-tests/html_syntax_parsing_resources/adoption02.dat similarity index 64% rename from tests/phpunit/data/html5lib-tests/tree-construction/adoption02.dat rename to tests/phpunit/data/web-platform-tests/html_syntax_parsing_resources/adoption02.dat index e54d8033bac71..acd388547a1ec 100644 --- a/tests/phpunit/data/html5lib-tests/tree-construction/adoption02.dat +++ b/tests/phpunit/data/web-platform-tests/html_syntax_parsing_resources/adoption02.dat @@ -37,3 +37,20 @@ |
| | + +#data +
+#errors +(1,6): expected-doctype-but-got-start-tag +(1,22): unexpected-start-tag-implies-table-voodoo +(1,30): end-tag-too-early-named +(1,36): unexpected-start-tag-implies-end-tag +(1,36): expected-closing-tag-but-got-eof +#document +| +| +| +| +| +| +| diff --git a/tests/phpunit/data/html5lib-tests/tree-construction/blocks.dat b/tests/phpunit/data/web-platform-tests/html_syntax_parsing_resources/blocks.dat similarity index 100% rename from tests/phpunit/data/html5lib-tests/tree-construction/blocks.dat rename to tests/phpunit/data/web-platform-tests/html_syntax_parsing_resources/blocks.dat diff --git a/tests/phpunit/data/html5lib-tests/tree-construction/comments01.dat b/tests/phpunit/data/web-platform-tests/html_syntax_parsing_resources/comments01.dat similarity index 100% rename from tests/phpunit/data/html5lib-tests/tree-construction/comments01.dat rename to tests/phpunit/data/web-platform-tests/html_syntax_parsing_resources/comments01.dat diff --git a/tests/phpunit/data/web-platform-tests/html_syntax_parsing_resources/common.js b/tests/phpunit/data/web-platform-tests/html_syntax_parsing_resources/common.js new file mode 100644 index 0000000000000..b3ac9ece70c43 --- /dev/null +++ b/tests/phpunit/data/web-platform-tests/html_syntax_parsing_resources/common.js @@ -0,0 +1,24 @@ +function mark_diffs(expected, actual) { + var expected_lines = expected.split("\n"); + var actual_lines = actual.split("\n"); + + var max_length = Math.max(expected_lines.length, actual_lines.length); + + var expected_diff = ["code", {}]; + var actual_diff = ["code", {}]; + + for (var i=0; i +| | | | diff --git a/tests/phpunit/data/html5lib-tests/tree-construction/inbody01.dat b/tests/phpunit/data/web-platform-tests/html_syntax_parsing_resources/inbody01.dat similarity index 100% rename from tests/phpunit/data/html5lib-tests/tree-construction/inbody01.dat rename to tests/phpunit/data/web-platform-tests/html_syntax_parsing_resources/inbody01.dat diff --git a/tests/phpunit/data/html5lib-tests/tree-construction/isindex.dat b/tests/phpunit/data/web-platform-tests/html_syntax_parsing_resources/isindex.dat similarity index 100% rename from tests/phpunit/data/html5lib-tests/tree-construction/isindex.dat rename to tests/phpunit/data/web-platform-tests/html_syntax_parsing_resources/isindex.dat diff --git a/tests/phpunit/data/html5lib-tests/tree-construction/main-element.dat b/tests/phpunit/data/web-platform-tests/html_syntax_parsing_resources/main-element.dat similarity index 100% rename from tests/phpunit/data/html5lib-tests/tree-construction/main-element.dat rename to tests/phpunit/data/web-platform-tests/html_syntax_parsing_resources/main-element.dat diff --git a/tests/phpunit/data/html5lib-tests/tree-construction/math.dat b/tests/phpunit/data/web-platform-tests/html_syntax_parsing_resources/math.dat similarity index 100% rename from tests/phpunit/data/html5lib-tests/tree-construction/math.dat rename to tests/phpunit/data/web-platform-tests/html_syntax_parsing_resources/math.dat diff --git a/tests/phpunit/data/html5lib-tests/tree-construction/menuitem-element.dat b/tests/phpunit/data/web-platform-tests/html_syntax_parsing_resources/menuitem-element.dat similarity index 97% rename from tests/phpunit/data/html5lib-tests/tree-construction/menuitem-element.dat rename to tests/phpunit/data/web-platform-tests/html_syntax_parsing_resources/menuitem-element.dat index fb13c3c33b0ab..f7c8e2c3ca74e 100644 --- a/tests/phpunit/data/html5lib-tests/tree-construction/menuitem-element.dat +++ b/tests/phpunit/data/web-platform-tests/html_syntax_parsing_resources/menuitem-element.dat @@ -161,13 +161,14 @@ #data #errors -33: Stray start tag “menuitem”. +1:34: ERROR: End tag 'select' isn't allowed here. Currently open tags: html, body, select, menuitem. #document | | | | |
+#document +| +| +| +| +| + +#data +
+#document +| +| +| +| +| +| +| + +#data + +#document +| +| +|

TEXT +#errors +#script-on +#document +| +| +| +|

+| +| id="B" +|

X +#errors +#script-on +#document +| +| +| +|

+| +| size="4" +| +| size="4" +| +| size="5" +| 3 +#errors +#script-on +#document +| +| +| +| "1" +| 4 +#errors +#script-on +#document +| +| +| +| "1" +| ` +// and lists each .dat file as ``. +// We fetch resources/NAME.dat, parse it, and run each entry: document tests +// parse via the page's run_type; entries with #document-fragment always parse +// via innerHTML. + +(() => { + "use strict"; + + const NAMESPACES = { + html: "http://www.w3.org/1999/xhtml", + math: "http://www.w3.org/1998/Math/MathML", + mathml: "http://www.w3.org/1998/Math/MathML", + svg: "http://www.w3.org/2000/svg", + xlink: "http://www.w3.org/1999/xlink", + xml: "http://www.w3.org/XML/1998/namespace", + xmlns: "http://www.w3.org/2000/xmlns/", + }; + const PREFIXES = {}; + for (const prefix of Object.keys(NAMESPACES)) { + PREFIXES[NAMESPACES[prefix]] = prefix; + } + PREFIXES[NAMESPACES.mathml] = "math"; + + function serializeTree(root) { + root.normalize(); + const lines = []; + // The .dat #document format prefixes each line with "|" + N spaces of + // indent, where the document itself has no "|" line, its direct children + // get 1 space, their children get 3, then 5, 7, … (i.e. 2*depth - 1). + const walk = (node, depth) => { + const pad = depth > 0 ? " ".repeat(2 * depth - 1) : ""; + const innerPad = " ".repeat(2 * depth + 1); + switch (node.nodeType) { + case Node.DOCUMENT_TYPE_NODE: + if (node.name) { + if (node.publicId || node.systemId) { + lines.push(`|${pad}`); + } else { + lines.push(`|${pad}`); + } + } else { + lines.push(`|${pad}`); + } + break; + case Node.DOCUMENT_NODE: + lines.push("#document"); + break; + case Node.DOCUMENT_FRAGMENT_NODE: + lines.push("#document-fragment"); + break; + case Node.COMMENT_NODE: + lines.push(`|${pad}`); + break; + case Node.PROCESSING_INSTRUCTION_NODE: + lines.push(`|${pad}`); + break; + case Node.TEXT_NODE: + lines.push(`|${pad}"${node.nodeValue}"`); + break; + case Node.ELEMENT_NODE: { + if (node.getAttribute("data-skip") !== null) return; + const tag = (node.namespaceURI && node.namespaceURI !== NAMESPACES.html) + ? `${PREFIXES[node.namespaceURI]} ${node.localName}` + : node.localName; + lines.push(`|${pad}<${tag}>`); + const attrs = [...node.attributes].map(a => [ + (a.namespaceURI ? PREFIXES[a.namespaceURI] + " " : "") + a.localName, + a.value, + ]); + attrs.sort((a, b) => a[0] === b[0] ? 0 : (a[0] > b[0] ? 1 : -1)); + for (const [name, value] of attrs) { + lines.push(`|${innerPad}${name}="${value}"`); + } + if (node.namespaceURI === NAMESPACES.html && node.localName === "template") { + lines.push(`|${innerPad}content`); + for (const child of node.content.childNodes) walk(child, depth + 2); + } + break; + } + } + for (const child of node.childNodes) walk(child, depth + 1); + }; + walk(root, 0); + return lines.join("\n"); + } + + // Per-flavor runners. Each fills `iframe` with the parser's output, then + // serializes and asserts. record() captures input/expected/actual on the + // shared map so failure diffs can be rendered after the run. + function makeDocRunner(inject) { + return ({ iframe, t, id, input, expected, record }) => { + record({ id, input, expected, actual: null }); + iframe.onload = () => t.step(() => { + iframe.onload = null; + const actual = serializeTree(iframe.contentDocument); + record({ id, input, expected, actual }); + assert_equals(actual, expected); + t.done(); + }); + inject(iframe, input, t); + }; + } + + const RUNNERS = { + url: makeDocRunner((iframe, input, t) => { + const blob = new Blob([input], { type: "text/html" }); + const url = URL.createObjectURL(blob); + iframe.src = url; + t.add_cleanup(() => URL.revokeObjectURL(url)); + }), + write: makeDocRunner((iframe, input) => { + iframe.contentDocument.open(); + iframe.contentDocument.write(input); + iframe.contentDocument.close(); + }), + write_single: makeDocRunner((iframe, input) => { + iframe.contentDocument.open(); + for (const ch of input) iframe.contentDocument.write(ch); + iframe.contentDocument.close(); + }), + innerHTML: ({ iframe, t, id, input, expected, container, record }) => { + const parts = container.split(" "); + const containerEl = parts.length > 1 + ? document.createElementNS(NAMESPACES[parts[0]], `${parts[0]}:${parts[1]}`) + : document.createElement(container); + containerEl.innerHTML = input; + const root = (containerEl.namespaceURI === NAMESPACES.html && containerEl.localName === "template") + ? containerEl.content : containerEl; + let actual = serializeTree(root); + record({ id, input, expected, actual, container }); + // serializeTree emits "#document-fragment"; the .dat expected tree uses + // "#document" as its root marker. + const lines = actual.split("\n"); + assert_not_equals(lines[0], "