buildPdfTokens($data); } public function exposeApplyPdfTokens(string $html, array $tokens): string { return $this->applyPdfTokens($html, $tokens); } }; } public function testBuildPdfTokensContainsHospitalAndPatientPlaceholders(): void { $controller = $this->buildTestController(); $tokens = $controller->exposeBuildPdfTokens([ 'patient_name' => 'John Doe', 'uhid' => 'UHID12345', 'invoice_code' => 'INV999', 'age' => '35 Y', 'gender' => 'Male', 'phone_no' => '9876543210', 'patient_address' => '123 Main Street', 'doctor_name' => 'Dr. Smith', 'doctor_education' => 'MBBS, MD', 'technician_name' => 'Alex', 'report_title' => 'X-RAY CHEST', ]); $this->assertArrayHasKey('{{H_Name}}', $tokens); $this->assertArrayHasKey('{{H_address_1}}', $tokens); $this->assertArrayHasKey('{{H_phone_No}}', $tokens); $this->assertArrayHasKey('{{H_logo}}', $tokens); $this->assertArrayHasKey('assets/images/{{H_logo}}', $tokens); $this->assertSame('John Doe', $tokens['{{patient_name}}']); $this->assertSame('John Doe', $tokens['{{pName}}']); $this->assertSame('UHID12345', $tokens['{{uhid}}']); $this->assertSame('INV999', $tokens['{{invoice_code}}']); $this->assertSame('9876543210', $tokens['{{phoneno}}']); $this->assertSame('123 Main Street', $tokens['{{p_address}}']); $this->assertSame('Dr. Smith', $tokens['{{doctor_name}}']); $this->assertSame('X-RAY CHEST', $tokens['{{report_title}}']); } public function testApplyPdfTokensReplacesTemplatePlaceholders(): void { $controller = $this->buildTestController(); $templateHtml = '
{{H_address_1}}, {{H_address_2}} | Phone: {{H_phone_No}}
' . '{{h_name}} - {{H_NAME}} - {{patient_NAME}} - {{UHID}}
'; $tokens = $controller->exposeBuildPdfTokens([ 'patient_name' => 'Bob Marley', 'uhid' => 'UHID-999', ]); $output = $controller->exposeApplyPdfTokens($templateHtml, $tokens); $this->assertStringNotContainsString('{{h_name}}', $output); $this->assertStringNotContainsString('{{H_NAME}}', $output); $this->assertStringNotContainsString('{{patient_NAME}}', $output); $this->assertStringNotContainsString('{{UHID}}', $output); $this->assertStringContainsString('Bob Marley', $output); $this->assertStringContainsString('UHID-999', $output); } }