Difference between revisions of "SpecialSelenium.php"

From Organic Design wiki
m
(restructure special page to a single table)
Line 21: Line 21:
 
   
 
   
 
public function execute() {
 
public function execute() {
global $wgOut, $wgParser, $wgRequest, $egResultsUrlPath;
+
global $wgOut, $wgParser, $wgRequest, $wgServer,
 +
$egSeleniumCategory, $egSeleniumSchdeule, $egSeleniumLog, $egSeleniumPath, $egResultsUrlPath;
  
 
# Process suite or test if ?suite=article_name in query string
 
# Process suite or test if ?suite=article_name in query string
Line 70: Line 71:
 
# No suite specified, render the main special page and form
 
# No suite specified, render the main special page and form
 
else {
 
else {
global $egSeleniumCategory, $egSeleniumSchdeule, $egSeleniumEnabled, $egSeleniumFailLog,
 
$egSeleniumPath, $egResultsUrlPath, $wgServer;
 
 
$this->setHeaders();
 
$this->setHeaders();
 
$title = Title::makeTitle(NS_SPECIAL, 'Selenium');
 
$title = Title::makeTitle(NS_SPECIAL, 'Selenium');
Line 79: Line 78:
 
$suites = array();
 
$suites = array();
 
$dbr = &wfGetDB(DB_SLAVE);
 
$dbr = &wfGetDB(DB_SLAVE);
 +
$cat = Title::makeTitle(NS_CATEGORY, $egSeleniumCategory)->getDBkey();
 
$cl  = $dbr->tableName('categorylinks');
 
$cl  = $dbr->tableName('categorylinks');
$res = $dbr->select($cl, 'cl_from', "cl_to = '$egSeleniumCategory'", __METHOD__, array('ORDER BY' => 'cl_sortkey'));
+
$res = $dbr->select($cl, 'cl_from', "cl_to = '$cat'", __METHOD__, array('ORDER BY' => 'cl_sortkey'));
 
while ($row = $dbr->fetchRow($res)) $suites[] = Title::newFromID($row[0])->getPrefixedText();
 
while ($row = $dbr->fetchRow($res)) $suites[] = Title::newFromID($row[0])->getPrefixedText();
  
# Render section for running tests manually with a select list of all the suites
+
# Split schedule into times and enabled suites
$wgOut->addWikitext('=='.wfMsg('selenium-runmanual').'==');
+
$schedule = array();
$html = "<fieldset><legend>".wfMsg('selenium-select')."</legend><ul>";
+
$enabled = array();
foreach ($suites as $suite) {
+
foreach ($egSeleniumSchdeule as $k => $v) is_numeric($k) ? $schedule[] = $v : $enabled[$k] = $v;
$path = "$ide?test=".urlencode($title->getLocalURL("suite=$suite"));
+
$desc = "<b>".array_pop($schedule)."</b>";
$html .= "<li><a href=\"$path\">$suite</a></li>\n";
+
if (count($schedule) > 0) $desc = "<b>".join("</b>, <b>", $schedule)."</b> and $desc";
}
+
 
$html .= "</ul></fieldset>";
+
# Render tables of suites and their information
$wgOut->addHTML($html);
+
$thead = "{|class=\"selenium-special\" border\n";
 +
$thead .= "!Test suite!!".wfMsg('selenium-schedule', $desc);
 +
$thead .= "!!".wfMsg('selenium-last')."!!".wfMsg('selenium-run')."!!\n";
 +
$tbody = '';
  
# Manage the automatic test run schedule
 
$wgOut->addWikitext('=='.wfMsg('selenium-manage').'==');
 
$schedule = "<b>".array_pop($egSeleniumSchdeule)."</b>";
 
if (count($egSeleniumSchdeule) > 0) $schedule = "<b>".join("</b>, <b>", $egSeleniumSchdeule)."</b> and $schedule";
 
$wgOut->addHTML("<fieldset><legend>".wfMsg('selenium-schedule', $schedule)."</legend>");
 
$form  = wfElement('form', array('action' => $title->getLocalURL('action=submit'), 'method' => 'post'), null);
 
 
foreach ($suites as $suite) {
 
foreach ($suites as $suite) {
$path = "$ide?test=".urlencode($title->getLocalURL("suite=$suite"));
+
$tbody .= "|-\n|valign=top|[[$suite]]\n|\n";
$form .= wfCheckLabel($suite, "wfEnabledTests[]", $suite, $checked = false)."<br />\n";
+
if (array_key_exists($suite, $enabled)) {
 +
foreach ($enabled[$suite] as $domain) $tbody .= "*$domain\n";
 +
} else $tbody .= "-\n";
 +
$tbody .= "|valign=top|last log item\n";
 +
$tbody .= "|valign=top|[$wgServer$ide?test=".urlencode($title->getLocalURL("suite=$suite"));
 +
$tbody .= " ".wfMsg('selenium-run')."]\n";
 
}
 
}
$form .= wfElement('input', array('type' => 'submit', name => 'wpSave', value => 'Save'))."</form><br />";
+
$wgOut->addWikitext("$thead$tbody|}\n".wfMsg('selenium-loginfo', $egSeleniumLog));
$wgOut->addHTML($form);
 
$wgOut->addWikitext(wfMsg('selenium-failinfo', $egSeleniumFailLog));
 
$wgOut->addHTML("</fieldset>");
 
 
# If suites have been enabled or disabled, update their categorisation
 
if ($wgRequest->getText('wpSave')) {
 
 
 
# Construct the posted checkboxes as a bullet list
 
$newList = '';
 
foreach ($egSeleniumEnabled as $suite) $newList .= "*[[$suite]]\n";
 
 
# Get the current state as an array from $egSeleniumEnabled article content
 
$cur = new Article(Title::newFromText($egSeleniumEnabled));
 
preg_match_all("|\\*\\[\\[(.+?)\\]\\]|", $cur->getContent(), $matches, PREG_PATTERN_ORDER);
 
$cur = $matches[1];
 
 
# Find which tests have been added or removed
 
$add = array();
 
$del = array();
 
 
if (count($add) || count($del)) {
 
# create a string describing the added and removed members
 
# render the string in a msg in the form
 
# update the $egSeleniumEnabled article with the new list using msg as comment
 
}
 
}
 
 
# Section about creating new tests
 
$wgOut->addWikitext('=='.wfMsg('selenium-create').'==');
 
$wgOut->addWikitext(wfMsg('selenium-createinfo', "$wgServer$ide"));
 
 
 
 
}
 
}
 
}
 
}
 
}
 
}

