mirror of
https://github.com/linuxserver/Heimdall.git
synced 2025-11-02 22:17:48 +09:00
Add tests and fix user edit form
This commit is contained in:
@@ -18,16 +18,23 @@ class SearchController extends Controller
|
||||
$requestprovider = $request->input('provider');
|
||||
$query = $request->input('q');
|
||||
|
||||
// Validate the presence and non-emptiness of the query parameter
|
||||
if (!$query || trim($query) === '') {
|
||||
abort(400, 'Missing or empty query parameter');
|
||||
}
|
||||
|
||||
$provider = Search::providerDetails($requestprovider);
|
||||
|
||||
if (!$provider || !isset($provider->type)) {
|
||||
abort(404, 'Invalid provider');
|
||||
}
|
||||
|
||||
if ($provider->type == 'standard') {
|
||||
return redirect($provider->url.'?'.$provider->query.'='.urlencode($query));
|
||||
} elseif ($provider->type == 'external') {
|
||||
$class = new $provider->class;
|
||||
//print_r($provider);
|
||||
return $class->getResults($query, $provider);
|
||||
}
|
||||
|
||||
//print_r($provider);
|
||||
}
|
||||
abort(404, 'Provider type not supported');}
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@ class UsersSeeder extends Seeder
|
||||
$user->username = 'admin';
|
||||
$user->email = 'admin@test.com';
|
||||
$user->password = null;
|
||||
$user->public_front = 0; // Default value for public_front
|
||||
$user->save();
|
||||
|
||||
$user_id = $user->id;
|
||||
|
||||
@@ -45,13 +45,13 @@
|
||||
<div style="margin-top: -40px; width: 100%; padding: 0" class="create">
|
||||
<div class="input">
|
||||
<label>{{ __('app.apps.password') }} *</label>
|
||||
{{ html()->password('password', array('class' => 'form-control'))->attributes(null) }}
|
||||
{{ html()->password('password', array('class' => 'form-control'))->attributes([]) }}
|
||||
<hr />
|
||||
|
||||
</div>
|
||||
<div class="input">
|
||||
<label>{{ __('app.user.password_confirm') }} *</label>
|
||||
{{ html()->password('password_confirmation', array('class' => 'form-control'))->attributes(null) }}
|
||||
{{ html()->password('password_confirmation', array('class' => 'form-control'))->attributes([]) }}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
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