2017-02-19 00:36:30 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Tests\Unit;
|
|
|
|
|
|
|
|
use Tests\TestCase;
|
2017-09-04 19:34:39 +01:00
|
|
|
use App\Services\IndieAuthService;
|
2017-02-19 00:36:30 +00:00
|
|
|
|
|
|
|
class IndieAuthServiceTest extends TestCase
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Test the getAuthorizationEndpoint method.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function test_indieauthservice_getauthorizationendpoint_method()
|
|
|
|
{
|
2017-09-04 19:34:39 +01:00
|
|
|
$service = new IndieAuthService();
|
2017-03-01 20:59:09 +00:00
|
|
|
$result = $service->getAuthorizationEndpoint(config('app.url'));
|
2017-02-19 00:36:30 +00:00
|
|
|
$this->assertEquals('https://indieauth.com/auth', $result);
|
|
|
|
}
|
|
|
|
|
2017-03-01 20:59:09 +00:00
|
|
|
/**
|
|
|
|
* Test the getAuthorizationEndpoint method returns null on failure.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function test_indieauthservice_getauthorizationendpoint_method_returns_null_on_failure()
|
|
|
|
{
|
2017-09-04 19:34:39 +01:00
|
|
|
$service = new IndieAuthService();
|
2017-03-01 20:59:09 +00:00
|
|
|
$result = $service->getAuthorizationEndpoint('http://example.org');
|
|
|
|
$this->assertEquals(null, $result);
|
|
|
|
}
|
|
|
|
|
2017-02-19 00:36:30 +00:00
|
|
|
/**
|
|
|
|
* Test that the Service build the correct redirect URL.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function test_indieauthservice_builds_correct_redirect_url()
|
|
|
|
{
|
2017-09-04 19:34:39 +01:00
|
|
|
$service = new IndieAuthService();
|
2017-02-19 00:36:30 +00:00
|
|
|
$result = $service->buildAuthorizationURL(
|
|
|
|
'https://indieauth.com/auth',
|
2017-03-01 20:59:09 +00:00
|
|
|
config('app.url')
|
2017-02-19 00:36:30 +00:00
|
|
|
);
|
|
|
|
$this->assertEquals(
|
|
|
|
'https://indieauth.com/auth?me=',
|
|
|
|
substr($result, 0, 30)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test the getTokenEndpoint method.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function test_indieauthservice_gettokenendpoint_method()
|
|
|
|
{
|
2017-09-04 19:34:39 +01:00
|
|
|
$service = new IndieAuthService();
|
2017-03-01 20:59:09 +00:00
|
|
|
$result = $service->getTokenEndpoint(config('app.url'));
|
2017-02-19 00:36:30 +00:00
|
|
|
$this->assertEquals(config('app.url') . '/api/token', $result);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test the discoverMicropubEndpoint method.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function test_indieauthservice_discovermicropubendpoint_method()
|
|
|
|
{
|
2017-09-04 19:34:39 +01:00
|
|
|
$service = new IndieAuthService();
|
2017-03-01 20:59:09 +00:00
|
|
|
$result = $service->discoverMicropubEndpoint(config('app.url'));
|
2017-02-19 00:36:30 +00:00
|
|
|
$this->assertEquals(config('app.url') . '/api/post', $result);
|
|
|
|
}
|
|
|
|
}
|