Revision as of 02:59, 3 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, $wgServer, $egSeleniumCategory, $egSeleniumSchdeule, $egSeleniumLog, $egSeleniumPath, $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 specified, render the main special page and form else { $this->setHeaders(); $title = Title::makeTitle(NS_SPECIAL, 'Selenium'); $ide = "$egSeleniumPath/core/TestRunner.html";

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

# Split schedule into times and enabled suites $schedule = array(); $enabled = array(); foreach ($egSeleniumSchdeule as $k => $v) is_numeric($k) ? $schedule[] = $v : $enabled[$k] = $v; $desc = "".array_pop($schedule).""; if (count($schedule) > 0) $desc = "".join(", ", $schedule)." and $desc";

# Render tables of suites and their information $thead = "{|class=\"selenium-special\" border\n"; $thead .= "!Test suite!!".wfMsg('selenium-schedule', $desc); $thead .= "!!".wfMsg('selenium-last')."!!".wfMsg('selenium-run')."!!\n"; $tbody = ;

foreach ($suites as $suite) { $tbody .= "|-\n|valign=top|$suite\n|\n"; if (array_key_exists($suite, $enabled)) { foreach ($enabled[$suite] as $domain) $tbody .= "*$domain\n"; } else $tbody .= "-\n"; $tbody .= "|valign=top|last log item\n"; $tbody .= "|valign=top|[$wgServer$ide?test=".urlencode($title->getLocalURL("suite=$suite")); $tbody .= " ".wfMsg('selenium-run')."]\n"; } $wgOut->addWikitext("$thead$tbody|}\n".wfMsg('selenium-loginfo', $egSeleniumLog)); } } }