public void BadImageInLinkBug() { CreateParser( "<a href=\"registration.asp?EventID=1272\"><img border=\"0\" src=\"\\images\\register.gif\"</a>", "http://www.fedpage.com/Event.asp?EventID=1272"); parser.RegisterScanners(); ParseAndAssertNodeCount(1); Assert.IsTrue(node[0] is LinkTag, "Node should be a HTMLLinkTag"); LinkTag linkTag = (LinkTag)node[0]; // Get the image tag from the link Node[] insideNodes = new AbstractNode[10]; int j = 0; foreach (Node nestedNode in linkTag) { insideNodes[j++] = nestedNode; } Assert.AreEqual(1, j, "Number of contained internal nodes"); Assert.IsTrue(insideNodes[0] is ImageTag); ImageTag imageTag = (ImageTag)insideNodes[0]; Assert.AreEqual("http://www.fedpage.com/images/register.gif", imageTag.ImageURL, "Image Tag Location"); }
public void Scan() { CreateParser("<A HREF=\"mytest.html\"><IMG SRC=\"abcd.jpg\">Hello World</A>", "http://www.yahoo.com"); // Register the image scanner LinkScanner linkScanner = new LinkScanner("-l"); parser.AddScanner(linkScanner); parser.AddScanner(linkScanner.CreateImageScanner("-i")); ParseAndAssertNodeCount(1); Assert.IsTrue(node[0] is LinkTag, "Node should be a link node"); LinkTag linkTag = (LinkTag)node[0]; // Get the link data and cross-check Node[] dataNode = new AbstractNode[10]; int i = 0; foreach (Node nestedNode in linkTag) { dataNode[i++] = nestedNode; } Assert.AreEqual(2, i, "Number of data nodes"); Assert.IsTrue(dataNode[0] is ImageTag, "First data node should be an Image Node"); Assert.IsTrue(dataNode[1] is StringNode, "Second data node shouls be a String Node"); // Check the contents of each data node ImageTag imageTag = (ImageTag)dataNode[0]; Assert.AreEqual("http://www.yahoo.com/abcd.jpg", imageTag.ImageURL, "Image URL"); StringNode stringNode = (StringNode)dataNode[1]; Assert.AreEqual("Hello World", stringNode.Text, "String Contents"); }
public void LinkDataContents() { CreateParser( "<a href=\"http://transfer.go.com/cgi/atransfer.pl?goto=http://www.signs.movies.com&name=114332&srvc=nws&context=283&guid=4AD5723D-C802-4310-A388-0B24E1A79689\" target=\"_new\"><img src=\"http://ad.abcnews.com/ad/sponsors/buena_vista_pictures/bvpi-ban0003.gif\" width=468 height=60 border=\"0\" alt=\"See Signs in Theaters 8-2 - Starring Mel Gibson\" align=><font face=\"verdana,arial,helvetica\" SIZE=\"1\"><b></b></font></a>", "http://transfer.go.com"); // Register the image scanner LinkScanner linkScanner = new LinkScanner("-l"); parser.AddScanner(linkScanner); parser.AddScanner(linkScanner.CreateImageScanner("-i")); ParseAndAssertNodeCount(1); Assert.IsTrue(node[0] is LinkTag, "Node 0 should be a link tag"); LinkTag linkTag = (LinkTag)node[0]; Assert.AreEqual( "http://transfer.go.com/cgi/atransfer.pl?goto=http://www.signs.movies.com&name=114332&srvc=nws&context=283&guid=4AD5723D-C802-4310-A388-0B24E1A79689", linkTag.Link, "Link URL"); Assert.AreEqual("", linkTag.LinkText, "Link Text"); Node[] containedNodes = new AbstractNode[10]; int i = 0; foreach (Node nestedNode in linkTag) { containedNodes[i++] = nestedNode; } Assert.AreEqual(5, i, "There should be 5 contained nodes in the link tag"); Assert.IsTrue(containedNodes[0] is ImageTag, "First contained node should be an image tag"); ImageTag imageTag = (ImageTag)containedNodes[0]; Assert.AreEqual("http://ad.abcnews.com/ad/sponsors/buena_vista_pictures/bvpi-ban0003.gif", imageTag.ImageURL, "Image Location"); Assert.AreEqual("60", imageTag["HEIGHT"], "Image Height"); Assert.AreEqual("468", imageTag["WIDTH"], "Image Width"); Assert.AreEqual("0", imageTag["BORDER"], "Image Border"); Assert.AreEqual("See Signs in Theaters 8-2 - Starring Mel Gibson", imageTag["ALT"], "Image Alt"); Assert.IsTrue(containedNodes[1] is Tag, "Second contained node should be Tag"); Tag tag1 = (Tag)containedNodes[1]; Assert.AreEqual("font face=\"verdana,arial,helvetica\" SIZE=\"1\"", tag1.Text, "Tag Contents"); Assert.IsTrue(containedNodes[2] is Tag, "Third contained node should be Tag"); Tag tag2 = (Tag)containedNodes[2]; Assert.AreEqual("b", tag2.Text, "Tag Contents"); Assert.IsTrue(containedNodes[3] is EndTag, "Fourth contained node should be HTMLEndTag"); EndTag endTag1 = (EndTag)containedNodes[3]; Assert.AreEqual("b", endTag1.Text, "Fourth Tag contents"); Assert.IsTrue(containedNodes[4] is EndTag, "Fifth contained node should be HTMLEndTag"); EndTag endTag2 = (EndTag)containedNodes[4]; Assert.AreEqual("font", endTag2.Text, "Fifth Tag contents"); }
public virtual void VisitImageTag(ImageTag imageTag) { }