standard Class Reference
[FOUnitTest]

This is the standard Unit Test Skin. More...

Inheritance diagram for standard:

unitTestSkin

List of all members.

Public Member Functions

 standard ()
 Constructor.
 begin ()
 Write webpage header for the Unit Test Gui.
 end ()
 Write webpage footer for the Unit Test Gui.
 writeGuiResult ($testResult)
 Will write a html result from a UnitTest result.
 getVariableInfo ($value)
 Return an information string about a variable.

Private Member Functions

 _writeHtmlHead ()
 Write the html < head > tag.
 _writeCSSStyle ()
 Write a html < style > tag for the html < head > tag.
 _writeToolBar ()
 Write a toolbar with which you can control the GUI.
 _writeStatusChanger ()
 Write the GUI buttons [Only Report Fails] [Details About Fails].
 _writeRunAllTests ()
 Write the [RUN ALL TESTS] button.
 _writeTestCaseNavigator ()
 Write the [Back] [Next] buttons, to switch current test case.
 _writeFileBrowser ()
 Write a file browse list of all test cases/classes.
 _writeStatus ()
 Write status and statistics about the tests.
 _getUrlArgument ($onlyReportFailes_=-1, $echoDetails_=-1, $currentTestCase_=-1, $runAllTests_=-1)
 Used by writeFileBrowser to build the anchors (a href) on the test gui.
 _getTestCount ()
 Return at padded testCount number, ie.
 _writeTestCaseName ($status_, $className_)
 Will write the class name above all tests from one test class.
 _writeSectionLabel ($status_, $sectionLabel_, $sectionTextArr_)
 Write the section label set by setSectionLabel in the unitTest.
 _writeSuccededTest ($type_, $code_)
 Write output for a succeded test.
 _writeFailedTest ($type_, $code_, $file_)
 Write output for a failed test.
 _writeFailDetails ($value1_, $value2_, $comment_)
 Write details about a failed test.
 _writeFailComment ($comment_)
 Write a failed test comment set by setFailedComment in the unitTest.
 _writeReturnVariable ($value1_, $value2_)
 Write the variable that was returned from the failed test.
 _writeExpectedReturnVariable ($value1_, $value2_)
 Write the expected return result from the failed test.

Private Attributes

 $_reportedCompareCount
 Number of compares reported to the user.
 $_testCount
 Number of tests executed.
 $_oldClassName
 Used by _writeTestCaseName, to only write the class name label, once per test class.


Detailed Description

This is the standard Unit Test Skin.

The class that are responsible for all GUI output.

Author:
Daniel Lindh <[email protected]>

Definition at line 12 of file Standard.class.php.


Member Function Documentation

standard::_getTestCount (  )  [private]

Return at padded testCount number, ie.

0004

Definition at line 354 of file Standard.class.php.

Referenced by _writeFailedTest(), and _writeSuccededTest().

00355   {
00356     return str_pad($this->_testCount, 4, '0', STR_PAD_LEFT);
00357   }

standard::_getUrlArgument ( onlyReportFailes_ = -1,
echoDetails_ = -1,
currentTestCase_ = -1,
runAllTests_ = -1 
) [private]

Used by writeFileBrowser to build the anchors (a href) on the test gui.

Definition at line 291 of file Standard.class.php.

References unitTestSkin::getParent().

Referenced by _writeFileBrowser(), _writeRunAllTests(), _writeStatusChanger(), and _writeTestCaseNavigator().

00297   {
00298     if ((int)$onlyReportFailes_ == -1)
00299     {
00300       $onlyReportFailes_ = $this->getParent()->getOnlyReportFailes();
00301     }
00302 
00303     if ((int)$echoDetails_ == -1)
00304     {
00305       $echoDetails_ = $this->getParent()->getReportFailDetails();
00306     }
00307 
00308     if ((int)$currentTestCase_ == -1)
00309     {
00310       $currentTestCase_ = $this->getParent()->getCurrentTestCase();
00311     }
00312 
00313     if ((int)$runAllTests_ == -1)
00314     {
00315       $runAllTests_ = 0;
00316     }
00317 
00318     $str  = '?formOnlyReportFailes=' . $onlyReportFailes_;
00319     $str .= '&formEchoDetails=' . $echoDetails_;
00320     $str .= '&formTestCase=' . $currentTestCase_;
00321     $str .= '&formRunAllTests=' . $runAllTests_;
00322 
00323     return $str;
00324   }

