Add a test for generated JSON

This commit is contained in:
Jonny Barnes 2017-05-19 11:30:28 +01:00
parent 9d9e3577bc
commit cdf265fcc1

View file

@ -0,0 +1,51 @@
<?php
namespace Tests\Feature;
use Mockery;
use Tests\TestCase;
use App\IndieWebUser;
use IndieAuth\Client as IndieClient;
use GuzzleHttp\Client as GuzzleClient;
use GuzzleHttp\Middleware;
use GuzzleHttp\HandlerStack;
use GuzzleHttp\Psr7\Response;
use GuzzleHttp\Handler\MockHandler;
use Illuminate\Foundation\Testing\WithoutMiddleware;
use Illuminate\Foundation\Testing\DatabaseMigrations;
use Illuminate\Foundation\Testing\DatabaseTransactions;
class MicropubClientControllerTest extends TestCase
{
use DatabaseTransactions;
public function test_json_syntax_is_created_correctly()
{
$container = [];
$history = Middleware::history($container);
$mock = new MockHandler([
new Response(201, ['Location' => 'http://example.org/a'], 'Created'),
]);
$stack = HandlerStack::create($mock);
$stack->push($history);
$guzzleClient = new GuzzleClient(['handler' => $stack]);
$this->app->instance(GuzzleClient::class, $guzzleClient);
$response = $this->post(
'/micropub',
[
'content' => 'Hello Fred',
'in-reply-to' => 'https://fredbloggs.com/note/abc',
'mp-syndicate-to' => ['https://twitter.com/jonnybarnes', 'https://facebook.com/jonnybarnes'],
]
);
$expected = '{"type":["h-entry"],"properties":{"content":["Hello Fred"],"in-reply-to":["https:\/\/fredbloggs.com\/note\/abc"],"mp-syndicate-to":["https:\/\/twitter.com\/jonnybarnes","https:\/\/facebook.com\/jonnybarnes"]}}';
foreach ($container as $transaction) {
$this->assertEquals($expected, $transaction['request']->getBody()->getContents());
}
}
}