Add KiCadHelper unit tests and fix PDF detection for external URLs

- Add comprehensive KiCadHelperTest with 14 test cases covering:
  - Stock quantity calculation (zero, single lot, multiple lots)
  - Stock exclusion of expired and unknown-quantity lots
  - Storage location display (present, absent, multiple)
  - Datasheet URL resolution by type name, attachment name, PDF extension
  - Datasheet fallback to Part-DB URL when no match
  - "Data sheet" (with space) name variant matching
- Fix PDF extension detection for external attachments (getExtension()
  returns null for external-only attachments, now also parses URL path)
This commit is contained in:
Sebastian Almberg 2026-02-08 10:37:37 +01:00
parent cc77007b49
commit 6422fa62d1
2 changed files with 372 additions and 3 deletions

View file

@ -439,9 +439,16 @@ class KiCadHelper
return $this->getAttachmentUrl($attachment);
}
//Track first PDF as fallback
if ($firstPdf === null && $attachment->getExtension() === 'pdf') {
$firstPdf = $attachment;
//Track first PDF as fallback (check internal extension or external URL path)
if ($firstPdf === null) {
$extension = $attachment->getExtension();
if ($extension === null && $attachment->hasExternal()) {
$urlPath = parse_url($attachment->getExternalPath(), PHP_URL_PATH) ?? '';
$extension = strtolower(pathinfo($urlPath, PATHINFO_EXTENSION));
}
if ($extension === 'pdf') {
$firstPdf = $attachment;
}
}
}