",
entry.content.to_s)
assert_equal("http://diveintomark.org/", entry.content.base)
# XXX unimplemented
# assert_equal("en", entry.content.lang)
end
def test_extensive_feed_parsing
feed = <dive into mark
A <em>lot</em> of effort
went into making this effortless
2005-07-31T12:29:29Ztag:example.org,2003:3Copyright (c) 2003, Mark Pilgrim
Example Toolkit
Atom draft-07 snapshotMark Pilgrimhttp://example.org/f8dy@example.comtag:example.org,2003:3.23972005-07-31T12:29:29Z
END
feed = Atom::Feed.parse(feed)
assert_equal("", feed.base)
assert_equal("text", feed.title["type"])
assert_equal("dive into mark", feed.title.to_s)
assert_equal("html", feed.subtitle["type"])
assert_equal("\n A lot of effort\n went into making this effortless\n ", feed.subtitle.to_s)
assert_equal(Time.parse("2005-07-31T12:29:29Z"), feed.updated)
assert_equal("tag:example.org,2003:3", feed.id)
assert_equal([], feed.authors)
alt = feed.links.find { |l| l["rel"] == "alternate" }
assert_equal("alternate", alt["rel"])
assert_equal("text/html", alt["type"])
assert_equal("en", alt["hreflang"])
assert_equal("http://example.org/", alt["href"])
assert_equal("text", feed.rights["type"])
assert_equal("Copyright (c) 2003, Mark Pilgrim", feed.rights.to_s)
assert_equal("\n Example Toolkit\n ", feed.generator)
# XXX unimplemented
# assert_equal("http://www.example.com/", feed.generator["uri"])
# assert_equal("1.0", feed.generator["version"])
assert_equal(1, feed.entries.length)
assert_equal "Atom draft-07 snapshot", feed.entries.first.title.to_s
end
def test_parse_html_content
xml = <
<p>...& as a result of this, I submit that <var>pi</var> < 4
END
entry = Atom::Entry.parse(xml)
assert_equal "html", entry.summary["type"]
assert_equal "
...& as a result of this, I submit that pi < 4", entry.summary.html.strip
end
def test_parse_goofy_entries
xml = <
END
entry = Atom::Entry.parse(xml)
assert_equal("", entry.content.to_s)
end
def test_parse_outofline_content
xml = <
Summary doesn't have src.
END
entry = Atom::Entry.parse xml
assert_raises(RuntimeError) { entry.summary["src"] }
assert_equal "Summary doesn't have src.", entry.summary.to_s.strip
xml = <
src means empty content.
END
entry = Atom::Entry.parse xml
assert_equal "http://necronomicorp.com/nil", entry.content["src"]
assert_equal "", entry.content.to_s
end
def test_serialize_base
entry = Atom::Entry.new
entry.base = "http://necronomicorp.com/nil"
base = get_elements(entry).root.attributes["xml:base"]
assert_equal "http://necronomicorp.com/nil", base
entry.base = URI.parse("http://necronomicorp.com/nil")
base = get_elements(entry).root.attributes["xml:base"]
assert_equal "http://necronomicorp.com/nil", base
end
def test_relative_base
base_url = "http://www.tbray.org/ongoing/ongoing.atom"
doc = ""
entry = Atom::Entry.parse(doc, base_url)
assert_equal("http://www.tbray.org/ongoing/When/200x/2006/10/11/", entry.base)
end
def test_edit_url
doc = <
END
entry = Atom::Entry.parse(doc)
assert_nil(entry.edit_url)
doc = <
END
entry = Atom::Entry.parse(doc)
assert_nil(entry.edit_url)
doc = <
END
entry = Atom::Entry.parse(doc)
assert_equal("http://necronomicorp.com/nil", entry.edit_url)
end
def assert_has_category xml, term
assert_not_nil(REXML::XPath.match(xml, "/entry/category[@term = #{term}]"))
end
def assert_has_content_type xml, type
assert_equal(type, xml.elements["/entry/content"].attributes["type"])
end
def get_entry
Atom::Entry.new
end
# round-trips it to make sure things stay the same
def get_elements entry
xml = entry.to_xml
assert_equal(entry.to_s, Atom::Entry.parse(xml).to_s)
base_check xml
xml
end
def base_check xml
assert_equal("entry", xml.root.name)
assert_equal("http://www.w3.org/2005/Atom", xml.root.namespace)
end
end