jonnybarnes.uk/tests/MicropubClientTest.php
Jonny Barnes 4833540642 Squashed commit of the following:
commit e7723f4290dd79eddc2a8dd1d4c2725914a90b55
Author: Jonny Barnes <jonny@jonnybarnes.uk>
Date:   Thu Nov 3 19:44:33 2016 +0000

    Add latest change to the changelog

commit e2104997ab796eeba320931beaec3bc99fd2d296
Author: Jonny Barnes <jonny@jonnybarnes.uk>
Date:   Thu Nov 3 19:43:27 2016 +0000

    Pass correct info to updated social links template

commit 586ca9b5446e272ef3b89a615ba0666e6f7d8d82
Author: Jonny Barnes <jonny@jonnybarnes.uk>
Date:   Thu Nov 3 19:42:08 2016 +0000

    Remove reply/like/repost links, add facebook link

commit 00483089380d2e00d24d86a4b1a03363161c7a97
Author: Jonny Barnes <jonny@jonnybarnes.uk>
Date:   Thu Nov 3 19:22:46 2016 +0000

    Add dummy Facebook URLs for syndication

commit 2e001b04e36a7fd1198fe5ee70db65cd2523e123
Author: Jonny Barnes <jonny@jonnybarnes.uk>
Date:   Thu Nov 3 19:22:11 2016 +0000

    Clarify that syndication isn’t being tested during micropub client integration test
2016-11-03 19:45:56 +00:00

84 lines
2.4 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
namespace App\Tests;
use TestCase;
use Lcobucci\JWT\Builder;
use Lcobucci\JWT\Signer\Hmac\Sha256;
use Illuminate\Foundation\Testing\WithoutMiddleware;
use Illuminate\Foundation\Testing\DatabaseMigrations;
use Illuminate\Foundation\Testing\DatabaseTransactions;
class MicropubClientTest extends TestCase
{
protected $appurl;
public function setUp()
{
parent::setUp();
$this->appurl = config('app.url');
}
/**
* Test the client gets shown for an unauthorised request.
*
* @return void
*/
public function testClientPageUnauthorised()
{
$this->visit($this->appurl . '/notes/new')
->see('IndieAuth');
}
public function testClientPageRecentAuth()
{
$syndication = [
[
'target' => 'https://twitter.com/jonnybarnes',
'name' => 'jonnybarnes on Twitter',
]
];
$this->withSession([
'me' => $this->appurl,
'syndication' => $syndication,
])->visit($this->appurl . '/notes/new')
->see($this->appurl)
->see('https://twitter.com/jonnybarnes');
}
public function testClientCreatesNewNoteWithTag()
{
//in this test, the syndication targets are blank
$faker = \Faker\Factory::create();
$note = 'Fake note from #PHPUnit: ' . $faker->text;
$this->withSession([
'me' => $this->appurl,
'token' => $this->getToken()
])->visit($this->appurl . '/notes/new')
->type($note, 'content')
->press('Submit');
$this->seeInDatabase('notes', ['note' => $note]);
$this->visit($this->appurl . '/notes/tagged/PHPUnit')
->see('PHPUnit');
//my client has made a request to my endpoint, which then adds
//to the db, so database transaction dont work
//so lets manually delete the new entry
$newNote = \App\Note::where('note', $note);
$newNote->forceDelete();
}
private function getToken()
{
$signer = new Sha256();
$token = (new Builder())
->set('client_id', 'https://quill.p3k.io')
->set('me', $this->appurl)
->set('scope', 'post')
->set('issued_at', time())
->sign($signer, env('APP_KEY'))
->getToken();
return $token;
}
}