Difference between revisions of "Selenium.class.php"

From Organic Design wiki
(add interfaces for new functions for scheduling)
(do need to wrap in selenium tags afterall)
Line 17: Line 17:
 
 
 
function __construct() {
 
function __construct() {
global $wgParser;
+
global $wgParser, $egSeleniumTag;
  
# Add the tag hooks
+
# Add the tag hook
$wgParser->setHook('body',  array($this, 'tagBody'));
+
$wgParser->setHook('selenium',  array($this, 'tagSelenium'));
$wgParser->setHook('head',  array($this, 'tagHead'));
 
$wgParser->setHook('html',  array($this, 'tagParseContent'));
 
$wgParser->setHook('thead', array($this, 'tagParseContent'));
 
$wgParser->setHook('tbody', array($this, 'tagParseContent'));
 
 
 
 
# Check the schedule and see if any test-runs should be spawned
 
# Check the schedule and see if any test-runs should be spawned
Line 31: Line 27:
  
 
/**
 
/**
* Body tags surround the main test table and should be converted to a div of class "selenium"
+
* Process a selenium tag with test syntax in it
 
* - this tag also handles the categorisation of the article into Category:Selenium
 
* - this tag also handles the categorisation of the article into Category:Selenium
 
*/
 
*/
public function tagBody($text, &$argv, &$parser) {
+
public function tagSelenium($text, &$argv, &$parser) {
 
global $egSeleniumCategory;
 
global $egSeleniumCategory;
 +
 +
# Get rid of unwanted tags
 +
$text = preg_replace("#\\s*<head>.+?</head>\\s*#is", "", $text);
 +
$text = preg_replace("#\\s*</?t?(html|head|body)>\\s*#i", "", $text);
 +
 +
# Categorise the article into Selenium tests category
 
$text .= "[[Category:$egSeleniumCategory]]";
 
$text .= "[[Category:$egSeleniumCategory]]";
 +
 +
# Parse the content normally and return wrapped in a div of class selenium
 
$text = $parser->parse($text, $parser->mTitle, $parser->mOptions, false, false)->getText();
 
$text = $parser->parse($text, $parser->mTitle, $parser->mOptions, false, false)->getText();
 
return "<div class=\"selenium\">$text</div>";
 
return "<div class=\"selenium\">$text</div>";
}
 
 
/**
 
* The head tag of a selenium test doesn't need to be rendered, so simply returns an empty string
 
*/
 
public function tagHead(&$text, &$argv, &$parser) {
 
return '';
 
}
 
 
/**
 
* The html, thead and tbody tags need to parse and return their content
 
*/
 
public function tagParseContent(&$text, &$argv, &$parser) {
 
return $parser->parse($text, $parser->mTitle, $parser->mOptions, false, false)->getText();
 
 
}
 
}
  

Revision as of 23:14, 1 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('Not an entry point.');

class Selenium {

function __construct() { global $wgParser, $egSeleniumTag;

# Add the tag hook $wgParser->setHook('selenium', array($this, 'tagSelenium'));

# Check the schedule and see if any test-runs should be spawned $this->checkSchedule(); }

/** * Process a selenium tag with test syntax in it * - this tag also handles the categorisation of the article into Category:Selenium */ public function tagSelenium($text, &$argv, &$parser) { global $egSeleniumCategory;

# Get rid of unwanted tags $text = preg_replace("#\\s*<head>.+?</head>\\s*#is", "", $text); $text = preg_replace("#\\s*</?t?(html|head|body)>\\s*#i", "", $text);

# Categorise the article into Selenium tests category $text .= "";

# Parse the content normally and return wrapped in a div of class selenium $text = $parser->parse($text, $parser->mTitle, $parser->mOptions, false, false)->getText();

return "

$text

";

}

/** * Check whether any tests should run and spawn them if so */ public function checkSchedule() { }

/** * Spawn a thread to run a test suite and report if failure */ public function spawnTestRunner() { }

/** * Notify a user about a test failure */ public function failureNotification() { }

/** * Needed in some versions to prevent Special:Version from breaking */ private function __toString() { return __CLASS__; } }