standard::_writeCSSStyle (  )  [private]

Write a html < style > tag for the html < head > tag.

Definition at line 101 of file Standard.class.php.

Referenced by _writeHtmlHead().

00102   {
00103   ?>
00104     <style>
00105       <!--
00106       body
00107       {
00108         font-family: Courier New;
00109         font-size: 10pt;
00110       }
00111 
00112       h1
00113       {
00114         text-align:center;
00115       }
00116 
00117       h2
00118       {
00119         margin-bottom: 0px;
00120       }
00121 
00122       .contentarea, .filebrowser, .status, .bodyarea
00123       {
00124         margin: 5px;
00125         padding: 5px;
00126         width: auto;
00127         float: left;
00128         border: 1px solid #0000ff;
00129       }
00130 
00131       .toolbar
00132       {
00133         margin: 5px;
00134         padding: 5px;
00135         width: auto;
00136         border: 1px solid #0000ff;
00137         float: top;
00138       }
00139 
00140       .bodyarea
00141       {
00142         border: 0px
00143       }
00144 
00145       a:link, a:visited
00146       {
00147         color:"#003399";
00148         text-decoration: none;
00149       }
00150 
00151       a:hover
00152       {
00153         color: #FF00FF
00154       }
00155 
00156       td
00157       {
00158         font-size: 10pt;
00159         padding: 1px;
00160         vertical-align: top;
00161       }
00162 
00163       -->
00164     </style>
00165   <?php
00166   }

standard::_writeExpectedReturnVariable ( value1_,
value2_ 
) [private]

Write the expected return result from the failed test.

Output looks like below.

  • First comes the output in form of a php formated array/variable.
  • A difference section that shows what difference are between return variable and expected return. It shows what was expected to be returned.

Return:

array ( '0' => 1, '1' => 2, '2' => 3, '3' => 4 )

Copy: 'array( "0" => 1, "1" => 2, "2" => 3, "3" => 4)'

Difference:

Definition at line 529 of file Standard.class.php.

Referenced by _writeFailDetails().

00530   {
00531     echo('<i><b>Expected return:</b></i><br/>');
00532     if (is_array($value2_))
00533     {
00534       echo('<pre>'.getHtmlArrayPhp($value2_).'</pre>');
00535       echo('<br/>');
00536       echo('Difference:' . getHtmlArray(array_diff_assoc_recursive($value2_, $value1_)));
00537     }
00538     else
00539     {
00540       echo($this->getVariableInfo($value2_).'<br/>');
00541     }
00542   }

standard::_writeFailComment ( comment_  )  [private]

Write a failed test comment set by setFailedComment in the unitTest.

Definition at line 448 of file Standard.class.php.

Referenced by _writeFailDetails().

00449   {
00450     if (!empty($comment_))
00451     {
00452       echo($comment_);
00453       echo('<br/>');
00454     }
00455   }

standard::_writeFailDetails ( value1_,
value2_,
comment_ 
) [private]

Write details about a failed test.

Definition at line 434 of file Standard.class.php.

References _writeExpectedReturnVariable(), _writeFailComment(), _writeReturnVariable(), and unitTestSkin::getParent().

Referenced by writeGuiResult().

00435   {
00436     if ($this->getParent()->getReportFailDetails())
00437     {
00438       $this->_writeFailComment($comment_);
00439       $this->_writeReturnVariable($value1_, $value2_);
00440       $this->_writeExpectedReturnVariable($value1_, $value2_);
00441       echo('<br/>');
00442     }
00443   }

standard::_writeFailedTest ( type_,
code_,
file_ 
) [private]

Write output for a failed test.

Definition at line 424 of file Standard.class.php.

References _getTestCount().

Referenced by writeGuiResult().

00425   {
00426     $this->_reportedCompareCount++;
00427     echo($this->_getTestCount() . ' <font color="red">ERROR - ' . $type_ . ' - ' . $code_ . '</font><br/>');
00428     echo('File: <font color="red">' . $file_ . '</font><br/>');
00429   }

standard::_writeFileBrowser (  )  [private]

Write a file browse list of all test cases/classes.

