Fork of Pleroma with site-specific changes and feature branches https://git.pleroma.social/pleroma/pleroma
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

60 lines
1.5KB

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