Difference between revisions of "SpecialSelenium.php"

From Organic Design wiki
(iniitalise $tests array)
(comment re TestRunner using stripped table)
Line 27: Line 27:
  
 
# Get the content of the suite article and parse it
 
# Get the content of the suite article and parse it
 +
# NOTE: parsing the content results in the head, body, thead, tbody etc being removed,
 +
#      but it seems that the TestRunner doesn't care and can work with the basic table structure
 
$suiteTitle = Title::newFromText($suite);
 
$suiteTitle = Title::newFromText($suite);
 
$suiteArticle = new Article($suiteTitle);
 
$suiteArticle = new Article($suiteTitle);

Revision as of 04:25, 2 August 2008

<?php /**

* Selenium extension
* Template:Php
* See http://www.mediawiki.org/Extension:Selenium for installation and usage details
* See http://www.organicdesign.co.nz/Extension_talk:Selenium.php for development notes and disucssion
* 
* @package MediaWiki
* @subpackage Extensions
* @author Marcus Davy User:Sven
* @copyright © 2007 Marcus Davy
* @licence GNU General Public Licence 2.0 or later
*/

if (!defined('MEDIAWIKI')) die();

class SpecialSelenium extends SpecialPage {

function __construct() { SpecialPage::SpecialPage('Selenium', , true, false, false, false); }

public function execute() { global $wgOut, $wgParser, $wgRequest, $egResultsUrlPath;

# Process suite or test if ?suite=article_name in query string if ($suite = $wgRequest->getText('suite')) {

# Get the content of the suite article and parse it # NOTE: parsing the content results in the head, body, thead, tbody etc being removed, # but it seems that the TestRunner doesn't care and can work with the basic table structure $suiteTitle = Title::newFromText($suite); $suiteArticle = new Article($suiteTitle); $text = $wgParser->parse($suiteArticle->getContent(), $suiteTitle, new ParserOptions(), true, true)->getText();

# Extract the tests from the expanded content and $numTests = preg_match_all(

"|

\\s*(.+?)\\s*

|is",

$text, $matches, PREG_PATTERN_ORDER );

# If any tests were extracted, build content and return it to the client if ($numTests > 0) {

# Re-organise the matched test content into a hash indexed by test name $tests = array(); for ($i = 0; $i < $numTests; $i++) $tests[$matches[1][$i]] = $matches[2][$i];

# If a test is specified, return it from the suite article content in raw HTML Selenium test format if ($test = $wgRequest->getText('test')) { if (array_key_exists($test, $tests)) print $tests[$test]; }

# Or if no test specified, return the whole suite in raw HTML Selenium test-suite format else { $html = " Selenium

\n"; $title = Title::makeTitle(NS_SPECIAL, 'Selenium'); foreach (array_keys($tests) as $test) { $url = $title->getLocalURL("suite=$suite&test=$test"); $html .= "\n"; } print "$html
$suite
$test

"; } } }

# No suite or test specified, render the main special page and form else { global $egSeleniumCategory, $egSeleniumPath, $egResultsUrlPath; $this->setHeaders(); $title = Title::makeTitle(NS_SPECIAL, 'Selenium');

# Render section for running tests manually with a select list of all the suites $wgOut->addWikitext('=='.wfMsg('selenium-runmanual').'==');

# Retrieve suites from Selenium category (only selenium tests should be in this cat) $suites = array(); $dbr = &wfGetDB(DB_SLAVE); $cl = $dbr->tableName('categorylinks'); $res = $dbr->select($cl, 'cl_from', "cl_to = '$egSeleniumCategory'", __METHOD__, array('ORDER BY' => 'cl_sortkey')); while ($row = $dbr->fetchRow($res)) $suites[] = Title::newFromID($row[0])->getPrefixedText();

$form = wfElement('form', array('action' => $title->getLocalURL('action=submit'), 'method' => 'post'), null); $form .= "<fieldset><legend>".wfMsg('selenium-select')."</legend>"; $form .= "<select name=\"selenium\"><option>".join("</option>\n<option>", $suites)."</option></select>"; $form .= wfElement('input', array('type' => 'submit', value => 'Go')); $form .= "

".wfCheckLabel(wfMsg('selenium-autorun'), 'wfRunAuto' , 'wfRunAuto', $checked = false); $form .= '</fieldset></form>'; $wgOut->addHTML($form);

# Render link to run test $selenium = $wgRequest->getText('selenium'); $path = "$egSeleniumPath/core/TestRunner.html?test=".urlencode($title->getLocalURL("suite=$selenium")); if ($wgRequest->getBool('wfRunAuto')) $path .= "&auto=true&resultsUrl=$egResultsUrlPath"; $wgOut->addHTML("<fieldset><legend>".wfMsg('selenium-runcore')."</legend><a href=\"$path\">$selenium</a></fieldset>");

$wgOut->addWikitext('=='.wfMsg('selenium-manage').'==');

$wgOut->addWikitext('=='.wfMsg('selenium-create').'==');

} } }