build: initialize RetroHub with Laravel, Inertia, Vue, and Horizon

This commit is contained in:
2026-08-10 13:45:18 +02:00
commit 717db65139
218 changed files with 28356 additions and 0 deletions
+54
View File
@@ -0,0 +1,54 @@
<?php
namespace Tests\Feature\Auth;
use App\Models\User;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;
class AuthenticationTest extends TestCase
{
use RefreshDatabase;
public function test_login_screen_can_be_rendered(): void
{
$response = $this->get('/login');
$response->assertStatus(200);
}
public function test_users_can_authenticate_using_the_login_screen(): void
{
$user = User::factory()->create();
$response = $this->post('/login', [
'email' => $user->email,
'password' => 'password',
]);
$this->assertAuthenticated();
$response->assertRedirect(route('dashboard', absolute: false));
}
public function test_users_can_not_authenticate_with_invalid_password(): void
{
$user = User::factory()->create();
$this->post('/login', [
'email' => $user->email,
'password' => 'wrong-password',
]);
$this->assertGuest();
}
public function test_users_can_logout(): void
{
$user = User::factory()->create();
$response = $this->actingAs($user)->post('/logout');
$this->assertGuest();
$response->assertRedirect('/');
}
}
@@ -0,0 +1,58 @@
<?php
namespace Tests\Feature\Auth;
use App\Models\User;
use Illuminate\Auth\Events\Verified;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\Event;
use Illuminate\Support\Facades\URL;
use Tests\TestCase;
class EmailVerificationTest extends TestCase
{
use RefreshDatabase;
public function test_email_verification_screen_can_be_rendered(): void
{
$user = User::factory()->unverified()->create();
$response = $this->actingAs($user)->get('/verify-email');
$response->assertStatus(200);
}
public function test_email_can_be_verified(): void
{
$user = User::factory()->unverified()->create();
Event::fake();
$verificationUrl = URL::temporarySignedRoute(
'verification.verify',
now()->addMinutes(60),
['id' => $user->id, 'hash' => sha1($user->email)]
);
$response = $this->actingAs($user)->get($verificationUrl);
Event::assertDispatched(Verified::class);
$this->assertTrue($user->fresh()->hasVerifiedEmail());
$response->assertRedirect(route('dashboard', absolute: false).'?verified=1');
}
public function test_email_is_not_verified_with_invalid_hash(): void
{
$user = User::factory()->unverified()->create();
$verificationUrl = URL::temporarySignedRoute(
'verification.verify',
now()->addMinutes(60),
['id' => $user->id, 'hash' => sha1('wrong-email')]
);
$this->actingAs($user)->get($verificationUrl);
$this->assertFalse($user->fresh()->hasVerifiedEmail());
}
}
@@ -0,0 +1,44 @@
<?php
namespace Tests\Feature\Auth;
use App\Models\User;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;
class PasswordConfirmationTest extends TestCase
{
use RefreshDatabase;
public function test_confirm_password_screen_can_be_rendered(): void
{
$user = User::factory()->create();
$response = $this->actingAs($user)->get('/confirm-password');
$response->assertStatus(200);
}
public function test_password_can_be_confirmed(): void
{
$user = User::factory()->create();
$response = $this->actingAs($user)->post('/confirm-password', [
'password' => 'password',
]);
$response->assertRedirect();
$response->assertSessionHasNoErrors();
}
public function test_password_is_not_confirmed_with_invalid_password(): void
{
$user = User::factory()->create();
$response = $this->actingAs($user)->post('/confirm-password', [
'password' => 'wrong-password',
]);
$response->assertSessionHasErrors();
}
}
+73
View File
@@ -0,0 +1,73 @@
<?php
namespace Tests\Feature\Auth;
use App\Models\User;
use Illuminate\Auth\Notifications\ResetPassword;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\Notification;
use Tests\TestCase;
class PasswordResetTest extends TestCase
{
use RefreshDatabase;
public function test_reset_password_link_screen_can_be_rendered(): void
{
$response = $this->get('/forgot-password');
$response->assertStatus(200);
}
public function test_reset_password_link_can_be_requested(): void
{
Notification::fake();
$user = User::factory()->create();
$this->post('/forgot-password', ['email' => $user->email]);
Notification::assertSentTo($user, ResetPassword::class);
}
public function test_reset_password_screen_can_be_rendered(): void
{
Notification::fake();
$user = User::factory()->create();
$this->post('/forgot-password', ['email' => $user->email]);
Notification::assertSentTo($user, ResetPassword::class, function ($notification) {
$response = $this->get('/reset-password/'.$notification->token);
$response->assertStatus(200);
return true;
});
}
public function test_password_can_be_reset_with_valid_token(): void
{
Notification::fake();
$user = User::factory()->create();
$this->post('/forgot-password', ['email' => $user->email]);
Notification::assertSentTo($user, ResetPassword::class, function ($notification) use ($user) {
$response = $this->post('/reset-password', [
'token' => $notification->token,
'email' => $user->email,
'password' => 'password',
'password_confirmation' => 'password',
]);
$response
->assertSessionHasNoErrors()
->assertRedirect(route('login'));
return true;
});
}
}
+51
View File
@@ -0,0 +1,51 @@
<?php
namespace Tests\Feature\Auth;
use App\Models\User;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\Hash;
use Tests\TestCase;
class PasswordUpdateTest extends TestCase
{
use RefreshDatabase;
public function test_password_can_be_updated(): void
{
$user = User::factory()->create();
$response = $this
->actingAs($user)
->from('/profile')
->put('/password', [
'current_password' => 'password',
'password' => 'new-password',
'password_confirmation' => 'new-password',
]);
$response
->assertSessionHasNoErrors()
->assertRedirect('/profile');
$this->assertTrue(Hash::check('new-password', $user->refresh()->password));
}
public function test_correct_password_must_be_provided_to_update_password(): void
{
$user = User::factory()->create();
$response = $this
->actingAs($user)
->from('/profile')
->put('/password', [
'current_password' => 'wrong-password',
'password' => 'new-password',
'password_confirmation' => 'new-password',
]);
$response
->assertSessionHasErrors('current_password')
->assertRedirect('/profile');
}
}
+31
View File
@@ -0,0 +1,31 @@
<?php
namespace Tests\Feature\Auth;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;
class RegistrationTest extends TestCase
{
use RefreshDatabase;
public function test_registration_screen_can_be_rendered(): void
{
$response = $this->get('/register');
$response->assertStatus(200);
}
public function test_new_users_can_register(): void
{
$response = $this->post('/register', [
'name' => 'Test User',
'email' => 'test@example.com',
'password' => 'password',
'password_confirmation' => 'password',
]);
$this->assertAuthenticated();
$response->assertRedirect(route('dashboard', absolute: false));
}
}
+76
View File
@@ -0,0 +1,76 @@
<?php
namespace Tests\Feature;
use App\Features\Consoles\Models\Console;
use App\Features\Games\Models\Game;
use App\Models\User;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;
class ConsoleTest extends TestCase
{
use RefreshDatabase;
public function test_consoles_index_requires_authentication(): void
{
$this->get(route('consoles.index'))->assertRedirect(route('login'));
}
public function test_consoles_index_can_be_rendered(): void
{
$user = User::factory()->create();
$this->actingAs($user)
->get(route('consoles.index'))
->assertOk();
}
public function test_consoles_index_shows_consoles(): void
{
$user = User::factory()->create();
Console::factory()->count(3)->create();
$this->actingAs($user)
->get(route('consoles.index'))
->assertOk();
}
public function test_console_show_requires_authentication(): void
{
$console = Console::factory()->create();
$this->get(route('consoles.show', $console->slug))
->assertRedirect(route('login'));
}
public function test_console_show_can_be_rendered(): void
{
$user = User::factory()->create();
$console = Console::factory()->create();
$this->actingAs($user)
->get(route('consoles.show', $console->slug))
->assertOk();
}
public function test_console_show_with_games(): void
{
$user = User::factory()->create();
$console = Console::factory()->create();
Game::factory()->count(5)->create(['console_id' => $console->id]);
$this->actingAs($user)
->get(route('consoles.show', $console->slug))
->assertOk();
}
public function test_console_show_returns_404_for_invalid_slug(): void
{
$user = User::factory()->create();
$this->actingAs($user)
->get(route('consoles.show', 'nonexistent'))
->assertNotFound();
}
}
+71
View File
@@ -0,0 +1,71 @@
<?php
namespace Tests\Feature;
use App\Features\Consoles\Models\Console;
use App\Features\Games\Models\Game;
use App\Features\Games\Models\RomFile;
use App\Models\User;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;
class DashboardTest extends TestCase
{
use RefreshDatabase;
public function test_dashboard_requires_authentication(): void
{
$this->get(route('dashboard'))->assertRedirect(route('login'));
}
public function test_dashboard_can_be_rendered(): void
{
$user = User::factory()->create();
$this->actingAs($user)
->get(route('dashboard'))
->assertOk();
}
public function test_dashboard_shows_stats_with_data(): void
{
$user = User::factory()->create();
$console = Console::factory()->create();
$game = Game::factory()->create(['console_id' => $console->id]);
RomFile::factory()->create(['game_id' => $game->id]);
$this->actingAs($user)
->get(route('dashboard'))
->assertOk();
}
public function test_dashboard_shows_recent_games(): void
{
$user = User::factory()->create();
$console = Console::factory()->create();
Game::factory()->count(3)->create(['console_id' => $console->id]);
$this->actingAs($user)
->get(route('dashboard'))
->assertOk();
}
public function test_dashboard_shows_consoles(): void
{
$user = User::factory()->create();
Console::factory()->count(5)->create();
$this->actingAs($user)
->get(route('dashboard'))
->assertOk();
}
public function test_dashboard_with_empty_data(): void
{
$user = User::factory()->create();
$this->actingAs($user)
->get(route('dashboard'))
->assertOk();
}
}
+19
View File
@@ -0,0 +1,19 @@
<?php
namespace Tests\Feature;
// use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;
class ExampleTest extends TestCase
{
/**
* A basic test example.
*/
public function test_the_application_returns_a_successful_response(): void
{
$response = $this->get('/');
$response->assertStatus(200);
}
}
+136
View File
@@ -0,0 +1,136 @@
<?php
namespace Tests\Feature;
use App\Features\Consoles\Models\Console;
use App\Features\Games\Models\Game;
use App\Models\User;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;
class GameTest extends TestCase
{
use RefreshDatabase;
public function test_game_show_requires_authentication(): void
{
$console = Console::factory()->create();
$game = Game::factory()->create(['console_id' => $console->id]);
$this->get(route('games.show', $game->slug))
->assertRedirect(route('login'));
}
public function test_game_show_can_be_rendered(): void
{
$user = User::factory()->create();
$console = Console::factory()->create();
$game = Game::factory()->create(['console_id' => $console->id]);
$this->actingAs($user)
->get(route('games.show', $game->slug))
->assertOk();
}
public function test_game_show_returns_404_for_invalid_slug(): void
{
$user = User::factory()->create();
$this->actingAs($user)
->get(route('games.show', 'nonexistent'))
->assertNotFound();
}
public function test_game_edit_requires_authentication(): void
{
$console = Console::factory()->create();
$game = Game::factory()->create(['console_id' => $console->id]);
$this->get(route('games.edit', $game->slug))
->assertRedirect(route('login'));
}
public function test_game_edit_can_be_rendered(): void
{
$user = User::factory()->create();
$console = Console::factory()->create();
$game = Game::factory()->create(['console_id' => $console->id]);
$this->actingAs($user)
->get(route('games.edit', $game->slug))
->assertOk();
}
public function test_game_update_requires_authentication(): void
{
$console = Console::factory()->create();
$game = Game::factory()->create(['console_id' => $console->id]);
$this->put(route('games.update', $game->slug), [
'title' => 'Updated Title',
])->assertRedirect(route('login'));
}
public function test_game_can_be_updated(): void
{
$user = User::factory()->create();
$console = Console::factory()->create();
$game = Game::factory()->create(['console_id' => $console->id]);
$this->actingAs($user)
->put(route('games.update', $game->slug), [
'title' => 'Updated Title',
'description' => 'Updated description',
'release_year' => 1990,
'developer' => 'Test Developer',
'publisher' => 'Test Publisher',
'genre' => 'Action',
'rating' => 8.5,
])
->assertRedirect();
$game->refresh();
$this->assertEquals('Updated Title', $game->title);
$this->assertEquals('Updated description', $game->description);
$this->assertEquals(1990, $game->release_year);
$this->assertEquals('Test Developer', $game->developer);
$this->assertEquals('Test Publisher', $game->publisher);
$this->assertEquals('Action', $game->genre);
$this->assertEquals(8.5, $game->rating);
}
public function test_game_update_validates_required_fields(): void
{
$user = User::factory()->create();
$console = Console::factory()->create();
$game = Game::factory()->create(['console_id' => $console->id]);
$this->actingAs($user)
->put(route('games.update', $game->slug), [
'title' => '',
])
->assertSessionHasErrors('title');
}
public function test_game_delete_requires_authentication(): void
{
$console = Console::factory()->create();
$game = Game::factory()->create(['console_id' => $console->id]);
$this->delete(route('games.destroy', $game->slug))
->assertRedirect(route('login'));
}
public function test_game_can_be_deleted(): void
{
$user = User::factory()->create();
$console = Console::factory()->create();
$game = Game::factory()->create(['console_id' => $console->id]);
$this->actingAs($user)
->delete(route('games.destroy', $game->slug))
->assertRedirect();
$this->assertDatabaseMissing('games', ['id' => $game->id]);
}
}
+99
View File
@@ -0,0 +1,99 @@
<?php
namespace Tests\Feature;
use App\Models\User;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;
class ProfileTest extends TestCase
{
use RefreshDatabase;
public function test_profile_page_is_displayed(): void
{
$user = User::factory()->create();
$response = $this
->actingAs($user)
->get('/profile');
$response->assertOk();
}
public function test_profile_information_can_be_updated(): void
{
$user = User::factory()->create();
$response = $this
->actingAs($user)
->patch('/profile', [
'name' => 'Test User',
'email' => 'test@example.com',
]);
$response
->assertSessionHasNoErrors()
->assertRedirect('/profile');
$user->refresh();
$this->assertSame('Test User', $user->name);
$this->assertSame('test@example.com', $user->email);
$this->assertNull($user->email_verified_at);
}
public function test_email_verification_status_is_unchanged_when_the_email_address_is_unchanged(): void
{
$user = User::factory()->create();
$response = $this
->actingAs($user)
->patch('/profile', [
'name' => 'Test User',
'email' => $user->email,
]);
$response
->assertSessionHasNoErrors()
->assertRedirect('/profile');
$this->assertNotNull($user->refresh()->email_verified_at);
}
public function test_user_can_delete_their_account(): void
{
$user = User::factory()->create();
$response = $this
->actingAs($user)
->delete('/profile', [
'password' => 'password',
]);
$response
->assertSessionHasNoErrors()
->assertRedirect('/');
$this->assertGuest();
$this->assertNull($user->fresh());
}
public function test_correct_password_must_be_provided_to_delete_account(): void
{
$user = User::factory()->create();
$response = $this
->actingAs($user)
->from('/profile')
->delete('/profile', [
'password' => 'wrong-password',
]);
$response
->assertSessionHasErrors('password')
->assertRedirect('/profile');
$this->assertNotNull($user->fresh());
}
}
+38
View File
@@ -0,0 +1,38 @@
<?php
namespace Tests\Feature;
use App\Models\User;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;
class ScraperTest extends TestCase
{
use RefreshDatabase;
public function test_scraper_index_requires_authentication(): void
{
$this->get(route('scraper.index'))->assertRedirect(route('login'));
}
public function test_scraper_index_can_be_rendered(): void
{
$user = User::factory()->create();
$this->actingAs($user)
->get(route('scraper.index'))
->assertOk();
}
public function test_scraper_search_requires_authentication(): void
{
$this->getJson(route('scraper.search', ['query' => 'mario']))
->assertRedirect();
}
public function test_scraper_apply_requires_authentication(): void
{
$this->post(route('scraper.apply', 'some-game'))
->assertRedirect(route('login'));
}
}
+91
View File
@@ -0,0 +1,91 @@
<?php
namespace Tests\Feature;
use App\Features\Consoles\Models\Console;
use App\Models\User;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Http\UploadedFile;
use Illuminate\Support\Facades\Storage;
use Tests\TestCase;
class UploadTest extends TestCase
{
use RefreshDatabase;
public function test_upload_index_requires_authentication(): void
{
$this->get(route('upload.index'))->assertRedirect(route('login'));
}
public function test_upload_index_can_be_rendered(): void
{
$user = User::factory()->create();
$this->actingAs($user)
->get(route('upload.index'))
->assertOk();
}
public function test_upload_store_requires_authentication(): void
{
$this->post(route('upload.store'))->assertRedirect(route('login'));
}
public function test_upload_store_validates_console_id(): void
{
$user = User::factory()->create();
$this->actingAs($user)
->post(route('upload.store'), [])
->assertSessionHasErrors('console_id');
}
public function test_upload_store_validates_rom_files(): void
{
$user = User::factory()->create();
$console = Console::factory()->create();
$this->actingAs($user)
->post(route('upload.store'), [
'console_id' => $console->id,
])
->assertSessionHasErrors('rom_files');
}
public function test_upload_store_rejects_invalid_extensions(): void
{
Storage::fake('local');
$user = User::factory()->create();
$console = Console::factory()->create(['rom_extensions' => ['nes']]);
$file = UploadedFile::fake()->create('game.exe', 100, 'application/octet-stream');
$this->actingAs($user)
->post(route('upload.store'), [
'console_id' => $console->id,
'rom_files' => [$file],
])
->assertRedirect();
Storage::disk('local')->assertMissing("roms/{$console->slug}/game.nes");
}
public function test_upload_store_accepts_valid_rom_files(): void
{
Storage::fake('local');
$user = User::factory()->create();
$console = Console::factory()->create(['rom_extensions' => ['nes']]);
$file = UploadedFile::fake()->createWithContent('game.nes', str_repeat('x', 1024));
$this->actingAs($user)
->post(route('upload.store'), [
'console_id' => $console->id,
'rom_files' => [$file],
])
->assertRedirect();
Storage::disk('local')->assertExists("roms/{$console->slug}/game.nes");
}
}
+145
View File
@@ -0,0 +1,145 @@
<?php
namespace Tests\Feature;
use App\Models\User;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;
class WebDavTest extends TestCase
{
use RefreshDatabase;
public function test_webdav_index_requires_authentication(): void
{
$this->get(route('settings.webdav'))->assertRedirect(route('login'));
}
public function test_webdav_index_can_be_rendered(): void
{
$user = User::factory()->create();
$this->actingAs($user)
->get(route('settings.webdav'))
->assertOk();
}
public function test_webdav_store_requires_authentication(): void
{
$this->post(route('settings.webdav.store'))->assertRedirect(route('login'));
}
public function test_webdav_store_validates_username(): void
{
$user = User::factory()->create();
$this->actingAs($user)
->post(route('settings.webdav.store'), [])
->assertSessionHasErrors('username');
}
public function test_webdav_store_validates_password(): void
{
$user = User::factory()->create();
$this->actingAs($user)
->post(route('settings.webdav.store'), [
'username' => 'testuser',
])
->assertSessionHasErrors('password');
}
public function test_webdav_store_requires_unique_username(): void
{
$user = User::factory()->create();
$user->webDavAccounts()->create([
'username' => 'existinguser',
'password_encrypted' => 'password123',
'enabled' => true,
'display_name' => 'existinguser',
]);
$this->actingAs($user)
->post(route('settings.webdav.store'), [
'username' => 'existinguser',
'password' => 'password123',
])
->assertSessionHasErrors('username');
}
public function test_webdav_store_requires_minimum_password_length(): void
{
$user = User::factory()->create();
$this->actingAs($user)
->post(route('settings.webdav.store'), [
'username' => 'newuser',
'password' => 'short',
])
->assertSessionHasErrors('password');
}
public function test_webdav_account_can_be_created(): void
{
$user = User::factory()->create();
$this->actingAs($user)
->post(route('settings.webdav.store'), [
'username' => 'newuser',
'password' => 'password123',
])
->assertRedirect();
$this->assertDatabaseHas('webdav_accounts', [
'username' => 'newuser',
]);
}
public function test_webdav_delete_requires_authentication(): void
{
$this->delete(route('settings.webdav.destroy', 1))
->assertRedirect(route('login'));
}
public function test_webdav_account_can_be_deleted(): void
{
$user = User::factory()->create();
$account = $user->webDavAccounts()->create([
'username' => 'deleteuser',
'password_encrypted' => 'password123',
'enabled' => true,
'display_name' => 'deleteuser',
]);
$this->actingAs($user)
->delete(route('settings.webdav.destroy', $account->id))
->assertRedirect();
$this->assertDatabaseMissing('webdav_accounts', [
'id' => $account->id,
]);
}
public function test_webdav_delete_only_allows_own_accounts(): void
{
$user1 = User::factory()->create();
$user2 = User::factory()->create();
$account = $user2->webDavAccounts()->create([
'username' => 'otheruser',
'password_encrypted' => 'password123',
'enabled' => true,
'display_name' => 'otheruser',
]);
$this->actingAs($user1)
->delete(route('settings.webdav.destroy', $account->id))
->assertNotFound();
$this->assertDatabaseHas('webdav_accounts', [
'id' => $account->id,
]);
}
}