require 'test/unit' require "openid/parse" class LinkParseTestCase < Test::Unit::TestCase def test_bad cases = < <> ]]> ]]> <link> <HtMl> <hEaD> <LiNk> <butternut> <html> <summer> <head> <turban> <link> <html> <head> <script> <link> <html><head><script><link> <html> <head> <!-- <link> <html> <head> <![CDATA[ <link> <html> <head> <![ACORN[ <link> ]]> <html> <head> <link> <html> <head> <link> <link> <html> <gold nugget> <head> <link> <link> <html> <head> <link> <LiNk> <body> <link> EOF results = [] cases.split("\n\n").each do |c| parse_link_attrs(c){ |x| results << x } end results.each {|r| assert(r == {}, r.to_s)} end def test_good_rel cases = [ "<html><head><link rel=openid.server>", "<html><head><link rel=openid.server />", "<html><head><link hubbard rel=openid.server>", "<html><head><link hubbard rel=openid.server></link>", "<html><head><link hubbard rel=openid.server />", "<html><head><link / rel=openid.server>", "<html><head><link rel='openid.server'>" ] results = [] cases.each do |c| parse_link_attrs(c) { |x| results << x } end assert_equal(cases.length, results.length) results.each { |x| assert(x["rel"] == "openid.server", x["rel"]) } end def test_good lj_test = <<EOF <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <link rel="stylesheet" href="http://www.livejournal.com/~serotta/res/319998/stylesheet?1130478711" type="text/css" /> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <meta name="foaf:maker" content="foaf:mbox_sha1sum '12f8abdacb5b1a806711e23249da592c0d316260'" /> <meta name="robots" content="noindex, nofollow, noarchive" /> <meta name="googlebot" content="nosnippet" /> <link rel="openid.server" href="http://www.livejournal.com/openid/server.bml" /> <title>Brian EOF cases = [ ["", [{"rel"=>"openid.server","href"=>"http://www.myopenid.com/server"}]], ### ["", [{"rel"=>"openid.server","href"=>"http://www.myopenid.com/server"}, {"rel"=>"openid.delegate","href"=>"http://example.myopenid.com/"}]], ### [lj_test, [{"rel"=>"stylesheet","type"=>"text/css","href"=>"http://www.livejournal.com/~serotta/res/319998/stylesheet?1130478711"}, {"rel"=>"openid.server","href"=>"http://www.livejournal.com/openid/server.bml"}]] ] cases.each do |unparsed, expected| actual = [] parse_link_attrs(unparsed) {|x| actual << x} assert_equal(expected, actual) end end end