createUser(['ROLE_CLINIC']); $clinic = new Clinic($owner); $this->em->persist($clinic); $doctor = new Doctor($this->createUser(['ROLE_DOCTOR']), 'دکتر تست'); $this->em->persist($doctor); $clinic->getDoctors()->add($doctor); $secretary = $this->createUser(['ROLE_SECRETARY']); $rel = new DoctorSecretary($doctor, $secretary, DoctorSecretary::OWNER_CLINIC, $clinic); $this->em->persist($rel); $this->em->persist(new UserActiveContext($secretary, $clinic->getUuid())); return [$secretary, $rel]; } public function testInventoryDeniedByDefault(): void { // DEFAULT_PERMISSIONS: inventory.* = false [$secretary] = $this->makeClinicSecretary(); $this->em->flush(); $this->authJson('GET', '/api/v1/inventory-items', $secretary); $this->assertSame(403, $this->responseCode()); } public function testInventoryAllowedWhenGranted(): void { [$secretary, $rel] = $this->makeClinicSecretary(); $rel->mergePermissions(['resources' => ['inventory' => ['view' => true]]]); $this->em->flush(); $this->authJson('GET', '/api/v1/inventory-items', $secretary); $this->assertSame(200, $this->responseCode()); } public function testPatientCreateDeniedByDefault(): void { // DEFAULT_PERMISSIONS: patients.create = false (view is true) [$secretary] = $this->makeClinicSecretary(); $this->em->flush(); $this->authJson('POST', '/api/v1/patient', $secretary, ['name' => 'x']); $this->assertSame(403, $this->responseCode()); } public function testInventoryCreateDeniedButViewGranted(): void { [$secretary, $rel] = $this->makeClinicSecretary(); $rel->mergePermissions(['resources' => ['inventory' => ['view' => true, 'create' => false]]]); $this->em->flush(); // مشاهده مجاز $this->authJson('GET', '/api/v1/inventory-items', $secretary); $this->assertSame(200, $this->responseCode()); // ایجاد ممنوع $this->authJson('POST', '/api/v1/inventory-item', $secretary, ['name' => 'گاز استریل']); $this->assertSame(403, $this->responseCode()); } // service-items (listAllItems) فقط توگلِ permission را می‌سنجد — برخلاف // service-sections که پیش از آن، گیتِ اشتراک (assertServicesGate) هم دارد. public function testServicesDeniedByDefault(): void { // DEFAULT_PERMISSIONS: services.* = false [$secretary] = $this->makeClinicSecretary(); $this->em->flush(); $this->authJson('GET', '/api/v1/service-items', $secretary); $this->assertSame(403, $this->responseCode()); } public function testServicesAllowedWhenGranted(): void { [$secretary, $rel] = $this->makeClinicSecretary(); $rel->mergePermissions(['resources' => ['services' => ['view' => true]]]); $this->em->flush(); $this->authJson('GET', '/api/v1/service-items', $secretary); $this->assertSame(200, $this->responseCode()); } public function testServicesCreateDeniedButViewGranted(): void { [$secretary, $rel] = $this->makeClinicSecretary(); $rel->mergePermissions(['resources' => ['services' => ['view' => true, 'create' => false]]]); $this->em->flush(); // مشاهده مجاز $this->authJson('GET', '/api/v1/service-items', $secretary); $this->assertSame(200, $this->responseCode()); // ایجاد ممنوع — گیتِ permission پیش از گیتِ اشتراک اجرا می‌شود. $this->authJson('POST', '/api/v1/service-section', $secretary, ['name' => 'بخش تست']); $this->assertSame(403, $this->responseCode()); } }