93d57ca22022e5af8bbc6b83a0cd054c4693d6f3
[lhc/web/wiklou.git] / includes / specials / SpecialSelenium.php
1 <?php
2
3 /**
4 * TODO: remove this feature
5 */
6
7 class SpecialSelenium extends SpecialPage {
8 function __construct() {
9 parent::__construct( 'Selenium', 'selenium', false );
10 }
11
12 function getDescription() {
13 return 'Selenium';
14 }
15
16 function execute() {
17 global $wgUser, $wgOut, $wgEnableSelenium, $wgRequest;
18
19 if ( !$wgEnableSelenium ) {
20 throw new MWException(
21 'Selenium special page invoked when it should not be registered!' );
22 }
23
24 $this->setHeaders();
25 if ( !$this->userCanExecute( $wgUser ) ) {
26 $this->displayRestrictionError();
27 return;
28 }
29
30 if ( $wgRequest->wasPosted() && $wgUser->matchEditToken( $wgRequest->getVal( 'token' ) ) ) {
31 $this->runTests();
32 }
33 $wgOut->addHTML(
34 Html::openElement( 'form', array(
35 'method' => 'POST',
36 'action' => $this->getTitle()->getLocalUrl(),
37 ) ) .
38 Html::input( 'submit', 'Run tests', 'submit' ) .
39 Html::hidden( 'token', $wgUser->editToken() ) .
40 '</form>'
41 );
42 }
43
44 function runTests() {
45 global $wgSeleniumTests, $wgOut;
46 SeleniumLoader::load();
47
48 $result = new PHPUnit_Framework_TestResult;
49 $logger = new SeleniumTestHTMLLogger;
50 $result->addListener( new SeleniumTestListener( $logger ) );
51 $logger->setHeaders();
52
53 // run tests
54 $suite = new SeleniumTestSuite;
55 foreach ( $wgSeleniumTests as $testClass ) {
56 $suite->addTest( new $testClass );
57 }
58 $wgOut->addHTML( '<div class="selenium">' );
59 $suite->run( $result );
60 $wgOut->addHTML( '</div>' );
61 }
62 }
63