diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/fixtures/fulmo.html | 151 | ||||
-rw-r--r-- | test/pleroma/web/activity_pub/mrf/fo_direct_reply_test.exs | 117 | ||||
-rw-r--r-- | test/pleroma/web/activity_pub/mrf/quiet_reply_test.exs | 140 | ||||
-rw-r--r-- | test/pleroma/web/metadata/providers/open_graph_test.exs | 55 | ||||
-rw-r--r-- | test/pleroma/web/metadata/providers/twitter_card_test.exs | 54 | ||||
-rw-r--r-- | test/pleroma/web/rich_media/parser_test.exs | 1 | ||||
-rw-r--r-- | test/pleroma/web/rich_media/parsers/twitter_card_test.exs | 37 |
7 files changed, 281 insertions, 274 deletions
diff --git a/test/fixtures/fulmo.html b/test/fixtures/fulmo.html new file mode 100644 index 000000000..e54eaf8d8 --- /dev/null +++ b/test/fixtures/fulmo.html @@ -0,0 +1,151 @@ +<!DOCTYPE html> +<html lang='eo'> + <head> + <meta charset='utf-8'/> + <meta name='author' content='Tirifto'/> + <meta name='generator' content='Pageling'/> + <meta name='viewport' content='width=device-width, + height=device-height, + initial-scale=1.0'/> + <link rel='stylesheet' type='text/css' href='/r/stiloj/tiriftejo.css'/> + <link rel='alternate' type='application/atom+xml' href='/eo/novajhoj.atom'/> + <link rel='icon' size='16x16' type='image/vnd.microsoft.icon' href='/favicon.ico'/> + <link rel='icon' size='128x128' type='image/png' href='/icon.png'/> + <link rel='alternate' hreflang='eo' href='https://tirifto.xwx.moe/eo/rakontoj/fulmo.html'/> + <title>Fulmo</title> + <meta property='og:title' content='Fulmo'/> + <meta property='og:type' content='website'/> + <meta property='og:url' content='https://tirifto.xwx.moe/eo/rakontoj/fulmo.html'/> + <meta property='og:site_name' content='Tiriftejo'/> + <meta property='og:locale' content='eo'/> + <meta property='og:description' content='Pri feoj, kiuj devis ordigi falintan arbon.'/> + <meta property='og:image' content='https://tirifto.xwx.moe/r/ilustrajhoj/pinglordigado.png'/> + <meta property='og:image:alt' content='Meze de arbaro kuŝas falinta trunko, sen pingloj kaj kun branĉoj derompitaj. Post ĝi videblas du feoj: florofeo maldekstre kaj nubofeo dekstre. La florofeo iom kaŝas sin post la trunko. La nubofeo staras kaj tenas amason da pigloj. Ili iom rigardas al si.'/> + <meta property='og:image:height' content='630'/> + <meta property='og:image:width' content='1200'/> + <meta property='og:image' content='https://tirifto.xwx.moe/r/opengraph/eo.png'/> + <meta property='og:image:alt' content='La tirifta okulo ĉirkaŭita de ornamaj steloj kaj la teksto: »Tiriftejo. Esperanto.«'/> + <meta property='og:image:height' content='630'/> + <meta property='og:image:width' content='1200'/> + </head> + <body> + <header id='website-header'> + <nav id='website-navigation'> + <input type='checkbox' id='website-navigation-toggle' + aria-description='Montri ligilojn al ĉefaj paĝoj de la retejo.'/> + <label for='website-navigation-toggle'>Paĝoj</label> + <a href='/eo/verkoj.html'>Verkoj</a> + <a href='/eo/novajhoj.html'>Novaĵoj</a> + <a href='/eo/donacoj.html'>Donacoj</a> + <a href='/eo/prio.html'>Prio</a> + <a href='/eo/amikoj.html'>Amikoj</a> + <a href='/eo/kontakto.html'>Kontakto</a> + + </nav> + <span id='eye' role='img' aria-label=''></span> + <nav id='language-switcher' + aria-roledescription='lingvo-ŝanĝilo'> + <input type='checkbox' id='language-switcher-toggle' + aria-description='Montri ligilojn al tradukoj de tiu ĉi paĝo.'/> + <label for='language-switcher-toggle'>Lingvoj</label> + <a href='fulmo.html' lang='eo' hreflang='eo'><img aria-hidden='true' alt='' src='/r/flagoj/eo.png'/>Esperanto</a> + </nav> + </header> + <div class='bodier'> + <nav id='work-links'> + <a href='.'>Ceteraj rakontoj</a> + <a href='../bildosignoj'>Bildosignoj</a> + <a href='../eseoj'>Eseoj</a> + <a href='../ludoj'>Ludoj</a> + <a href='../poemoj'>Poemoj</a> + <a href='../vortaroj'>Vortaroj</a> + </nav> + <main> + <article> + <header> + <h1>Fulmo</h1> + <p>Skribis Tirifto</p> + <time datetime='2025-01-31'>2025-01-31</time> + </header> + <p>»Kial ĉiam mi? Tio ne justas! Oni kulpigas min, sed ja ne mi kulpas!« La nubofeo lamentis, dum ĝi ordigis restaĵojn de falinta arbo. Plejparto el la pingloj estis brulintaj, kaj el la trunko ankoraŭ leviĝis fumo.</p> + <p>Subite aŭdeblis ekstraj kraketoj deapude. Ĝi rigardis flanken, kaj vidis iun kaŭri apud la arbo, derompi branĉetojn, kaj orde ilin amasigi. Ŝajnis, ke ekde sia rimarkiĝo, la nekonatulo laŭeble kuntiriĝis, kaj strebis labori kiel eble plej silente.</p> + <p>»Saluton…?« La nubofeo stariĝis, alporolante la eston. Tiu kvazaŭ frostiĝis, sed timeme ankaŭ stariĝis.</p> + <p>»S- Saluton…« Ĝi respondis sen kuraĝo rigardi ĝiadirekten. Nun stare, videblis ke ĝi estas verdanta florofeo.</p> + <p>»… kion vi faras tie ĉi?« La nubofeo demandis.</p> + <p>»Nu… tiel kaj tiel… mi ordigas.«</p> + <p>»Ho. Mi ricevis taskon ordigi ĉi tie… se vi povas atendi, vi ne bezonas peni!«</p> + <p>»N- Nu… mi tamen volus…« Parolis la florofeo, plu deturnante la kapon.</p> + <p>»Nu… bone, se vi tion deziras… dankon!« La nubofeo dankis, kaj returniĝis al sia laboro.</p> + <p>Fojfoje ĝi scivole rigardis al sia nova kunlaboranto, kaj fojfoje renkontis similan rigardon de ĝia flanko, kiuokaze ambaŭ rigardoj rapide revenis al la ordigataj pingloj kaj branĉetoj. »(Kial tiom volonte helpi min?)« Pensis al si la nubofeo. »(Ĉu ĝi simple tiom bonkoras? Ĝi ja tre bele floras; eble ankaŭ ĝia koro tiel same belas…)« Kaj vere, ĝiaj surfloroj grandanime malfermis siajn belkolorajn folietojn, kaj bonodoris al mondo.</p> + <figure> + <picture> + <source srcset='/r/ilustrajhoj/pinglordigado.jxl' type='image/jxl'/> + <img src='/r/ilustrajhoj/pinglordigado.png' alt='Meze de arbaro kuŝas falinta trunko, sen pingloj kaj kun branĉoj derompitaj. Post ĝi videblas du feoj: florofeo maldekstre kaj nubofeo dekstre. La florofeo iom kaŝas sin post la trunko. La nubofeo staras kaj tenas amason da pigloj. Ili iom rigardas al si.'/> + </picture> + <figcaption> + Pinglordigado + <details> + <summary>© <time datetime='2025'>2025</time> Tirifto</summary> + <a href='https://artlibre.org/'><img src='/r/permesiloj/lal.svg' class='stamp licence' alt='Emblemo: Permesilo de arto libera'/></a> + </details> + </figcaption> + </figure> + <p>Post iom da tempo, ĉiu feo tralaboris ĝis la trunkomezo, kaj proksimiĝis al la alia feo. Kaj tiam ekpezis sur ili devosento rompi la silenton.</p> + <p>»… kia bela vetero, ĉu ne?« Diris la nubofeo, tuj rimarkonte, ke mallumiĝas, kaj la ĉielo restas kovrita de nuboj.</p> + <p>»Jes ja! Tre nube. Mi ŝatas nubojn!« Respondis la alia entuziasme, sed tuj haltetis kaj deturnis la kapon. Ambaŭ feoj daŭrigis laboron silente, kaj plu proksimiĝis, ĝis tiu preskaŭ estis finita.</p> + <p>»H… H… Ho ne…!« Subite ekdiris la nubofeo urĝe.</p> + <p>»Kio okazas?!«</p> + <p>»T… Tern…!«</p> + <p>»Jen! Tenu!« La florofeo etendis manon kun granda folio. La nubofeo ĝin prenis, kaj tien ternis. Aperis ekfulmo, kaj la cindriĝinta folio disfalis.</p> + <p>»Pardonu… mi ne volis…« Bedaŭris la nubofeo. »Mi ne scias, kial tio ĉiam okazas! Tiom plaĉas al mi promeni tere, sed ĉiuj diras, ke mi maldevus, ĉar ial ĝi ĉiam finiĝas tiel ĉi.« Ĝi montris al la arbo. »Eble ili pravas…«</p> + <p>»Nu…« diris la florofeo bedaŭre, kaj etendis la manon.</p> + <p>»H… H… Ne ree…!«</p> + <p>Ekfulmis. Alia ĵus metita folio cindriĝis en la manoj de la florofeo, time ferminta la okulojn.</p> + <p>»Dankegon… mi tre ŝatas vian helpon! Kaj mi ne… ne…«</p> + <p>Metiĝis. Ekfulmis. Cindriĝis.</p> + <p>»Io tre iritas mian nazon!« Plendis la nubofeo. Poste ĝi rimarkis la florpolvon, kiu disŝutiĝis el la florofeo en la tutan ĉirkaŭaĵon, kaj eĉ tuj antaŭ la nubofeon.</p> + <p>»N- Nu…« Diris la florofeo, honte rigardanta la teron. »… pardonu.«</p> + <footer> + <noscript><p>Ĉu vi ŝatas la verkon? <a href='/eo/donacoj.html'>Subtenu min</a> aŭ kopiu adreson de la verko por diskonigi ĝin!</p></noscript> + <script id='underbuttons'> + /* @license magnet:?xt=urn:btih:90dc5c0be029de84e523b9b3922520e79e0e6f08&dn=cc0.txt CC0-1.0 */ + document.getElementById('underbuttons').outerHTML = "<p><a href='/eo/donacoj.html' class='button' target='_blank'>Subtenu min</a> <button onclick='navigator.clipboard.writeText(window.location.href.split(\"\#\")[0]).then(() => window.alert(\"Ligilo al ĉi tiu verko estas kopiita. Sendu ĝin al iu por diskonigi la verkon! 🐱\"))'>Diskonigu la verkon</button></p>" + /* @license-end */ + </script> + <details class='history'> + <summary>Historio</summary> + <dl> + <dt><time datetime='2025-01-31'>2025-01-31</time></dt> + <dd>Unua publikigo.</dd> + </dl> + </details> + <details class='licence' open='details'> + <summary>Permesilo</summary> + <p>Ĉi tiun verkon vi rajtas libere kopii, disdoni, kaj ŝanĝi, laŭ kondiĉoj de la <a href='https://artlibre.org/'>Permesilo de arto libera</a>. (Resume: Vi devas mencii la aŭtoron kaj doni ligilon al la verko. Se vi ŝanĝas la verkon, vi devas laŭeble noti la faritajn ŝanĝojn, ilian daton, kaj eldoni ilin sub la sama permesilo.)</p> + <a href='https://artlibre.org/'><img src='/r/permesiloj/lal.svg' class='stamp licence' alt='Emblemo: Permesilo de arto libera'/></a> + </details> + </footer> + </article> + </main> + </div> + <footer id='website-footer'> + <div class='stamps'> + <a href='https://gnu.org/'> + <img class='stamp' src='/r/retetikedoj/gnu.png' lang='en' alt='GNU'/></a> + <img class='stamp' src='/r/retetikedoj/ihhtus.png' lang='el' alt='ΙΧΘΥΣ'/> + <img class='stamp' src='/r/retetikedoj/be-kind.apng' lang='en' alt='Be kind.'/> + <img class='stamp' src='/r/retetikedoj/kulturo-libera.png' lang='eo' alt='Kulturo libera.'/> + <img class='stamp' src='/r/retetikedoj/discord.png' lang='en' alt='Say ‘no’ to Discord.'/> + <a href='https://xwx.moe/'> + <img class='stamp' src='/r/retetikedoj/xwx-moe.png' alt='xwx.moe'/></a> + <a href='https://mojeek.co.uk' hreflang='en'> + <img class='stamp' src='/r/retetikedoj/mojeek.png' lang='en' alt='Mojeek'/></a> + <a href='https://raku.org/' hreflang='en'> + <img class='stamp' src='/r/retetikedoj/raku.png' alt='Raku'/></a> + <picture> + <source srcset='/r/retetikedoj/jxl.jxl' type='image/jxl'/> + <img class='stamp' src='/r/retetikedoj/jxl.png' alt='JPEG XL'/></picture> + </div> + </footer> + </body> +</html> diff --git a/test/pleroma/web/activity_pub/mrf/fo_direct_reply_test.exs b/test/pleroma/web/activity_pub/mrf/fo_direct_reply_test.exs deleted file mode 100644 index 2d6af3b68..000000000 --- a/test/pleroma/web/activity_pub/mrf/fo_direct_reply_test.exs +++ /dev/null @@ -1,117 +0,0 @@ -# Pleroma: A lightweight social networking server -# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/> -# SPDX-License-Identifier: AGPL-3.0-only - -defmodule Pleroma.Web.ActivityPub.MRF.FODirectReplyTest do - use Pleroma.DataCase - import Pleroma.Factory - - require Pleroma.Constants - - alias Pleroma.Object - alias Pleroma.Web.ActivityPub.MRF.FODirectReply - alias Pleroma.Web.CommonAPI - - test "replying to followers-only/private is changed to direct" do - batman = insert(:user, nickname: "batman") - robin = insert(:user, nickname: "robin") - - {:ok, post} = - CommonAPI.post(batman, %{ - status: "Has anyone seen Selina Kyle's latest selfies?", - visibility: "private" - }) - - reply = %{ - "type" => "Create", - "actor" => robin.ap_id, - "to" => [batman.ap_id, robin.follower_address], - "cc" => [], - "object" => %{ - "type" => "Note", - "actor" => robin.ap_id, - "content" => "@batman 🤤 ❤️ 🐈⬛", - "to" => [batman.ap_id, robin.follower_address], - "cc" => [], - "inReplyTo" => Object.normalize(post).data["id"] - } - } - - expected_to = [batman.ap_id] - expected_cc = [] - - assert {:ok, filtered} = FODirectReply.filter(reply) - - assert expected_to == filtered["to"] - assert expected_cc == filtered["cc"] - assert expected_to == filtered["object"]["to"] - assert expected_cc == filtered["object"]["cc"] - end - - test "replies to unlisted posts are unmodified" do - batman = insert(:user, nickname: "batman") - robin = insert(:user, nickname: "robin") - - {:ok, post} = - CommonAPI.post(batman, %{ - status: "Has anyone seen Selina Kyle's latest selfies?", - visibility: "unlisted" - }) - - reply = %{ - "type" => "Create", - "actor" => robin.ap_id, - "to" => [batman.ap_id, robin.follower_address], - "cc" => [], - "object" => %{ - "type" => "Note", - "actor" => robin.ap_id, - "content" => "@batman 🤤 ❤️ 🐈<200d>⬛", - "to" => [batman.ap_id, robin.follower_address], - "cc" => [], - "inReplyTo" => Object.normalize(post).data["id"] - } - } - - assert {:ok, filtered} = FODirectReply.filter(reply) - - assert match?(^filtered, reply) - end - - test "replies to public posts are unmodified" do - batman = insert(:user, nickname: "batman") - robin = insert(:user, nickname: "robin") - - {:ok, post} = - CommonAPI.post(batman, %{status: "Has anyone seen Selina Kyle's latest selfies?"}) - - reply = %{ - "type" => "Create", - "actor" => robin.ap_id, - "to" => [batman.ap_id, robin.follower_address], - "cc" => [], - "object" => %{ - "type" => "Note", - "actor" => robin.ap_id, - "content" => "@batman 🤤 ❤️ 🐈<200d>⬛", - "to" => [batman.ap_id, robin.follower_address], - "cc" => [], - "inReplyTo" => Object.normalize(post).data["id"] - } - } - - assert {:ok, filtered} = FODirectReply.filter(reply) - - assert match?(^filtered, reply) - end - - test "non-reply posts are unmodified" do - batman = insert(:user, nickname: "batman") - - {:ok, post} = CommonAPI.post(batman, %{status: "To the Batmobile!"}) - - assert {:ok, filtered} = FODirectReply.filter(post) - - assert match?(^filtered, post) - end -end diff --git a/test/pleroma/web/activity_pub/mrf/quiet_reply_test.exs b/test/pleroma/web/activity_pub/mrf/quiet_reply_test.exs deleted file mode 100644 index 79e64d650..000000000 --- a/test/pleroma/web/activity_pub/mrf/quiet_reply_test.exs +++ /dev/null @@ -1,140 +0,0 @@ -# Pleroma: A lightweight social networking server -# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/> -# SPDX-License-Identifier: AGPL-3.0-only - -defmodule Pleroma.Web.ActivityPub.MRF.QuietReplyTest do - use Pleroma.DataCase - import Pleroma.Factory - - require Pleroma.Constants - - alias Pleroma.Object - alias Pleroma.Web.ActivityPub.MRF.QuietReply - alias Pleroma.Web.CommonAPI - - test "replying to public post is forced to be quiet" do - batman = insert(:user, nickname: "batman") - robin = insert(:user, nickname: "robin") - - {:ok, post} = CommonAPI.post(batman, %{status: "To the Batmobile!"}) - - reply = %{ - "type" => "Create", - "actor" => robin.ap_id, - "to" => [ - batman.ap_id, - Pleroma.Constants.as_public() - ], - "cc" => [robin.follower_address], - "object" => %{ - "type" => "Note", - "actor" => robin.ap_id, - "content" => "@batman Wait up, I forgot my spandex!", - "to" => [ - batman.ap_id, - Pleroma.Constants.as_public() - ], - "cc" => [robin.follower_address], - "inReplyTo" => Object.normalize(post).data["id"] - } - } - - expected_to = [batman.ap_id, robin.follower_address] - expected_cc = [Pleroma.Constants.as_public()] - - assert {:ok, filtered} = QuietReply.filter(reply) - - assert expected_to == filtered["to"] - assert expected_cc == filtered["cc"] - assert expected_to == filtered["object"]["to"] - assert expected_cc == filtered["object"]["cc"] - end - - test "replying to unlisted post is unmodified" do - batman = insert(:user, nickname: "batman") - robin = insert(:user, nickname: "robin") - - {:ok, post} = CommonAPI.post(batman, %{status: "To the Batmobile!", visibility: "private"}) - - reply = %{ - "type" => "Create", - "actor" => robin.ap_id, - "to" => [batman.ap_id], - "cc" => [], - "object" => %{ - "type" => "Note", - "actor" => robin.ap_id, - "content" => "@batman Wait up, I forgot my spandex!", - "to" => [batman.ap_id], - "cc" => [], - "inReplyTo" => Object.normalize(post).data["id"] - } - } - - assert {:ok, filtered} = QuietReply.filter(reply) - - assert match?(^filtered, reply) - end - - test "replying direct is unmodified" do - batman = insert(:user, nickname: "batman") - robin = insert(:user, nickname: "robin") - - {:ok, post} = CommonAPI.post(batman, %{status: "To the Batmobile!"}) - - reply = %{ - "type" => "Create", - "actor" => robin.ap_id, - "to" => [batman.ap_id], - "cc" => [], - "object" => %{ - "type" => "Note", - "actor" => robin.ap_id, - "content" => "@batman Wait up, I forgot my spandex!", - "to" => [batman.ap_id], - "cc" => [], - "inReplyTo" => Object.normalize(post).data["id"] - } - } - - assert {:ok, filtered} = QuietReply.filter(reply) - - assert match?(^filtered, reply) - end - - test "replying followers-only is unmodified" do - batman = insert(:user, nickname: "batman") - robin = insert(:user, nickname: "robin") - - {:ok, post} = CommonAPI.post(batman, %{status: "To the Batmobile!"}) - - reply = %{ - "type" => "Create", - "actor" => robin.ap_id, - "to" => [batman.ap_id, robin.follower_address], - "cc" => [], - "object" => %{ - "type" => "Note", - "actor" => robin.ap_id, - "content" => "@batman Wait up, I forgot my spandex!", - "to" => [batman.ap_id, robin.follower_address], - "cc" => [], - "inReplyTo" => Object.normalize(post).data["id"] - } - } - - assert {:ok, filtered} = QuietReply.filter(reply) - - assert match?(^filtered, reply) - end - - test "non-reply posts are unmodified" do - batman = insert(:user, nickname: "batman") - - {:ok, post} = CommonAPI.post(batman, %{status: "To the Batmobile!"}) - - assert {:ok, filtered} = QuietReply.filter(post) - - assert match?(^filtered, post) - end -end diff --git a/test/pleroma/web/metadata/providers/open_graph_test.exs b/test/pleroma/web/metadata/providers/open_graph_test.exs index 6a0fc9b10..29cc036ba 100644 --- a/test/pleroma/web/metadata/providers/open_graph_test.exs +++ b/test/pleroma/web/metadata/providers/open_graph_test.exs @@ -9,6 +9,7 @@ defmodule Pleroma.Web.Metadata.Providers.OpenGraphTest do alias Pleroma.UnstubbedConfigMock, as: ConfigMock alias Pleroma.Web.Metadata.Providers.OpenGraph + alias Pleroma.Web.Metadata.Utils setup do ConfigMock @@ -197,4 +198,58 @@ defmodule Pleroma.Web.Metadata.Providers.OpenGraphTest do "http://localhost:4001/proxy/preview/LzAnlke-l5oZbNzWsrHfprX1rGw/aHR0cHM6Ly9wbGVyb21hLmdvdi9hYm91dC9qdWNoZS53ZWJt/juche.webm" ], []} in result end + + test "meta tag ordering matches attachment order" do + user = insert(:user, name: "Jimmy Hendriks", bio: "born 19 March 1994") + + note = + insert(:note, %{ + data: %{ + "actor" => user.ap_id, + "tag" => [], + "id" => "https://pleroma.gov/objects/whatever", + "summary" => "", + "content" => "pleroma in a nutshell", + "attachment" => [ + %{ + "url" => [ + %{ + "mediaType" => "image/png", + "href" => "https://example.com/first.png", + "height" => 1024, + "width" => 1280 + } + ] + }, + %{ + "url" => [ + %{ + "mediaType" => "image/png", + "href" => "https://example.com/second.png", + "height" => 1024, + "width" => 1280 + } + ] + } + ] + } + }) + + result = OpenGraph.build_tags(%{object: note, url: note.data["id"], user: user}) + + assert [ + {:meta, [property: "og:title", content: Utils.user_name_string(user)], []}, + {:meta, [property: "og:url", content: "https://pleroma.gov/objects/whatever"], []}, + {:meta, [property: "og:description", content: "pleroma in a nutshell"], []}, + {:meta, [property: "og:type", content: "article"], []}, + {:meta, [property: "og:image", content: "https://example.com/first.png"], []}, + {:meta, [property: "og:image:alt", content: nil], []}, + {:meta, [property: "og:image:width", content: "1280"], []}, + {:meta, [property: "og:image:height", content: "1024"], []}, + {:meta, [property: "og:image", content: "https://example.com/second.png"], []}, + {:meta, [property: "og:image:alt", content: nil], []}, + {:meta, [property: "og:image:width", content: "1280"], []}, + {:meta, [property: "og:image:height", content: "1024"], []} + ] == result + end end diff --git a/test/pleroma/web/metadata/providers/twitter_card_test.exs b/test/pleroma/web/metadata/providers/twitter_card_test.exs index f8d01c5c8..f9e917719 100644 --- a/test/pleroma/web/metadata/providers/twitter_card_test.exs +++ b/test/pleroma/web/metadata/providers/twitter_card_test.exs @@ -202,4 +202,58 @@ defmodule Pleroma.Web.Metadata.Providers.TwitterCardTest do {:meta, [name: "twitter:player:stream:content_type", content: "video/webm"], []} ] == result end + + test "meta tag ordering matches attachment order" do + user = insert(:user, name: "Jimmy Hendriks", bio: "born 19 March 1994") + + note = + insert(:note, %{ + data: %{ + "actor" => user.ap_id, + "tag" => [], + "id" => "https://pleroma.gov/objects/whatever", + "summary" => "", + "content" => "pleroma in a nutshell", + "attachment" => [ + %{ + "url" => [ + %{ + "mediaType" => "image/png", + "href" => "https://example.com/first.png", + "height" => 1024, + "width" => 1280 + } + ] + }, + %{ + "url" => [ + %{ + "mediaType" => "image/png", + "href" => "https://example.com/second.png", + "height" => 1024, + "width" => 1280 + } + ] + } + ] + } + }) + + result = TwitterCard.build_tags(%{object: note, activity_id: note.data["id"], user: user}) + + assert [ + {:meta, [name: "twitter:title", content: Utils.user_name_string(user)], []}, + {:meta, [name: "twitter:description", content: "pleroma in a nutshell"], []}, + {:meta, [name: "twitter:card", content: "summary_large_image"], []}, + {:meta, [name: "twitter:image", content: "https://example.com/first.png"], []}, + {:meta, [name: "twitter:image:alt", content: ""], []}, + {:meta, [name: "twitter:player:width", content: "1280"], []}, + {:meta, [name: "twitter:player:height", content: "1024"], []}, + {:meta, [name: "twitter:card", content: "summary_large_image"], []}, + {:meta, [name: "twitter:image", content: "https://example.com/second.png"], []}, + {:meta, [name: "twitter:image:alt", content: ""], []}, + {:meta, [name: "twitter:player:width", content: "1280"], []}, + {:meta, [name: "twitter:player:height", content: "1024"], []} + ] == result + end end diff --git a/test/pleroma/web/rich_media/parser_test.exs b/test/pleroma/web/rich_media/parser_test.exs index 8fd75b57a..20f61badc 100644 --- a/test/pleroma/web/rich_media/parser_test.exs +++ b/test/pleroma/web/rich_media/parser_test.exs @@ -54,7 +54,6 @@ defmodule Pleroma.Web.RichMedia.ParserTest do {:ok, %{ "card" => "summary", - "site" => "@flickr", "image" => "https://farm6.staticflickr.com/5510/14338202952_93595258ff_z.jpg", "title" => "Small Island Developing States Photo Submission", "description" => "View the album on Flickr.", diff --git a/test/pleroma/web/rich_media/parsers/twitter_card_test.exs b/test/pleroma/web/rich_media/parsers/twitter_card_test.exs index e84a4e50a..15b272ff2 100644 --- a/test/pleroma/web/rich_media/parsers/twitter_card_test.exs +++ b/test/pleroma/web/rich_media/parsers/twitter_card_test.exs @@ -17,10 +17,6 @@ defmodule Pleroma.Web.RichMedia.Parsers.TwitterCardTest do assert TwitterCard.parse(html, %{}) == %{ - "app:id:googleplay" => "com.nytimes.android", - "app:name:googleplay" => "NYTimes", - "app:url:googleplay" => "nytimes://reader/id/100000006583622", - "site" => nil, "description" => "With little oversight, the N.Y.P.D. has been using powerful surveillance technology on photos of children and teenagers.", "image" => @@ -44,7 +40,7 @@ defmodule Pleroma.Web.RichMedia.Parsers.TwitterCardTest do "description" => "With little oversight, the N.Y.P.D. has been using powerful surveillance technology on photos of children and teenagers.", "image" => - "https://static01.nyt.com/images/2019/08/01/nyregion/01nypd-juveniles-promo/01nypd-juveniles-promo-videoSixteenByNineJumbo1600.jpg", + "https://static01.nyt.com/images/2019/08/01/nyregion/01nypd-juveniles-promo/01nypd-juveniles-promo-facebookJumbo.jpg", "image:alt" => "", "title" => "She Was Arrested at 14. Then Her Photo Went to a Facial Recognition Database.", @@ -61,16 +57,12 @@ defmodule Pleroma.Web.RichMedia.Parsers.TwitterCardTest do assert TwitterCard.parse(html, %{}) == %{ - "app:id:googleplay" => "com.nytimes.android", - "app:name:googleplay" => "NYTimes", - "app:url:googleplay" => "nytimes://reader/id/100000006583622", "card" => "summary_large_image", "description" => "With little oversight, the N.Y.P.D. has been using powerful surveillance technology on photos of children and teenagers.", "image" => - "https://static01.nyt.com/images/2019/08/01/nyregion/01nypd-juveniles-promo/01nypd-juveniles-promo-videoSixteenByNineJumbo1600.jpg", + "https://static01.nyt.com/images/2019/08/01/nyregion/01nypd-juveniles-promo/01nypd-juveniles-promo-facebookJumbo.jpg", "image:alt" => "", - "site" => nil, "title" => "She Was Arrested at 14. Then Her Photo Went to a Facial Recognition Database.", "url" => @@ -90,13 +82,11 @@ defmodule Pleroma.Web.RichMedia.Parsers.TwitterCardTest do assert TwitterCard.parse(html, %{}) == %{ - "site" => "@atlasobscura", "title" => "The Missing Grave of Margaret Corbin, Revolutionary War Veteran", "card" => "summary_large_image", "image" => image_path, "description" => "She's the only woman veteran honored with a monument at West Point. But where was she buried?", - "site_name" => "Atlas Obscura", "type" => "article", "url" => "http://www.atlasobscura.com/articles/margaret-corbin-grave-west-point" } @@ -109,12 +99,8 @@ defmodule Pleroma.Web.RichMedia.Parsers.TwitterCardTest do assert TwitterCard.parse(html, %{}) == %{ - "site" => nil, "title" => "She Was Arrested at 14. Then Her Photo Went to a Facial Recognition Database.", - "app:id:googleplay" => "com.nytimes.android", - "app:name:googleplay" => "NYTimes", - "app:url:googleplay" => "nytimes://reader/id/100000006583622", "description" => "With little oversight, the N.Y.P.D. has been using powerful surveillance technology on photos of children and teenagers.", "image" => @@ -124,4 +110,23 @@ defmodule Pleroma.Web.RichMedia.Parsers.TwitterCardTest do "https://www.nytimes.com/2019/08/01/nyregion/nypd-facial-recognition-children-teenagers.html" } end + + test "takes first image if multiple are specified" do + html = + File.read!("test/fixtures/fulmo.html") + |> Floki.parse_document!() + + assert TwitterCard.parse(html, %{}) == + %{ + "description" => "Pri feoj, kiuj devis ordigi falintan arbon.", + "image" => "https://tirifto.xwx.moe/r/ilustrajhoj/pinglordigado.png", + "title" => "Fulmo", + "type" => "website", + "url" => "https://tirifto.xwx.moe/eo/rakontoj/fulmo.html", + "image:alt" => + "Meze de arbaro kuŝas falinta trunko, sen pingloj kaj kun branĉoj derompitaj. Post ĝi videblas du feoj: florofeo maldekstre kaj nubofeo dekstre. La florofeo iom kaŝas sin post la trunko. La nubofeo staras kaj tenas amason da pigloj. Ili iom rigardas al si.", + "image:height" => "630", + "image:width" => "1200" + } + end end |