Key is zerobased and currentTestCase starts at 1.

Definition at line 256 of file Standard.class.php.

References _getUrlArgument(), and unitTestSkin::getParent().

Referenced by end().

00257   {
00258     foreach($this->getParent()->getTestCaseFiles() as $key => $row)
00259     {
00260       if ($row['package'] != $oldPackage)
00261       {
00262         echo('<B>'.$row['package'].'</B><br/>');
00263         $oldPackage = $row['package'];
00264       }
00265 
00266       if ($key == $this->getParent()->getCurrentTestCase())
00267       {
00268         echo('<b>&nbsp;&nbsp;<a href="' . $this->_getUrlArgument(-1, -1, $key) . '">'.$row['class_name'] . '</a></b><br/>');
00269       }
00270       else
00271       {
00272         echo('&nbsp;&nbsp;<a href="' . $this->_getUrlArgument(-1, -1, $key) . '">'.$row['class_name'] . '</a><br/>');
00273       }
00274     }
00275   }

standard::_writeHtmlHead (  )  [private]

Write the html < head > tag.

Definition at line 83 of file Standard.class.php.

References _writeCSSStyle().

Referenced by begin().

00084   {
00085     echo('<head>');
00086       echo('<title>');
00087         echo('FareOffice Unit Tester ');
00088       echo('</title>');
00089 
00090       echo('<meta name="author" content="Daniel Lindh, aka Arlukin, aka Master Po" />');
00091       echo('<meta name="robots" content="noindex,nofollow" />');
00092       echo('<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-15" />');
00093 
00094       $this->_writeCSSStyle();
00095     echo('</head>');
00096   }

standard::_writeReturnVariable ( value1_,
value2_ 
) [private]

Write the variable that was returned from the failed test.

Output looks like below.

  • First comes the output in form of a php formated array/variable.
  • A copy section that can be used to copy directly into the test.
  • A difference section that shows what difference are between return variable and expected return. It shows what is returned.

Return:

array ( '0' => 1, '1' => 2, '2' => 3, '3' => 4 )

Copy: 'array( "0" => 1, "1" => 2, "2" => 3, "3" => 4)'

Difference:

Definition at line 482 of file Standard.class.php.

References getHtmlArrayPhp().

Referenced by _writeFailDetails().

00483   {
00484     echo('<i><b>Return:</b></i><br/>');
00485 
00486     if (is_array($value1_))
00487     {
00488       $search = array("'", '"', '<br/>', "\t", '&nbsp;');
00489       $replace = array("\'", '\"', '', '', '');
00490       echo('<pre>' . getHtmlArrayPhp($value1_) . '</pre>');
00491       echo('Copy:<br/>\'' . str_replace($search, $replace, getHtmlArrayPhp($value1_)) . '\'<br/>');
00492       echo('<br/>');
00493       echo('Difference:' . getHtmlArray(array_diff_assoc_recursive($value1_, $value2_)));
00494     }
00495     else
00496     {
00497       $search = array("'", '"');
00498       $replace = array("\'", '\"');
00499       echo($this->getVariableInfo($value1_).'<br/>');
00500       echo('Copy:<br/>\'"' . htmlentities(str_replace($search, $replace, $value1_)).'"\'<br/>');
00501     }
00502   }

standard::_writeRunAllTests (  )  [private]

Write the [RUN ALL TESTS] button.

Definition at line 217 of file Standard.class.php.

References _getUrlArgument().

Referenced by _writeToolBar().

00218   {
00219     echo('<a href="'.$this->_getUrlArgument(-1, -1, -1, true).'">[RUN ALL TESTS]</a>&nbsp;');
00220   }

standard::_writeSectionLabel ( status_,
sectionLabel_,
sectionTextArr_ 
) [private]

Write the section label set by setSectionLabel in the unitTest.

Definition at line 384 of file Standard.class.php.

References unitTestSkin::getParent().

Referenced by writeGuiResult().

00385   {
00386     if
00387     (
00388       $sectionLabel_ != $this->_oldSectionLabel &&
00389       (
00390         $status_ == false ||
00391         !$this->getParent()->getOnlyReportFailes()
00392       )
00393     )
00394     {
00395       echo('<br/>');
00396       echo('<b>' . $sectionLabel_ . '</b><br/>');
00397 
00398       foreach($sectionTextArr_ as $text)
00399       {
00400         echo($text . '<br/>');
00401       }
00402 
00403       $this->_oldSectionLabel = $sectionLabel_;
00404     }
00405   }

