home *** CD-ROM | disk | FTP | other *** search
/ Cricao de Sites - 650 Layouts Prontos / WebMasters.iso / Servidores / xampp-win32-1.6.7-installer.exe / php / PEAR / PHPUnit2 / Util / CodeCoverage / Renderer / HTML.php next >
Encoding:
PHP Script  |  2008-07-02  |  5.4 KB  |  192 lines

  1. <?php
  2. /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
  3.  
  4. /**
  5.  * PHP Version 5
  6.  *
  7.  * Copyright (c) 2002-2006, Sebastian Bergmann <sb@sebastian-bergmann.de>.
  8.  * All rights reserved.
  9.  *
  10.  * Redistribution and use in source and binary forms, with or without
  11.  * modification, are permitted provided that the following conditions
  12.  * are met:
  13.  *
  14.  *   * Redistributions of source code must retain the above copyright
  15.  *     notice, this list of conditions and the following disclaimer.
  16.  * 
  17.  *   * Redistributions in binary form must reproduce the above copyright
  18.  *     notice, this list of conditions and the following disclaimer in
  19.  *     the documentation and/or other materials provided with the
  20.  *     distribution.
  21.  *
  22.  *   * Neither the name of Sebastian Bergmann nor the names of his
  23.  *     contributors may be used to endorse or promote products derived
  24.  *     from this software without specific prior written permission.
  25.  *
  26.  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  27.  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  28.  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  29.  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  30.  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  31.  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  32.  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  33.  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  34.  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRIC
  35.  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
  36.  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  37.  * POSSIBILITY OF SUCH DAMAGE.
  38.  *
  39.  * @category   Testing
  40.  * @package    PHPUnit2
  41.  * @author     Sebastian Bergmann <sb@sebastian-bergmann.de>
  42.  * @copyright  2002-2006 Sebastian Bergmann <sb@sebastian-bergmann.de>
  43.  * @license    http://www.opensource.org/licenses/bsd-license.php  BSD License
  44.  * @version    CVS: $Id: HTML.php,v 1.7.2.3 2005/12/17 16:04:58 sebastian Exp $
  45.  * @link       http://pear.php.net/package/PHPUnit2
  46.  * @since      File available since Release 2.3.0
  47.  */
  48.  
  49. require_once 'PHPUnit2/Util/CodeCoverage/Renderer.php';
  50.  
  51. /**
  52.  * Renders Code Coverage information in HTML format.
  53.  *
  54.  * Formatting of the generated HTML can be achieved through
  55.  * CSS (codecoverage.css).
  56.  *
  57.  * Example
  58.  *
  59.  * <code>
  60.  * td.ccLineNumber, td.ccCoveredLine, td.ccUncoveredLine, td.ccNotExecutableLine {
  61.  *   font-family: monospace;
  62.  *   white-space: pre;
  63.  * }
  64.  *
  65.  * td.ccLineNumber, td.ccCoveredLine {
  66.  *   background-color: #aaaaaa;
  67.  * }
  68.  *
  69.  * td.ccNotExecutableLine {
  70.  *   color: #aaaaaa;
  71.  * }
  72.  * </code>
  73.  *
  74.  * @category   Testing
  75.  * @package    PHPUnit2
  76.  * @author     Sebastian Bergmann <sb@sebastian-bergmann.de>
  77.  * @copyright  2002-2006 Sebastian Bergmann <sb@sebastian-bergmann.de>
  78.  * @license    http://www.opensource.org/licenses/bsd-license.php  BSD License
  79.  * @version    Release: 2.3.6
  80.  * @link       http://pear.php.net/package/PHPUnit2
  81.  * @since      Class available since Release 2.1.0
  82.  */
  83. class PHPUnit2_Util_CodeCoverage_Renderer_HTML extends PHPUnit2_Util_CodeCoverage_Renderer {
  84.     const pageHeader =
  85. '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  86.     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  87.  
  88. <html xmlns="http://www.w3.org/1999/xhtml">
  89.   <head>
  90.     <link href="codecoverage.css" type="text/css" rel="stylesheet" />
  91.   </head>
  92.   <body>
  93. ';
  94.  
  95.     const pageFooter =
  96. '  </body>
  97. </html>
  98. ';
  99.  
  100.     const sourceFileHeader =
  101. '   <table style="border: 1px solid black" cellspacing="0" cellpadding="0" width="100%">
  102. ';
  103.  
  104.     const sourceFileFooter =
  105. '   </table>
  106. ';
  107.  
  108.     const codeLine =
  109. '     <tr><td class="ccLineNumber">%s</td><td class="%s">%s</td></tr>
  110. ';
  111.  
  112.     /**
  113.      * @return string
  114.      * @access protected
  115.      * @since  Method available since Release 2.1.1
  116.      */
  117.     protected function header() {
  118.         return self::pageHeader;
  119.     }
  120.  
  121.     /**
  122.      * @return string
  123.      * @access protected
  124.      * @since  Method available since Release 2.1.1
  125.      */
  126.     protected function footer() {
  127.         return self::pageFooter;
  128.     }
  129.  
  130.     /**
  131.      * @param  string $sourceFile
  132.      * @return string
  133.      * @access protected
  134.      */
  135.     protected function startSourceFile($sourceFile) {
  136.         return self::sourceFileHeader;
  137.     }
  138.  
  139.     /**
  140.      * @param  string $sourceFile
  141.      * @return string
  142.      * @access protected
  143.      */
  144.     protected function endSourceFile($sourceFile) {
  145.         return self::sourceFileFooter;
  146.     }
  147.  
  148.     /**
  149.      * @param  array $codeLines
  150.      * @param  array $executedLines
  151.      * @return string
  152.      * @access protected
  153.      */
  154.     protected function renderSourceFile($codeLines, $executedLines) {
  155.         $buffer = '';
  156.         $line   = 1;
  157.  
  158.         foreach ($codeLines as $codeLine) {
  159.             $lineStyle = 'ccNotExecutableLine';
  160.  
  161.             if (isset($executedLines[$line])) {
  162.                 if ($executedLines[$line] > 0) {
  163.                     $lineStyle = 'ccCoveredLine';
  164.                 } else {
  165.                     $lineStyle = 'ccUncoveredLine';
  166.                 }
  167.             }
  168.  
  169.             $buffer .= sprintf(
  170.               self::codeLine,
  171.  
  172.               $line,
  173.               $lineStyle,
  174.               htmlspecialchars(rtrim($codeLine))
  175.             );
  176.  
  177.             $line++;
  178.         }
  179.  
  180.         return $buffer;
  181.     }
  182. }
  183.  
  184. /*
  185.  * Local variables:
  186.  * tab-width: 4
  187.  * c-basic-offset: 4
  188.  * c-hanging-comment-ender-p: nil
  189.  * End:
  190.  */
  191. ?>
  192.