diff options
Diffstat (limited to 'system/libraries/Unit_test.php')
-rw-r--r-- | system/libraries/Unit_test.php | 122 |
1 files changed, 52 insertions, 70 deletions
diff --git a/system/libraries/Unit_test.php b/system/libraries/Unit_test.php index 5bd7e801a..38d767c69 100644 --- a/system/libraries/Unit_test.php +++ b/system/libraries/Unit_test.php @@ -1,13 +1,25 @@ -<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); +<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); /** * CodeIgniter * * An open source application development framework for PHP 5.1.6 or newer * + * NOTICE OF LICENSE + * + * Licensed under the Open Software License version 3.0 + * + * This source file is subject to the Open Software License (OSL 3.0) that is + * bundled with this package in the files license.txt / license.rst. It is + * also available through the world wide web at this URL: + * http://opensource.org/licenses/OSL-3.0 + * If you did not receive a copy of the license and are unable to obtain it + * through the world wide web, please send an email to + * licensing@ellislab.com so we can send you a copy immediately. + * * @package CodeIgniter - * @author ExpressionEngine Dev Team - * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc. - * @license http://codeigniter.com/user_guide/license.html + * @author EllisLab Dev Team + * @copyright Copyright (c) 2008 - 2012, EllisLab, Inc. (http://ellislab.com/) + * @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0) * @link http://codeigniter.com * @since Version 1.3.1 * @filesource @@ -23,17 +35,17 @@ * @package CodeIgniter * @subpackage Libraries * @category UnitTesting - * @author ExpressionEngine Dev Team - * @link http://codeigniter.com/user_guide/libraries/uri.html + * @author EllisLab Dev Team + * @link http://codeigniter.com/user_guide/libraries/unit_testing.html */ class CI_Unit_test { - var $active = TRUE; - var $results = array(); - var $strict = FALSE; - var $_template = NULL; - var $_template_rows = NULL; - var $_test_items_visible = array(); + public $active = TRUE; + public $results = array(); + public $strict = FALSE; + protected $_template = NULL; + protected $_template_rows = NULL; + protected $_test_items_visible = array(); public function __construct() { @@ -58,11 +70,10 @@ class CI_Unit_test { * * Runs the supplied tests * - * @access public * @param array * @return void */ - function set_test_items($items = array()) + public function set_test_items($items = array()) { if ( ! empty($items) AND is_array($items)) { @@ -77,13 +88,12 @@ class CI_Unit_test { * * Runs the supplied tests * - * @access public * @param mixed * @param mixed * @param string * @return string */ - function run($test, $expected = TRUE, $test_name = 'undefined', $notes = '') + public function run($test, $expected = TRUE, $test_name = 'undefined', $notes = '') { if ($this->active == FALSE) { @@ -98,11 +108,7 @@ class CI_Unit_test { } else { - if ($this->strict == TRUE) - $result = ($test === $expected) ? TRUE : FALSE; - else - $result = ($test == $expected) ? TRUE : FALSE; - + $result = ($this->strict == TRUE) ? ($test === $expected) : ($test == $expected); $extype = gettype($expected); } @@ -130,12 +136,11 @@ class CI_Unit_test { * * Displays a table with the test data * - * @access public * @return string */ - function report($result = array()) + public function report($result = array()) { - if (count($result) == 0) + if (count($result) === 0) { $result = $this->result(); } @@ -164,10 +169,7 @@ class CI_Unit_test { } } - $temp = $this->_template_rows; - $temp = str_replace('{item}', $key, $temp); - $temp = str_replace('{result}', $val, $temp); - $table .= $temp; + $table .= str_replace(array('{item}', '{result}'), array($key, $val), $this->_template_rows); } $r .= str_replace('{rows}', $table, $this->_template); @@ -183,13 +185,12 @@ class CI_Unit_test { * * Causes the evaluation to use === rather than == * - * @access public * @param bool * @return null */ - function use_strict($state = TRUE) + public function use_strict($state = TRUE) { - $this->strict = ($state == FALSE) ? FALSE : TRUE; + $this->strict = (bool) $state; } // -------------------------------------------------------------------- @@ -199,13 +200,12 @@ class CI_Unit_test { * * Enables/disables unit testing * - * @access public * @param bool * @return null */ - function active($state = TRUE) + public function active($state = TRUE) { - $this->active = ($state == FALSE) ? FALSE : TRUE; + $this->active = (bool) $state; } // -------------------------------------------------------------------- @@ -215,15 +215,14 @@ class CI_Unit_test { * * Returns the raw result data * - * @access public * @return array */ - function result($results = array()) + public function result($results = array()) { $CI =& get_instance(); $CI->load->language('unit_test'); - if (count($results) == 0) + if (count($results) === 0) { $results = $this->results; } @@ -273,11 +272,10 @@ class CI_Unit_test { * * This lets us set the template to be used to display results * - * @access public * @param string * @return void */ - function set_template($template) + public function set_template($template) { $this->_template = $template; } @@ -289,19 +287,17 @@ class CI_Unit_test { * * This lets us show file names and line numbers * - * @access private * @return array */ - function _backtrace() + protected function _backtrace() { if (function_exists('debug_backtrace')) { $back = debug_backtrace(); - - $file = ( ! isset($back['1']['file'])) ? '' : $back['1']['file']; - $line = ( ! isset($back['1']['line'])) ? '' : $back['1']['line']; - - return array('file' => $file, 'line' => $line); + return array( + 'file' => (isset($back[1]['file']) ? $back[1]['file'] : ''), + 'line' => (isset($back[1]['line']) ? $back[1]['line'] : '') + ); } return array('file' => 'Unknown', 'line' => 'Unknown'); } @@ -311,19 +307,14 @@ class CI_Unit_test { /** * Get Default Template * - * @access private * @return string */ - function _default_template() + protected function _default_template() { - $this->_template = "\n".'<table style="width:100%; font-size:small; margin:10px 0; border-collapse:collapse; border:1px solid #CCC;">'; - $this->_template .= '{rows}'; - $this->_template .= "\n".'</table>'; - - $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 .= "\n\t".'</tr>'; + $this->_template = "\n".'<table style="width:100%; font-size:small; margin:10px 0; border-collapse:collapse; border:1px solid #CCC;">{rows}'."\n".'</table>'; + + $this->_template_rows = "\n\t<tr>\n\t\t".'<th style="text-align: left; border-bottom:1px solid #CCC;">{item}</th>' + . "\n\t\t".'<td style="border-bottom:1px solid #CCC;">{result}</td>'."\n\t</tr>"; } // -------------------------------------------------------------------- @@ -333,30 +324,23 @@ class CI_Unit_test { * * Harvests the data within the template {pseudo-variables} * - * @access private * @return void */ - function _parse_template() + protected function _parse_template() { if ( ! is_null($this->_template_rows)) { return; } - if (is_null($this->_template)) + if (is_null($this->_template) OR ! preg_match("/\{rows\}(.*?)\{\/rows\}/si", $this->_template, $match)) { $this->_default_template(); return; } - if ( ! preg_match("/\{rows\}(.*?)\{\/rows\}/si", $this->_template, $match)) - { - $this->_default_template(); - return; - } - - $this->_template_rows = $match['1']; - $this->_template = str_replace($match['0'], '{rows}', $this->_template); + $this->_template_rows = $match[1]; + $this->_template = str_replace($match[0], '{rows}', $this->_template); } } @@ -365,8 +349,6 @@ class CI_Unit_test { /** * Helper functions to test boolean true/false * - * - * @access private * @return bool */ function is_true($test) @@ -380,4 +362,4 @@ function is_false($test) /* End of file Unit_test.php */ -/* Location: ./system/libraries/Unit_test.php */
\ No newline at end of file +/* Location: ./system/libraries/Unit_test.php */ |