assertNotFalse($content); $this->assertStringContainsString( 'sanitizeTextLine($customer->getName() ?? \'Ukendt\', 100)', $content, 'recipient.name must be sanitized via sanitizeTextLine with a 100-char cap' ); } public function testEndpointSanitizesRecipientAddress(): void { $path = __DIR__ . '/../../../modules/economic/endpoints/invoices/economic_invoices_drafts_endpoint.php'; $content = file_get_contents($path); $this->assertNotFalse($content); $this->assertStringContainsString( 'sanitizeTextLine($customer->getAddress() ?? \'Ukendt\', 250)', $content, 'recipient.address must be sanitized via sanitizeTextLine with a 250-char cap' ); } public function testEndpointSanitizesRecipientZip(): void { $path = __DIR__ . '/../../../modules/economic/endpoints/invoices/economic_invoices_drafts_endpoint.php'; $content = file_get_contents($path); $this->assertNotFalse($content); $this->assertStringContainsString( 'sanitizeTextLine($customer->getZipCode() ?? \'Ukendt\', 20)', $content, 'recipient.zip must be sanitized via sanitizeTextLine with a 20-char cap' ); } public function testEndpointSanitizesRecipientCity(): void { $path = __DIR__ . '/../../../modules/economic/endpoints/invoices/economic_invoices_drafts_endpoint.php'; $content = file_get_contents($path); $this->assertNotFalse($content); $this->assertStringContainsString( 'sanitizeTextLine($customer->getCity() ?? \'Ukendt\', 100)', $content, 'recipient.city must be sanitized via sanitizeTextLine with a 100-char cap' ); } public function testEndpointStripsNonDigitsFromEan(): void { $path = __DIR__ . '/../../../modules/economic/endpoints/invoices/economic_invoices_drafts_endpoint.php'; $content = file_get_contents($path); $this->assertNotFalse($content); $this->assertStringContainsString( "preg_replace('/[^0-9]/', '', \$customer_ean)", $content, 'recipient.ean must be stripped to digits only' ); } public function testEndpointOmitsEmptyEanInsteadOfSendingEmptyString(): void { $path = __DIR__ . '/../../../modules/economic/endpoints/invoices/economic_invoices_drafts_endpoint.php'; $content = file_get_contents($path); $this->assertNotFalse($content); // After stripping non-digits, if the result is empty we should remove the key $this->assertStringContainsString( "unset(\$recipient['ean']);", $content, 'recipient.ean must be removed from the payload when the sanitized EAN is empty' ); // Verify the conditional structure: if empty, unset $this->assertMatchesRegularExpression( "/\\\$recipient\\['ean'\\]\\s*=\\s*preg_replace\\(\\s*['\\/\\^0-9\\/']/", $content, 'recipient.ean must be assigned via preg_replace with a non-digit-stripping pattern' ); } }