commit fa51cd728fbb13ebadfc45d90dc24c284a31f4ae Author: Jonny Barnes <jonny@jonnybarnes.uk> Date: Sat Oct 1 14:25:50 2016 +0100 Update changelog commit 93e6a92c664cb42da679c5bb2e37cabec0e7fb99 Author: Jonny Barnes <jonny@jonnybarnes.uk> Date: Sat Oct 1 14:25:00 2016 +0100 test create new place with uncertainty parameter commit 3d793801b3c0e93228ce5c6bae83c74b130127c0 Author: Jonny Barnes <jonny@jonnybarnes.uk> Date: Sat Oct 1 14:24:35 2016 +0100 Parse correctly to take into account uncertainty parameter commit d9060332a484ff414ed4dac03fa39838d7b73b54 Author: Jonny Barnes <jonny@jonnybarnes.uk> Date: Sat Oct 1 11:11:56 2016 +0100 Better comments commit 298663cf7beaf4893d326aae880d64279ce4af37 Author: Jonny Barnes <jonny@jonnybarnes.uk> Date: Fri Sep 30 22:59:08 2016 +0100 Allow tagged notes to be deleted, didn’t know that wasn’t possible before :/ commit 7f5c65c6d858321526b7f0ac84c527dc2f09614a Author: Jonny Barnes <jonny@jonnybarnes.uk> Date: Fri Sep 30 22:57:57 2016 +0100 Better test for creating a new note via mircropub, the new note gets deleted
83 lines
2.3 KiB
PHP
83 lines
2.3 KiB
PHP
<?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()
|
||
{
|
||
$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 don’t 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;
|
||
}
|
||
}
|