standard::_writeStatus (  )  [private]

Write status and statistics about the tests.

Definition at line 280 of file Standard.class.php.

Referenced by end().

00281   {
00282     echo('Reported tests: ' . $this->_reportedCompareCount . '<br/>');
00283     echo('Executed tests: ' . $this->_testCount . '<br/>');
00284   }

standard::_writeStatusChanger (  )  [private]

Write the GUI buttons [Only Report Fails] [Details About Fails].

Definition at line 181 of file Standard.class.php.

References _getUrlArgument(), and unitTestSkin::getParent().

Referenced by _writeToolBar().

00182   {
00183     if ($this->getParent()->getOnlyReportFailes())
00184     {
00185       echo('<b><a href="' . $this->_getUrlArgument(false, -1) . '">');
00186         echo('[Only Report Fails]');
00187       echo('</a></b>');
00188     }
00189     else
00190     {
00191       echo('<a href="' . $this->_getUrlArgument(true, -1) . '">');
00192         echo('[Only Report Fails]');
00193       echo('</a>');
00194     }
00195 
00196     echo('&nbsp;');
00197 
00198     if ($this->getParent()->getReportFailDetails())
00199     {
00200       echo('<b><a href="'.$this->_getUrlArgument(-1, false).'">');
00201         echo('[Details About Fails]');
00202       echo('</a></b>');
00203     }
00204     else
00205     {
00206       echo('<a href="'.$this->_getUrlArgument(-1, true).'">');
00207         echo('[Details About Fails]');
00208       echo('</a>');
00209     }
00210 
00211     echo('&nbsp;');
00212   }

standard::_writeSuccededTest ( type_,
code_ 
) [private]

Write output for a succeded test.

Will not write any output if "only report fails" status is set.

Definition at line 412 of file Standard.class.php.

References _getTestCount(), and unitTestSkin::getParent().

Referenced by writeGuiResult().

00413   {
00414     if (!$this->getParent()->getOnlyReportFailes())
00415     {
00416       $this->_reportedCompareCount++;
00417       echo($this->_getTestCount() . ' OK - ' . $type_ . ' - ' . $code_ . '<br/>');
00418     }
00419   }

standard::_writeTestCaseName ( status_,
className_ 
) [private]

Will write the class name above all tests from one test class.

Will not write the class name if bOnlyReportFailes is set.

Definition at line 364 of file Standard.class.php.

References unitTestSkin::getParent().

Referenced by writeGuiResult().

00365   {
00366     if
00367     (
00368       $className_ != $this->_oldClassName &&
00369       (
00370         $status_ == false ||
00371         !$this->getParent()->getOnlyReportFailes()
00372       )
00373     )
00374     {
00375       echo('<h2>' . $className_ . '</h2>');
00376 
00377       $this->_oldClassName = $className_;
00378     }
00379   }

standard::_writeTestCaseNavigator (  )  [private]

Write the [Back] [Next] buttons, to switch current test case.

Definition at line 225 of file Standard.class.php.

References _getUrlArgument(), and unitTestSkin::getParent().

Referenced by _writeToolBar().

00226   {
00227     $currentTestCase = $this->getParent()->getCurrentTestCase();
00228     $total = $this->getParent()->getNumOfTestCases();
00229 
00230     if ($currentTestCase > 1)
00231     {
00232       echo('<b><a href="' . $this->_getUrlArgument(-1, -1, $currentTestCase-1) . '">[Back]</a></b>');
00233     }
00234     else
00235     {
00236       echo('[Back]');
00237     }
00238 
00239     echo(' ' . $currentTestCase . '/' . $total . ' ');
00240 
00241     if ($currentTestCase < $total )
00242     {
00243       echo('<b><a href="' . $this->_getUrlArgument(-1, -1, $currentTestCase+1) . '">[Next]</a></b>');
00244     }
00245     else
00246     {
00247       echo('[Next]');
00248     }
00249   }

standard::_writeToolBar (  )  [private]

Write a toolbar with which you can control the GUI.

Definition at line 171 of file Standard.class.php.

