logo

pleroma

My custom branche(s) on git.pleroma.social/pleroma/pleroma git clone https://hacktivis.me/git/pleroma.git

autolinker_to_linkify_test.exs (2333B)


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