Upgrade to Laravel 13

This commit is contained in:
Jonny Barnes 2026-04-07 09:01:19 +01:00
commit 9f012b01e4
Signed by: jonny
SSH key fingerprint: SHA256:CTuSlns5U7qlD9jqHvtnVmfYV3Zwl2Z7WnJ4/dqOaL8
117 changed files with 1878 additions and 2215 deletions

View file

@ -55,11 +55,11 @@ class ArticlesTest extends TestCase
$user = User::factory()->make();
$faker = Factory::create();
$text = $faker->text;
if ($fh = fopen(sys_get_temp_dir() . '/article.md', 'w')) {
if ($fh = fopen(sys_get_temp_dir().'/article.md', 'w')) {
fwrite($fh, $text);
fclose($fh);
}
$path = sys_get_temp_dir() . '/article.md';
$path = sys_get_temp_dir().'/article.md';
$file = new UploadedFile($path, 'article.md', 'text/plain', null, true);
$this->actingAs($user)
@ -83,7 +83,7 @@ class ArticlesTest extends TestCase
]);
$response = $this->actingAs($user)
->get('/admin/blog/' . $article->id . '/edit');
->get('/admin/blog/'.$article->id.'/edit');
$response->assertSeeText('This is *my* new blog. It uses `Markdown`.');
}
@ -94,7 +94,7 @@ class ArticlesTest extends TestCase
$article = Article::factory()->create();
$this->actingAs($user)
->post('/admin/blog/' . $article->id, [
->post('/admin/blog/'.$article->id, [
'_method' => 'PUT',
'title' => 'My New Blog',
'main' => 'This article has been edited',
@ -112,7 +112,7 @@ class ArticlesTest extends TestCase
$article = Article::factory()->create();
$this->actingAs($user)
->post('/admin/blog/' . $article->id, [
->post('/admin/blog/'.$article->id, [
'_method' => 'DELETE',
]);
$this->assertSoftDeleted('articles', [

View file

@ -59,7 +59,7 @@ class ClientsTest extends TestCase
]);
$response = $this->actingAs($user)
->get('/admin/clients/' . $client->id . '/edit');
->get('/admin/clients/'.$client->id.'/edit');
$response->assertSee('https://jbl5.dev/notes/new');
}
@ -70,7 +70,7 @@ class ClientsTest extends TestCase
$client = MicropubClient::factory()->create();
$this->actingAs($user)
->post('/admin/clients/' . $client->id, [
->post('/admin/clients/'.$client->id, [
'_method' => 'PUT',
'client_url' => 'https://jbl5.dev/notes/new',
'client_name' => 'JBL5dev',
@ -90,7 +90,7 @@ class ClientsTest extends TestCase
]);
$this->actingAs($user)
->post('/admin/clients/' . $client->id, [
->post('/admin/clients/'.$client->id, [
'_method' => 'DELETE',
]);
$this->assertDatabaseMissing('clients', [

View file

@ -21,9 +21,9 @@ class ContactsTest extends TestCase
protected function tearDown(): void
{
if (file_exists(public_path() . '/assets/profile-images/tantek.com/image')) {
unlink(public_path() . '/assets/profile-images/tantek.com/image');
rmdir(public_path() . '/assets/profile-images/tantek.com');
if (file_exists(public_path().'/assets/profile-images/tantek.com/image')) {
unlink(public_path().'/assets/profile-images/tantek.com/image');
rmdir(public_path().'/assets/profile-images/tantek.com');
}
parent::tearDown();
}
@ -69,7 +69,7 @@ class ContactsTest extends TestCase
$user = User::factory()->make();
$contact = Contact::factory()->create();
$response = $this->actingAs($user)->get('/admin/contacts/' . $contact->id . '/edit');
$response = $this->actingAs($user)->get('/admin/contacts/'.$contact->id.'/edit');
$response->assertViewIs('admin.contacts.edit');
}
@ -79,7 +79,7 @@ class ContactsTest extends TestCase
$user = User::factory()->make();
$contact = Contact::factory()->create();
$this->actingAs($user)->post('/admin/contacts/' . $contact->id, [
$this->actingAs($user)->post('/admin/contacts/'.$contact->id, [
'_method' => 'PUT',
'name' => 'Tantek Celik',
'nick' => 'tantek',
@ -95,13 +95,13 @@ class ContactsTest extends TestCase
#[Test]
public function admin_can_edit_contact_and_upload_avatar(): void
{
copy(__DIR__ . '/../../aaron.png', sys_get_temp_dir() . '/tantek.png');
$path = sys_get_temp_dir() . '/tantek.png';
copy(__DIR__.'/../../aaron.png', sys_get_temp_dir().'/tantek.png');
$path = sys_get_temp_dir().'/tantek.png';
$file = new UploadedFile($path, 'tantek.png', 'image/png', null, true);
$user = User::factory()->make();
$contact = Contact::factory()->create();
$this->actingAs($user)->post('/admin/contacts/' . $contact->id, [
$this->actingAs($user)->post('/admin/contacts/'.$contact->id, [
'_method' => 'PUT',
'name' => 'Tantek Celik',
'nick' => 'tantek',
@ -110,8 +110,8 @@ class ContactsTest extends TestCase
'avatar' => $file,
]);
$this->assertFileEquals(
__DIR__ . '/../../aaron.png',
public_path() . '/assets/profile-images/tantek.com/image'
__DIR__.'/../../aaron.png',
public_path().'/assets/profile-images/tantek.com/image'
);
}
@ -125,7 +125,7 @@ class ContactsTest extends TestCase
'nick' => 'tantek',
]);
$this->actingAs($user)->post('/admin/contacts/' . $contact->id, [
$this->actingAs($user)->post('/admin/contacts/'.$contact->id, [
'_method' => 'DELETE',
]);
$this->assertDatabaseMissing('contacts', [
@ -141,7 +141,7 @@ class ContactsTest extends TestCase
<img class="u-photo" alt="" src="http://tantek.com/tantek.png">
</div>
HTML;
$file = fopen(__DIR__ . '/../../aaron.png', 'rb');
$file = fopen(__DIR__.'/../../aaron.png', 'rb');
$mock = new MockHandler([
new Response(200, ['Content-Type' => 'text/html'], $html),
new Response(200, ['Content-Type' => 'image/png'], $file),
@ -154,11 +154,11 @@ class ContactsTest extends TestCase
'homepage' => 'https://tantek.com',
]);
$this->actingAs($user)->get('/admin/contacts/' . $contact->id . '/getavatar');
$this->actingAs($user)->get('/admin/contacts/'.$contact->id.'/getavatar');
$this->assertFileEquals(
__DIR__ . '/../../aaron.png',
public_path() . '/assets/profile-images/tantek.com/image'
__DIR__.'/../../aaron.png',
public_path().'/assets/profile-images/tantek.com/image'
);
}
@ -174,9 +174,9 @@ class ContactsTest extends TestCase
$user = User::factory()->make();
$contact = Contact::factory()->create();
$response = $this->actingAs($user)->get('/admin/contacts/' . $contact->id . '/getavatar');
$response = $this->actingAs($user)->get('/admin/contacts/'.$contact->id.'/getavatar');
$response->assertRedirect('/admin/contacts/' . $contact->id . '/edit');
$response->assertRedirect('/admin/contacts/'.$contact->id.'/edit');
}
#[Test]
@ -197,9 +197,9 @@ class ContactsTest extends TestCase
$user = User::factory()->make();
$contact = Contact::factory()->create();
$response = $this->actingAs($user)->get('/admin/contacts/' . $contact->id . '/getavatar');
$response = $this->actingAs($user)->get('/admin/contacts/'.$contact->id.'/getavatar');
$response->assertRedirect('/admin/contacts/' . $contact->id . '/edit');
$response->assertRedirect('/admin/contacts/'.$contact->id.'/edit');
}
#[Test]
@ -211,8 +211,8 @@ class ContactsTest extends TestCase
]);
$user = User::factory()->make();
$response = $this->actingAs($user)->get('/admin/contacts/' . $contact->id . '/getavatar');
$response = $this->actingAs($user)->get('/admin/contacts/'.$contact->id.'/getavatar');
$response->assertRedirect('/admin/contacts/' . $contact->id . '/edit');
$response->assertRedirect('/admin/contacts/'.$contact->id.'/edit');
}
}

View file

@ -59,7 +59,7 @@ class LikesTest extends TestCase
$like = Like::factory()->create();
$response = $this->actingAs($user)
->get('/admin/likes/' . $like->id . '/edit');
->get('/admin/likes/'.$like->id.'/edit');
$response->assertSee('Edit Like');
}
@ -71,7 +71,7 @@ class LikesTest extends TestCase
$like = Like::factory()->create();
$this->actingAs($user)
->post('/admin/likes/' . $like->id, [
->post('/admin/likes/'.$like->id, [
'_method' => 'PUT',
'like_url' => 'https://example.com',
]);
@ -89,7 +89,7 @@ class LikesTest extends TestCase
$user = User::factory()->make();
$this->actingAs($user)
->post('/admin/likes/' . $like->id, [
->post('/admin/likes/'.$like->id, [
'_method' => 'DELETE',
]);
$this->assertDatabaseMissing('likes', [

View file

@ -54,7 +54,7 @@ class NotesTest extends TestCase
$user = User::factory()->make();
$note = Note::factory()->create();
$response = $this->actingAs($user)->get('/admin/notes/' . $note->id . '/edit');
$response = $this->actingAs($user)->get('/admin/notes/'.$note->id.'/edit');
$response->assertViewIs('admin.notes.edit');
}
@ -65,7 +65,7 @@ class NotesTest extends TestCase
$user = User::factory()->make();
$note = Note::factory()->create();
$this->actingAs($user)->post('/admin/notes/' . $note->id, [
$this->actingAs($user)->post('/admin/notes/'.$note->id, [
'_method' => 'PUT',
'content' => 'An edited note',
'webmentions' => true,
@ -83,7 +83,7 @@ class NotesTest extends TestCase
$user = User::factory()->make();
$note = Note::factory()->create();
$this->actingAs($user)->post('/admin/notes/' . $note->id, [
$this->actingAs($user)->post('/admin/notes/'.$note->id, [
'_method' => 'DELETE',
]);
$this->assertSoftDeleted('notes', [

View file

@ -4,6 +4,7 @@ declare(strict_types=1);
namespace Tests\Feature\Admin;
use App\Models\Note;
use App\Models\Place;
use App\Models\User;
use Illuminate\Foundation\Testing\RefreshDatabase;
@ -55,7 +56,7 @@ class PlacesTest extends TestCase
$user = User::factory()->make();
$place = Place::factory()->create();
$response = $this->actingAs($user)->get('/admin/places/' . $place->id . '/edit');
$response = $this->actingAs($user)->get('/admin/places/'.$place->id.'/edit');
$response->assertViewIs('admin.places.edit');
}
@ -67,7 +68,7 @@ class PlacesTest extends TestCase
'name' => 'The Bridgewater Pub',
]);
$this->actingAs($user)->post('/admin/places/' . $place->id, [
$this->actingAs($user)->post('/admin/places/'.$place->id, [
'_method' => 'PUT',
'name' => 'The Bridgewater',
'description' => 'Who uses “Pub” anyway',
@ -78,4 +79,62 @@ class PlacesTest extends TestCase
'name' => 'The Bridgewater',
]);
}
#[Test]
public function merge_index_page_loads(): void
{
$user = User::factory()->make();
// Use specific coordinates to avoid haversine acos overflow with extreme faker values
$place = Place::factory()->create(['latitude' => 53.48, 'longitude' => -2.24]);
$response = $this->actingAs($user)->get('/admin/places/'.$place->id.'/merge');
$response->assertViewIs('admin.places.merge.index');
}
#[Test]
public function merge_edit_page_loads(): void
{
$user = User::factory()->make();
$place1 = Place::factory()->create();
$place2 = Place::factory()->create();
$response = $this->actingAs($user)->get('/admin/places/'.$place1->id.'/merge/'.$place2->id);
$response->assertViewIs('admin.places.merge.edit');
}
#[Test]
public function merge_store_with_delete_one_moves_notes_and_deletes_place1(): void
{
$user = User::factory()->make();
$place1 = Place::factory()->create();
$place2 = Place::factory()->create();
$note = Note::factory()->create(['place_id' => $place1->id]);
$this->actingAs($user)->post('/admin/places/merge', [
'place1' => $place1->id,
'place2' => $place2->id,
'delete' => '1',
]);
$this->assertDatabaseMissing('places', ['id' => $place1->id]);
$this->assertDatabaseHas('notes', ['id' => $note->id, 'place_id' => $place2->id]);
}
#[Test]
public function merge_store_with_delete_two_moves_notes_and_deletes_place2(): void
{
$user = User::factory()->make();
$place1 = Place::factory()->create();
$place2 = Place::factory()->create();
$note = Note::factory()->create(['place_id' => $place2->id]);
$this->actingAs($user)->post('/admin/places/merge', [
'place1' => $place1->id,
'place2' => $place2->id,
'delete' => '2',
]);
$this->assertDatabaseMissing('places', ['id' => $place2->id]);
$this->assertDatabaseHas('notes', ['id' => $note->id, 'place_id' => $place1->id]);
}
}

View file

@ -0,0 +1,136 @@
<?php
declare(strict_types=1);
namespace Tests\Feature\Admin;
use App\Models\SyndicationTarget;
use App\Models\User;
use Illuminate\Foundation\Testing\RefreshDatabase;
use PHPUnit\Framework\Attributes\Test;
use Tests\TestCase;
class SyndicationTargetsTest extends TestCase
{
use RefreshDatabase;
#[Test]
public function index_requires_authentication(): void
{
$response = $this->get('/admin/syndication');
$response->assertRedirect();
}
#[Test]
public function index_lists_syndication_targets(): void
{
$user = User::factory()->make();
$target = SyndicationTarget::factory()->create();
$response = $this->actingAs($user)->get('/admin/syndication');
$response->assertOk();
$response->assertSeeText($target->uid);
}
#[Test]
public function create_page_loads(): void
{
$user = User::factory()->make();
$response = $this->actingAs($user)->get('/admin/syndication/create');
$response->assertOk();
}
#[Test]
public function store_creates_a_new_syndication_target(): void
{
$user = User::factory()->make();
$this->actingAs($user)->post('/admin/syndication', [
'uid' => 'https://mastodon.social/users/me',
'name' => 'Mastodon',
]);
$this->assertDatabaseHas('syndication_targets', [
'uid' => 'https://mastodon.social/users/me',
'name' => 'Mastodon',
]);
}
#[Test]
public function store_redirects_to_index_after_creation(): void
{
$user = User::factory()->make();
$response = $this->actingAs($user)->post('/admin/syndication', [
'uid' => 'https://mastodon.social/users/me',
'name' => 'Mastodon',
]);
$response->assertRedirect('/admin/syndication');
}
#[Test]
public function edit_page_loads_with_target_data(): void
{
$user = User::factory()->make();
$target = SyndicationTarget::factory()->create(['name' => 'My Mastodon']);
$response = $this->actingAs($user)->get("/admin/syndication/{$target->id}/edit");
$response->assertOk();
$response->assertSee('value="My Mastodon"', false);
}
#[Test]
public function update_modifies_syndication_target(): void
{
$user = User::factory()->make();
$target = SyndicationTarget::factory()->create(['name' => 'Old Name']);
$this->actingAs($user)->put("/admin/syndication/{$target->id}", [
'uid' => $target->uid,
'name' => 'New Name',
]);
$this->assertDatabaseHas('syndication_targets', [
'id' => $target->id,
'name' => 'New Name',
]);
}
#[Test]
public function update_redirects_to_index(): void
{
$user = User::factory()->make();
$target = SyndicationTarget::factory()->create();
$response = $this->actingAs($user)->put("/admin/syndication/{$target->id}", [
'uid' => $target->uid,
'name' => 'Updated Name',
]);
$response->assertRedirect('/admin/syndication');
}
#[Test]
public function destroy_deletes_syndication_target(): void
{
$user = User::factory()->make();
$target = SyndicationTarget::factory()->create();
$this->actingAs($user)->delete("/admin/syndication/{$target->id}");
$this->assertDatabaseMissing('syndication_targets', ['id' => $target->id]);
}
#[Test]
public function destroy_redirects_to_index(): void
{
$user = User::factory()->make();
$target = SyndicationTarget::factory()->create();
$response = $this->actingAs($user)->delete("/admin/syndication/{$target->id}");
$response->assertRedirect('/admin/syndication');
}
}