jonnybarnes.uk/tests/WebMentionsTest.php

92 lines
2.6 KiB
PHP
Raw Permalink 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 Illuminate\Foundation\Testing\WithoutMiddleware;
use Illuminate\Foundation\Testing\DatabaseMigrations;
use Illuminate\Foundation\Testing\DatabaseTransactions;
class WebMentionsTest extends TestCase
{
protected $appurl;
public function setUp()
{
parent::setUp();
$this->appurl = config('app.url');
}
/**
* Test webmentions without source and target are rejected.
*
* @return void
*/
public function testWebmentionsWithoutSourceAndTargetAreRejected()
{
$this->call('POST', $this->appurl . '/webmention', ['source' => 'https://example.org/post/123']);
$this->assertResponseStatus(400)
->see('You need both the target and source parameters');
}
/**
* Test invalid target gets a 400 response.
*
* @return void
*/
public function testInvalidTargetReturns400Response()
{
$this->call('POST', $this->appurl . '/webmention', [
'source' => 'https://example.org/post/123',
'target' => $this->appurl . '/invalid/target'
]);
$this->assertResponseStatus(400)
->see('Invalid request');
}
/**
* Test blog target gets a 501 response.
*
* @return void
*/
public function testBlogpostTargetReturns501Response()
{
$this->call('POST', $this->appurl . '/webmention', [
'source' => 'https://example.org/post/123',
'target' => $this->appurl . '/blog/target'
]);
$this->assertResponseStatus(501)
->see('I dont accept webmentions for blog posts yet.');
}
/**
* Test that a non-existant note gives a 400 response.
*
* @return void
*/
public function testNonexistantNoteReturns400Response()
{
$this->call('POST', $this->appurl . '/webmention', [
'source' => 'https://example.org/post/123',
'target' => $this->appurl . '/notes/ZZZZZ'
]);
$this->assertResponseStatus(400)
->see('This note doesnt exist.');
}
/**
* Test a legit webmention triggers the ProcessWebMention job.
*
* @return void
*/
public function testLegitimateWebmnetionTriggersProcessWebMentionJob()
{
$this->expectsJobs(\App\Jobs\ProcessWebMention::class);
$this->call('POST', $this->appurl . '/webmention', [
'source' => 'https://example.org/post/123',
'target' => $this->appurl . '/notes/B'
]);
$this->assertResponseStatus(202)
->see('Webmention received, it will be processed shortly');
}
}