1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
5 defmodule Pleroma.XmlBuilderTest do
6 use Pleroma.DataCase, async: true
7 alias Pleroma.XmlBuilder
9 test "Build a basic xml string from a tuple" do
10 data = {:feed, %{xmlns: "http://www.w3.org/2005/Atom"}, "Some content"}
12 expected_xml = "<feed xmlns=\"http://www.w3.org/2005/Atom\">Some content</feed>"
14 assert XmlBuilder.to_xml(data) == expected_xml
17 test "returns a complete document" do
18 data = {:feed, %{xmlns: "http://www.w3.org/2005/Atom"}, "Some content"}
21 "<?xml version=\"1.0\" encoding=\"UTF-8\"?><feed xmlns=\"http://www.w3.org/2005/Atom\">Some content</feed>"
23 assert XmlBuilder.to_doc(data) == expected_xml
26 test "Works without attributes" do
32 expected_xml = "<feed>Some content</feed>"
34 assert XmlBuilder.to_xml(data) == expected_xml
37 test "It works with nested tuples" do
42 {:lament, %{configuration: "puzzle"}, "pinhead"}
47 ~s[<feed><guy>brush</guy><lament configuration="puzzle">pinhead</lament></feed>]
49 assert XmlBuilder.to_xml(data) == expected_xml
52 test "Represents NaiveDateTime as iso8601" do
53 assert XmlBuilder.to_xml(~N[2000-01-01 13:13:33]) == "2000-01-01T13:13:33"
56 test "Uses self-closing tags when no content is giving" do
62 expected_xml = ~s[<link rel="self" />]
63 assert XmlBuilder.to_xml(data) == expected_xml