Improve tests

This commit is contained in:
Jonny Barnes 2022-05-14 17:44:14 +01:00
parent 427debaba4
commit 48d1c9a00b
18 changed files with 267 additions and 14 deletions

View file

@ -79,5 +79,12 @@ class ArticlesTest extends TestCase
$emptyScope = Article::date()->get();
$this->assertCount(2, $emptyScope);
// Check the December case
$article = Article::factory()->create([
'created_at' => Carbon::now()->setMonth(12)->toDateTimeString(),
'updated_at' => Carbon::now()->setMonth(12)->toDateTimeString(),
]);
$this->assertCount(1, Article::date(date('Y'), 12)->get());
}
}

View file

@ -89,23 +89,25 @@ class ProcessWebMentionJobTest extends TestCase
Queue::fake();
$parser = new Parser();
$note = Note::factory()->create();
$source = 'https://aaronpk.localhost/reply/1';
WebMention::factory()->create([
'source' => $source,
'target' => $note->longurl,
]);
$html = <<<HTML
<div class="h-entry">
<p>In reply to <a class="u-in-reply-to" href="/notes/E">a note</a></p>
<p>In reply to <a class="u-in-reply-to" href="{$note->longurl}">a note</a></p>
<div class="e-content">Updated reply</div>
</div>
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://aaronpk.localhost/reply/1';
$job = new ProcessWebMention($note, $source);
$job->handle($parser, $client);
@ -114,7 +116,7 @@ class ProcessWebMentionJobTest extends TestCase
'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": ["' . config('app.url') . '/notes/E"]}}], "rel-urls": []}',
'mf2' => '{"rels": [], "items": [{"type": ["h-entry"], "properties": {"content": [{"html": "Updated reply", "value": "Updated reply"}], "in-reply-to": ["' . $note->longurl . '"]}}], "rel-urls": []}',
]);
}

View file

@ -31,6 +31,17 @@ class LikesTest extends TestCase
$this->assertEquals('some plaintext content', $like->content);
}
/** @test */
public function weCanHandleBlankContent(): void
{
$like = new Like();
$like->url = 'https://example.org/post/123';
$like->content = null;
$like->save();
$this->assertNull($like->content);
}
/** @test */
public function htmlLikeContentIsFiltered(): void
{