Monday, November 21, 2011

Upgrading testlink, changed test case formatting in exported document when exporting test cases

We had testlink 1.8.4 and we upgraded to 1.9.3, one of the differences we noted is that 1.9.3 test cases now have steps and when doing export for test cases, the test cases in the exported document looked different that we had exported before. we already exported one document with all test cases from 1.8.4 and did lots of changes. and we wanted to have 1.9.3 exported test cases looks the same

I started looking into the code, and found it in file \lib\functions\print.inc.php

    if ($tcInfo[$key] != '')
    {
        $code .= '<tr>' .
                 '<td><span class="label">' . $labels['step_number'] .':</span></td>' .
                 '<td><span class="label">' . $labels['step_actions'] .':</span></td>' .
                 '<td><span class="label">' . $labels['expected_results'] .':</span></td></tr>';
       
        $loop2do = count($tcInfo[$key]);
        for($ydx=0 ; $ydx < $loop2do; $ydx++)
        {
            $code .= '<tr>' .
                     '<td width="5">' .  $tcInfo[$key][$ydx]['step_number'] . '</td>' .
                     '<td>' .  $tcInfo[$key][$ydx]['actions'] . '</td>' .
                     '<td>' .  $tcInfo[$key][$ydx]['expected_results'] . '</td>' .
                     '</tr>';
        }

 

The above code created a table with a column for step number, column for step actions, column for step results, then there is a loop to create rows for each step. We wanted to get ride of step number column and have just one row for with one cell for step details, and another row for expected results, I have changed the code to be like below

    if ($tcInfo[$key] != '')
    {
        $loop2do = count($tcInfo[$key]);
        for($ydx=0 ; $ydx < $loop2do; $ydx++)
        {
            $code .= '<tr><td colspan="' .  $cfg['tableColspan'] . '"><span class="label">' . $labels['step_actions'] . ':</span><br />' .   $tcInfo[$key][$ydx]['actions'] . '</td></tr>' .
                     '<tr><td colspan="' .  $cfg['tableColspan'] . '"><span class="label">' . $labels['expected_results'] . ':</span><br />' .  $tcInfo[$key][$ydx]['expected_results'] . '</td></tr>';
        }

    }

This worked out great, now it looks exactly like test cases we had before