Modified Special:Categories to subclass SpecialPage
[lhc/web/wiklou.git] / includes / specials / SpecialSelenium.php
1 <?php
2 /**
3 * Implements Special:Selenium
4 *
5 * @file
6 * @ingroup SpecialPage
7 * @todo Remove this feature
8 */
9
10 /**
11 * @ingroup SpecialPage
12 */
13 class SpecialSelenium extends SpecialPage {
14 function __construct() {
15 parent::__construct( 'Selenium', 'selenium', false );
16 }
17
18 function getDescription() {
19 return 'Selenium';
20 }
21
22 function execute( $par ) {
23 global $wgUser, $wgOut, $wgEnableSelenium, $wgRequest;
24
25 if ( !$wgEnableSelenium ) {
26 throw new MWException(
27 'Selenium special page invoked when it should not be registered!' );
28 }
29
30 $this->setHeaders();
31 if ( !$this->userCanExecute( $wgUser ) ) {
32 $this->displayRestrictionError();
33 return;
34 }
35
36 if ( $wgRequest->wasPosted() && $wgUser->matchEditToken( $wgRequest->getVal( 'token' ) ) ) {
37 $this->runTests();
38 }
39 $wgOut->addHTML(
40 Html::openElement( 'form', array(
41 'method' => 'POST',
42 'action' => $this->getTitle()->getLocalUrl(),
43 ) ) .
44 Html::input( 'submit', 'Run tests', 'submit' ) .
45 Html::hidden( 'token', $wgUser->editToken() ) .
46 '</form>'
47 );
48 }
49
50 function runTests() {
51 global $wgSeleniumTestSuites, $wgOut, $wgSeleniumLogger;
52 SeleniumLoader::load();
53
54 $result = new PHPUnit_Framework_TestResult;
55 $wgSeleniumLogger = new SeleniumTestHTMLLogger;
56 $result->addListener( new SeleniumTestListener( $wgSeleniumLogger ) );
57 //$wgSeleniumLogger->setHeaders();
58
59 // run tests
60 $wgOut->addHTML( '<div class="selenium">' );
61
62 // for some really strange reason, foreach doesn't work here. It produces an infinite loop,
63 // executing only the first test suite.
64 for ( $i = 0; $i < count( $wgSeleniumTestSuites ); $i++ ) {
65 $suite = new $wgSeleniumTestSuites[$i];
66 $suite->addTests();
67 $suite->run( $result );
68 }
69 $wgOut->addHTML( '</div>' );
70 }
71 }
72