test/test_xml.rb in atom-tools-0.9.2 vs test/test_xml.rb in atom-tools-0.9.3
- old
+ new
@@ -4,16 +4,16 @@
require "atom/service"
class AtomTest < Test::Unit::TestCase
def test_text_type_text
entry = get_entry
-
+
entry.title = "Atom-drunk pirates run amok!"
assert_equal("text", entry.title["type"])
xml = get_elements entry
-
+
assert_equal("Atom-drunk pirates run amok!", xml.elements["/entry/title"].text)
end
def test_text_type_html
entry = get_entry
@@ -32,21 +32,30 @@
entry.title = "Atom-drunk pirates <em>run amok</em>!"
entry.title["type"] = "xhtml"
xml = get_elements entry
-
+
base_check xml
assert_equal(XHTML::NS, xml.elements["/entry/title/div"].namespace)
assert_equal("run amok", xml.elements["/entry/title/div/em"].text)
end
+ def test_html_text_with_entities
+ entry = get_entry
+
+ entry.title = "Atoms discovered to be smaller than 1μm"
+ entry.title["type"] = "html"
+
+ assert_match(/&mu;/, entry.to_s)
+ end
+
def test_author
entry = get_entry
a = entry.authors.new
-
+
a.name= "Brendan Taylor"
a.uri = "http://necronomicorp.com/blog/"
xml = get_elements entry
@@ -109,10 +118,36 @@
assert_equal(REXML::Element, xml.elements["/entry/test"].class)
assert_equal("http://purl.org/", xml.elements["/entry/test"].namespace)
end
+ def test_roundtrip_extension
+ entry = Atom::Entry.parse("<entry xmlns='http://www.w3.org/2005/Atom' xmlns:nil='http://necronomicorp.com/nil'><nil:ext/></entry>")
+
+ assert_match(/xmlns:nil='http:\/\/necronomicorp.com\/nil'/, entry.to_s)
+ end
+
+ def test_app_control
+ entry = get_entry
+
+ assert !entry.draft
+
+ assert_nil get_elements(entry).elements["/entry/control"]
+
+ entry.draft = true
+
+ xml = get_elements entry
+
+ assert_equal Atom::PP_NS, xml.elements["/entry/control"].namespace
+ assert_equal Atom::PP_NS, xml.elements["/entry/control/draft"].namespace
+ assert_equal "yes", xml.elements["/entry/control/draft"].text
+
+ entry2 = Atom::Entry.parse xml
+
+ assert entry.draft
+ end
+
def test_extensive_enty_parsing
str = '<entry xmlns="http://www.w3.org/2005/Atom">
<title>Atom draft-07 snapshot</title>
<link rel="alternate" type="text/html"
href="http://example.org/2005/04/02/atom"/>
@@ -139,14 +174,14 @@
</div>
</content>
</entry>'
entry = Atom::Entry.parse(str)
-
+
assert_equal("Atom draft-07 snapshot", entry.title.to_s)
assert_equal("tag:example.org,2003:3.2397", entry.id)
-
+
assert_equal(Time.parse("2005-07-31T12:29:29Z"), entry.updated)
assert_equal(Time.parse("2003-12-13T08:29:29-04:00"), entry.published)
assert_equal(2, entry.links.length)
assert_equal("alternate", entry.links.first["rel"])
@@ -160,20 +195,20 @@
assert_equal(1, entry.authors.length)
assert_equal("Mark Pilgrim", entry.authors.first.name)
assert_equal("http://example.org/", entry.authors.first.uri)
assert_equal("f8dy@example.com", entry.authors.first.email)
-
+
assert_equal(2, entry.contributors.length)
assert_equal("Sam Ruby", entry.contributors.first.name)
assert_equal("Joe Gregorio", entry.contributors.last.name)
-
+
assert_equal("xhtml", entry.content["type"])
-
+
assert_match("<p><i>[Update: The Atom draft is finished.]</i></p>",
entry.content.to_s)
-
+
assert_equal("http://diveintomark.org/", entry.content.base)
# XXX unimplemented
# assert_equal("en", entry.content.lang)
end
@@ -237,11 +272,11 @@
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
@@ -257,19 +292,31 @@
assert_equal "html", entry.summary["type"]
assert_equal "<p>...& as a result of this, I submit that <var>pi</var> < 4", entry.summary.html.strip
end
+ def test_parse_goofy_entries
+xml = <<END
+<entry xmlns="http://www.w3.org/2005/Atom">
+<content type="html"></content>
+</entry>
+END
+
+ entry = Atom::Entry.parse(xml)
+
+ assert_equal("", entry.content.to_s)
+ end
+
def test_parse_outofline_content
xml = <<END
<entry xmlns="http://www.w3.org/2005/Atom">
<summary src="http://necronomicorp.com/nil">
Summary doesn't have src.
</summary>
</entry>
END
-
+
entry = Atom::Entry.parse xml
assert_raises(RuntimeError) { entry.summary["src"] }
assert_equal "Summary doesn't have src.", entry.summary.to_s.strip
@@ -289,11 +336,11 @@
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")
@@ -302,15 +349,15 @@
end
def test_relative_base
base_url = "http://www.tbray.org/ongoing/ongoing.atom"
doc = "<entry xmlns='http://www.w3.org/2005/Atom' xml:base='When/200x/2006/10/11/'/>"
-
+
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 xmlns="http://www.w3.org/2005/Atom"><link rel="edit"/></entry>
END
entry = Atom::Entry.parse(doc)
@@ -322,11 +369,11 @@
END
entry = Atom::Entry.parse(doc)
assert_nil(entry.edit_url)
-
+
doc = <<END
<entry xmlns="http://www.w3.org/2005/Atom">
<link rel="edit" href="http://necronomicorp.com/nil"/>
</entry>
END
@@ -334,11 +381,10 @@
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
@@ -351,13 +397,13 @@
# 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)
-
+ 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)