webfinger: support JSON output
[akkoma] / test / xml_builder_test.exs
1 defmodule Pleroma.XmlBuilderTest do
2 use Pleroma.DataCase
3 alias Pleroma.XmlBuilder
4
5 test "Build a basic xml string from a tuple" do
6 data = { :feed, %{ xmlns: "http://www.w3.org/2005/Atom"}, "Some content" }
7
8 expected_xml = "<feed xmlns=\"http://www.w3.org/2005/Atom\">Some content</feed>"
9
10 assert XmlBuilder.to_xml(data) == expected_xml
11 end
12
13 test "returns a complete document" do
14 data = { :feed, %{ xmlns: "http://www.w3.org/2005/Atom"}, "Some content" }
15
16 expected_xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><feed xmlns=\"http://www.w3.org/2005/Atom\">Some content</feed>"
17
18 assert XmlBuilder.to_doc(data) == expected_xml
19 end
20
21 test "Works without attributes" do
22 data = {
23 :feed,
24 "Some content"
25 }
26
27 expected_xml = "<feed>Some content</feed>"
28
29 assert XmlBuilder.to_xml(data) == expected_xml
30 end
31
32 test "It works with nested tuples" do
33 data = {
34 :feed,
35 [
36 {:guy, "brush"},
37 {:lament, %{ configuration: "puzzle" }, "pinhead" }
38 ]
39 }
40
41 expected_xml = ~s[<feed><guy>brush</guy><lament configuration="puzzle">pinhead</lament></feed>]
42
43 assert XmlBuilder.to_xml(data) == expected_xml
44 end
45
46 test "Represents NaiveDateTime as iso8601" do
47 assert XmlBuilder.to_xml(~N[2000-01-01 13:13:33]) == "2000-01-01T13:13:33"
48 end
49
50 test "Uses self-closing tags when no content is giving" do
51 data = {
52 :link,
53 %{ rel: "self" }
54 }
55
56 expected_xml = ~s[<link rel="self" />]
57 assert XmlBuilder.to_xml(data) == expected_xml
58 end
59 end