jonnybarnes.uk/tests/Feature/NotesControllerTest.php
Jonny Barnes db09718a96
Switch Bridgy syndication from Micropub to webmention
Bridgy's Micropub endpoint required per-silo access tokens and posted
raw markdown content directly. Switch to Bridgy's webmention publish
endpoint instead: POST source/target to /publish/webmention and let
Bridgy re-fetch the note page, which now carries hidden verification
links for silos not yet syndicated. Removes the now-unused
config/bridgy.php and BRIDGY_MASTODON_TOKEN env var, and caps both
jobs to a single try since retries would send Bridgy a duplicate
publish webmention.
2026-07-14 17:36:25 +01:00

114 lines
3 KiB
PHP

<?php
declare(strict_types=1);
namespace Tests\Feature;
use App\Models\Note;
use Illuminate\Foundation\Testing\RefreshDatabase;
use PHPUnit\Framework\Attributes\Test;
use Tests\TestCase;
class NotesControllerTest extends TestCase
{
use RefreshDatabase;
/**
* Test the `/notes` page returns 200, this should
* mean the database is being hit.
*/
#[Test]
public function notes_page_loads(): void
{
$response = $this->get('/notes');
$response->assertStatus(200);
}
/**
* Test a specific note.
*/
#[Test]
public function specific_note_page_loads(): void
{
$note = Note::factory()->create();
$response = $this->get($note->uri);
$response->assertViewHas('note');
}
/** @todo */
/* @test *
public function noteReplyingToTweet(): void
{
$response = $this->get('/notes/B');
$response->assertViewHas('note');
}*/
/**
* Test that `/note/{decID}` redirects to `/notes/{nb60id}`.
*/
#[Test]
public function old_note_urls_redirect(): void
{
$note = Note::factory()->create();
$response = $this->get('/note/'.$note->id);
$response->assertRedirect($note->uri);
}
/**
* Visit the tagged page and check the tag view data.
*/
#[Test]
public function tagged_notes_page_loads(): void
{
$response = $this->get('/notes/tagged/beer');
$response->assertViewHas('tag', 'beer');
}
#[Test]
public function unknown_note_gives404(): void
{
$response = $this->get('/notes/112233');
$response->assertNotFound();
}
#[Test]
public function check_note_id_not_out_of_range(): void
{
$response = $this->get('/notes/photou-photologo');
$response->assertNotFound();
}
/**
* Notes not yet syndicated should carry the hidden Bridgy publish
* verification links, so Bridgy can confirm intent when it re-fetches
* the page after receiving our webmention.
*/
#[Test]
public function note_page_includes_bridgy_verification_links_when_not_yet_syndicated(): void
{
$note = Note::factory()->create();
$response = $this->get($note->uri);
$response->assertSee('https://brid.gy/publish/mastodon', false);
$response->assertSee('https://brid.gy/publish/bluesky', false);
}
/**
* Once a note has been syndicated to a silo, the hidden verification
* link for that silo should no longer be rendered.
*/
#[Test]
public function note_page_omits_bridgy_verification_link_once_syndicated(): void
{
$note = Note::factory()->create();
$note->mastodon_url = 'https://mastodon.example/@jonny/1';
$note->bluesky_url = 'https://bsky.app/profile/jonnybarnes.uk/1';
$note->save();
$response = $this->get($note->uri);
$response->assertDontSee('https://brid.gy/publish/mastodon', false);
$response->assertDontSee('https://brid.gy/publish/bluesky', false);
}
}