jonnybarnes.uk/tests/Feature/MicropubClientControllerTest.php

48 lines
1.5 KiB
PHP
Raw Normal View History

2017-05-19 11:30:28 +01:00
<?php
namespace Tests\Feature;
use Tests\TestCase;
use GuzzleHttp\Client;
2017-05-19 11:30:28 +01:00
use GuzzleHttp\Middleware;
use GuzzleHttp\HandlerStack;
use GuzzleHttp\Psr7\Response;
use GuzzleHttp\Handler\MockHandler;
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);
// add the history middleware to the stack
2017-05-19 11:30:28 +01:00
$stack->push($history);
$client = new Client(['handler' => $stack]);
2017-05-19 11:30:28 +01:00
app()->instance(Client::class, $client);
2017-05-19 11:30:28 +01:00
$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"]}}';
2017-05-19 11:30:28 +01:00
foreach ($container as $transaction) {
$this->assertEquals($expected, $transaction['request']->getBody()->getContents());
}
}
}