Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions app/Http/Controllers/SearchController.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,23 @@ public function index(Request $request)
$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');}
}
1 change: 1 addition & 0 deletions database/seeders/UsersSeeder.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public function run(): void
$user->username = 'admin';
$user->email = '[email protected]';
$user->password = null;
$user->public_front = 0; // Default value for public_front
$user->save();

$user_id = $user->id;
Expand Down
4 changes: 2 additions & 2 deletions resources/views/users/form.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -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>

Expand Down
19 changes: 19 additions & 0 deletions tests/Feature/ImportTest.php
Original file line number Diff line number Diff line change
@@ -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 changes: 53 additions & 0 deletions tests/Feature/SearchTest.php
Original file line number Diff line number Diff line change
@@ -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 changes: 52 additions & 0 deletions tests/Feature/UserEditTest.php
Original file line number Diff line number Diff line change
@@ -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' => '[email protected]',
]);

$data = [
'username' => 'newusername',
'email' => '[email protected]',
'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' => '[email protected]',
]);
}
}