mirror of
https://github.com/linuxserver/Heimdall.git
synced 2026-02-21 12:10:34 +09:00
Add tests and fix user edit form
This commit is contained in:
19
tests/Feature/ImportTest.php
Normal file
19
tests/Feature/ImportTest.php
Normal file
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Tests\TestCase;
|
||||
|
||||
class ImportTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
public function test_import_page_loads_successfully(): void
|
||||
{
|
||||
$response = $this->get(route('items.import'));
|
||||
|
||||
$response->assertStatus(200);
|
||||
$response->assertSee('Import');
|
||||
}
|
||||
}
|
||||
53
tests/Feature/SearchTest.php
Normal file
53
tests/Feature/SearchTest.php
Normal file
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Tests\TestCase;
|
||||
|
||||
class SearchTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
public function test_search_page_redirects_correctly(): void
|
||||
{
|
||||
$provider = 'google'; // Example provider
|
||||
$query = 'test'; // Example search term
|
||||
|
||||
$response = $this->get(route('search', ['provider' => $provider, 'q' => $query]));
|
||||
|
||||
$response->assertStatus(302);
|
||||
|
||||
$expectedUrl = 'https://www.google.com/search?q=' . urlencode($query);
|
||||
$response->assertRedirect($expectedUrl);
|
||||
}
|
||||
|
||||
public function test_search_page_with_invalid_provider(): void
|
||||
{
|
||||
$provider = 'invalid_provider'; // Invalid provider
|
||||
$query = 'test'; // Example search term
|
||||
|
||||
$response = $this->get(route('search', ['provider' => $provider, 'q' => $query]));
|
||||
|
||||
$response->assertStatus(404); // Assert that the response status is 404
|
||||
}
|
||||
|
||||
public function test_search_page_without_query_parameter(): void
|
||||
{
|
||||
$provider = 'google'; // Example provider
|
||||
|
||||
$response = $this->get(route('search', ['provider' => $provider]));
|
||||
|
||||
$response->assertStatus(400); // Assert that the response status is 400 (Bad Request)
|
||||
}
|
||||
|
||||
public function test_search_page_with_empty_query(): void
|
||||
{
|
||||
$provider = 'google'; // Example provider
|
||||
$query = ''; // Empty search term
|
||||
|
||||
$response = $this->get(route('search', ['provider' => $provider, 'q' => $query]));
|
||||
|
||||
$response->assertStatus(400); // Assert that the response status is 400 (Bad Request)
|
||||
}
|
||||
}
|
||||
52
tests/Feature/UserEditTest.php
Normal file
52
tests/Feature/UserEditTest.php
Normal file
@@ -0,0 +1,52 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use App\User;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Tests\TestCase;
|
||||
|
||||
class UserEditTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
public function test_user_edit_page_loads_successfully(): void
|
||||
{
|
||||
$this->seed();
|
||||
|
||||
$user = User::factory()->create();
|
||||
|
||||
$response = $this->get(route('users.edit', $user->id));
|
||||
|
||||
$response->assertStatus(200);
|
||||
$response->assertSee($user->username); // Verify username is displayed
|
||||
$response->assertSee(__('app.user.email')); // Verify email field is present
|
||||
}
|
||||
|
||||
public function test_user_can_be_updated(): void
|
||||
{
|
||||
$this->seed();
|
||||
|
||||
$user = User::factory()->create([
|
||||
'username' => 'oldusername',
|
||||
'email' => 'oldemail@example.com',
|
||||
]);
|
||||
|
||||
$data = [
|
||||
'username' => 'newusername',
|
||||
'email' => 'newemail@example.com',
|
||||
'password' => 'newpassword',
|
||||
'password_confirmation' => 'newpassword',
|
||||
'public_front' => 1, // Include public_front in the test data
|
||||
];
|
||||
|
||||
$response = $this->patch(route('users.update', $user->id), $data);
|
||||
|
||||
$response->assertRedirect(route('dash'));
|
||||
$this->assertDatabaseHas('users', [
|
||||
'id' => $user->id,
|
||||
'username' => 'newusername',
|
||||
'email' => 'newemail@example.com',
|
||||
]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user