Skip to content

Commit

Permalink
Export TestSuites and TestCases Attachments in XML
Browse files Browse the repository at this point in the history
    If the new checkbox "Export attachments" is checked in the GUI (disabled
    by default)
  • Loading branch information
Bob Le Bricodeur committed Oct 29, 2017
1 parent 525479f commit 0b6edcc
Show file tree
Hide file tree
Showing 6 changed files with 112 additions and 7 deletions.
8 changes: 6 additions & 2 deletions gui/templates/testcases/tcExport.tpl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{*
TestLink Open Source Project - http://testlink.sourceforge.net/
$Id: tcExport.tpl,v 1.14 2010/11/06 11:42:47 amkhullar Exp $
$Id: tcExport.tpl 28 2017-10-23 14:56:03Z clm $
test case export initial page
Expand All @@ -13,7 +13,7 @@ test case export initial page
s='export_filename,warning_empty_filename,file_type,warning,export_cfields,title_req_export,
view_file_format_doc,export_with_keywords,btn_export,export_tcase_external_id,btn_cancel,
view_file_format_doc,export_with_prefix,export_summary,export_steps,export_preconditions,
export_testcase_requirements'}
export_testcase_requirements,export_attachments'}

{$cfg_section=$smarty.template|basename|replace:".tpl":""}
{config_load file="input_dimensions.conf" section=$cfg_section}
Expand Down Expand Up @@ -121,6 +121,10 @@ function mirrorCheckbox(sourceOID,targetOID)
<td>{$labels.export_with_keywords}</td>
<td><input type="checkbox" name="exportKeywords" value="1" /></td>
</tr>
<tr>
<td>{$labels.export_attachments}</td>
<td><input type="checkbox" name="exportAttachments" value="1" /></td>
</tr>



Expand Down
49 changes: 48 additions & 1 deletion lib/functions/testcase.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -3794,6 +3794,52 @@ function exportTestCaseDataToXML($tcase_id,$tcversion_id,$tproject_id=null,
$tc_data[0]['xmlrequirements'] = exportDataToXML($requirements,$reqRootElem,$reqElemTemplate,$reqDecode,true);
}
}

if (isset($optExport['ATTACHMENTS']) && $optExport['ATTACHMENTS'])
{
$attachments=null;

// get all attachments
$attachmentInfos = $this->attachmentRepository->getAttachmentInfosFor($tcase_id,$this->attachmentTableName,'id');

// get all attachments content and encode it in base64
if ($attachmentInfos)
{
foreach ($attachmentInfos as $attachmentInfo)
{
$aID = $attachmentInfo["id"];
$content = $this->attachmentRepository->getAttachmentContent($aID, $attachmentInfo);

if ($content != null)
{
$attachments[$aID]["id"] = $aID;
$attachments[$aID]["name"] = $attachmentInfo["file_name"];
$attachments[$aID]["file_type"] = $attachmentInfo["file_type"];
$attachments[$aID]["title"] = $attachmentInfo["title"];
$attachments[$aID]["date_added"] = $attachmentInfo["date_added"];
$attachments[$aID]["content"] = base64_encode($content);
}
}
}

if( !is_null($attachments) && count($attachments) > 0 )
{
$attchRootElem = "\t<attachments>\n{{XMLCODE}}\t</attachments>\n";
$attchElemTemplate = "\t\t<attachment>\n" .
"\t\t\t<id><![CDATA[||ATTACHMENT_ID||]]></id>\n" .
"\t\t\t<name><![CDATA[||ATTACHMENT_NAME||]]></name>\n" .
"\t\t\t<file_type><![CDATA[||ATTACHMENT_FILE_TYPE||]]></file_type>\n" .
"\t\t\t<title><![CDATA[||ATTACHMENT_TITLE||]]></title>\n" .
"\t\t\t<date_added><![CDATA[||ATTACHMENT_DATE_ADDED||]]></date_added>\n" .
"\t\t\t<content><![CDATA[||ATTACHMENT_CONTENT||]]></content>\n" .
"\t\t</attachment>\n";

$attchDecode = array ("||ATTACHMENT_ID||" => "id", "||ATTACHMENT_NAME||" => "name",
"||ATTACHMENT_FILE_TYPE||" => "file_type", "||ATTACHMENT_TITLE||" => "title",
"||ATTACHMENT_DATE_ADDED||" => "date_added", "||ATTACHMENT_CONTENT||" => "content");
$tc_data[0]['xmlattachments'] = exportDataToXML($attachments,$attchRootElem,$attchElemTemplate,$attchDecode,true);
}
}

