Difference between revisions of "Selenium.class.php"
(execute runTests.php in background on schedule) |
m |
||
Line 37: | Line 37: | ||
# The suite being processed is the article title text, keep track of number of tests in it | # The suite being processed is the article title text, keep track of number of tests in it | ||
$suite = $parser->mTitle->getPrefixedText(); | $suite = $parser->mTitle->getPrefixedText(); | ||
− | $this->testCount = array_key_exists($suite, $this->testCount) ? $this->testCount[$suite]+ | + | $this->testCount[$suite] = array_key_exists($suite, $this->testCount) ? $this->testCount[$suite]+1 : 1; |
# Get name of test from title tag | # Get name of test from title tag | ||
Line 58: | Line 58: | ||
*/ | */ | ||
public function checkSchedule() { | public function checkSchedule() { | ||
+ | global $egSeleniumSchdeule; | ||
$ts = date('H:i'); | $ts = date('H:i'); | ||
if (in_array($ts, $egSeleniumSchdeule)) { | if (in_array($ts, $egSeleniumSchdeule)) { | ||
− | $ts = date('d M Y').", $ts" | + | $ts = date('d M Y').", $ts"; |
# Get the last log entry | # Get the last log entry |
Revision as of 02:58, 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('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[$suite] = array_key_exists($suite, $this->testCount) ? $this->testCount[$suite]+1 : 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 "
";
}
/** * Check whether any tests should run */ public function checkSchedule() { global $egSeleniumSchdeule; $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__; } }