Files
crmPRO/tests/Domain/Tasks/TaskAttachmentRepositoryTest.php
Jacek Pyziak 8f2e332069 Add unit tests for MailToTaskImporter attachment name normalization
- Implemented tests for various scenarios of attachment name normalization in MailToTaskImporter.
- Covered cases for technical names, named files, missing extensions, and content-based detection.
- Added tests for extracting names from MIME headers, including handling of Content-Description.
2026-02-18 23:30:11 +01:00

49 lines
1.6 KiB
PHP

<?php
require_once __DIR__ . '/../../../autoload/Domain/Tasks/TaskAttachmentRepository.php';
use Domain\Tasks\TaskAttachmentRepository;
function run_task_attachment_repository_tests()
{
assert_true(
TaskAttachmentRepository::effectiveTitle( ' Raport ', 'plik.pdf' ) === 'Raport',
'Expected effective title to prefer trimmed custom title.'
);
assert_true(
TaskAttachmentRepository::effectiveTitle( '', 'plik.pdf' ) === 'plik.pdf',
'Expected effective title to fallback to original file name.'
);
$sanitized = TaskAttachmentRepository::sanitizeFileName( 'Załącznik #1 (final).pdf' );
assert_true(
strpos( $sanitized, '#' ) === false
&& strpos( $sanitized, '(' ) === false
&& strpos( $sanitized, ')' ) === false
&& strpos( $sanitized, ' ' ) === false
&& substr( $sanitized, -4 ) === '.pdf',
'Expected sanitized file name to remove unsupported characters and keep extension.'
);
assert_true(
TaskAttachmentRepository::detectExtensionFromContent( "%PDF-1.7\nexample" ) === 'pdf',
'Expected PDF extension to be detected from binary content.'
);
assert_true(
TaskAttachmentRepository::effectiveTitleWithExtension( '', 'zalacznik', 'pdf', '' ) === 'zalacznik.pdf',
'Expected display title fallback to include file extension.'
);
assert_true(
TaskAttachmentRepository::effectiveTitleWithExtension(
'zalacznik.pdf',
'VIDOK_Instrukcja Montażu I Uruchomienia - Wyroby Elektryczne.pdf',
'pdf',
''
) === 'VIDOK_Instrukcja Montażu I Uruchomienia - Wyroby Elektryczne.pdf',
'Expected generic title to be ignored when original file name is available.'
);
}