Selenium.class.php

From Organic Design wiki
Revision as of 12:24, 2 August 2008 by Nad (talk | contribs) (execute runTests.php in background on schedule)

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