References _writeRunAllTests(), _writeStatusChanger(), and _writeTestCaseNavigator().

Referenced by begin().

00172   {
00173     $this->_writeStatusChanger();
00174     $this->_writeRunAllTests();
00175     $this->_writeTestCaseNavigator();
00176   }

standard::begin (  ) 

Write webpage header for the Unit Test Gui.

The execution order for the webpage building are begin(); writeGuiResult(); end();

These three functions should create a full html page with < html > < head >< body > etc.

Reimplemented from unitTestSkin.

Definition at line 34 of file Standard.class.php.

References _writeHtmlHead(), and _writeToolBar().

00035   {
00036     echo('<html>');
00037       $this->_writeHtmlHead();
00038       echo('<body>');
00039 
00040       echo('<div class="bodyarea">');
00041         echo('<h1>FareOffice Unit Tester</h1>');
00042 
00043         echo('<div class="toolbar">');
00044         $this->_writeToolBar();
00045         echo('</div>');
00046 
00047         echo('<div class="contentarea">');
00048   }

standard::end (  ) 

Write webpage footer for the Unit Test Gui.

See also:
: begin()

Reimplemented from unitTestSkin.

Definition at line 55 of file Standard.class.php.

References _writeFileBrowser(), and _writeStatus().

00056   {
00057         if ($this->_testCount)
00058         {
00059           echo('<br/><b>Finish</b><br/>');
00060         }
00061         else
00062         {
00063           echo('You must choose a test case to run.');
00064         }
00065         echo('</div>');
00066 
00067         echo('<div class="filebrowser">');
00068         $this->_writeFileBrowser();
00069         echo('</div>');
00070 
00071         echo('<div class="status">');
00072         $this->_writeStatus();
00073         echo('</div>');
00074 
00075       echo('</div>');
00076       echo('</body>');
00077     echo('</html>');
00078   }

standard::getVariableInfo ( value  ) 

Return an information string about a variable.

ie. string(6) "Daniel"

Definition at line 549 of file Standard.class.php.

00550   {
00551     if (is_bool($value) )
00552     {
00553       if ($value)
00554       {
00555         $humanReadableValue = 'true';
00556       }
00557       else
00558       {
00559         $humanReadableValue = 'false';
00560       }
00561     }
00562     else
00563     {
00564       $humanReadableValue = $value;
00565     }
00566 
00567     return gettype($value).'('.strlen($value).') "'.$humanReadableValue.'"';
00568   }

standard::standard (  ) 

Constructor.

Definition at line 17 of file Standard.class.php.

00018   {
00019     $this->_testCount = 0;
00020     $this->_reportedCompareCount = 0;
00021   }

standard::writeGuiResult ( testResult  ) 

Will write a html result from a UnitTest result.

See also:
: begin()

Reimplemented from unitTestSkin.

Definition at line 331 of file Standard.class.php.

References $_testCount, _writeFailDetails(), _writeFailedTest(), _writeSectionLabel(), _writeSuccededTest(), and _writeTestCaseName().

00332   {
00333     foreach($testResult as $_testCount => $row)
00334     {
00335       $this->_testCount++;
00336       $this->_writeTestCaseName($row['status'], $row['class_name']);
00337       $this->_writeSectionLabel($row['status'], $row['section_label'], $row['section_text']);
00338 
00339       if ($row['status'] == true)
00340       {
00341         $this->_writeSuccededTest($row['type'], $row['code']);
00342       }
00343       else
00344       {
00345         $this->_writeFailedTest($row['type'], $row['code'], $row['file']);
00346         $this->_writeFailDetails($row['return'], $row['expected_return'], $row['fail_comment']);
00347       }
00348     }
00349   }


Member Data Documentation

standard::$_oldClassName [private]

Used by _writeTestCaseName, to only write the class name label, once per test class.

Definition at line 584 of file Standard.class.php.

standard::$_reportedCompareCount [private]

Number of compares reported to the user.

Definition at line 573 of file Standard.class.php.

standard::$_testCount [private]

Number of tests executed.

Definition at line 578 of file Standard.class.php.

Referenced by writeGuiResult().


The documentation for this class was generated from the following file:

Generated on Wed May 6 23:28:24 2009 for fareofficelib by  doxygen 1.5.8