get(route( config('unit-tests.route.prefix') . 'testimonials.' . config('unit-tests.view.resources-index') )); $response->assertRedirect(route(config('unit-tests.route.prefix') . 'login')); } public function test_guest_cannot_access_testimonials_read_view(): void { $model = Testimonial::factory()->createOneQuietly(); $response = $this->get(route( config('unit-tests.route.prefix') . 'testimonials.' . config('unit-tests.view.resources-read'), $model->getKey() )); $response->assertRedirect(route(config('unit-tests.route.prefix') . 'login')); } public function test_guest_cannot_access_testimonials_create_view(): void { $response = $this->get(route( config('unit-tests.route.prefix') . 'testimonials.' . config('unit-tests.view.resources-create') )); $response->assertRedirect(route(config('unit-tests.route.prefix') . 'login')); } public function test_guest_cannot_access_testimonials_update_view(): void { $model = Testimonial::factory()->createOneQuietly(); $response = $this->get(route( config('unit-tests.route.prefix') . 'testimonials.' . config('unit-tests.view.resources-update'), $model->getKey() )); $response->assertRedirect(route(config('unit-tests.route.prefix') . 'login')); } /** * TESTS GUEST CANNOT POST MODEL. */ public function test_guest_cannot_create_testimonial(): void { $model = Testimonial::factory()->createOneQuietly(); $response = $this->post( route( config('unit-tests.route.prefix') . 'testimonials.' . config('unit-tests.route.action-create'), $model->getKey() ), $model->toArray() ); $response->assertRedirect(route(config('unit-tests.route.prefix') . 'login')); } public function test_guest_cannot_update_testimonial(): void { $model = Testimonial::factory()->createOneQuietly(); $response = $this->patch( route( config('unit-tests.route.prefix') . 'testimonials.' . config('unit-tests.route.action-update'), $model->getKey() ), $model->toArray() ); $response->assertRedirect(route(config('unit-tests.route.prefix') . 'login')); } public function test_guest_cannot_delete_testimonial(): void { $model = Testimonial::factory()->createOneQuietly(); $response = $this->delete( route( config('unit-tests.route.prefix') . 'testimonials.' . config('unit-tests.route.action-delete'), $model->getKey() ), $model->toArray() ); $response->assertRedirect(route(config('unit-tests.route.prefix') . 'login')); } /** * TESTS USER CONCEPTOR ACCESS VIEWS. */ public function test_user_conceptor_can_access_testimonials_index_view(): void { $authModel = AuthModel::factory()->createOneQuietly(); $authModel->update(['role' => RoleEnum::conceptor]); $response = $this->actingAs($authModel, 'backend')->get( route(config('unit-tests.route.prefix') . 'testimonials.' . config('unit-tests.view.resources-index')) ); $response->assertSuccessful(); $response->assertViewIs( config('unit-tests.view.prefix') . 'pages.testimonials.' . config('unit-tests.view.resources-index') ); } public function test_user_conceptor_can_access_testimonials_read_view(): void { $authModel = AuthModel::factory()->createOneQuietly(); $authModel->update(['role' => RoleEnum::conceptor]); $model = Testimonial::factory()->createOneQuietly(); $response = $this->actingAs($authModel, 'backend')->get( route(config('unit-tests.route.prefix') . 'testimonials.' . config('unit-tests.view.resources-read'), $model) ); $response->assertSuccessful(); $response->assertViewIs( config('unit-tests.view.prefix') . 'pages.testimonials.' . config('unit-tests.view.resources-read') ); } public function test_user_conceptor_can_access_testimonials_create_view(): void { $authModel = AuthModel::factory()->createOneQuietly(); $authModel->update(['role' => RoleEnum::conceptor]); $response = $this->actingAs($authModel, 'backend')->get( route(config('unit-tests.route.prefix') . 'testimonials.' . config('unit-tests.view.resources-create')) ); $response->assertSuccessful(); $response->assertViewIs( config('unit-tests.view.prefix') . 'pages.testimonials.' . config('unit-tests.view.resources-create') ); } public function test_user_conceptor_can_access_testimonials_update_view(): void { $authModel = AuthModel::factory()->createOneQuietly(); $authModel->update(['role' => RoleEnum::conceptor]); $model = Testimonial::factory()->createOneQuietly(); $response = $this->actingAs($authModel, 'backend')->get( route(config('unit-tests.route.prefix') . 'testimonials.' . config('unit-tests.view.resources-update'), $model) ); $response->assertSuccessful(); $response->assertViewIs( config('unit-tests.view.prefix') . 'pages.testimonials.' . config('unit-tests.view.resources-update') ); } /** * TESTS CAN ACTIONS ON MODEL. */ public function test_can_create_testimonial(): void { $model = Testimonial::factory()->createOneQuietly(); $this->assertModelExists($model); } public function test_can_update_testimonial(): void { $model = Testimonial::factory()->createOneQuietly(); $fieldTest = ''; foreach (config('unit-tests.list-fields') as $field) { if (Schema::hasColumn($model->getTable(), $field)) { $model->update([$field => 'test']); $fieldTest = $field; break; } } $this->assertTrue($model->wasChanged()); $this->assertTrue(array_key_exists($fieldTest, $model->getChanges())); $this->assertModelExists($model); } public function test_can_delete_testimonial(): void { $model = Testimonial::factory()->createOneQuietly(); $model->delete(); $this->assertModelMissing($model); } }