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.

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