<?php namespace Tests\Feature; use Tests\TestCase; use Illuminate\Foundation\Testing\RefreshDatabase; use App\Models\{User,Role,Office,OfficeIpRule,Shift,Employee}; class AttendanceSecurityTest extends TestCase { use RefreshDatabase; public function test_attendance_is_denied_outside_approved_ip():void { $role=Role::create(['name'=>'Employee','slug'=>'employee']);$u=User::create(['name'=>'Test','email'=>'t@example.com','password'=>'secret']);$u->email_verified_at=now();$u->save();$u->roles()->attach($role);$o=Office::create(['name'=>'HQ','code'=>'HQ','timezone'=>'Asia/Karachi']);OfficeIpRule::create(['office_id'=>$o->id,'label'=>'office','cidr'=>'10.0.0.0/24','is_active'=>true]);$s=Shift::create(['name'=>'General','start_time'=>'09:00','end_time'=>'18:00']);Employee::create(['user_id'=>$u->id,'employee_code'=>'E1','office_id'=>$o->id,'shift_id'=>$s->id,'status'=>'active']);$r=$this->actingAs($u)->withServerVariables(['REMOTE_ADDR'=>'203.0.113.10'])->post('/attendance/punch',['action'=>'check_in']);$r->assertSessionHasErrors('attendance');$this->assertDatabaseCount('attendance_records',0);$this->assertDatabaseHas('attendance_attempts',['user_id'=>$u->id,'allowed'=>0]); } }