Alpha Framework alpha--controller
[ class tree: alpha--controller ] [ index: alpha--controller ] [ all elements ]

Source for file ViewTestResults.php

Documentation is available at ViewTestResults.php

  1. <?php
  2.  
  3. // include the config file
  4. if(!isset($config)) {
  5.     require_once '../util/AlphaConfig.inc';
  6.     $config AlphaConfig::getInstance();
  7. }
  8.  
  9. // add PHPUnit to the include_path
  10. ini_set('include_path'ini_get('include_path').PATH_SEPARATOR.$config->get('sysRoot').'alpha/lib/PEAR/PHPUnit-3.2.9');
  11. require_once 'PHPUnit/Framework.php';
  12. require_once 'PHPUnit/TextUI/TestRunner.php';
  13.  
  14. require_once $config->get('sysRoot').'alpha/util/Logger.inc';
  15. require_once $config->get('sysRoot').'alpha/model/PersonObject.inc';
  16. require_once $config->get('sysRoot').'alpha/model/TagObject.inc';
  17. require_once $config->get('sysRoot').'alpha/controller/AlphaControllerInterface.inc';
  18. require_once $config->get('sysRoot').'alpha/controller/AlphaController.inc';
  19. require_once $config->get('sysRoot').'alpha/tests/Enum_Test.php';
  20. require_once $config->get('sysRoot').'alpha/tests/DEnum_Test.php';
  21. require_once $config->get('sysRoot').'alpha/tests/Sequence_Test.php';
  22. require_once $config->get('sysRoot').'alpha/tests/Boolean_Test.php';
  23. require_once $config->get('sysRoot').'alpha/tests/Date_Test.php';
  24. require_once $config->get('sysRoot').'alpha/tests/Timestamp_Test.php';
  25. require_once $config->get('sysRoot').'alpha/tests/Integer_Test.php';
  26. require_once $config->get('sysRoot').'alpha/tests/Double_Test.php';
  27. require_once $config->get('sysRoot').'alpha/tests/Exceptions_Test.php';
  28. require_once $config->get('sysRoot').'alpha/tests/String_Test.php';
  29. require_once $config->get('sysRoot').'alpha/tests/Text_Test.php';
  30. require_once $config->get('sysRoot').'alpha/tests/Relation_Test.php';
  31. require_once $config->get('sysRoot').'alpha/tests/Tag_Test.php';
  32. require_once $config->get('sysRoot').'alpha/tests/AlphaDAO_Test.php';
  33. require_once $config->get('sysRoot').'alpha/tests/AlphaValidator_Test.php';
  34. require_once $config->get('sysRoot').'alpha/tests/AlphaController_Test.php';
  35. require_once $config->get('sysRoot').'alpha/tests/FrontController_Test.php';
  36. require_once $config->get('sysRoot').'alpha/tests/AlphaView_Test.php';
  37. require_once $config->get('sysRoot').'alpha/tests/Image_Test.php';
  38. require_once $config->get('sysRoot').'alpha/tests/AlphaAgentUtils_Test.php';
  39. require_once $config->get('sysRoot').'alpha/tests/AlphaConfig_Test.php';
  40. require_once $config->get('sysRoot').'alpha/tests/AlphaFeed_Test.php';
  41. require_once $config->get('sysRoot').'alpha/tests/AlphaFilters_Test.php';
  42.  
  43. /**
  44.  * Controller which displays all of the unit test results
  45.  * 
  46.  * @package alpha::controller
  47.  * @since 1.0
  48.  * @author John Collins <dev@alphaframework.org>
  49.  * @version $Id: ViewTestResults.php 1453 2011-12-04 15:12:54Z johnc $
  50.  * @license http://www.opensource.org/licenses/bsd-license.php The BSD License
  51.  * @copyright Copyright (c) 2011, John Collins (founder of Alpha Framework).
  52.  *  All rights reserved.
  53.  * 
  54.  *  <pre>
  55.  *  Redistribution and use in source and binary forms, with or
  56.  *  without modification, are permitted provided that the
  57.  *  following conditions are met:
  58.  * 
  59.  *  * Redistributions of source code must retain the above
  60.  *    copyright notice, this list of conditions and the
  61.  *    following disclaimer.
  62.  *  * Redistributions in binary form must reproduce the above
  63.  *    copyright notice, this list of conditions and the
  64.  *    following disclaimer in the documentation and/or other
  65.  *    materials provided with the distribution.
  66.  *  * Neither the name of the Alpha Framework nor the names
  67.  *    of its contributors may be used to endorse or promote
  68.  *    products derived from this software without specific
  69.  *    prior written permission.
  70.  *   
  71.  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
  72.  *  CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
  73.  *  INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  74.  *  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  75.  *  DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
  76.  *  CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  77.  *  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  78.  *  NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  79.  *  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  80.  *  HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  81.  *  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
  82.  *  OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  83.  *  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  84.  *  </pre>
  85.  *  
  86.  */
  87. class ViewTestResults extends AlphaController implements AlphaControllerInterface {    
  88.     /**
  89.      * Trace logger
  90.      * 
  91.      * @var Logger 
  92.      * @since 1.0
  93.      */
  94.     private static $logger null;
  95.     
  96.     /**
  97.      * The constructor
  98.      * 
  99.      * @since 1.0
  100.      */
  101.     public function __construct({
  102.         global $config;
  103.         
  104.         /*
  105.          * we are supressing the display and logging of errors on this page, as we 
  106.          * are only interested in tests that fail and the reasons given for failing
  107.          * 
  108.          */
  109.         $config->set('sysTraceLevel''FATAL');        
  110.         
  111.         // ensure that the super class constructor is called, indicating the rights group
  112.         parent::__construct('Admin');
  113.         
  114.         // set up the title and meta details
  115.         $this->setTitle('Alpha Core Unit Test Results');
  116.     }
  117.     
  118.     /**
  119.      * Handle GET requests
  120.      * 
  121.      * @param array $params 
  122.      * @since 1.0
  123.      */
  124.     public function doGET($params{
  125.         global $config;
  126.             
  127.         echo AlphaView::displayPageHead($this);
  128.         
  129.         // flip the standard database settings with the test ones
  130.         $config->set('sysDB'$config->get('sysDBTest'));
  131.         $config->set('sysDBUsername'$config->get('sysDBTestUsername'));
  132.         $config->set('sysDBPassword'$config->get('sysDBTestPassword'));
  133.         $config->set('sysDBHost'$config->get('sysDBTestHost'));
  134.         // force a disconnect to break any existing connections to the main database 
  135.         AlphaDAO::disconnect();
  136.         
  137.         if($config->get('sysDB'== ''{
  138.             echo AlphaView::displayErrorMessage('Unable to run the unit tests as no test database is configured!');
  139.             echo AlphaView::displayPageFoot($this);
  140.             return;
  141.         }
  142.         
  143.         $runningTime 0;
  144.         $testCount 0;
  145.         
  146.         echo '<h2>Core Complex Data Types</h2>';
  147.         
  148.         // **** begin test suite ****
  149.         echo '<h3>Enum:</h3>';
  150.         
  151.         $suite new PHPUnit_Framework_TestSuite();
  152.         $suite->addTestSuite('Enum_Test');
  153.         $result $suite->run();
  154.         $runningTime+=$result->time();
  155.         $testCount+=$result->count();
  156.                 
  157.         $this->printTestResult($result);
  158.         
  159.         echo '<p>Running time: '.$runningTime.'</p>';
  160.         
  161.         // **** begin test suite ****
  162.         echo '<h3>DEnum:</h3>';
  163.         
  164.         $suite new PHPUnit_Framework_TestSuite();
  165.         $suite->addTestSuite('DEnum_Test');
  166.         $result $suite->run();
  167.         $runningTime+=$result->time();
  168.         $testCount+=$result->count();
  169.                 
  170.         $this->printTestResult($result);
  171.         
  172.         echo '<p>Running time: '.$runningTime.'</p>';
  173.         
  174.         // **** begin test suite ****
  175.         echo '<h3>Sequence:</h3>';
  176.         
  177.         $suite new PHPUnit_Framework_TestSuite();
  178.         $suite->addTestSuite('Sequence_Test');
  179.         $result $suite->run();
  180.         $runningTime+=$result->time();
  181.         $testCount+=$result->count();
  182.                 
  183.         $this->printTestResult($result);
  184.         
  185.         echo '<p>Running time: '.$runningTime.'</p>';
  186.         
  187.         // **** begin test suite ****
  188.         echo '<h3>Boolean:</h3>';
  189.         
  190.         $suite new PHPUnit_Framework_TestSuite();
  191.         $suite->addTestSuite('Boolean_Test');
  192.         $result $suite->run();
  193.         $runningTime+=$result->time();
  194.         $testCount+=$result->count();
  195.                 
  196.         $this->printTestResult($result);
  197.         
  198.         echo '<p>Running time: '.$runningTime.'</p>';
  199.         
  200.         // **** begin test suite ****
  201.         echo '<h3>Date:</h3>';
  202.         
  203.         $suite new PHPUnit_Framework_TestSuite();
  204.         $suite->addTestSuite('Date_Test');
  205.         $result $suite->run();
  206.         $runningTime+=$result->time();
  207.         $testCount+=$result->count();
  208.                 
  209.         $this->printTestResult($result);
  210.         
  211.         echo '<p>Running time: '.$runningTime.'</p>';
  212.         
  213.         // **** begin test suite ****
  214.         echo '<h3>Timestamp:</h3>';
  215.         
  216.         $suite new PHPUnit_Framework_TestSuite();
  217.         $suite->addTestSuite('Timestamp_Test');
  218.         $result $suite->run();
  219.         $runningTime+=$result->time();
  220.         $testCount+=$result->count();
  221.                 
  222.         $this->printTestResult($result);
  223.         
  224.         echo '<p>Running time: '.$runningTime.'</p>';
  225.         
  226.         // **** begin test suite ****
  227.         echo '<h3>Integer:</h3>';
  228.         
  229.         $suite new PHPUnit_Framework_TestSuite();
  230.         $suite->addTestSuite('Integer_Test');
  231.         $result $suite->run();
  232.         $runningTime+=$result->time();
  233.         $testCount+=$result->count();
  234.                 
  235.         $this->printTestResult($result);
  236.         
  237.         echo '<p>Running time: '.$runningTime.'</p>';
  238.         
  239.         // **** begin test suite ****
  240.         echo '<h3>Double:</h3>';
  241.         
  242.         $suite new PHPUnit_Framework_TestSuite();
  243.         $suite->addTestSuite('Double_Test');
  244.         $result $suite->run();
  245.         $runningTime+=$result->time();
  246.         $testCount+=$result->count();
  247.                 
  248.         $this->printTestResult($result);
  249.         
  250.         echo '<p>Running time: '.$runningTime.'</p>';
  251.         
  252.         // **** begin test suite ****
  253.         echo '<h3>String:</h3>';
  254.         
  255.         $suite new PHPUnit_Framework_TestSuite();
  256.         $suite->addTestSuite('String_Test');
  257.         $result $suite->run();
  258.         $runningTime+=$result->time();
  259.         $testCount+=$result->count();
  260.                 
  261.         $this->printTestResult($result);
  262.         
  263.         echo '<p>Running time: '.$runningTime.'</p>';
  264.         
  265.         // **** begin test suite ****
  266.         echo '<h3>Text:</h3>';
  267.         
  268.         $suite new PHPUnit_Framework_TestSuite();
  269.         $suite->addTestSuite('Text_Test');
  270.         $result $suite->run();
  271.         $runningTime+=$result->time();
  272.         $testCount+=$result->count();
  273.                 
  274.         $this->printTestResult($result);
  275.         
  276.         echo '<p>Running time: '.$runningTime.'</p>';
  277.         
  278.         // **** begin test suite ****
  279.         echo '<h3>Relation:</h3>';
  280.         
  281.         $suite new PHPUnit_Framework_TestSuite();
  282.         $suite->addTestSuite('Relation_Test');
  283.         $result $suite->run();
  284.         $runningTime+=$result->time();
  285.         $testCount+=$result->count();
  286.                 
  287.         $this->printTestResult($result);
  288.         
  289.         echo '<p>Running time: '.$runningTime.'</p>';
  290.         
  291.         // **** begin test suite ****
  292.         echo '<h3>Exception Handling:</h3>';
  293.         
  294.         $suite new PHPUnit_Framework_TestSuite();
  295.         $suite->addTestSuite('Exceptions_Test');
  296.         $result $suite->run();
  297.         $runningTime+=$result->time();
  298.         $testCount+=$result->count();
  299.                 
  300.         $this->printTestResult($result);
  301.         
  302.         echo '<p>Running time: '.$runningTime.'</p>';
  303.         
  304.         // **** begin test suite ****
  305.         echo '<h3>Tag:</h3>';
  306.         
  307.         $suite new PHPUnit_Framework_TestSuite();
  308.         $suite->addTestSuite('Tag_Test');
  309.         $result $suite->run();
  310.         $runningTime+=$result->time();
  311.         $testCount+=$result->count();
  312.                 
  313.         $this->printTestResult($result);
  314.         
  315.         echo '<p>Running time: '.$runningTime.'</p>';
  316.         
  317.         // **** begin test suite ****
  318.         echo '<h3>MySQL AlphaDAO:</h3>';
  319.         
  320.         $suite new PHPUnit_Framework_TestSuite();
  321.         $suite->addTestSuite('AlphaDAO_Test');
  322.         $result $suite->run();
  323.         $runningTime+=$result->time();
  324.         $testCount+=$result->count();
  325.                 
  326.         $this->printTestResult($result);
  327.         
  328.         echo '<p>Running time: '.$runningTime.'</p>';
  329.         
  330.         // **** begin test suite ****
  331.         echo '<h3>AlphaValidator helper:</h3>';
  332.         
  333.         $suite new PHPUnit_Framework_TestSuite();
  334.         $suite->addTestSuite('AlphaValidator_Test');
  335.         $result $suite->run();
  336.         $runningTime+=$result->time();
  337.         $testCount+=$result->count();
  338.                 
  339.         $this->printTestResult($result);
  340.         
  341.         echo '<p>Running time: '.$runningTime.'</p>';
  342.         
  343.         // **** begin test suite ****
  344.         echo '<h3>AlphaController:</h3>';
  345.         
  346.         $suite new PHPUnit_Framework_TestSuite();
  347.         $suite->addTestSuite('AlphaController_Test');
  348.         $result $suite->run();
  349.         $runningTime+=$result->time();
  350.         $testCount+=$result->count();
  351.                 
  352.         $this->printTestResult($result);
  353.         
  354.         echo '<p>Running time: '.$runningTime.'</p>';
  355.         
  356.         // **** begin test suite ****
  357.         echo '<h3>FrontController:</h3>';
  358.         
  359.         $suite new PHPUnit_Framework_TestSuite();
  360.         $suite->addTestSuite('FrontController_Test');
  361.         $result $suite->run();
  362.         $runningTime+=$result->time();
  363.         $testCount+=$result->count();
  364.                 
  365.         $this->printTestResult($result);
  366.         
  367.         echo '<p>Running time: '.$runningTime.'</p>';
  368.         
  369.         // **** begin test suite ****
  370.         echo '<h3>AlphaView:</h3>';
  371.         
  372.         $suite new PHPUnit_Framework_TestSuite();
  373.         $suite->addTestSuite('AlphaView_Test');
  374.         $result $suite->run();
  375.         $runningTime+=$result->time();
  376.         $testCount+=$result->count();
  377.                 
  378.         $this->printTestResult($result);
  379.         
  380.         echo '<p>Running time: '.$runningTime.'</p>';
  381.         
  382.         // **** begin test suite ****
  383.         echo '<h3>Image:</h3>';
  384.         
  385.         $suite new PHPUnit_Framework_TestSuite();
  386.         $suite->addTestSuite('Image_Test');
  387.         $result $suite->run();
  388.         $runningTime+=$result->time();
  389.         $testCount+=$result->count();
  390.                 
  391.         $this->printTestResult($result);
  392.         
  393.         echo '<p>Running time: '.$runningTime.'</p>';
  394.         
  395.         // **** begin test suite ****
  396.         echo '<h3>AlphaAgentUtils:</h3>';
  397.         
  398.         $suite new PHPUnit_Framework_TestSuite();
  399.         $suite->addTestSuite('AlphaAgentUtils_Test');
  400.         $result $suite->run();
  401.         $runningTime+=$result->time();
  402.         $testCount+=$result->count();
  403.                 
  404.         $this->printTestResult($result);
  405.         
  406.         echo '<p>Running time: '.$runningTime.'</p>';
  407.         
  408.         // **** begin test suite ****
  409.         echo '<h3>AlphaConfig:</h3>';
  410.         
  411.         $suite new PHPUnit_Framework_TestSuite();
  412.         $suite->addTestSuite('AlphaConfig_Test');
  413.         $result $suite->run();
  414.         $runningTime+=$result->time();
  415.         $testCount+=$result->count();
  416.                 
  417.         $this->printTestResult($result);
  418.         
  419.         echo '<p>Running time: '.$runningTime.'</p>';
  420.         
  421.         // **** begin test suite ****
  422.         echo '<h3>AlphaFeed:</h3>';
  423.         
  424.         $suite new PHPUnit_Framework_TestSuite();
  425.         $suite->addTestSuite('AlphaFeed_Test');
  426.         $result $suite->run();
  427.         $runningTime+=$result->time();
  428.         $testCount+=$result->count();
  429.                 
  430.         $this->printTestResult($result);
  431.         
  432.         echo '<p>Running time: '.$runningTime.'</p>';
  433.         
  434.         // **** begin test suite ****
  435.         echo '<h3>AlphaFilters:</h3>';
  436.         
  437.         $suite new PHPUnit_Framework_TestSuite();
  438.         $suite->addTestSuite('AlphaFilters_Test');
  439.         $result $suite->run();
  440.         $runningTime+=$result->time();
  441.         $testCount+=$result->count();
  442.                 
  443.         $this->printTestResult($result);
  444.         
  445.         echo '<p>Running time: '.$runningTime.'</p>';
  446.         
  447.         echo '<h3>Total tests ran: '.$testCount.'</h3>';
  448.         echo '<h3>Total running time: '.$runningTime.'</h3>';
  449.         
  450.         echo AlphaView::displayPageFoot($this);
  451.     }
  452.     
  453.     /**
  454.      * Handle POST requests
  455.      * 
  456.      * @param array $params 
  457.      * @since 1.0
  458.      */
  459.     public function doPOST($params{
  460.     }
  461.     
  462.     /**
  463.      * Prints the test result HTML & CSS for the passed PHPUnit test result
  464.      * 
  465.      * @param PHPUnit_Framework_TestResult $result 
  466.      * @since 1.0
  467.      */
  468.     private function printTestResult($result{
  469.         if($result->wasSuccessful()) {
  470.             echo '<div class="ui-state-highlight ui-corner-all" style="padding: 0pt 0.7em;">';
  471.             echo '<p><span class="ui-icon ui-icon-info" style="float: left; margin-right: 0.3em;"></span>';
  472.             echo '<strong>Success</strong><pre>';
  473.         }else{
  474.             echo '<div class="ui-state-error ui-corner-all" style="padding: 0pt 0.7em;">'
  475.             echo '<p><span class="ui-icon ui-icon-alert" style="float: left; margin-right: 0.3em;"></span>';
  476.             echo '<strong>Fail</strong><pre>';
  477.         }
  478.             
  479.         $report new PHPUnit_TextUI_ResultPrinter();        
  480.         $report->printResult($result);
  481.         echo '</pre></p></div>';
  482.     }
  483. }
  484.  
  485. // now build the new controller if this file is called directly
  486. if ('ViewTestResults.php' == basename($_SERVER['PHP_SELF'])) {
  487.     $controller new ViewTestResults();
  488.     
  489.     if(!empty($_POST)) {            
  490.         $controller->doPOST($_POST);
  491.     }else{
  492.         $controller->doGET($_GET);
  493.     }
  494. }
  495.  
  496. ?>

Documentation generated on Tue, 13 Dec 2011 20:27:56 +0000 by phpDocumentor 1.4.3