1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
5 defmodule Pleroma.Web.RichMedia.Parsers.TwitterCardTest do
6 use ExUnit.Case, async: true
7 alias Pleroma.Web.RichMedia.Parsers.TwitterCard
9 test "returns error when html not contains twitter card" do
10 assert TwitterCard.parse([{"html", [], [{"head", [], []}, {"body", [], []}]}], %{}) ==
11 {:error, "No twitter card metadata found"}
14 test "parses twitter card with only name attributes" do
16 File.read!("test/fixtures/nypd-facial-recognition-children-teenagers3.html")
17 |> Floki.parse_document!()
19 assert TwitterCard.parse(html, %{}) ==
22 "app:id:googleplay": "com.nytimes.android",
23 "app:name:googleplay": "NYTimes",
24 "app:url:googleplay": "nytimes://reader/id/100000006583622",
27 "She Was Arrested at 14. Then Her Photo Went to a Facial Recognition Database. - The New York Times"
31 test "parses twitter card with only property attributes" do
33 File.read!("test/fixtures/nypd-facial-recognition-children-teenagers2.html")
34 |> Floki.parse_document!()
36 assert TwitterCard.parse(html, %{}) ==
39 card: "summary_large_image",
41 "With little oversight, the N.Y.P.D. has been using powerful surveillance technology on photos of children and teenagers.",
43 "https://static01.nyt.com/images/2019/08/01/nyregion/01nypd-juveniles-promo/01nypd-juveniles-promo-videoSixteenByNineJumbo1600.jpg",
46 "She Was Arrested at 14. Then Her Photo Went to a Facial Recognition Database.",
48 "https://www.nytimes.com/2019/08/01/nyregion/nypd-facial-recognition-children-teenagers.html"
52 test "parses twitter card with name & property attributes" do
54 File.read!("test/fixtures/nypd-facial-recognition-children-teenagers.html")
55 |> Floki.parse_document!()
57 assert TwitterCard.parse(html, %{}) ==
60 "app:id:googleplay": "com.nytimes.android",
61 "app:name:googleplay": "NYTimes",
62 "app:url:googleplay": "nytimes://reader/id/100000006583622",
63 card: "summary_large_image",
65 "With little oversight, the N.Y.P.D. has been using powerful surveillance technology on photos of children and teenagers.",
67 "https://static01.nyt.com/images/2019/08/01/nyregion/01nypd-juveniles-promo/01nypd-juveniles-promo-videoSixteenByNineJumbo1600.jpg",
71 "She Was Arrested at 14. Then Her Photo Went to a Facial Recognition Database.",
73 "https://www.nytimes.com/2019/08/01/nyregion/nypd-facial-recognition-children-teenagers.html"
77 test "respect only first title tag on the page" do
79 "https://assets.atlasobscura.com/media/W1siZiIsInVwbG9hZHMvYXNzZXRzLzkwYzgyMzI4LThlMDUtNGRiNS05MDg3LTUzMGUxZTM5N2RmMmVkOTM5ZDM4MGM4OTIx" <>
80 "YTQ5MF9EQVIgZXhodW1hdGlvbiBvZiBNYXJnYXJldCBDb3JiaW4gZ3JhdmUgMTkyNi5qcGciXSxbInAiLCJjb252ZXJ0IiwiIl0sWyJwIiwiY29udmVydCIsIi1xdWFsaXR5IDgxIC1hdXRvLW9" <>
81 "yaWVudCJdLFsicCIsInRodW1iIiwiNjAweD4iXV0/DAR%20exhumation%20of%20Margaret%20Corbin%20grave%201926.jpg"
84 File.read!("test/fixtures/margaret-corbin-grave-west-point.html") |> Floki.parse_document!()
86 assert TwitterCard.parse(html, %{}) ==
89 site: "@atlasobscura",
91 "The Missing Grave of Margaret Corbin, Revolutionary War Veteran - Atlas Obscura",
92 card: "summary_large_image",
97 test "takes first founded title in html head if there is html markup error" do
99 File.read!("test/fixtures/nypd-facial-recognition-children-teenagers4.html")
100 |> Floki.parse_document!()
102 assert TwitterCard.parse(html, %{}) ==
107 "She Was Arrested at 14. Then Her Photo Went to a Facial Recognition Database. - The New York Times",
108 "app:id:googleplay": "com.nytimes.android",
109 "app:name:googleplay": "NYTimes",
110 "app:url:googleplay": "nytimes://reader/id/100000006583622"