1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163
|
require "rss-testcase"
require "rss/atom"
module RSS
class TestParserAtom < TestCase
def test_entry_validation
assert_ns("", Atom::URI) do
Parser.parse(<<-EOA)
<entry/>
EOA
end
assert_ns("", Atom::URI) do
Parser.parse(<<-EOA)
<entry xmlns="hoge"/>
EOA
end
assert_parse(<<-EOA, :missing_tag, "id", "entry") do
<entry xmlns="#{Atom::URI}"/>
EOA
end
assert_parse(<<-EOA, :missing_tag, "title", "entry") do
<entry xmlns="#{Atom::URI}">
<id>urn:uuid:506e336c-a26e-4457-917b-b89dca7ae746</id>
</entry>
EOA
end
assert_parse(<<-EOA, :missing_tag, "updated", "entry") do
<entry xmlns="#{Atom::URI}">
<id>urn:uuid:506e336c-a26e-4457-917b-b89dca7ae746</id>
<title>Example Entry</title>
</entry>
EOA
end
assert_parse(<<-EOA, :missing_tag, "author", "entry") do
<entry xmlns="#{Atom::URI}">
<id>urn:uuid:506e336c-a26e-4457-917b-b89dca7ae746</id>
<title>Example Entry</title>
<updated>2003-10-10T18:30:02Z</updated>
</entry>
EOA
end
assert_parse(<<-EOA, :nothing_raised) do
<entry xmlns="#{Atom::URI}">
<id>urn:uuid:506e336c-a26e-4457-917b-b89dca7ae746</id>
<title>Example Entry</title>
<updated>2003-10-10T18:30:02Z</updated>
<author>
<name>A person</name>
</author>
</entry>
EOA
end
end
def test_entry
entry = RSS::Parser.parse(<<-EOA)
<?xml version="1.0" encoding="utf-8"?>
<entry xmlns="http://www.w3.org/2005/Atom">
<author>
<name>A person</name>
</author>
<title>Atom-Powered Robots Run Amok</title>
<link href="http://example.org/2003/12/13/atom03"/>
<id>urn:uuid:1225c695-cfb8-4ebb-aaaa-80da344efa6a</id>
<updated>2003-12-13T18:30:02Z</updated>
<summary>Some text.</summary>
</entry>
EOA
assert_not_nil(entry)
assert_equal("Atom-Powered Robots Run Amok", entry.title.content)
assert_equal("http://example.org/2003/12/13/atom03", entry.link.href)
assert_equal("urn:uuid:1225c695-cfb8-4ebb-aaaa-80da344efa6a",
entry.id.content)
assert_equal(Time.parse("2003-12-13T18:30:02Z"), entry.updated.content)
assert_equal("Some text.", entry.summary.content)
end
def test_entry_author
assert_atom_person("author", method(:make_entry_document)) do |entry|
assert_equal(2, entry.authors.size)
entry.authors.last
end
end
def test_entry_category
assert_atom_category(method(:make_entry_document)) do |entry|
assert_equal(1, entry.categories.size)
entry.category
end
end
def test_entry_content_text
assert_atom_content(method(:make_entry_document)) do |entry|
entry.content
end
end
def test_entry_contributor
assert_atom_person("contributor", method(:make_entry_document)) do |entry|
assert_equal(1, entry.contributors.size)
entry.contributor
end
end
def test_entry_id
entry = RSS::Parser.parse(make_entry_document)
assert_equal(ENTRY_ID, entry.id.content)
end
def test_entry_link
assert_atom_link(method(:make_entry_document)) do |entry|
assert_equal(1, entry.links.size)
entry.link
end
end
def test_published
generator = method(:make_entry_document)
assert_atom_date_construct("published", generator) do |entry|
entry.published
end
end
def test_entry_rights
generator = method(:make_entry_document)
assert_atom_text_construct("rights", generator) do |entry|
entry.rights
end
end
def test_entry_source
generator = method(:make_entry_document_with_open_source)
assert_atom_source(generator) do |entry|
assert_not_nil(entry.source)
entry.source
end
end
def test_entry_summary
generator = method(:make_entry_document)
assert_atom_text_construct("summary", generator) do |entry|
entry.summary
end
end
def test_entry_title
entry = RSS::Parser.parse(make_entry_document)
assert_equal(ENTRY_TITLE, entry.title.content)
end
def test_entry_updated
entry = RSS::Parser.parse(make_entry_document)
assert_equal(Time.parse(ENTRY_UPDATED), entry.updated.content)
end
end
end
|