From 9fcd16ec16bea09e77d0d7b153f00d3b0dfe6e95 Mon Sep 17 00:00:00 2001 From: Jonny Barnes Date: Wed, 9 Nov 2022 19:32:22 +0000 Subject: [PATCH] Handle finding webmention targets better If a site does not support webmentions, my code should not error --- app/Jobs/SendWebMentions.php | 7 +++++-- tests/Unit/Jobs/SendWebMentionJobTest.php | 14 ++++++++++++++ 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/app/Jobs/SendWebMentions.php b/app/Jobs/SendWebMentions.php index 815eb2be..92267d18 100644 --- a/app/Jobs/SendWebMentions.php +++ b/app/Jobs/SendWebMentions.php @@ -100,9 +100,12 @@ class SendWebMentions implements ShouldQueue } elseif (array_key_exists('http://webmention.org/', $rels[0])) { $endpoint = $rels[0]['http://webmention.org/'][0]; } - if ($endpoint) { - return $this->resolveUri($endpoint, $url); + + if ($endpoint === null) { + return null; } + + return $this->resolveUri($endpoint, $url); } /** diff --git a/tests/Unit/Jobs/SendWebMentionJobTest.php b/tests/Unit/Jobs/SendWebMentionJobTest.php index 213ad200..2f185b3a 100644 --- a/tests/Unit/Jobs/SendWebMentionJobTest.php +++ b/tests/Unit/Jobs/SendWebMentionJobTest.php @@ -109,4 +109,18 @@ class SendWebMentionJobTest extends TestCase $job->handle(); $this->assertTrue(true); } + + /** @test */ + public function linksInNotesCanNotSupportWebmentions(): void + { + $mock = new MockHandler([ + new Response(200), + ]); + $handler = HandlerStack::create($mock); + $client = new Client(['handler' => $handler]); + $this->app->instance(Client::class, $client); + + $job = new SendWebMentions(new Note()); + $this->assertNull($job->discoverWebmentionEndpoint('https://example.org')); + } }