Difference between revisions of "Selenium.class.php"

From Organic Design wiki
(do need to wrap in selenium tags afterall)
m
Line 20: Line 20:
  
 
# Add the tag hook
 
# Add the tag hook
$wgParser->setHook('selenium', array($this, 'tagSelenium'));
+
$wgParser->setHook($egSeleniumTag, array($this, 'tagSelenium'));
 
 
 
# 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 32: Line 32:
 
public function tagSelenium($text, &$argv, &$parser) {
 
public function tagSelenium($text, &$argv, &$parser) {
 
global $egSeleniumCategory;
 
global $egSeleniumCategory;
 +
 +
# Get name of test from title tag
 +
$name = preg_match("|<title>(.+?)</title>|i", $text, $match) ? $match[1] : 'untitled';
  
 
# Get rid of unwanted tags
 
# Get rid of unwanted tags
$text = preg_replace("#\\s*<head>.+?</head>\\s*#is", "", $text);
+
$text = preg_replace("#\\s*<head>.+</head>\\s*#is", "", $text);
 
$text = preg_replace("#\\s*</?t?(html|head|body)>\\s*#i", "", $text);
 
$text = preg_replace("#\\s*</?t?(html|head|body)>\\s*#i", "", $text);
  
Line 42: Line 45:
 
# Parse the content normally and return wrapped in a div of class selenium
 
# 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\" id=\"$name\">$text</div><!-- selenium end -->";
 
}
 
}
  

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

class Selenium {

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

# Add the tag hook $wgParser->setHook($egSeleniumTag, 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 name of test from title tag $name = preg_match("|<title>(.+?)</title>|i", $text, $match) ? $match[1] : 'untitled';

# 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__; } }