1+ <?php
2+
3+ namespace Tests \Feature ;
4+
5+ use Illuminate \Foundation \Testing \RefreshDatabase ;
6+ use Tests \TestCase ;
7+
8+ class SearchTest extends TestCase
9+ {
10+ use RefreshDatabase;
11+
12+ public function test_search_page_redirects_correctly (): void
13+ {
14+ $ provider = 'google ' ; // Example provider
15+ $ query = 'test ' ; // Example search term
16+
17+ $ response = $ this ->get (route ('search ' , ['provider ' => $ provider , 'q ' => $ query ]));
18+
19+ $ response ->assertStatus (302 );
20+
21+ $ expectedUrl = 'https://www.google.com/search?q= ' . urlencode ($ query );
22+ $ response ->assertRedirect ($ expectedUrl );
23+ }
24+
25+ public function test_search_page_with_invalid_provider (): void
26+ {
27+ $ provider = 'invalid_provider ' ; // Invalid provider
28+ $ query = 'test ' ; // Example search term
29+
30+ $ response = $ this ->get (route ('search ' , ['provider ' => $ provider , 'q ' => $ query ]));
31+
32+ $ response ->assertStatus (404 ); // Assert that the response status is 404
33+ }
34+
35+ public function test_search_page_without_query_parameter (): void
36+ {
37+ $ provider = 'google ' ; // Example provider
38+
39+ $ response = $ this ->get (route ('search ' , ['provider ' => $ provider ]));
40+
41+ $ response ->assertStatus (400 ); // Assert that the response status is 400 (Bad Request)
42+ }
43+
44+ public function test_search_page_with_empty_query (): void
45+ {
46+ $ provider = 'google ' ; // Example provider
47+ $ query = '' ; // Empty search term
48+
49+ $ response = $ this ->get (route ('search ' , ['provider ' => $ provider , 'q ' => $ query ]));
50+
51+ $ response ->assertStatus (400 ); // Assert that the response status is 400 (Bad Request)
52+ }
53+ }
0 commit comments