Skip to content

Commit

Permalink
more updates for the reporting - export functionality complete. There…
Browse files Browse the repository at this point in the history
…'s a sample HTML template in there.
  • Loading branch information
enygma committed Nov 16, 2010
1 parent f42f0aa commit 2cc8c01
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 29 deletions.
1 change: 1 addition & 0 deletions frisk
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ set_include_path(get_include_path().
PATH_SEPARATOR.__DIR__.'/lib/Exceptions'); PATH_SEPARATOR.__DIR__.'/lib/Exceptions');


HelperArguments::execute($_SERVER['argv']); HelperArguments::execute($_SERVER['argv']);
HelperConfig::setConfigValue('basedir',__DIR__);


// See if they just need help // See if they just need help
if(HelperArguments::getArgument('help')){ if(HelperArguments::getArgument('help')){
Expand Down
1 change: 1 addition & 0 deletions inc/report_templates/HtmlTemplate.txt
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
<body> <body>
<table cellpadding="3" cellspacing="0" border="1"> <table cellpadding="3" cellspacing="0" border="1">


[report_table_body]


</table> </table>
</body> </body>
Expand Down
70 changes: 41 additions & 29 deletions lib/Helper/HelperReporting.php
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
class HelperReporting extends Helper class HelperReporting extends Helper
{ {


private static $reportTemplateDir = '';
private static $reportExportDir = '';

/** /**
* Local container for testing results * Local container for testing results
*/ */
Expand All @@ -23,11 +26,22 @@ class HelperReporting extends Helper
*/ */
public function execute($testingResults,$outputType = 'html') public function execute($testingResults,$outputType = 'html')
{ {
self::$testingResults=$testingResults; self::$reportTemplateDir = HelperConfig::getConfigValue('basedir').'/inc/report_templates';
self::$reportExportDir = Helperconfig::getConfigValue('basedir').'/inc/report_export';
self::$testingResults = $testingResults;

// Be sure the directories exist!
if(!is_dir(self::$reportTemplateDir)){
throw new Exception('Report template directory does not exist! ('.self::$reportTemplateDir.')');
}
if(!is_dir(self::$reportExportDir)){
throw new Exception('Report export directory does not exist! ('.self::$reportExportDir.')');
}


$methodName = 'report'.ucwords(strtolower($outputType)); $methodName = 'report'.ucwords(strtolower($outputType));
if(method_exists(__CLASS__,$methodName)){ if(method_exists(__CLASS__,$methodName)){
self::$methodName($testingResults); $reportData = self::$methodName($testingResults);
self::exportReport($reportData,$outputType);
}else{ }else{
throw new Exception(ucwords(strtolower($outputType)).' reporting not allowed.'); throw new Exception(ucwords(strtolower($outputType)).' reporting not allowed.');
} }
Expand All @@ -41,8 +55,8 @@ public function execute($testingResults,$outputType = 'html')
*/ */
public function loadReportTemplate($reportType = 'html') public function loadReportTemplate($reportType = 'html')
{ {
$reportData = ''; $filePath = self::$reportTemplateDir.'/'.ucwords(strtolower($reportType)).'Template.txt';
return $reportData; return (is_file($filePath)) ? file_get_contents($filePath) : null;
} }


/** /**
Expand All @@ -52,10 +66,28 @@ public function loadReportTemplate($reportType = 'html')
* @param array $reportData Test run results * @param array $reportData Test run results
* @return templated results * @return templated results
*/ */
public function applyReportTemplate($reportType = 'html') public function applyReportTemplate($reportType = 'html',$reportData)
{ {
$template = self::loadReportTemplate($reportType); $template = self::loadReportTemplate($reportType);
return null; $replaceKeys = array_keys($reportData);
foreach($replaceKeys as $index => $key){
$replaceKeys[$index]='['.$key.']';
}
$template = str_replace($replaceKeys,array_values($reportData),$template);

return $template;
}

/**
* Export report data to the export directory by: date.type_ext
*
* @param string $reportData string of data resulting from applyTemplate
* @return void
*/
public function exportReport($reportData,$outputType)
{
$filePath = self::$reportExportDir.'/'.date('YmdHis').'.'.strtolower($outputType);
file_put_contents($filePath,$reportData);
} }


/** /**
Expand All @@ -68,19 +100,7 @@ public function applyReportTemplate($reportType = 'html')
*/ */
public function reportHtml($results) public function reportHtml($results)
{ {
// conver this over with the two methods above $html='';
$html=sprintf('
<html>
<head>
<style>
span.pass { background-color: #08DD08; }
span.fail { background-color: #BB1111; }
</style>
</head>
<body>
<table cellpadding="3" cellspacing="0" border="1">
');
// output the results in a single HTML file
foreach($results as $testName => $tests){ foreach($results as $testName => $tests){
$html.='<tr><td colspan="">'.$testName.'</tr>'."\n"; $html.='<tr><td colspan="">'.$testName.'</tr>'."\n";
foreach($tests as $methodName => $methods){ foreach($tests as $methodName => $methods){
Expand All @@ -94,16 +114,8 @@ public function reportHtml($results)
} }
} }
} }

$templateData = array('report_table_body'=>$html);
$html.=sprintf(' return self::applyReportTemplate('html',$templateData);
</table>
</body>
</html>
');

echo $html;

return $html;
} }
} }


Expand Down

0 comments on commit 2cc8c01

Please sign in to comment.