Difference between revisions of "Selenium.class.php"

From Organic Design wiki
m
(execute runTests.php in background on schedule)
Line 15: Line 15:
  
 
class Selenium {
 
class Selenium {
+
 
 +
var $testCount = array(); # keep track of number of tests in each suite processed
 +
 
 
function __construct() {
 
function __construct() {
 
global $wgParser, $egSeleniumTag;
 
global $wgParser, $egSeleniumTag;
Line 21: Line 23:
 
# Add the tag hook
 
# Add the tag hook
 
$wgParser->setHook($egSeleniumTag, 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
 
$this->checkSchedule();
 
$this->checkSchedule();
Line 33: Line 35:
 
global $egSeleniumCategory;
 
global $egSeleniumCategory;
  
 +
# The suite being processed is the article title text, keep track of number of tests in it
 +
$suite = $parser->mTitle->getPrefixedText();
 +
$this->testCount = array_key_exists($suite, $this->testCount) ? $this->testCount[$suite]++ : 1;
 +
 
# Get name of test from title tag
 
# Get name of test from title tag
 
$name = preg_match("|<title>(.+?)</title>|i", $text, $match) ? $match[1] : 'untitled';
 
$name = preg_match("|<title>(.+?)</title>|i", $text, $match) ? $match[1] : 'untitled';
Line 40: Line 46:
 
$text = preg_replace("#\\s*</?t?(html|head|body)>\\s*#i", "", $text);
 
$text = preg_replace("#\\s*</?t?(html|head|body)>\\s*#i", "", $text);
  
# Categorise the article into Selenium tests category
+
# Categorise the article into Selenium tests category if more than one test in this suite
$text .= "[[Category:$egSeleniumCategory]]";
+
if ($this->testCount[$suite] > 1) $text .= "[[Category:$egSeleniumCategory]]";
  
# 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 and id of test name
 
$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\" id=\"$name\">$text</div><!-- selenium end -->";
+
return "<div class=\"selenium\" id=\"$name\">$text</div><!-- selenium-end -->";
 
}
 
}
  
 
/**
 
/**
* Check whether any tests should run and spawn them if so
+
* Check whether any tests should run
 
*/
 
*/
 
public function checkSchedule() {
 
public function checkSchedule() {
}
+
$ts = date('H:i');
 +
if (in_array($ts, $egSeleniumSchdeule)) {
 +
$ts = date('d M Y').", $ts");
  
/**
+
# Get the last log entry
* Spawn a thread to run a test suite and report if failure
 
*/
 
public function spawnTestRunner() {
 
}
 
  
/**
+
# If tests for this time and day haven't run yet, run them now
* Notify a user about a test failure
+
if ("Last log entry time stamp not equal to current") {
*/
+
$dir = dirname(__FILE__);
public function failureNotification() {
+
$pid = shell_exec("php $dir/runTests.php &");
 +
}
 +
}
 
}
 
}
  

Revision as of 12:24, 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 {

var $testCount = array(); # keep track of number of tests in each suite processed

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;

# The suite being processed is the article title text, keep track of number of tests in it $suite = $parser->mTitle->getPrefixedText(); $this->testCount = array_key_exists($suite, $this->testCount) ? $this->testCount[$suite]++ : 1;

# 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 if more than one test in this suite if ($this->testCount[$suite] > 1) $text .= "";

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

return "

$text

";

}

/** * Check whether any tests should run */ public function checkSchedule() { $ts = date('H:i'); if (in_array($ts, $egSeleniumSchdeule)) { $ts = date('d M Y').", $ts");

# Get the last log entry

# If tests for this time and day haven't run yet, run them now if ("Last log entry time stamp not equal to current") { $dir = dirname(__FILE__); $pid = shell_exec("php $dir/runTests.php &"); } } }

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