logo

pleroma

My custom branche(s) on git.pleroma.social/pleroma/pleroma

xml_builder_test.exs (1712B)


  1. # Pleroma: A lightweight social networking server
  2. # Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
  3. # SPDX-License-Identifier: AGPL-3.0-only
  4. defmodule Pleroma.XmlBuilderTest do
  5. use Pleroma.DataCase
  6. alias Pleroma.XmlBuilder
  7. test "Build a basic xml string from a tuple" do
  8. data = {:feed, %{xmlns: "http://www.w3.org/2005/Atom"}, "Some content"}
  9. expected_xml = "<feed xmlns=\"http://www.w3.org/2005/Atom\">Some content</feed>"
  10. assert XmlBuilder.to_xml(data) == expected_xml
  11. end
  12. test "returns a complete document" do
  13. data = {:feed, %{xmlns: "http://www.w3.org/2005/Atom"}, "Some content"}
  14. expected_xml =
  15. "<?xml version=\"1.0\" encoding=\"UTF-8\"?><feed xmlns=\"http://www.w3.org/2005/Atom\">Some content</feed>"
  16. assert XmlBuilder.to_doc(data) == expected_xml
  17. end
  18. test "Works without attributes" do
  19. data = {
  20. :feed,
  21. "Some content"
  22. }
  23. expected_xml = "<feed>Some content</feed>"
  24. assert XmlBuilder.to_xml(data) == expected_xml
  25. end
  26. test "It works with nested tuples" do
  27. data = {
  28. :feed,
  29. [
  30. {:guy, "brush"},
  31. {:lament, %{configuration: "puzzle"}, "pinhead"}
  32. ]
  33. }
  34. expected_xml =
  35. ~s[<feed><guy>brush</guy><lament configuration="puzzle">pinhead</lament></feed>]
  36. assert XmlBuilder.to_xml(data) == expected_xml
  37. end
  38. test "Represents NaiveDateTime as iso8601" do
  39. assert XmlBuilder.to_xml(~N[2000-01-01 13:13:33]) == "2000-01-01T13:13:33"
  40. end
  41. test "Uses self-closing tags when no content is giving" do
  42. data = {
  43. :link,
  44. %{rel: "self"}
  45. }
  46. expected_xml = ~s[<link rel="self" />]
  47. assert XmlBuilder.to_xml(data) == expected_xml
  48. end
  49. end