Use context_ids directly if we have them.
[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 =
17 "<?xml version=\"1.0\" encoding=\"UTF-8\"?><feed xmlns=\"http://www.w3.org/2005/Atom\">Some content</feed>"
18
19 assert XmlBuilder.to_doc(data) == expected_xml
20 end
21
22 test "Works without attributes" do
23 data = {
24 :feed,
25 "Some content"
26 }
27
28 expected_xml = "<feed>Some content</feed>"
29
30 assert XmlBuilder.to_xml(data) == expected_xml
31 end
32
33 test "It works with nested tuples" do
34 data = {
35 :feed,
36 [
37 {:guy, "brush"},
38 {:lament, %{configuration: "puzzle"}, "pinhead"}
39 ]
40 }
41
42 expected_xml =
43 ~s[<feed><guy>brush</guy><lament configuration="puzzle">pinhead</lament></feed>]
44
45 assert XmlBuilder.to_xml(data) == expected_xml
46 end
47
48 test "Represents NaiveDateTime as iso8601" do
49 assert XmlBuilder.to_xml(~N[2000-01-01 13:13:33]) == "2000-01-01T13:13:33"
50 end
51
52 test "Uses self-closing tags when no content is giving" do
53 data = {
54 :link,
55 %{rel: "self"}
56 }
57
58 expected_xml = ~s[<link rel="self" />]
59 assert XmlBuilder.to_xml(data) == expected_xml
60 end
61 end