SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    Grumpy Minimalist
    Join Date
    Jul 2006
    Location
    Ontario, Canada
    Posts
    424
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    SimpleTest: Pre-made HtmlReporters

    Hi,

    I'm currently developing my application with SimpleTest, and would like a little more verboseness in the output of a GroupTest using an HtmlReporter. I know that it's possible to extend the HtmlReporter to accomplish what I want, but I was wondering if there's a place where this has already been done.

    I'm sure that somewhere there's a list of "SimpleTest Themes" or something of the sort, but searches on Google and SitePoint have come up with nothing of value. Does anybody know of any such sites?

    It's not that I wouldn't do it myself; I just don't want to reinvent the wheel where it's not needed.

    Thanks for any insight!

  2. #2
    SitePoint Wizard silver trophy kyberfabrikken's Avatar
    Join Date
    Jun 2004
    Location
    Copenhagen, Denmark
    Posts
    6,157
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    There is limb_unit, which is for the command line though.

  3. #3
    Grumpy Minimalist
    Join Date
    Jul 2006
    Location
    Ontario, Canada
    Posts
    424
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Alright, I went ahead and spent a few hours to develop my own viewer which displays every event. Here's the final code for anybody who wants to get more information out of their HTML displays:

    Code PHP:
    <?php
    	class VerboseViewer extends HtmlReporter
    	{
    		protected $casePasses = 0;
    		protected $caseFails = 0;
    		protected $caseErrors = 0;
     
    		public function __construct($encoding = 'ISO-8859-1')
    		{
    			parent::__construct($encoding);
    		}
     
    		public function paintHeader($test_name)
    		{
    			?><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
    			<html>
    				<head>
    					<meta http-equiv="Content-Type" content="text/html; charset=<?php echo(htmlentities($this->_character_set)); ?>">
    					<meta http-equiv="cache-control" content="no-cache">
    					<meta name="googlebot" content="noarchive">
    					<meta name="rating" content="general">
    					<meta name="revisit-after" content="5 days">
    					<meta name="robots" content="noindex,nofollow">
    					<meta http-equiv="Content-Script-Type" content="text/javascript">
    					<meta http-equiv="Content-Style-Type" content="text/css">
    					<title><?php echo(htmlentities('SimpleTest Framework: ' . $test_name)); ?></title>
    					<style type="text/css">
    					<!--
    						body
    						{
    							font-family: arial;
    						}
     
    						div.group
    						{
    							margin:30pt;
    							background-color:#DDDDDD;
    							border-style:solid;
    							border-width:1px;
    							border-color:#000000;
    						}
     
    						div.group h1
    						{
    							margin:0;
    							margin-left:2pt;
    							margin-top:1pt;
    							font-size:0.8em;
    							font-weight:normal;
    							color:#999999;
    						}
     
    						div.case
    						{
    							padding:5pt;
    						}
     
    						div.case h1
    						{
    							color:#000000;
    							font-weight:bold;
    							font-size:1.5em;
    						}
     
    						div.method
    						{
    							padding-left:7pt;
    						}
     
    						div.method h1
    						{
    							font-size:1.2em;
    						}
     
    						span.pass em
    						{
    							font-style:normal;
    							font-weight:bold;
    						}
     
    						span.fail em
    						{
    							font-style:normal;
    							font-weight:bold;
    						}
     
    						span.error em
    						{
    							font-style:normal;
    							font-weight:bold;
    						}
     
    						span.exception em
    						{
    							font-style:normal;
    							font-weight:bold;
    						}
     
    						span.message em
    						{
    							font-style:normal;
    							font-weight:bold;
    						}
     
    						span.pass
    						{
    							display:block;
    							margin-left:10pt;
    							color:#007700;
    							font-size:0.8em;
    						}
     
    						span.fail
    						{
    							display:block;
    							margin-left:10pt;
    							color:#FF0000;
    							font-size:0.8em;
    						}
     
    						span.error
    						{
    							display:block;
    							margin-left:10pt;
    							color:#FF0000;
    							font-size:0.8em;
    							font-style:italic;
    						}
     
    						span.exception
    						{
    							display:block;
    							margin-left:10pt;
    							color:#FF0000;
    							font-size:0.8em;
    							font-style:italic;
    						}
     
    						span.message
    						{
    							display:block;
    							margin-left:10pt;
    							color:#000000;
    							font-size:0.8em;
    						}
     
    						div.good_result
    						{
    							margin-top:8pt;
    							margin-left:15pt;
    							background-color:#BBDDBB;
    							padding:3pt;
    							font-size:0.8em;
    							font-weight:bold;
    							color:#007700;
    							width:300pt;
    						}
     
    						div.bad_result
    						{
    							margin-top:8pt;
    							margin-left:15pt;
    							background-color:#DDBBBB;
    							padding:3pt;
    							font-size:0.8em;
    							font-weight:bold;
    							color:#FF0000;
    							width:300pt;
    						}
    					-->
    					</style>
    				</head>
    				<body>
    			<?php
    		}
     
    		public function paintFooter($test_name)
    		{
    			?>
    				</body>
    			</html>
    			<?php
    		}
     
    		public function paintGroupStart($test_name, $size)
    		{
    			parent::paintGroupStart($test_name, $size);
    			$breadcrumb = $this->getTestList();
    			if (count($breadcrumb) > 1)
    			{
    				?>
    					<div class="group">
    						<h1><?php echo(htmlentities($test_name)); ?></h1>
    				<?php
    			}
    		}
     
    		public function paintGroupEnd($test_name)
    		{
    			$breadcrumb = $this->getTestList();
    			if (count($breadcrumb) > 1)
    			{
    				?>
    					</div>
    				<?php
    			}
    			parent::paintGroupEnd($test_name);
    		}
     
    		public function paintCaseStart($test_name)
    		{
    			parent::paintCaseStart($test_name);
    			$this->casePasses = 0;
    			$this->caseFails = 0;
    			$this->caseErrors = 0;
    			?>
    				<div class="case">
    					<h1><?php echo(htmlentities($test_name)); ?></h1>
    			<?php
    		}
     
    		public function paintCaseEnd($test_name)
    		{
    			parent::paintCaseEnd($test_name);
    			?>
    					<div class="<?php echo($this->caseFails > 0 || $this->caseErrors > 0 ? 'bad' : 'good'); ?>_result"><?php
    						echo(htmlentities('Case ' . $this->getTestCaseProgress() . '/' . $this->getTestCaseCount() . ': ' .
    							$this->casePasses . ' Passes, ' . $this->caseFails . ' Failures, ' . $this->caseErrors . ' Errors')); ?></div>
    				</div>
    			<?php
    		}
     
    		public function paintMethodStart($test_name)
    		{
    			parent::paintMethodStart($test_name);
    			?>
    				<div class="method">
    					<h1>:: <?php echo(htmlentities($test_name)); ?></h1>
    			<?php
    		}
     
    		public function paintMethodEnd($test_name)
    		{
    			parent::paintMethodEnd($test_name);
    			?>
    				</div>
    			<?php
    		}
     
    		public function paintFail($message)
    		{
    			$this->caseFails++;
    			?>
    				<span class="fail"><em>Fail:</em> <?php echo(htmlentities($message)); ?></span>
    			<?php
    		}
     
    		public function paintPass($message)
    		{
    			$this->casePasses++;
    			?>
    				<span class="pass"><em>Pass:</em> <?php echo(htmlentities($message)); ?></span>
    			<?php
    		}
     
    		public function paintError($message)
    		{
    			$this->caseErrors++;
    			?>
    				<span class="error"><em>Error:</em> <?php echo(htmlentities($message)); ?></span>
    			<?php
    		}
     
    		public function paintException($message)
    		{
    			$this->caseErrors++;
    			?>
    				<span class="exception"><em>Exception:</em> <?php echo(htmlentities($message)); ?></span>
    			<?php
    		}
     
    		public function paintMessage($message)
    		{
    			?>
    				<span class="message"><em>Message:</em> <?php echo(htmlentities($message)); ?></span>
    			<?php
    		}
     
    		public function paintFormattedMessage($message)
    		{
    			?>
    				<span class="message"><em>Message:</em> <?php echo($message); ?></span>
    			<?php
    		}
    	}
    ?>

    The HTML makes it easily customizable using the CSS in paintHeader(). Usage is the same as a standard HtmlReporter:
    Code PHP:
    $group = new GroupTest('My Test Suite');
    $group->addTestFile('Testers/path/test1.php');
    $group->addTestFile('Testers/path/test2.php');
    $group->addTestFile('Testers/path/test3.php');
    $group->run(new VerboseViewer());


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •