create(); $this->get(route('educations.index'))->assertRedirect(route('login')); $this->get(route('educations.create'))->assertRedirect(route('login')); $this->post(route('educations.store'), [])->assertRedirect(route('login')); $this->get(route('educations.edit', $education))->assertRedirect(route('login')); $this->patch(route('educations.update', $education), [])->assertRedirect(route('login')); $this->delete(route('educations.destroy', $education))->assertRedirect(route('login')); }); test('an authenticated user can view the education overview', function () { $user = User::factory()->create(); $education = Education::factory()->create(); $this->actingAs($user) ->get(route('educations.index')) ->assertOk() ->assertViewIs('educations.index') ->assertViewHas('educations', fn ($educations) => $educations->contains($education)); }); test('an authenticated user can create an education with an image', function () { $user = User::factory()->create(); $response = $this->actingAs($user)->post(route('educations.store'), [ 'opleiding' => 'HBO-ICT', 'instituut' => 'Hogeschool Utrecht', 'startdatum' => '2020-09-01', 'einddatum' => '2024-07-01', 'beschrijving' => 'Software engineering en web development.', 'afbeelding' => UploadedFile::fake()->image('education.jpg'), ]); $response ->assertSessionHasNoErrors() ->assertRedirect(route('educations.index')); $education = Education::where('opleiding', 'HBO-ICT')->firstOrFail(); $this->assertDatabaseHas('education', [ 'id' => $education->id, 'instituut' => 'Hogeschool Utrecht', ]); $this->assertDatabaseHas('media', [ 'model_type' => Education::class, 'model_id' => $education->id, 'collection_name' => 'image', ]); }); test('an authenticated user can update an education and replace its image', function () { $user = User::factory()->create(); $education = Education::factory()->current()->create([ 'opleiding' => 'HBO-ICT', 'instituut' => 'Hogeschool Utrecht', 'startdatum' => '2020-09-01', ]); $education ->addMedia(UploadedFile::fake()->image('old-education.jpg')) ->toMediaCollection('image'); $response = $this->actingAs($user)->patch(route('educations.update', $education), [ 'opleiding' => 'Software Engineering', 'instituut' => 'Avans Hogeschool', 'startdatum' => '2021-09-01', 'einddatum' => '2025-07-01', 'beschrijving' => 'Verdieping in backend development.', 'afbeelding' => UploadedFile::fake()->image('new-education.jpg'), ]); $response ->assertSessionHasNoErrors() ->assertRedirect(route('educations.index')); expect($education->refresh()) ->opleiding->toBe('Software Engineering') ->instituut->toBe('Avans Hogeschool') ->getMedia('image')->toHaveCount(1); }); test('an authenticated user can delete an education and its image', function () { $user = User::factory()->create(); $education = Education::factory()->current()->create(); $education ->addMedia(UploadedFile::fake()->image('education.jpg')) ->toMediaCollection('image'); $this->actingAs($user) ->delete(route('educations.destroy', $education)) ->assertRedirect(route('educations.index')); $this->assertDatabaseMissing('education', ['id' => $education->id]); $this->assertDatabaseMissing('media', [ 'model_type' => Education::class, 'model_id' => $education->id, ]); });