1 /*
2 * Copyright (c) 2002-2025 Gargoyle Software Inc.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 * https://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15 package org.htmlunit.html;
16
17 import org.htmlunit.SimpleWebTestCase;
18 import org.junit.jupiter.api.Test;
19
20 /**
21 * Tests for {@link HtmlOrderedList}.
22 *
23 * @author Ahmed Ashour
24 * @author Marc Guillemot
25 * @author Ronald Brill
26 */
27 public class HtmlOrderedListTest extends SimpleWebTestCase {
28
29 /**
30 * @throws Exception if the test fails
31 */
32 @Test
33 public void asNormalizedText() throws Exception {
34 final String html = DOCTYPE_HTML
35 + "<html><head>\n"
36 + "</head><body>\n"
37 + " <ol id='foo'>\n"
38 + " <li>first item</li>\n"
39 + " <li>second item</li>\n"
40 + "something without li node\n"
41 + " <li>third item</li>\n"
42 + " </ol>\n"
43 + " </table>\n"
44 + "</body></html>";
45
46 final HtmlPage page = loadPage(html);
47 final HtmlElement node = page.getHtmlElementById("foo");
48 final String expectedText = "1. first item"
49 + "\n2. second item"
50 + "\nsomething without li node"
51 + "\n3. third item";
52
53 assertEquals(expectedText, node.asNormalizedText());
54 assertEquals(expectedText, page.asNormalizedText());
55 }
56
57 /**
58 * Browsers ignore closing information in a self closing OL tag.
59 * @throws Exception if the test fails
60 */
61 @Test
62 public void asXml() throws Exception {
63 final String content = DOCTYPE_HTML
64 + "<html><head></head><body>\n"
65 + "<ol id='myNode'></ol>\n"
66 + "foo\n"
67 + "</form></body></html>";
68 final HtmlPage page = loadPage(content);
69 final HtmlElement element = page.getHtmlElementById("myNode");
70
71 // assertEquals("<ol id=\"myNode\"></ol>", element.asXml());
72 assertEquals("<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\r\n"
73 + "<html>\r\n"
74 + " <head/>\r\n"
75 + " <body>\r\n"
76 + " <ol id=\"myNode\"></ol>\n"
77 + "foo\n"
78 + "</body>\r\n"
79 + "</html>", page.asXml());
80 }
81 }