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