From c1e72be0c31c9aaf4dfa3a6929325755c5359a28 Mon Sep 17 00:00:00 2001 From: Jonny Barnes Date: Sat, 18 Feb 2017 15:29:55 +0000 Subject: [PATCH] Add WebMention tests --- tests/Feature/WebMentionsControllerTest.php | 84 +++++++++++++++++++++ 1 file changed, 84 insertions(+) create mode 100644 tests/Feature/WebMentionsControllerTest.php diff --git a/tests/Feature/WebMentionsControllerTest.php b/tests/Feature/WebMentionsControllerTest.php new file mode 100644 index 00000000..163eb4ce --- /dev/null +++ b/tests/Feature/WebMentionsControllerTest.php @@ -0,0 +1,84 @@ +call('POST', '/webmention', ['source' => 'https://example.org/post/123']); + $response->assertStatus(400); + } + + /** + * Test invalid target gets a 400 response. + * + * @return void + */ + public function test_invalid_target_returns_400_response() + { + $response = $this->call('POST', '/webmention', [ + 'source' => 'https://example.org/post/123', + 'target' => config('app.url') . '/invalid/target' + ]); + $response->assertStatus(400); + } + + /** + * Test blog target gets a 501 response due to me not supporting it. + * + * @return void + */ + public function test_blog_target_returns_501_response() + { + $response = $this->call('POST', '/webmention', [ + 'source' => 'https://example.org/post/123', + 'target' => config('app.url') . '/blog/target' + ]); + $response->assertStatus(501); + } + + /** + * Test that a non-existant note gives a 400 response. + * + * @return void + */ + public function test_nonexistant_note_returns_400_response() + { + $response = $this->call('POST', '/webmention', [ + 'source' => 'https://example.org/post/123', + 'target' => config('app.url') . '/notes/ZZZZZ' + ]); + $response->assertStatus(400); + } + + /** + * Test a legit webmention triggers the ProcessWebMention job. + * + * @return void + */ + public function test_legitimate_webmnetion_triggers_processwebmention_job() + { + Queue::fake(); + + $response = $this->call('POST', '/webmention', [ + 'source' => 'https://example.org/post/123', + 'target' => config('app.url') . '/notes/B' + ]); + $response->assertStatus(202); + + Queue::assertPushed(ProcessWebMention::class); + } +}