1 27 package org.htmlparser.tests.tagTests; 28 29 import org.htmlparser.tags.FormTag; 30 import org.htmlparser.tags.InputTag; 31 import org.htmlparser.tags.TableColumn; 32 import org.htmlparser.tags.TableRow; 33 import org.htmlparser.tags.TableTag; 34 import org.htmlparser.tests.ParserTestCase; 35 import org.htmlparser.util.ParserException; 36 37 public class InputTagTest extends ParserTestCase { 38 39 static 40 { 41 System.setProperty ("org.htmlparser.tests.tagTests.InputTagTest", "InputTagTest"); 42 } 43 44 public InputTagTest(String name) 45 { 46 super(name); 47 } 48 49 public void testToHTML() throws ParserException 50 { 51 String testHTML = "<INPUT type=\"text\" name=\"Google\">"; 52 createParser(testHTML); 53 parseAndAssertNodeCount(1); 54 assertTrue("Node 1 should be INPUT Tag",node[0] instanceof InputTag); 55 InputTag InputTag; 56 InputTag = (InputTag) node[0]; 57 assertStringEquals ("HTML String",testHTML,InputTag.toHtml()); 58 } 59 60 64 public void testToHTML2() throws ParserException 65 { 66 String testHTML ="<INPUT type=\"checkbox\" " 67 +"name=\"cbCheck\" checked>"; 68 createParser(testHTML); 69 parseAndAssertNodeCount(1); 70 assertTrue("Node 1 should be INPUT Tag", 71 node[0] instanceof InputTag); 72 InputTag InputTag; 73 InputTag = (InputTag) node[0]; 74 assertStringEquals("HTML String", testHTML, InputTag.toHtml()); 75 } 76 77 public void testScan() throws ParserException 78 { 79 createParser("<INPUT type=\"text\" name=\"Google\">","http://www.google.com/test/index.html"); 80 parseAndAssertNodeCount(1); 81 assertTrue(node[0] instanceof InputTag); 82 83 InputTag inputTag = (InputTag) node[0]; 85 assertEquals("Type","text",inputTag.getAttribute("TYPE")); 86 assertEquals("Name","Google",inputTag.getAttribute("NAME")); 87 } 88 89 92 public void testTable () throws ParserException 93 { 94 String html = 95 "<table>" + 96 "<tr>" + 97 "<td>" + 98 "<form>" + 99 "<input name=input1>" + 100 "</td>" + 101 "<tr>" + 103 "<td>" + 104 "<input name=input2>" + 105 "</td>" + 106 "</tr>" + 107 "</form>" + 108 "</table>"; 109 createParser (html); 110 parseAndAssertNodeCount (1); 111 assertTrue ("not a table", node[0] instanceof TableTag); 112 TableTag table = (TableTag)node[0]; 113 assertTrue ("not two rows", 2 == table.getRowCount ()); 114 TableRow row = table.getRow (0); 116 assertTrue ("not one column", 1 == row.getColumnCount ()); 117 TableColumn column = row.getColumns ()[0]; 118 assertTrue ("not one child", 1 == column.getChildCount ()); 119 assertTrue ("column doesn't have a form", column.getChild (0) instanceof FormTag); 120 FormTag form = (FormTag)column.getChild (0); 121 assertTrue ("form only has one input field", 2 == form.getFormInputs ().size ()); 122 } 123 124 }
| Popular Tags
|