1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2022 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", [], []}]}], %{}) == %{}
13 test "parses twitter card with only name attributes" do
15 File.read!("test/fixtures/nypd-facial-recognition-children-teenagers3.html")
16 |> Floki.parse_document!()
18 assert TwitterCard.parse(html, %{}) ==
20 "app:id:googleplay" => "com.nytimes.android",
21 "app:name:googleplay" => "NYTimes",
22 "app:url:googleplay" => "nytimes://reader/id/100000006583622",
25 "With little oversight, the N.Y.P.D. has been using powerful surveillance technology on photos of children and teenagers.",
27 "https://static01.nyt.com/images/2019/08/01/nyregion/01nypd-juveniles-promo/01nypd-juveniles-promo-facebookJumbo.jpg",
30 "https://www.nytimes.com/2019/08/01/nyregion/nypd-facial-recognition-children-teenagers.html",
32 "She Was Arrested at 14. Then Her Photo Went to a Facial Recognition Database."
36 test "parses twitter card with only property attributes" do
38 File.read!("test/fixtures/nypd-facial-recognition-children-teenagers2.html")
39 |> Floki.parse_document!()
41 assert TwitterCard.parse(html, %{}) ==
43 "card" => "summary_large_image",
45 "With little oversight, the N.Y.P.D. has been using powerful surveillance technology on photos of children and teenagers.",
47 "https://static01.nyt.com/images/2019/08/01/nyregion/01nypd-juveniles-promo/01nypd-juveniles-promo-videoSixteenByNineJumbo1600.jpg",
50 "She Was Arrested at 14. Then Her Photo Went to a Facial Recognition Database.",
52 "https://www.nytimes.com/2019/08/01/nyregion/nypd-facial-recognition-children-teenagers.html",
57 test "parses twitter card with name & property attributes" do
59 File.read!("test/fixtures/nypd-facial-recognition-children-teenagers.html")
60 |> Floki.parse_document!()
62 assert TwitterCard.parse(html, %{}) ==
64 "app:id:googleplay" => "com.nytimes.android",
65 "app:name:googleplay" => "NYTimes",
66 "app:url:googleplay" => "nytimes://reader/id/100000006583622",
67 "card" => "summary_large_image",
69 "With little oversight, the N.Y.P.D. has been using powerful surveillance technology on photos of children and teenagers.",
71 "https://static01.nyt.com/images/2019/08/01/nyregion/01nypd-juveniles-promo/01nypd-juveniles-promo-videoSixteenByNineJumbo1600.jpg",
75 "She Was Arrested at 14. Then Her Photo Went to a Facial Recognition Database.",
77 "https://www.nytimes.com/2019/08/01/nyregion/nypd-facial-recognition-children-teenagers.html",
82 test "respect only first title tag on the page" do
84 "https://assets.atlasobscura.com/media/W1siZiIsInVwbG9hZHMvYXNzZXRzLzkwYzgyMzI4LThlMDUtNGRiNS05MDg3LTUzMGUxZTM5N2RmMmVkOTM5ZDM4MGM4OTIx" <>
85 "YTQ5MF9EQVIgZXhodW1hdGlvbiBvZiBNYXJnYXJldCBDb3JiaW4gZ3JhdmUgMTkyNi5qcGciXSxbInAiLCJjb252ZXJ0IiwiIl0sWyJwIiwiY29udmVydCIsIi1xdWFsaXR5IDgxIC1hdXRvLW9" <>
86 "yaWVudCJdLFsicCIsInRodW1iIiwiNjAweD4iXV0/DAR%20exhumation%20of%20Margaret%20Corbin%20grave%201926.jpg"
89 File.read!("test/fixtures/margaret-corbin-grave-west-point.html") |> Floki.parse_document!()
91 assert TwitterCard.parse(html, %{}) ==
93 "site" => "@atlasobscura",
94 "title" => "The Missing Grave of Margaret Corbin, Revolutionary War Veteran",
95 "card" => "summary_large_image",
96 "image" => image_path,
98 "She's the only woman veteran honored with a monument at West Point. But where was she buried?",
99 "site_name" => "Atlas Obscura",
101 "url" => "http://www.atlasobscura.com/articles/margaret-corbin-grave-west-point"
105 test "takes first founded title in html head if there is html markup error" do
107 File.read!("test/fixtures/nypd-facial-recognition-children-teenagers4.html")
108 |> Floki.parse_document!()
110 assert TwitterCard.parse(html, %{}) ==
114 "She Was Arrested at 14. Then Her Photo Went to a Facial Recognition Database.",
115 "app:id:googleplay" => "com.nytimes.android",
116 "app:name:googleplay" => "NYTimes",
117 "app:url:googleplay" => "nytimes://reader/id/100000006583622",
119 "With little oversight, the N.Y.P.D. has been using powerful surveillance technology on photos of children and teenagers.",
121 "https://static01.nyt.com/images/2019/08/01/nyregion/01nypd-juveniles-promo/01nypd-juveniles-promo-facebookJumbo.jpg",
124 "https://www.nytimes.com/2019/08/01/nyregion/nypd-facial-recognition-children-teenagers.html"