logo

pleroma

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

20200716195806_autolinker_to_linkify_test.exs (2155B)


  1. defmodule Pleroma.Repo.Migrations.AutolinkerToLinkifyTest do
  2. use Pleroma.DataCase
  3. import Pleroma.Factory
  4. import Pleroma.Tests.Helpers
  5. alias Pleroma.ConfigDB
  6. setup do: clear_config(Pleroma.Formatter)
  7. setup_all do: require_migration("20200716195806_autolinker_to_linkify")
  8. test "change/0 converts auto_linker opts for Pleroma.Formatter", %{migration: migration} do
  9. autolinker_opts = [
  10. extra: true,
  11. validate_tld: true,
  12. class: false,
  13. strip_prefix: false,
  14. new_window: false,
  15. rel: "testing"
  16. ]
  17. insert(:config, group: :auto_linker, key: :opts, value: autolinker_opts)
  18. migration.change()
  19. assert nil == ConfigDB.get_by_params(%{group: :auto_linker, key: :opts})
  20. %{value: new_opts} = ConfigDB.get_by_params(%{group: :pleroma, key: Pleroma.Formatter})
  21. assert new_opts == [
  22. class: false,
  23. extra: true,
  24. new_window: false,
  25. rel: "testing",
  26. strip_prefix: false
  27. ]
  28. Pleroma.Config.put(Pleroma.Formatter, new_opts)
  29. assert new_opts == Pleroma.Config.get(Pleroma.Formatter)
  30. {text, _mentions, []} =
  31. Pleroma.Formatter.linkify(
  32. "https://www.businessinsider.com/walmart-will-close-stores-on-thanksgiving-ending-black-friday-tradition-2020-7\n\nOmg will COVID finally end Black Friday???"
  33. )
  34. assert text ==
  35. "<a href=\"https://www.businessinsider.com/walmart-will-close-stores-on-thanksgiving-ending-black-friday-tradition-2020-7\" rel=\"testing\">https://www.businessinsider.com/walmart-will-close-stores-on-thanksgiving-ending-black-friday-tradition-2020-7</a>\n\nOmg will COVID finally end Black Friday???"
  36. end
  37. test "transform_opts/1 returns a list of compatible opts", %{migration: migration} do
  38. old_opts = [
  39. extra: true,
  40. validate_tld: true,
  41. class: false,
  42. strip_prefix: false,
  43. new_window: false,
  44. rel: "qqq"
  45. ]
  46. expected_opts = [
  47. class: false,
  48. extra: true,
  49. new_window: false,
  50. rel: "qqq",
  51. strip_prefix: false
  52. ]
  53. assert migration.transform_opts(old_opts) == expected_opts
  54. end
  55. end