diff --git a/tests/Feature/IndieAuthControllerTest.php b/tests/Feature/IndieAuthControllerTest.php new file mode 100644 index 00000000..c5ed4de1 --- /dev/null +++ b/tests/Feature/IndieAuthControllerTest.php @@ -0,0 +1,51 @@ +call('GET', '/indieauth/start', ['me' => 'http://example.org']); + $this->assertSame(config('app.url') . '/micropub/create', $response->headers->get('Location')); + } + + /** + * Now we test the `start` method as a whole. + * + * @return void + */ + public function test_indieauthcontroller_begin_auth_redirects_to_endpoint() + { + $response = $this->call('GET', '/indieauth/start', ['me' => config('app.url')]); + $this->assertSame( + 'https://indieauth.com/auth?me=', + substr($response->headers->get('Location'), 0, 30) + ); + } + + /** + * Test the `callback` method. + * + * @return void + */ + public function test_indieauthcontroller_callback_method_gives_error_with_mismatched_state() + { + $response = $this->withSession(['state' => 'state-session']) + ->call( + 'GET', + 'indieauth/callback', + ['me', config('app.url'), 'state' => 'request-session'] + ); + $response->assertSessionHasErrors(); + } +} diff --git a/tests/Unit/IndieAuthServiceTest.php b/tests/Unit/IndieAuthServiceTest.php new file mode 100644 index 00000000..3035d8f5 --- /dev/null +++ b/tests/Unit/IndieAuthServiceTest.php @@ -0,0 +1,69 @@ +getAuthorizationEndpoint(config('app.url'), $client); + $this->assertEquals('https://indieauth.com/auth', $result); + } + + /** + * Test that the Service build the correct redirect URL. + * + * @return void + */ + public function test_indieauthservice_builds_correct_redirect_url() + { + $service = new \App\Services\IndieAuthService(); + $client = new \IndieAuth\Client(); + $result = $service->buildAuthorizationURL( + 'https://indieauth.com/auth', + config('app.url'), + $client + ); + $this->assertEquals( + 'https://indieauth.com/auth?me=', + substr($result, 0, 30) + ); + } + + /** + * Test the getTokenEndpoint method. + * + * @return void + */ + public function test_indieauthservice_gettokenendpoint_method() + { + $service = new \App\Services\IndieAuthService(); + $client = new \IndieAuth\Client(); + $result = $service->getTokenEndpoint(config('app.url'), $client); + $this->assertEquals(config('app.url') . '/api/token', $result); + } + + /** + * Test the discoverMicropubEndpoint method. + * + * @return void + */ + public function test_indieauthservice_discovermicropubendpoint_method() + { + $service = new \App\Services\IndieAuthService(); + $client = new \IndieAuth\Client(); + $result = $service->discoverMicropubEndpoint(config('app.url'), $client); + $this->assertEquals(config('app.url') . '/api/post', $result); + } +}