MD Test Case Import - sebiboga/testlink-upgraded GitHub Wiki

MD Test Case Import — REST BFF API

Endpoint: POST /api/testcasesimport/?action=import_md&tproject_id=<id> Auth: TestLink session (cookie), permission mgt_modify_tc on target project Parser: lib/functions/markdown_tc_import.class.php (pure parser, no DB access) Format reference: tmp/TLU_Test_Cases.md

Request

Param Where Notes
tproject_id query target test project (falls back to session project)
markdown form field the MD text; OR multipart file field uploadedFile
dry_run query 1 = parse + resolve + report, zero DB writes
hit_criteria query name (default) | internalID | externalID — all accepted; only name implemented for MD
action_on_hit query skip (default) | create_new_version | generate_new | update_last_version

Limits: payload larger than import_file_max_size_bytes → HTTP 413.

Semantics

  1. Metadata header is parsed (Project/Prefix/Author/Date). If the file names a different project than the target, response carries projectMismatch — caller decides.
  2. Suites match by name (case-insensitive) anywhere in the project; missing ones are created under the project root.
  3. Cases duplicate by title within the target suite → skipped, new version created, or new TC created (see action_on_hit).
  4. Steps support *Expected:* inline markers; importance mapped High/Medium/Low → 3/2/1.
  5. Response reports per-item arrays: created, skipped, newVersions, failed, plus suitesCreated, suitesMatched, parserErrors.

Example

curl -b cookies.txt -X POST \
  -F "markdown=@TLU_Test_Cases.md" \
  "http://host/api/testcasesimport/?action=import_md&tproject_id=29&dry_run=1"
{"status":"ok","dry_run":true,"createdCount":120,"skippedCount":0,
 "newVersionCount":0,"failedCount":0,"suitesCreated":["Header","Dashboard"],
 "parserErrors":[],
 "projectMismatch":{"file":"TLU: TestLink Upgraded 2.0.1","target":"MD Import Fixture"}}

Verified behavior (suite 27 in tmp/TLU_Test_Cases.md)

dry-run no-write · real create with external IDs · idempotent re-import · create_new_version doubles tcversions · generate_new creates new TC when name matches · full-file dry run (122 cases/24 suites) · 403 without rights · 413 over size limit · no Event Viewer pollution.

Duplicate actions (action_on_hit)

When a case matches an existing TC in the target suite (by hit_criteria):

  • skip — leave the existing TC untouched (added to skipped).
  • create_new_version — bump to a fresh test case version, then update it (added to newVersions; the human-readable version number increments).
  • update_last_version — resolve the latest version via get_last_version_info() and update it in place (no new version); legacy parity with lib/testcases/tcImport.php:384-427. If the name matches no existing TC it falls through to create, matching legacy case 0.
  • generate_new — bypass duplicate detection and always create a new TC (legacy parity: tcImport.php:274-276).

Legacy parity notes (vs lib/testcases/tcImport.php)

Same permission model and size cap; duplicate criteria limited to name (legacy also has internalID/externalID); all four legacy actions supported (skip, create_new_version, generate_new, update_last_version).

Modernized UI (gui/templates/testcases/tcImport.html)

The import screen is modernized as a standalone HTML+JS+CSS page backed by the BFF above.

Entry points (already switched)

  • ASIDE/Test Specification: Test Cases > Import Test Cases (project root, lib/functions/common.php:1895)
  • Test Specification > containerView Import button (containerView.tpl:41-44)
  • Test Suite text buttons Import (containerViewTestSuiteTextButtons.inc.tpl:129, dashio + tl-classic)

Features

  • File type selector XML (legacy form passthrough → lib/testcases/tcImport.php) vs Markdown (.md) (BFF).
  • MD mode: dry-run toggle → PREVIEW report with created/skipped/duplicate tables, zero DB writes; project-mismatch banner when file header names another project.
  • Duplicate hit criteria (name-only for MD) + action for duplicates (skip / create new version / generate new).
  • Client-side size guard (toast at import_file_max_size_bytes) before upload; server 413 backup.
  • mgt_modify_tc gate: no-rights users see a lock notice and a disabled Upload button.
  • Mandatory i18n via TLi18n — all labels keyed in every locale bundle.

Import screen

Markdown dry-run preview

Project mismatch warning

UI regression suite

Suite 63 in tmp/TLU_Test_Cases.md (11 test cases covering render, MD/XML toggle, dry-run, real import + DB verify, idempotent re-import, project mismatch, oversize, no-permission, XML passthrough, cancel, Event Viewer cleanliness).