root/trunk/application/libraries/MY_Unit_test.php

User picture

Author: m4rw3r

Revision: 279 («Previous)


File Size: 2.39 KB

(June 27, 2008 18:39 UTC) Almost 4 years ago


  

 
Show/hide line numbers
<?php
class MY_Unit_test extends CI_Unit_test{
	function summary_report($result = array(),$list = false){
		if (count($result) == 0)
		{
			$result = $this->result();
		}
		$CI =& get_instance();
		$num_passed = 0;
		foreach ($result as $res){
			if($res['Result'] == $CI->lang->line('ut_passed'))
				$num_passed++;
		}
		$q = '<table style="width:100%; font-size:small; margin:10px 0; border-collapse:collapse; border:1px solid #CCC;">
	<tr>
		<th style="text-align: left; border-bottom:1px solid #CCC;">Total number of tests</th>
		<td style="border-bottom:1px solid #CCC;">' . count($result) . '</td>
	</tr>
	<tr>
		<th style="text-align: left; border-bottom:1px solid #CCC;">Number of passed tests</th>
		<td style="border-bottom:1px solid #CCC;">' . $num_passed . '</td>
	</tr>
	<tr>
		<th style="text-align: left; border-bottom:1px solid #CCC;">Whole test suite passed</th>
		<td style="border-bottom:1px solid #CCC;">'. ($num_passed == count($result) ? '<span style="color: #0C0;">YES</span>' : '<span style="color: #C00;">NO</span>') . '</td>
	</tr>
	<tr>
		<th style="text-align: left; border-bottom:1px solid #CCC;">Tests:</th>
		<td style="border-bottom:1px solid #CCC;"></td>
	</tr>';
		$CI->load->language('unit_test');

		$this->_parse_template();

		$r = '';
		foreach ($result as $res)
		{
			$table = '';

			foreach ($res as $key => $val)
			{

				if ($key == $CI->lang->line('ut_result'))
				{
					if ($val == $CI->lang->line('ut_passed'))
					{
						$val = '<span style="color: #0C0;">'.$val.'</span>';
					}
					elseif ($val == $CI->lang->line('ut_failed'))
					{
						$val = '<span style="color: #C00;">'.$val.'</span>';
					}
				}

				$temp = $this->_template_rows;
				$temp = str_replace('{item}', $key, $temp);
				$temp = str_replace('{result}', $val, $temp);
				$table .= $temp;
			}

			$r .= str_replace('{rows}', $table, $this->_template);
		}
		return $q.$r.'</table>';
	}
	function _default_template()
	{	
		$this->_template = "\n".'<tr><th style="text-align: left; border-bottom:1px solid #CCC;"></th><td style="border-bottom:1px solid #CCC;"></td></tr>';
		$this->_template .= '{rows}';
		$this->_template .= '';
		
		$this->_template_rows = "\n\t".'<tr>';
		$this->_template_rows .= "\n\t\t".'<th style="text-align: left; border-bottom:1px solid #CCC;">{item}</th>';
		$this->_template_rows .= "\n\t\t".'<td style="border-bottom:1px solid #CCC;">{result}</td>';
		$this->_template_rows .= '</tr>';
	}
}