-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
746eca3
commit f49b1a8
Showing
1 changed file
with
34 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?php | ||
|
||
namespace Tests\Feature\Controllers; | ||
|
||
use App\Models\Category; | ||
use App\Models\Product; | ||
use Illuminate\Foundation\Testing\RefreshDatabase; | ||
use Tests\TestCase; | ||
|
||
class HomeControllerTest extends TestCase | ||
{ | ||
use RefreshDatabase; | ||
|
||
/** | ||
* Test if the index method returns the welcome view with categories and products. | ||
* | ||
* @return void | ||
*/ | ||
public function test_index_returns_welcome_view_with_categories_and_products() | ||
{ | ||
// Given some categories and products exist in the database | ||
$categories = Category::factory()->count(3)->create(); | ||
$products = Product::factory()->count(5)->create(); | ||
|
||
// When a user visits the home page | ||
$response = $this->get('/'); | ||
|
||
// Then they should see the welcome view with categories and products | ||
$response->assertStatus(200) | ||
->assertViewIs('welcome') // Assert that the view is correct | ||
->assertViewHas('categories', $categories) // Assert that categories are passed to the view | ||
->assertViewHas('products', $products); // Assert that products are passed to the view | ||
} | ||
} |