exists(storage_path() . '/HTML/https')) { $fs->deleteDirectory(storage_path() . '/HTML/https'); } parent::tearDown(); } #[Test] public function failureGettingWebmentionThrowsAnException(): void { $this->expectException(RemoteContentNotFoundException::class); $parser = new Parser; $mock = new MockHandler([ new Response(404), ]); $handler = HandlerStack::create($mock); $client = new Client(['handler' => $handler]); $note = Note::factory()->create(); $source = 'https://example.org/mention/1/'; $job = new ProcessWebMention($note, $source); $job->handle($parser, $client); } #[Test] public function newWebmentionGetsSavedByJob(): void { Queue::fake(); $parser = new Parser; $html = <<<'HTML'
I liked a note.
HTML; $html = str_replace('href="', 'href="' . config('app.url'), $html); $mock = new MockHandler([ new Response(200, [], $html), ]); $handler = HandlerStack::create($mock); $client = new Client(['handler' => $handler]); $note = Note::factory()->create(); $source = 'https://example.org/mention/1/'; $job = new ProcessWebMention($note, $source); $job->handle($parser, $client); Queue::assertPushed(SaveProfileImage::class); $this->assertDatabaseHas('webmentions', [ 'source' => $source, 'type' => 'like-of', ]); } #[Test] public function existingWebmentionGetsUpdatedByJob(): void { Queue::fake(); $parser = new Parser; $note = Note::factory()->create(); $source = 'https://aaronpk.localhost/reply/1'; WebMention::factory()->create([ 'source' => $source, 'target' => $note->longurl, ]); $html = <<

In reply to a note

Updated reply
HTML; $mock = new MockHandler([ new Response(200, [], $html), ]); $handler = HandlerStack::create($mock); $client = new Client(['handler' => $handler]); $job = new ProcessWebMention($note, $source); $job->handle($parser, $client); Queue::assertPushed(SaveProfileImage::class); $this->assertDatabaseHas('webmentions', [ 'source' => $source, 'type' => 'in-reply-to', // phpcs:ignore Generic.Files.LineLength.TooLong 'mf2' => '{"rels": [], "items": [{"type": ["h-entry"], "properties": {"content": [{"html": "Updated reply", "value": "Updated reply"}], "in-reply-to": ["' . $note->longurl . '"]}}], "rel-urls": []}', ]); } #[Test] public function webmentionReplyGetsDeletedWhenReplyToValueChanges(): void { $parser = new Parser; $html = <<<'HTML'

In reply to a note

Replying to someone else
HTML; $mock = new MockHandler([ new Response(200, [], $html), ]); $handler = HandlerStack::create($mock); $client = new Client(['handler' => $handler]); $note = Note::factory()->create(); $source = 'https://example.org/reply/1'; $webmention = new WebMention; $webmention->source = $source; $webmention->target = config('app.url') . '/notes/E'; $webmention->type = 'in-reply-to'; $webmention->save(); $this->assertDatabaseHas('webmentions', [ 'source' => $source, ]); $job = new ProcessWebMention($note, $source); $job->handle($parser, $client); $this->assertDatabaseMissing('webmentions', [ 'source' => $source, ]); } #[Test] public function webmentionLikeGetsDeletedWhenLikeOfValueChanges(): void { $parser = new Parser; $html = <<<'HTML'

In reply to a note

I like someone else now
HTML; $mock = new MockHandler([ new Response(200, [], $html), ]); $handler = HandlerStack::create($mock); $client = new Client(['handler' => $handler]); $note = Note::factory()->create(); $source = 'https://example.org/reply/1'; $webmention = new WebMention; $webmention->source = $source; $webmention->target = config('app.url') . '/notes/E'; $webmention->type = 'like-of'; $webmention->save(); $this->assertDatabaseHas('webmentions', [ 'source' => $source, ]); $job = new ProcessWebMention($note, $source); $job->handle($parser, $client); $this->assertDatabaseMissing('webmentions', [ 'source' => $source, ]); } #[Test] public function webmentionRepostGetsDeletedWhenRepostOfValueChanges(): void { $parser = new Parser; $html = <<<'HTML'

In reply to a note

Reposting someone else
HTML; $mock = new MockHandler([ new Response(200, [], $html), ]); $handler = HandlerStack::create($mock); $client = new Client(['handler' => $handler]); $note = Note::factory()->create(); $source = 'https://example.org/reply/1'; $webmention = new WebMention; $webmention->source = $source; $webmention->target = config('app.url') . '/notes/E'; $webmention->type = 'repost-of'; $webmention->save(); $this->assertDatabaseHas('webmentions', [ 'source' => $source, ]); $job = new ProcessWebMention($note, $source); $job->handle($parser, $client); $this->assertDatabaseMissing('webmentions', [ 'source' => $source, ]); } }