Test Case Compare Modernized - sebiboga/testlink-upgraded GitHub Wiki
Modernization of the legacy compare-versions screen (lib/testcases/tcCompareVersions.php,
gui/templates/dashio/testcases/tcCompareVersions.tpl) โ GitHub issue
#809.
The legacy Smarty screen is replaced by a standalone Dashio page
(gui/templates/testcases/tcCompare.html) backed by a plain-PHP REST BFF API
(api/testcasescompare/index.php). The Test Case Viewer toolbar Compare Versions
button now opens the modern screen instead of submitting the legacy POST form.
Path: Test Spec โ Test Case Viewer โ toolbar Compare Versions
URL: gui/templates/testcases/tcCompare.html?tproject_id=..&testcase_id=..
BFF API: GET /api/testcasescompare/?action=info + GET /api/testcasescompare/?action=compare
Rights: any authenticated session (parity with legacy, which is read-only).
Tracking issue: #809
| Section | Description |
|---|---|
| Heading | Compare title + test-case context (name + id) |
| Version table | One row per version: version number, radio Version A (left), radio Version B (right), modified/created timestamp, author |
| Diff method | Radio HTML (code) comparison (DaisyDiff) vs Text (inline) comparison (legacy line diff) |
| Context rows | Only for text mode: Context lines number + Show all toggle |
| Action | Compare selected versions and Cancel |
Default selection mirrors legacy: the newest version is pre-selected on the right
and the previous one on the left (matching the legacy {if $mycount == 2} /
{if $mycount == 1} defaults).
- On load the page calls
GET /api/testcasescompare/?action=infoto resolve the test case, its version list (with modification/creation timestamp + author) and the default text-diff context. - The user picks two different versions and a diff method, then clicks Compare selected versions.
- The page calls
GET /api/testcasescompare/?action=comparewithversion_left,version_right,use_html_comp, and (text mode)context/context_show_all. - The BFF runs the same third_party diff engines as the legacy controller
(
third_party/diff/diff.phpinline()for text,HTMLDifferfor HTML) and returns per-section diffs. The client renders each section with an i18n heading and a localized change-count message.
| Key | Source |
|---|---|
summary |
tcversions.summary (left vs right version) |
preconditions |
tcversions.preconditions |
steps |
concatenated step actions with line breaks |
expected_results |
concatenated step expected results with line breaks |
| Case | Result |
|---|---|
No testcase_id
|
warn box tcc.errNoTestcase, Compare disabled |
| Test case not found | HTTP 404 {"status":"error","message":"Test case not found"}
|
| Same version selected twice | local toast tcc.warnSameVersions, no request |
| Blank / non-numeric / negative context | local toast tcc.warnInvalidContext, no request |
Explicit context 0
|
sent to the BFF as context=0 and honored end-to-end (diff renders only the changed lines, see below) |
| Not authenticated | HTTP 401 {"status":"error","message":"Not authenticated"}
|
Gap-fix restoring legacy parity for the Text (inline) diff context field
(lib/testcases/tcCompareVersions.php:97-106 init_args +
gui/templates/dashio/testcases/tcCompareVersions.tpl:77-91 validateForm):
-
Legacy treats a numeric
contextvalue exactly as given โ0is honored (the diff engine'sshowline()has an explicitlinepadding === 0branch that prints only changed lines,third_party/diff/diff.php:79). It only falls back to thediffEngineconfig default (config_get('diffEngine')->context, typically 5) when the parameter is absent or non-numeric. -
Pre-fix regressions (both from the original #809 port): a blank field was
silently coerced to
0bydoCompare, and an explicit0was dropped to the config default by the BFF โ both diverging from legacy. -
Fix:
tcCompare.htmldoCompare()now reads the raw field value; blank/null,NaNorcontext < 0trigger thetcc.warnInvalidContexttoast and nothing is sent to the BFF.api/testcasescompare/index.phpparses the parameter with an explicit-1sentinel ($context = ($rawCtx >= 0) ? $rawCtx : $defaultCtx;where$defaultCtx = diffEngine->context || 5);context_show_all=1still maps tocontext = null(render everything). -
i18n: the
tcc.warnInvalidContextkey already existed in all 10 bundles โ no new keys were required for this fix.
- The BFF reuses the exact legacy diff logic (
buildDiff()intcCompareVersions.php), including the step concatenation with<br /><br />separators and the</p> โ </p>\nline-break insertion for the text engine. -
Event Viewer fix: the legacy controller resolved the section messages and
subtitle with
lang_get('num_changes'/'no_changes'/'diff_subtitle_tc'). Those strings are missing from mostlocale/*/strings.txt, which firedE_WARNING Undefined array keyinto the Event Viewer on every compare. The BFF now returns raw counts + version ids and the client resolves all messages viaTLi18nkeys (tcc.numChanges,tcc.noChanges,tcc.subtitle,tcc.heading.*), so the Event Viewer stays clean.
| Method | Endpoint | Description |
|---|---|---|
| GET | /api/testcasescompare/?action=info |
test case name + version list + default context |
| GET | /api/testcasescompare/?action=compare |
side-by-side / inline diff of two versions |
All routes require a valid session (return 401 otherwise).
All labels, titles, headings, messages and placeholders use client-side TLi18n
keys under the tcc.* namespace (30 keys) present in all 10 locale bundles
(gui/templates/i18n/{en,ro,de,es,fr,it,ja,pt,ru,zh}.json). Bundle consistency is
enforced by tools/lint_i18n.py; every bundle passes python3 -m json.tool.
TestLink 2.0.1 ยท Compare Test Case Versions ยท Refs #809, #1327