+/**
+ ** a test for "Special:Chemicalsources" (extension Special page).
+ */
+class specialChemicalsourcesTest extends pageTest {
+ function __construct() {
+ $this->pagePath = "index.php?title=Special:Chemicalsources";
+
+ // choose an input format to use.
+ $format = wikiFuzz::chooseInput(
+ array( 'go',
+ 'CAS',
+ 'EINECS',
+ 'CHEBI',
+ 'PubChem',
+ 'SMILES',
+ 'InChI',
+ 'ATCCode',
+ 'KEGG',
+ 'RTECS',
+ 'ECNumber',
+ 'DrugBank',
+ 'Formula',
+ 'Name'
+ )
+ );
+
+ // values for different formats usually start with either letters or numbers.
+ switch ($format) {
+ case 'Name' : $value = "A"; break;
+ case 'InChI' :
+ case 'SMILES' :
+ case 'Formula': $value = "C"; break;
+ default : $value = "0"; break;
+ }
+
+ // and then we append the fuzz input.
+ $this->params = array ($format => $value . wikifuzz::makeFuzz(2) );
+ }
+}
+
+
+/**
+ ** A test for api.php (programmatic interface to MediaWiki in XML/JSON/RSS/etc formats).
+ ** Quite involved to test because there are lots of options/parameters, and because
+ ** for a lot of the functionality if all the parameters don't make sense then it just
+ ** returns the help screen - so currently a lot of the tests aren't actually doing much
+ ** because something wasn't right in the query.
+ **
+ ** @todo: Incomplete / unfinished; Runs too fast (suggests not much testing going on).
+ */
+class api extends pageTest {
+
+ // API login mode.
+ private static function loginMode() {
+ $arr = array ( "lgname" => wikifuzz::makeFuzz(2),
+ "lgpassword" => wikifuzz::makeFuzz(2),
+ );
+ // sometimes we want to specify the extra "lgdomain" parameter.
+ if (wikiFuzz::randnum(3) == 0) {
+ $arr["lgdomain"] = wikiFuzz::chooseInput( array("1", 0, "", wikiFuzz::makeFuzz(2)) );
+ }
+
+ return $arr;
+ }
+
+ // API OpenSearch mode.
+ private static function opensearchMode() {
+ return array ("search" => wikifuzz::makeFuzz(2));
+ }
+
+ // API watchlist feed mode.
+ private static function feedwatchlistMode() {
+ // FIXME: add "wikifuzz::makeFuzz(2)" as possible value below?
+ return array ("feedformat" => wikiFuzz::chooseInput( array("rss", "atom") ) );
+ }
+
+ // API query mode.
+ private static function queryMode() {
+ // FIXME: add "wikifuzz::makeFuzz(2)" as possible params for the elements below?
+ // Suspect this will stuff up the tests more, but need to check.
+ $params = array (
+ // FIXME: More titles.
+ "titles" => wikiFuzz::chooseInput( array("Main Page")),
+ // FIXME: More pageids.
+ "pageids" => 1,
+ "prop" => wikiFuzz::chooseInput( array("info", "revisions", "watchlist")),
+ "list" => wikiFuzz::chooseInput( array("allpages", "logevents", "watchlist", "usercontribs", "recentchanges", "backlinks", "embeddedin", "imagelinks") ),
+ "meta" => wikiFuzz::chooseInput( array("siteinfo")),
+ "generator" => wikiFuzz::chooseInput( array("allpages", "logevents", "watchlist", "info", "revisions") ),
+ "siprop" => wikiFuzz::chooseInput( array("general", "namespaces", "general|namespaces") ),
+ );
+
+ // Add extra parameters based on what list choice we got.
+ switch ($params["list"]) {
+ case "usercontribs" : self::addListParams ($params, "uc", array("limit", "start", "end", "user", "dir") ); break;
+ case "allpages" : self::addListParams ($params, "ap", array("from", "prefix", "namespace", "filterredir", "limit") ); break;
+ case "watchlist" : self::addListParams ($params, "wl", array("allrev", "start", "end", "namespace", "dir", "limit", "prop") ); break;
+ case "logevents" : self::addListParams ($params, "le", array("limit", "type", "start", "end", "user", "dir") ); break;
+ case "recentchanges": self::addListParams ($params, "rc", array("limit", "prop", "show", "namespace", "start", "end", "dir") ); break;
+ case "backlinks" : self::addListParams ($params, "bl", array("continue", "namespace", "redirect", "limit") ); break;
+ case "embeddedin" : self::addListParams ($params, "ei", array("continue", "namespace", "redirect", "limit") ); break;
+ case "imagelinks" : self::addListParams ($params, "il", array("continue", "namespace", "redirect", "limit") ); break;
+ }
+
+ if ($params["prop"] == "revisions") {
+ self::addListParams ($params, "rv", array("prop", "limit", "startid", "endid", "end", "dir") );
+ }
+
+ // Sometimes we want redirects, sometimes we don't.
+ if (wikiFuzz::randnum(3) == 0) {
+ $params["redirects"] = wikiFuzz::chooseInput( array("1", 0, "", wikiFuzz::makeFuzz(2)) );
+ }
+
+ return $params;
+ }
+
+ // Adds all the elements to the array, using the specified prefix.
+ private static function addListParams(&$array, $prefix, $elements) {
+ foreach ($elements as $element) {
+ $array[$prefix . $element] = self::getParamDetails($element);
+ }
+ }
+
+ // For a given element name, returns the data for that element.
+ private static function getParamDetails($element) {
+ switch ($element) {
+ case 'startid' :
+ case 'endid' :
+ case 'start' :
+ case 'end' :
+ case 'limit' : return wikiFuzz::chooseInput( array("0", "-1", "---'----------0", "+1", "8134", "320742734234235", "20060230121212", wikiFuzz::randnum(9000, -100), wikiFuzz::makeFuzz(2)) );
+ case 'dir' : return wikiFuzz::chooseInput( array("newer", "older", wikifuzz::makeFuzz(2) ) );
+ case 'user' : return wikiFuzz::chooseInput( array(USER_ON_WIKI, wikifuzz::makeFuzz(2) ) );
+ case 'namespace' : return wikiFuzz::chooseInput( array(-2, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 200000, wikifuzz::makeFuzz(2)) );
+ case 'filterredir': return wikiFuzz::chooseInput( array("all", "redirects", "nonredirectsallpages", wikifuzz::makeFuzz(2)) );
+ case 'allrev' : return wikiFuzz::chooseInput( array("1", 0, "", wikiFuzz::makeFuzz(2)) );
+ case 'prop' : return wikiFuzz::chooseInput( array("user", "comment", "timestamp", "patrol", "flags", "user|user|comment|flags", wikifuzz::makeFuzz(2) ) );
+ case 'type' : return wikiFuzz::chooseInput( array("block", "protect", "rights", "delete", "upload", "move", "import", "renameuser", "newusers", "makebot", wikifuzz::makeFuzz(2) ) );
+ case 'hide' : return wikiFuzz::chooseInput( array("minor", "bots", "anons", "liu", "liu|bots|", wikifuzz::makeFuzz(2) ) );
+ case 'show' : return wikiFuzz::chooseInput( array('minor', '!minor', 'bot', '!bot', 'anon', '!anon', wikifuzz::makeFuzz(2) ) );
+ default : return wikifuzz::makeFuzz(2);
+ }
+ }
+
+ // Entry point.
+ function __construct() {
+ $this->pagePath = "api.php";
+
+ $modes = array ("help",
+ "login",
+ "opensearch",
+ "feedwatchlist",
+ "query");
+ $action = wikiFuzz::chooseInput( array_merge ($modes, array(wikifuzz::makeFuzz(2))) );
+
+ switch ($action) {
+ case "login" : $this->params = self::loginMode();
+ break;
+ case "opensearch" : $this->params = self::opensearchMode();
+ break;
+ case "feedwatchlist" : $this->params = self::feedwatchlistMode();
+ break;
+ case "query" : $this->params = self::queryMode();
+ break;
+ case "help" :
+ default : // Do something random - "Crazy Ivan" mode.
+ $random_mode = wikiFuzz::chooseInput( $modes ) . "Mode";
+ // There is no "helpMode".
+ if ($random_mode == "helpMode") $random_mode = "queryMode";
+ $this->params = self::$random_mode();
+ break;
+ }
+
+ // Save the selected action.
+ $this->params["action"] = $action;
+
+ // Set the cookie:
+ // FIXME: need to get this cookie dynamically set, rather than hard-coded.
+ $this->cookie = "wikidbUserID=10001; wikidbUserName=Test; wikidb_session=178df0fe68c75834643af65dec9ec98a; wikidbToken=1adc6753d62c44aec950c024d7ae0540";
+
+ // Output format
+ $this->params["format"] = wikiFuzz::chooseInput( array("json", "jsonfm", "php", "phpfm",
+ "wddx", "wddxfm", "xml", "xmlfm",
+ "yaml", "yamlfm", "raw", "rawfm",
+ wikifuzz::makeFuzz(2) ) );
+
+ // Page does not produce HTML (sometimes).
+ $this->tidyValidate = false;
+ }
+}
+
+
+/**
+ ** a page test for the GeSHi extension.
+ */
+class GeSHi_Test extends pageTest {
+
+ private function getGeSHiContent() {
+ return "<source lang=\"" . $this->getLang() . "\" "
+ . (wikiFuzz::randnum(2) == 0 ? "line " : "")
+ . (wikiFuzz::randnum(2) == 0 ? "strict " : "")
+ . "start=" . wikiFuzz::chooseInput( array(wikiFuzz::randnum(-6000,6000), wikifuzz::makeFuzz(2)) )
+ . ">"
+ . wikiFuzz::makeFuzz(2)
+ . "</source>";
+ }
+
+ private function getLang() {
+ return wikiFuzz::chooseInput( array( "actionscript", "ada", "apache", "applescript", "asm", "asp", "autoit", "bash", "blitzbasic", "bnf", "c", "c_mac", "caddcl", "cadlisp", "cfdg", "cfm", "cpp", "cpp-qt",
+ "csharp", "css", "d", "delphi", "diff", "div", "dos", "eiffel", "fortran", "freebasic", "gml", "groovy", "html4strict", "idl", "ini", "inno", "io", "java", "java5",
+ "javascript", "latex", "lisp", "lua", "matlab", "mirc", "mpasm", "mysql", "nsis", "objc", "ocaml", "ocaml-brief", "oobas", "oracle8", "pascal", "perl", "php",
+ "php-brief", "plsql", "python", "qbasic", "rails", "reg", "robots", "ruby", "sas", "scheme", "sdlbasic", "smalltalk", "smarty", "sql", "tcl", "text", "thinbasic",
+ "tsql", "vb", "vbnet", "vhdl", "visualfoxpro", "winbatch", "xml", "xpp", "z80", wikifuzz::makeFuzz(1) ) );
+ }
+
+ function __construct() {
+ $this->pagePath = "index.php?title=WIKIFUZZ";
+
+ $this->params = array (
+ "action" => "submit",
+ "wpMinoredit" => "test",
+ "wpPreview" => "test",
+ "wpSection" => "test",
+ "wpEdittime" => "test",
+ "wpSummary" => "test",
+ "wpScrolltop" => "test",
+ "wpStarttime" => "test",
+ "wpAutoSummary" => "test",
+ "wpTextbox1" => $this->getGeSHiContent() // the main wiki text, contains fake GeSHi content.
+ );
+ }
+}
+