// ------------------------------------------------------------------------------------
if(!isset($optExport['TCSTEPS']) || $optExport['TCSTEPS'])
Expand Down Expand Up @@ -3893,7 +3939,7 @@ function exportTestCaseDataToXML($tcase_id,$tcversion_id,$tproject_id=null,
"\t<is_open>||ISOPEN||</is_open>\n" .
"\t<active>||ACTIVE||</active>\n" .
"||STEPS||\n" .
"||KEYWORDS||||CUSTOMFIELDS||||REQUIREMENTS||{$addElemTpl}</testcase>\n";
"||KEYWORDS||||CUSTOMFIELDS||||REQUIREMENTS||||ATTACHMENTS||{$addElemTpl}</testcase>\n";


// ||yyy||-> tags, {{xxx}} -> attribute
Expand Down Expand Up @@ -3921,6 +3967,7 @@ function exportTestCaseDataToXML($tcase_id,$tcversion_id,$tproject_id=null,
"||KEYWORDS||" => "xmlkeywords",
"||CUSTOMFIELDS||" => "xmlcustomfields",
"||REQUIREMENTS||" => "xmlrequirements",
"||ATTACHMENTS||" => "xmlattachments",
"||RELATIONS||" => "xmlrelations");


Expand Down
48 changes: 47 additions & 1 deletion lib/functions/testsuite.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -1152,6 +1152,7 @@ function exportTestSuiteDataToXML($container_id,$tproject_id,$optExport = array(
if($doRecursion)
{
$cfXML = null;
$attachmentsXML = null;
$kwXML = null;
$tsuiteData = $this->get_by_id($container_id);
if( isset($optExport['KEYWORDS']) && $optExport['KEYWORDS'])
Expand All @@ -1169,11 +1170,56 @@ function exportTestSuiteDataToXML($container_id,$tproject_id,$optExport = array(
{
$cfXML = $this->cfield_mgr->exportValueAsXML($cfMap);
}
}
if (isset($optExport['ATTACHMENTS']) && $optExport['ATTACHMENTS'])
{
$attachments=null;

// get all attachments
$attachmentInfos = $this->attachmentRepository->getAttachmentInfosFor($container_id,$this->attachmentTableName,'id');

// get all attachments content and encode it in base64
if ($attachmentInfos)
{
foreach ($attachmentInfos as $attachmentInfo)
{
$aID = $attachmentInfo["id"];
$content = $this->attachmentRepository->getAttachmentContent($aID, $attachmentInfo);

if ($content != null)
{
$attachments[$aID]["id"] = $aID;
$attachments[$aID]["name"] = $attachmentInfo["file_name"];
$attachments[$aID]["file_type"] = $attachmentInfo["file_type"];
$attachments[$aID]["title"] = $attachmentInfo["title"];
$attachments[$aID]["date_added"] = $attachmentInfo["date_added"];
$attachments[$aID]["content"] = base64_encode($content);
}
}
}

if( !is_null($attachments) && count($attachments) > 0 )
{
$attchRootElem = "<attachments>\n{{XMLCODE}}</attachments>\n";
$attchElemTemplate = "\t<attachment>\n" .
"\t\t<id><![CDATA[||ATTACHMENT_ID||]]></id>\n" .
"\t\t<name><![CDATA[||ATTACHMENT_NAME||]]></name>\n" .
"\t\t<file_type><![CDATA[||ATTACHMENT_FILE_TYPE||]]></file_type>\n" .
"\t\t<title><![CDATA[||ATTACHMENT_TITLE||]]></title>\n" .
"\t\t<date_added><![CDATA[||ATTACHMENT_DATE_ADDED||]]></date_added>\n" .
"\t\t<content><![CDATA[||ATTACHMENT_CONTENT||]]></content>\n" .
"\t</attachment>\n";

$attchDecode = array ("||ATTACHMENT_ID||" => "id", "||ATTACHMENT_NAME||" => "name",
"||ATTACHMENT_FILE_TYPE||" => "file_type", "||ATTACHMENT_TITLE||" => "title",
"||ATTACHMENT_DATE_ADDED||" => "date_added", "||ATTACHMENT_CONTENT||" => "content");
$attachmentsXML = exportDataToXML($attachments,$attchRootElem,$attchElemTemplate,$attchDecode,true);
}
}
$xmlTC = '<testsuite id="' . $tsuiteData['id'] . '" ' .
'name="' . htmlspecialchars($tsuiteData['name']). '" >' .
"\n<node_order><![CDATA[{$tsuiteData['node_order']}]]></node_order>\n" .
"<details><![CDATA[{$tsuiteData['details']}]]></details> \n{$kwXML}{$cfXML}";
"<details><![CDATA[{$tsuiteData['details']}]]></details> \n{$kwXML}{$cfXML}{$attachmentsXML}";
}
else
{
Expand Down
3 changes: 2 additions & 1 deletion lib/testcases/tcExport.php
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ function init_args(&$dbHandler)

$k2l = array('useRecursion','exportReqs','exportCFields','exportKeywords',
'exportTestCaseExternalID','exportTCSummary','exportTCPreconditions',
'exportTCSteps');
'exportTCSteps', 'exportAttachments');
foreach ($k2l as $key)
{
$args->$key = isset($_REQUEST[$key]) ? intval($_REQUEST[$key]) : 0;
Expand All @@ -181,6 +181,7 @@ function init_args(&$dbHandler)
'RECURSIVE' => $args->useRecursion,
'TCSUMMARY' => $args->exportTCSummary,
'TCPRECONDITIONS' => $args->exportTCPreconditions,
'ATTACHMENTS' => $args->exportAttachments,
'TCSTEPS' => $args->exportTCSteps);


Expand Down
5 changes: 4 additions & 1 deletion locale/en_GB/strings.txt
Original file line number Diff line number Diff line change
Expand Up @@ -845,7 +845,9 @@ $TLS_filter_active_inactive = "Active/Inactive";
$TLS_show_only_active_testcases = "At least ONE version is ACTIVE";
$TLS_show_only_inactive_testcases = "ALL versions are INACTIVE";
$TLS_show_whole_spec_on_right_panel = 'Show Full (on right pane)';

$TLS_test_grouped_by_label = "Tests Grouped By";
$TLS_mode_test_suite = "Test Suite";
$TLS_mode_req_coverage = "Requirements";

// ----- gui/templates/execNavigator.tpl -----
$TLS_TestPlan = $TLS_testplan;
Expand Down Expand Up @@ -2166,6 +2168,7 @@ $TLS_export_tcase_external_id = 'Export Test Case external ID';
$TLS_export_with_prefix = 'With Test Case prefix';

$TLS_export_with_keywords = "Export with keywords";
$TLS_export_attachments = "Export attachments";
$TLS_warning_empty_filename = "Please give a file name";
$TLS_export_steps = "Export Test Case Steps";
$TLS_export_summary = "Export Test Case Summary";
Expand Down
6 changes: 5 additions & 1 deletion locale/fr_FR/strings.txt
Original file line number Diff line number Diff line change
Expand Up @@ -845,7 +845,10 @@ $TLS_filter_active_inactive = "Actif/Inactif";
$TLS_show_only_active_testcases = "Au moins UNE version de la fiche de test est ACTIVÉE";
$TLS_show_only_inactive_testcases = "TOUTES les versions de la fiche de test sont DÉSACTIVÉES.";
$TLS_show_whole_spec_on_right_panel = 'Montrer tout (dans le panneau de droite)';

$TLS_test_grouped_by = "Tests regroupés par";
$TLS_mode_test_suite = "Séquence de test";
$TLS_mode_req_coverage = "Exigence";
$TLS_parent_child_relation = "Relation parent enfant";

// ----- gui/templates/execNavigator.tpl -----
$TLS_TestPlan = $TLS_testplan;
Expand Down Expand Up @@ -2166,6 +2169,7 @@ $TLS_export_tcase_external_id = "Exporter l’ID externe des fiches de test";
$TLS_export_with_prefix = 'Exporter le préfixe des fiches de test';

$TLS_export_with_keywords = "Exporter les mots-clés";
$TLS_export_attachments = "Exporter les pièces jointes";
$TLS_warning_empty_filename = "Veuillez renseigner le nom du fichier.";
$TLS_export_steps = "Exporter les étapes de test";
$TLS_export_summary = "Exporter le résumé de test";
Expand Down

0 comments on commit 0b6edcc

Please sign in to comment.