1 27 package org.htmlparser.tests.tagTests; 28 29 import org.htmlparser.tags.OptionTag; 30 import org.htmlparser.tags.SelectTag; 31 import org.htmlparser.tests.ParserTestCase; 32 import org.htmlparser.util.ParserException; 33 34 public class SelectTagTest extends ParserTestCase 35 { 36 static 37 { 38 System.setProperty ("org.htmlparser.tests.tagTests.SelectTagTest", "SelectTagTest"); 39 } 40 41 private String testHTML = "<SELECT name=\"Nominees\">\n"+ 42 "<option value=\"Spouse\">Spouse"+ 43 "<option value=\"Father\"></option>\n"+ 44 "<option value=\"Mother\">Mother\n" + 45 "<option value=\"Son\">\nSon\n</option>"+ 46 "<option value=\"Daughter\">\nDaughter\n"+ 47 "<option value=\"Nephew\">\nNephew</option>\n"+ 48 "<option value=\"Niece\">Niece\n" + 49 "</select>"; 50 51 private String correctedHTML = "<SELECT name=\"Nominees\">\n"+ 52 "<option value=\"Spouse\">Spouse</option>"+ 53 "<option value=\"Father\"></option>\n"+ 54 "<option value=\"Mother\">Mother\n</option>" + 55 "<option value=\"Son\">\nSon\n</option>"+ 56 "<option value=\"Daughter\">\nDaughter\n</option>"+ 57 "<option value=\"Nephew\">\nNephew</option>\n"+ 58 "<option value=\"Niece\">Niece\n</option>" + 59 "</select>"; 60 61 private SelectTag selectTag; 62 private String html = "<Select name=\"Remarks\">" + 63 "<option value='option1'>option1</option>" + 64 "</Select>" + 65 "<Select name=\"something\">" + 66 "<option value='option2'>option2</option>" + 67 "</Select>" + 68 "<Select></Select>" + 69 "<Select name=\"Remarks\">The death threats of the organization\n" + 70 "refused to intimidate the soldiers</Select>" + 71 "<Select name=\"Remarks\">The death threats of the LTTE\n" + 72 "refused to intimidate the Tamilians\n</Select>"; 73 74 public SelectTagTest(String name) 75 { 76 super(name); 77 } 78 79 protected void setUp() throws Exception { 80 super.setUp(); 81 createParser(testHTML); 82 parseAndAssertNodeCount(1); 83 assertTrue("Node 1 should be Select Tag",node[0] instanceof SelectTag); 84 selectTag = (SelectTag) node[0]; 85 } 86 87 public void testToHTML() throws ParserException 88 { 89 assertStringEquals("HTML String", correctedHTML, selectTag.toHtml()); 90 } 91 92 public void testGetOptionTags() { 93 OptionTag [] optionTags = selectTag.getOptionTags(); 94 assertEquals("option tag array length",7,optionTags.length); 95 assertEquals("option tag 1","Spouse",optionTags[0].getOptionText()); 96 assertEquals("option tag 7","Niece\n",optionTags[6].getOptionText()); 97 } 98 99 public void testScan() throws ParserException 100 { 101 102 createParser(html,"http://www.google.com/test/index.html"); 103 parseAndAssertNodeCount(5); 104 105 for(int j=0;j<nodeCount;j++) 107 assertTrue(node[j] instanceof SelectTag); 108 109 SelectTag selectTag = (SelectTag)node[0]; 110 OptionTag [] optionTags = selectTag.getOptionTags(); 111 assertEquals("option tag array length",1,optionTags.length); 112 assertEquals("option tag value","option1",optionTags[0].getOptionText()); 113 } 114 115 118 public void testSelectTagWithComments() throws Exception { 119 createParser( 120 "<form>" + 121 "<select> " + 122 "<!-- 1 --><option selected>123 " + 123 "<option>345 " + 124 "</select> " + 125 "</form>" 126 ); 127 parseAndAssertNodeCount(1); 128 } 129 } 130
| Popular Tags
|