* Follow-up for r50691, add \n to be safe in case there is line-start sensitive markup
[lhc/web/wiklou.git] / maintenance / parserTests.inc
1 <?php
2 # Copyright (C) 2004 Brion Vibber <brion@pobox.com>
3 # http://www.mediawiki.org/
4 #
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 2 of the License, or
8 # (at your option) any later version.
9 #
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
14 #
15 # You should have received a copy of the GNU General Public License along
16 # with this program; if not, write to the Free Software Foundation, Inc.,
17 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 # http://www.gnu.org/copyleft/gpl.html
19
20 /**
21 * @todo Make this more independent of the configuration (and if possible the database)
22 * @todo document
23 * @file
24 * @ingroup Maintenance
25 */
26
27 /** */
28 $options = array( 'quick', 'color', 'quiet', 'help', 'show-output', 'record' );
29 $optionsWithArgs = array( 'regex', 'seed', 'setversion' );
30
31 require_once( 'commandLine.inc' );
32 require_once( "$IP/maintenance/parserTestsParserHook.php" );
33 require_once( "$IP/maintenance/parserTestsStaticParserHook.php" );
34 require_once( "$IP/maintenance/parserTestsParserTime.php" );
35
36 /**
37 * @ingroup Maintenance
38 */
39 class ParserTest {
40 /**
41 * boolean $color whereas output should be colorized
42 */
43 private $color;
44
45 /**
46 * boolean $showOutput Show test output
47 */
48 private $showOutput;
49
50 /**
51 * boolean $useTemporaryTables Use temporary tables for the temporary database
52 */
53 private $useTemporaryTables = true;
54
55 /**
56 * boolean $databaseSetupDone True if the database has been set up
57 */
58 private $databaseSetupDone = false;
59
60 /**
61 * string $oldTablePrefix Original table prefix
62 */
63 private $oldTablePrefix;
64
65 private $maxFuzzTestLength = 300;
66 private $fuzzSeed = 0;
67 private $memoryLimit = 50;
68
69 /**
70 * Sets terminal colorization and diff/quick modes depending on OS and
71 * command-line options (--color and --quick).
72 */
73 public function ParserTest() {
74 global $options;
75
76 # Only colorize output if stdout is a terminal.
77 $this->color = !wfIsWindows() && posix_isatty(1);
78
79 if( isset( $options['color'] ) ) {
80 switch( $options['color'] ) {
81 case 'no':
82 $this->color = false;
83 break;
84 case 'yes':
85 default:
86 $this->color = true;
87 break;
88 }
89 }
90 $this->term = $this->color
91 ? new AnsiTermColorer()
92 : new DummyTermColorer();
93
94 $this->showDiffs = !isset( $options['quick'] );
95 $this->showProgress = !isset( $options['quiet'] );
96 $this->showFailure = !(
97 isset( $options['quiet'] )
98 && ( isset( $options['record'] )
99 || isset( $options['compare'] ) ) ); // redundant output
100
101 $this->showOutput = isset( $options['show-output'] );
102
103
104 if (isset($options['regex'])) {
105 if ( isset( $options['record'] ) ) {
106 echo "Warning: --record cannot be used with --regex, disabling --record\n";
107 unset( $options['record'] );
108 }
109 $this->regex = $options['regex'];
110 } else {
111 # Matches anything
112 $this->regex = '';
113 }
114
115 if( isset( $options['record'] ) ) {
116 $this->recorder = new DbTestRecorder( $this );
117 } elseif( isset( $options['compare'] ) ) {
118 $this->recorder = new DbTestPreviewer( $this );
119 } else {
120 $this->recorder = new TestRecorder( $this );
121 }
122 $this->keepUploads = isset( $options['keep-uploads'] );
123
124 if ( isset( $options['seed'] ) ) {
125 $this->fuzzSeed = intval( $options['seed'] ) - 1;
126 }
127
128 $this->hooks = array();
129 $this->functionHooks = array();
130 }
131
132 /**
133 * Remove last character if it is a newline
134 */
135 private function chomp($s) {
136 if (substr($s, -1) === "\n") {
137 return substr($s, 0, -1);
138 }
139 else {
140 return $s;
141 }
142 }
143
144 /**
145 * Run a fuzz test series
146 * Draw input from a set of test files
147 */
148 function fuzzTest( $filenames ) {
149 $dict = $this->getFuzzInput( $filenames );
150 $dictSize = strlen( $dict );
151 $logMaxLength = log( $this->maxFuzzTestLength );
152 $this->setupDatabase();
153 ini_set( 'memory_limit', $this->memoryLimit * 1048576 );
154
155 $numTotal = 0;
156 $numSuccess = 0;
157 $user = new User;
158 $opts = ParserOptions::newFromUser( $user );
159 $title = Title::makeTitle( NS_MAIN, 'Parser_test' );
160
161 while ( true ) {
162 // Generate test input
163 mt_srand( ++$this->fuzzSeed );
164 $totalLength = mt_rand( 1, $this->maxFuzzTestLength );
165 $input = '';
166 while ( strlen( $input ) < $totalLength ) {
167 $logHairLength = mt_rand( 0, 1000000 ) / 1000000 * $logMaxLength;
168 $hairLength = min( intval( exp( $logHairLength ) ), $dictSize );
169 $offset = mt_rand( 0, $dictSize - $hairLength );
170 $input .= substr( $dict, $offset, $hairLength );
171 }
172
173 $this->setupGlobals();
174 $parser = $this->getParser();
175 // Run the test
176 try {
177 $parser->parse( $input, $title, $opts );
178 $fail = false;
179 } catch ( Exception $exception ) {
180 $fail = true;
181 }
182
183 if ( $fail ) {
184 echo "Test failed with seed {$this->fuzzSeed}\n";
185 echo "Input:\n";
186 var_dump( $input );
187 echo "\n\n";
188 echo "$exception\n";
189 } else {
190 $numSuccess++;
191 }
192 $numTotal++;
193 $this->teardownGlobals();
194 $parser->__destruct();
195
196 if ( $numTotal % 100 == 0 ) {
197 $usage = intval( memory_get_usage( true ) / $this->memoryLimit / 1048576 * 100 );
198 echo "{$this->fuzzSeed}: $numSuccess/$numTotal (mem: $usage%)\n";
199 if ( $usage > 90 ) {
200 echo "Out of memory:\n";
201 $memStats = $this->getMemoryBreakdown();
202 foreach ( $memStats as $name => $usage ) {
203 echo "$name: $usage\n";
204 }
205 $this->abort();
206 }
207 }
208 }
209 }
210
211 /**
212 * Get an input dictionary from a set of parser test files
213 */
214 function getFuzzInput( $filenames ) {
215 $dict = '';
216 foreach( $filenames as $filename ) {
217 $contents = file_get_contents( $filename );
218 preg_match_all( '/!!\s*input\n(.*?)\n!!\s*result/s', $contents, $matches );
219 foreach ( $matches[1] as $match ) {
220 $dict .= $match . "\n";
221 }
222 }
223 return $dict;
224 }
225
226 /**
227 * Get a memory usage breakdown
228 */
229 function getMemoryBreakdown() {
230 $memStats = array();
231 foreach ( $GLOBALS as $name => $value ) {
232 $memStats['$'.$name] = strlen( serialize( $value ) );
233 }
234 $classes = get_declared_classes();
235 foreach ( $classes as $class ) {
236 $rc = new ReflectionClass( $class );
237 $props = $rc->getStaticProperties();
238 $memStats[$class] = strlen( serialize( $props ) );
239 $methods = $rc->getMethods();
240 foreach ( $methods as $method ) {
241 $memStats[$class] += strlen( serialize( $method->getStaticVariables() ) );
242 }
243 }
244 $functions = get_defined_functions();
245 foreach ( $functions['user'] as $function ) {
246 $rf = new ReflectionFunction( $function );
247 $memStats["$function()"] = strlen( serialize( $rf->getStaticVariables() ) );
248 }
249 asort( $memStats );
250 return $memStats;
251 }
252
253 function abort() {
254 $this->abort();
255 }
256
257 /**
258 * Run a series of tests listed in the given text files.
259 * Each test consists of a brief description, wikitext input,
260 * and the expected HTML output.
261 *
262 * Prints status updates on stdout and counts up the total
263 * number and percentage of passed tests.
264 *
265 * @param array of strings $filenames
266 * @return bool True if passed all tests, false if any tests failed.
267 */
268 public function runTestsFromFiles( $filenames ) {
269 $this->recorder->start();
270 $this->setupDatabase();
271 $ok = true;
272 foreach( $filenames as $filename ) {
273 $ok = $this->runFile( $filename ) && $ok;
274 }
275 $this->teardownDatabase();
276 $this->recorder->report();
277 $this->recorder->end();
278 return $ok;
279 }
280
281 private function runFile( $filename ) {
282 $infile = fopen( $filename, 'rt' );
283 if( !$infile ) {
284 wfDie( "Couldn't open $filename\n" );
285 } else {
286 global $IP;
287 $relative = wfRelativePath( $filename, $IP );
288 $this->showRunFile( $relative );
289 }
290
291 $data = array();
292 $section = null;
293 $n = 0;
294 $ok = true;
295 while( false !== ($line = fgets( $infile ) ) ) {
296 $n++;
297 $matches = array();
298 if( preg_match( '/^!!\s*(\w+)/', $line, $matches ) ) {
299 $section = strtolower( $matches[1] );
300 if( $section == 'endarticle') {
301 if( !isset( $data['text'] ) ) {
302 wfDie( "'endarticle' without 'text' at line $n of $filename\n" );
303 }
304 if( !isset( $data['article'] ) ) {
305 wfDie( "'endarticle' without 'article' at line $n of $filename\n" );
306 }
307 $this->addArticle($this->chomp($data['article']), $this->chomp($data['text']), $n);
308 $data = array();
309 $section = null;
310 continue;
311 }
312 if( $section == 'endhooks' ) {
313 if( !isset( $data['hooks'] ) ) {
314 wfDie( "'endhooks' without 'hooks' at line $n of $filename\n" );
315 }
316 foreach( explode( "\n", $data['hooks'] ) as $line ) {
317 $line = trim( $line );
318 if( $line ) {
319 $this->requireHook( $line );
320 }
321 }
322 $data = array();
323 $section = null;
324 continue;
325 }
326 if( $section == 'endfunctionhooks' ) {
327 if( !isset( $data['functionhooks'] ) ) {
328 wfDie( "'endfunctionhooks' without 'functionhooks' at line $n of $filename\n" );
329 }
330 foreach( explode( "\n", $data['functionhooks'] ) as $line ) {
331 $line = trim( $line );
332 if( $line ) {
333 $this->requireFunctionHook( $line );
334 }
335 }
336 $data = array();
337 $section = null;
338 continue;
339 }
340 if( $section == 'end' ) {
341 if( !isset( $data['test'] ) ) {
342 wfDie( "'end' without 'test' at line $n of $filename\n" );
343 }
344 if( !isset( $data['input'] ) ) {
345 wfDie( "'end' without 'input' at line $n of $filename\n" );
346 }
347 if( !isset( $data['result'] ) ) {
348 wfDie( "'end' without 'result' at line $n of $filename\n" );
349 }
350 if( !isset( $data['options'] ) ) {
351 $data['options'] = '';
352 }
353 else {
354 $data['options'] = $this->chomp( $data['options'] );
355 }
356 if (!isset( $data['config'] ) )
357 $data['config'] = '';
358
359 if (preg_match('/\\bdisabled\\b/i', $data['options'])
360 || !preg_match("/{$this->regex}/i", $data['test'])) {
361 # disabled test
362 $data = array();
363 $section = null;
364 continue;
365 }
366 $result = $this->runTest(
367 $this->chomp( $data['test'] ),
368 $this->chomp( $data['input'] ),
369 $this->chomp( $data['result'] ),
370 $this->chomp( $data['options'] ),
371 $this->chomp( $data['config'] )
372 );
373 $ok = $ok && $result;
374 $this->recorder->record( $this->chomp( $data['test'] ), $result );
375 $data = array();
376 $section = null;
377 continue;
378 }
379 if ( isset ($data[$section] ) ) {
380 wfDie( "duplicate section '$section' at line $n of $filename\n" );
381 }
382 $data[$section] = '';
383 continue;
384 }
385 if( $section ) {
386 $data[$section] .= $line;
387 }
388 }
389 if ( $this->showProgress ) {
390 print "\n";
391 }
392 return $ok;
393 }
394
395 /**
396 * Get a Parser object
397 */
398 function getParser() {
399 global $wgParserConf;
400 $class = $wgParserConf['class'];
401 $parser = new $class( $wgParserConf );
402 foreach( $this->hooks as $tag => $callback ) {
403 $parser->setHook( $tag, $callback );
404 }
405 foreach( $this->functionHooks as $tag => $bits ) {
406 list( $callback, $flags ) = $bits;
407 $parser->setFunctionHook( $tag, $callback, $flags );
408 }
409 wfRunHooks( 'ParserTestParser', array( &$parser ) );
410 return $parser;
411 }
412
413 /**
414 * Run a given wikitext input through a freshly-constructed wiki parser,
415 * and compare the output against the expected results.
416 * Prints status and explanatory messages to stdout.
417 *
418 * @param string $input Wikitext to try rendering
419 * @param string $result Result to output
420 * @return bool
421 */
422 private function runTest( $desc, $input, $result, $opts, $config ) {
423 if( $this->showProgress ) {
424 $this->showTesting( $desc );
425 }
426
427 $this->setupGlobals($opts, $config);
428
429 $user = new User();
430 $options = ParserOptions::newFromUser( $user );
431
432 if (preg_match('/\\bmath\\b/i', $opts)) {
433 # XXX this should probably be done by the ParserOptions
434 $options->setUseTex(true);
435 }
436
437 $m = array();
438 if (preg_match('/title=\[\[(.*)\]\]/', $opts, $m)) {
439 $titleText = $m[1];
440 }
441 else {
442 $titleText = 'Parser test';
443 }
444
445 $noxml = (bool)preg_match( '~\\b noxml \\b~x', $opts );
446 $parser = $this->getParser();
447 $title =& Title::makeTitle( NS_MAIN, $titleText );
448
449 $matches = array();
450 if (preg_match('/\\bpst\\b/i', $opts)) {
451 $out = $parser->preSaveTransform( $input, $title, $user, $options );
452 } elseif (preg_match('/\\bmsg\\b/i', $opts)) {
453 $out = $parser->transformMsg( $input, $options );
454 } elseif( preg_match( '/\\bsection=([\w-]+)\b/i', $opts, $matches ) ) {
455 $section = $matches[1];
456 $out = $parser->getSection( $input, $section );
457 } elseif( preg_match( '/\\breplace=([\w-]+),"(.*?)"/i', $opts, $matches ) ) {
458 $section = $matches[1];
459 $replace = $matches[2];
460 $out = $parser->replaceSection( $input, $section, $replace );
461 } else {
462 $output = $parser->parse( $input, $title, $options, true, true, 1337 );
463 $out = $output->getText();
464
465 if (preg_match('/\\bill\\b/i', $opts)) {
466 $out = $this->tidy( implode( ' ', $output->getLanguageLinks() ) );
467 } else if (preg_match('/\\bcat\\b/i', $opts)) {
468 global $wgOut;
469 $wgOut->addCategoryLinks($output->getCategories());
470 $cats = $wgOut->getCategoryLinks();
471 if ( isset( $cats['normal'] ) ) {
472 $out = $this->tidy( implode( ' ', $cats['normal'] ) );
473 } else {
474 $out = '';
475 }
476 }
477
478 $result = $this->tidy($result);
479 }
480
481 $this->teardownGlobals();
482
483 if( $result === $out && ( $noxml === true || $this->wellFormed( $out ) ) ) {
484 return $this->showSuccess( $desc );
485 } else {
486 return $this->showFailure( $desc, $result, $out );
487 }
488 }
489
490
491 /**
492 * Use a regex to find out the value of an option
493 * @param $regex A regex, the first group will be the value returned
494 * @param $opts Options line to look in
495 * @param $defaults Default value returned if the regex does not match
496 */
497 private static function getOptionValue( $regex, $opts, $default ) {
498 $m = array();
499 if( preg_match( $regex, $opts, $m ) ) {
500 return $m[1];
501 } else {
502 return $default;
503 }
504 }
505
506 /**
507 * Set up the global variables for a consistent environment for each test.
508 * Ideally this should replace the global configuration entirely.
509 */
510 private function setupGlobals($opts = '', $config = '') {
511 if( !isset( $this->uploadDir ) ) {
512 $this->uploadDir = $this->setupUploadDir();
513 }
514
515 # Find out values for some special options.
516 $lang =
517 self::getOptionValue( '/language=([a-z]+(?:_[a-z]+)?)/', $opts, 'en' );
518 $variant =
519 self::getOptionValue( '/variant=([a-z]+(?:-[a-z]+)?)/', $opts, false );
520 $maxtoclevel =
521 self::getOptionValue( '/wgMaxTocLevel=(\d+)/', $opts, 999 );
522 $linkHolderBatchSize =
523 self::getOptionValue( '/wgLinkHolderBatchSize=(\d+)/', $opts, 1000 );
524
525 $settings = array(
526 'wgServer' => 'http://localhost',
527 'wgScript' => '/index.php',
528 'wgScriptPath' => '/',
529 'wgArticlePath' => '/wiki/$1',
530 'wgActionPaths' => array(),
531 'wgLocalFileRepo' => array(
532 'class' => 'LocalRepo',
533 'name' => 'local',
534 'directory' => $this->uploadDir,
535 'url' => 'http://example.com/images',
536 'hashLevels' => 2,
537 'transformVia404' => false,
538 ),
539 'wgEnableUploads' => true,
540 'wgStyleSheetPath' => '/skins',
541 'wgSitename' => 'MediaWiki',
542 'wgServerName' => 'Britney Spears',
543 'wgLanguageCode' => $lang,
544 'wgContLanguageCode' => $lang,
545 'wgDBprefix' => 'parsertest_',
546 'wgRawHtml' => preg_match('/\\brawhtml\\b/i', $opts),
547 'wgLang' => null,
548 'wgContLang' => null,
549 'wgNamespacesWithSubpages' => array( 0 => preg_match('/\\bsubpage\\b/i', $opts)),
550 'wgMaxTocLevel' => $maxtoclevel,
551 'wgCapitalLinks' => true,
552 'wgNoFollowLinks' => true,
553 'wgNoFollowDomainExceptions' => array(),
554 'wgThumbnailScriptPath' => false,
555 'wgUseTeX' => false,
556 'wgLocaltimezone' => 'UTC',
557 'wgAllowExternalImages' => true,
558 'wgUseTidy' => false,
559 'wgDefaultLanguageVariant' => $variant,
560 'wgVariantArticlePath' => false,
561 'wgGroupPermissions' => array( '*' => array(
562 'createaccount' => true,
563 'read' => true,
564 'edit' => true,
565 'createpage' => true,
566 'createtalk' => true,
567 ) ),
568 'wgNamespaceProtection' => array( NS_MEDIAWIKI => 'editinterface' ),
569 'wgDefaultExternalStore' => array(),
570 'wgForeignFileRepos' => array(),
571 'wgLinkHolderBatchSize' => $linkHolderBatchSize,
572 'wgEnforceHtmlIds' => true,
573 'wgExternalLinkTarget' => false,
574 'wgAlwaysUseTidy' => false,
575 'wgSectionContainers' => false,
576 );
577
578 if ($config) {
579 $configLines = explode( "\n", $config );
580
581 foreach( $configLines as $line ) {
582 list( $var, $value ) = explode( '=', $line, 2 );
583
584 $settings[$var] = eval("return $value;" );
585 }
586 }
587
588 $this->savedGlobals = array();
589 foreach( $settings as $var => $val ) {
590 $this->savedGlobals[$var] = $GLOBALS[$var];
591 $GLOBALS[$var] = $val;
592 }
593 $langObj = Language::factory( $lang );
594 $GLOBALS['wgLang'] = $langObj;
595 $GLOBALS['wgContLang'] = $langObj;
596 $GLOBALS['wgMemc'] = new FakeMemCachedClient;
597
598 //$GLOBALS['wgMessageCache'] = new MessageCache( new BagOStuff(), false, 0, $GLOBALS['wgDBname'] );
599
600 global $wgUser;
601 $wgUser = new User();
602 }
603
604 /**
605 * List of temporary tables to create, without prefix.
606 * Some of these probably aren't necessary.
607 */
608 private function listTables() {
609 global $wgDBtype;
610 $tables = array('user', 'page', 'page_restrictions',
611 'protected_titles', 'revision', 'text', 'pagelinks', 'imagelinks',
612 'categorylinks', 'templatelinks', 'externallinks', 'langlinks',
613 'site_stats', 'hitcounter', 'ipblocks', 'image', 'oldimage',
614 'recentchanges', 'watchlist', 'math', 'interwiki',
615 'querycache', 'objectcache', 'job', 'redirect', 'querycachetwo',
616 'archive', 'user_groups', 'page_props', 'category'
617 );
618
619 if ($wgDBtype === 'mysql')
620 array_push( $tables, 'searchindex' );
621
622 // Allow extensions to add to the list of tables to duplicate;
623 // may be necessary if they hook into page save or other code
624 // which will require them while running tests.
625 wfRunHooks( 'ParserTestTables', array( &$tables ) );
626
627 return $tables;
628 }
629
630 /**
631 * Set up a temporary set of wiki tables to work with for the tests.
632 * Currently this will only be done once per run, and any changes to
633 * the db will be visible to later tests in the run.
634 */
635 private function setupDatabase() {
636 global $wgDBprefix, $wgDBtype;
637 if ( $this->databaseSetupDone ) {
638 return;
639 }
640 if ( $wgDBprefix === 'parsertest_' ) {
641 throw new MWException( 'setupDatabase should be called before setupGlobals' );
642 }
643 $this->databaseSetupDone = true;
644 $this->oldTablePrefix = $wgDBprefix;
645
646 # CREATE TEMPORARY TABLE breaks if there is more than one server
647 # FIXME: r40209 makes temporary tables break even with just one server
648 # FIXME: (bug 15892); disabling the feature entirely as a temporary fix
649 if ( true || wfGetLB()->getServerCount() != 1 ) {
650 $this->useTemporaryTables = false;
651 }
652
653 $temporary = $this->useTemporaryTables ? 'TEMPORARY' : '';
654
655 $db = wfGetDB( DB_MASTER );
656 $tables = $this->listTables();
657
658 if ( !( $wgDBtype == 'mysql' && strcmp( $db->getServerVersion(), '4.1' ) < 0 ) ) {
659 # Database that supports CREATE TABLE ... LIKE
660
661 if( $wgDBtype == 'postgres' ) {
662 $def = 'INCLUDING DEFAULTS';
663 $temporary = 'TEMPORARY';
664 } else {
665 $def = '';
666 }
667 foreach ( $tables as $tbl ) {
668 # Clean up from previous aborted run. So that table escaping
669 # works correctly across DB engines, we need to change the pre-
670 # fix back and forth so tableName() works right.
671 $this->changePrefix( $this->oldTablePrefix );
672 $oldTableName = $db->tableName( $tbl );
673 $this->changePrefix( 'parsertest_' );
674 $newTableName = $db->tableName( $tbl );
675
676 if ( $db->tableExists( $tbl ) && $wgDBtype != 'postgres' ) {
677 $db->query( "DROP TABLE $newTableName" );
678 }
679 # Create new table
680 $db->query( "CREATE $temporary TABLE $newTableName (LIKE $oldTableName $def)" );
681 }
682 } else {
683 # Hack for MySQL versions < 4.1, which don't support
684 # "CREATE TABLE ... LIKE". Note that
685 # "CREATE TEMPORARY TABLE ... SELECT * FROM ... LIMIT 0"
686 # would not create the indexes we need....
687 #
688 # Note that we don't bother changing around the prefixes here be-
689 # cause we know we're using MySQL anyway.
690 foreach ($tables as $tbl) {
691 $oldTableName = $db->tableName( $tbl );
692 $res = $db->query("SHOW CREATE TABLE $oldTableName");
693 $row = $db->fetchRow($res);
694 $create = $row[1];
695 $create_tmp = preg_replace('/CREATE TABLE `(.*?)`/',
696 "CREATE $temporary TABLE `parsertest_$tbl`", $create);
697 if ($create === $create_tmp) {
698 # Couldn't do replacement
699 wfDie("could not create temporary table $tbl");
700 }
701 $db->query($create_tmp);
702 }
703 }
704
705 $this->changePrefix( 'parsertest_' );
706
707 # Hack: insert a few Wikipedia in-project interwiki prefixes,
708 # for testing inter-language links
709 $db->insert( 'interwiki', array(
710 array( 'iw_prefix' => 'wikipedia',
711 'iw_url' => 'http://en.wikipedia.org/wiki/$1',
712 'iw_local' => 0 ),
713 array( 'iw_prefix' => 'meatball',
714 'iw_url' => 'http://www.usemod.com/cgi-bin/mb.pl?$1',
715 'iw_local' => 0 ),
716 array( 'iw_prefix' => 'zh',
717 'iw_url' => 'http://zh.wikipedia.org/wiki/$1',
718 'iw_local' => 1 ),
719 array( 'iw_prefix' => 'es',
720 'iw_url' => 'http://es.wikipedia.org/wiki/$1',
721 'iw_local' => 1 ),
722 array( 'iw_prefix' => 'fr',
723 'iw_url' => 'http://fr.wikipedia.org/wiki/$1',
724 'iw_local' => 1 ),
725 array( 'iw_prefix' => 'ru',
726 'iw_url' => 'http://ru.wikipedia.org/wiki/$1',
727 'iw_local' => 1 ),
728 ) );
729
730 # Hack: Insert an image to work with
731 $db->insert( 'image', array(
732 'img_name' => 'Foobar.jpg',
733 'img_size' => 12345,
734 'img_description' => 'Some lame file',
735 'img_user' => 1,
736 'img_user_text' => 'WikiSysop',
737 'img_timestamp' => $db->timestamp( '20010115123500' ),
738 'img_width' => 1941,
739 'img_height' => 220,
740 'img_bits' => 24,
741 'img_media_type' => MEDIATYPE_BITMAP,
742 'img_major_mime' => "image",
743 'img_minor_mime' => "jpeg",
744 'img_metadata' => serialize( array() ),
745 ) );
746
747 # Update certain things in site_stats
748 $db->insert( 'site_stats', array( 'ss_row_id' => 1, 'ss_images' => 1, 'ss_good_articles' => 1 ) );
749 }
750
751 /**
752 * Change the table prefix on all open DB connections/
753 */
754 protected function changePrefix( $prefix ) {
755 global $wgDBprefix;
756 wfGetLBFactory()->forEachLB( array( $this, 'changeLBPrefix' ), array( $prefix ) );
757 $wgDBprefix = $prefix;
758 }
759
760 public function changeLBPrefix( $lb, $prefix ) {
761 $lb->forEachOpenConnection( array( $this, 'changeDBPrefix' ), array( $prefix ) );
762 }
763
764 public function changeDBPrefix( $db, $prefix ) {
765 $db->tablePrefix( $prefix );
766 }
767
768 private function teardownDatabase() {
769 global $wgDBprefix;
770 if ( !$this->databaseSetupDone ) {
771 return;
772 }
773 $this->changePrefix( $this->oldTablePrefix );
774 $this->databaseSetupDone = false;
775 if ( $this->useTemporaryTables ) {
776 # Don't need to do anything
777 return;
778 }
779
780 /*
781 $tables = $this->listTables();
782 $db = wfGetDB( DB_MASTER );
783 foreach ( $tables as $table ) {
784 $db->query( "DROP TABLE `parsertest_$table`" );
785 }*/
786 }
787
788 /**
789 * Create a dummy uploads directory which will contain a couple
790 * of files in order to pass existence tests.
791 * @return string The directory
792 */
793 private function setupUploadDir() {
794 global $IP;
795 if ( $this->keepUploads ) {
796 $dir = wfTempDir() . '/mwParser-images';
797 if ( is_dir( $dir ) ) {
798 return $dir;
799 }
800 } else {
801 $dir = wfTempDir() . "/mwParser-" . mt_rand() . "-images";
802 }
803
804 wfDebug( "Creating upload directory $dir\n" );
805 if ( file_exists( $dir ) ) {
806 wfDebug( "Already exists!\n" );
807 return $dir;
808 }
809 wfMkdirParents( $dir . '/3/3a' );
810 copy( "$IP/skins/monobook/headbg.jpg", "$dir/3/3a/Foobar.jpg" );
811 return $dir;
812 }
813
814 /**
815 * Restore default values and perform any necessary clean-up
816 * after each test runs.
817 */
818 private function teardownGlobals() {
819 RepoGroup::destroySingleton();
820 FileCache::destroySingleton();
821 LinkCache::singleton()->clear();
822 foreach( $this->savedGlobals as $var => $val ) {
823 $GLOBALS[$var] = $val;
824 }
825 if( isset( $this->uploadDir ) ) {
826 $this->teardownUploadDir( $this->uploadDir );
827 unset( $this->uploadDir );
828 }
829 }
830
831 /**
832 * Remove the dummy uploads directory
833 */
834 private function teardownUploadDir( $dir ) {
835 if ( $this->keepUploads ) {
836 return;
837 }
838
839 // delete the files first, then the dirs.
840 self::deleteFiles(
841 array (
842 "$dir/3/3a/Foobar.jpg",
843 "$dir/thumb/3/3a/Foobar.jpg/180px-Foobar.jpg",
844 "$dir/thumb/3/3a/Foobar.jpg/200px-Foobar.jpg",
845 "$dir/thumb/3/3a/Foobar.jpg/640px-Foobar.jpg",
846 "$dir/thumb/3/3a/Foobar.jpg/120px-Foobar.jpg",
847 )
848 );
849
850 self::deleteDirs(
851 array (
852 "$dir/3/3a",
853 "$dir/3",
854 "$dir/thumb/6/65",
855 "$dir/thumb/6",
856 "$dir/thumb/3/3a/Foobar.jpg",
857 "$dir/thumb/3/3a",
858 "$dir/thumb/3",
859 "$dir/thumb",
860 "$dir",
861 )
862 );
863 }
864
865 /**
866 * Delete the specified files, if they exist.
867 * @param array $files full paths to files to delete.
868 */
869 private static function deleteFiles( $files ) {
870 foreach( $files as $file ) {
871 if( file_exists( $file ) ) {
872 unlink( $file );
873 }
874 }
875 }
876
877 /**
878 * Delete the specified directories, if they exist. Must be empty.
879 * @param array $dirs full paths to directories to delete.
880 */
881 private static function deleteDirs( $dirs ) {
882 foreach( $dirs as $dir ) {
883 if( is_dir( $dir ) ) {
884 rmdir( $dir );
885 }
886 }
887 }
888
889 /**
890 * "Running test $desc..."
891 */
892 protected function showTesting( $desc ) {
893 print "Running test $desc... ";
894 }
895
896 /**
897 * Print a happy success message.
898 *
899 * @param string $desc The test name
900 * @return bool
901 */
902 protected function showSuccess( $desc ) {
903 if( $this->showProgress ) {
904 print $this->term->color( '1;32' ) . 'PASSED' . $this->term->reset() . "\n";
905 }
906 return true;
907 }
908
909 /**
910 * Print a failure message and provide some explanatory output
911 * about what went wrong if so configured.
912 *
913 * @param string $desc The test name
914 * @param string $result Expected HTML output
915 * @param string $html Actual HTML output
916 * @return bool
917 */
918 protected function showFailure( $desc, $result, $html ) {
919 if( $this->showFailure ) {
920 if( !$this->showProgress ) {
921 # In quiet mode we didn't show the 'Testing' message before the
922 # test, in case it succeeded. Show it now:
923 $this->showTesting( $desc );
924 }
925 print $this->term->color( '31' ) . 'FAILED!' . $this->term->reset() . "\n";
926 if ( $this->showOutput ) {
927 print "--- Expected ---\n$result\n--- Actual ---\n$html\n";
928 }
929 if( $this->showDiffs ) {
930 print $this->quickDiff( $result, $html );
931 if( !$this->wellFormed( $html ) ) {
932 print "XML error: $this->mXmlError\n";
933 }
934 }
935 }
936 return false;
937 }
938
939 /**
940 * Run given strings through a diff and return the (colorized) output.
941 * Requires writable /tmp directory and a 'diff' command in the PATH.
942 *
943 * @param string $input
944 * @param string $output
945 * @param string $inFileTail Tailing for the input file name
946 * @param string $outFileTail Tailing for the output file name
947 * @return string
948 */
949 protected function quickDiff( $input, $output, $inFileTail='expected', $outFileTail='actual' ) {
950 $prefix = wfTempDir() . "/mwParser-" . mt_rand();
951
952 $infile = "$prefix-$inFileTail";
953 $this->dumpToFile( $input, $infile );
954
955 $outfile = "$prefix-$outFileTail";
956 $this->dumpToFile( $output, $outfile );
957
958 $diff = `diff -au $infile $outfile`;
959 unlink( $infile );
960 unlink( $outfile );
961
962 return $this->colorDiff( $diff );
963 }
964
965 /**
966 * Write the given string to a file, adding a final newline.
967 *
968 * @param string $data
969 * @param string $filename
970 */
971 private function dumpToFile( $data, $filename ) {
972 $file = fopen( $filename, "wt" );
973 fwrite( $file, $data . "\n" );
974 fclose( $file );
975 }
976
977 /**
978 * Colorize unified diff output if set for ANSI color output.
979 * Subtractions are colored blue, additions red.
980 *
981 * @param string $text
982 * @return string
983 */
984 protected function colorDiff( $text ) {
985 return preg_replace(
986 array( '/^(-.*)$/m', '/^(\+.*)$/m' ),
987 array( $this->term->color( 34 ) . '$1' . $this->term->reset(),
988 $this->term->color( 31 ) . '$1' . $this->term->reset() ),
989 $text );
990 }
991
992 /**
993 * Show "Reading tests from ..."
994 *
995 * @param String $path
996 */
997 protected function showRunFile( $path ){
998 print $this->term->color( 1 ) .
999 "Reading tests from \"$path\"..." .
1000 $this->term->reset() .
1001 "\n";
1002 }
1003
1004 /**
1005 * Insert a temporary test article
1006 * @param string $name the title, including any prefix
1007 * @param string $text the article text
1008 * @param int $line the input line number, for reporting errors
1009 */
1010 private function addArticle($name, $text, $line) {
1011 $this->setupGlobals();
1012 $title = Title::newFromText( $name );
1013 if ( is_null($title) ) {
1014 wfDie( "invalid title at line $line\n" );
1015 }
1016
1017 $aid = $title->getArticleID( GAID_FOR_UPDATE );
1018 if ($aid != 0) {
1019 wfDie( "duplicate article at line $line\n" );
1020 }
1021
1022 $art = new Article($title);
1023 $art->insertNewArticle($text, '', false, false );
1024 $this->teardownGlobals();
1025 }
1026
1027 /**
1028 * Steal a callback function from the primary parser, save it for
1029 * application to our scary parser. If the hook is not installed,
1030 * die a painful dead to warn the others.
1031 * @param string $name
1032 */
1033 private function requireHook( $name ) {
1034 global $wgParser;
1035 if( isset( $wgParser->mTagHooks[$name] ) ) {
1036 $this->hooks[$name] = $wgParser->mTagHooks[$name];
1037 } else {
1038 wfDie( "This test suite requires the '$name' hook extension.\n" );
1039 }
1040 }
1041
1042 /**
1043 * Steal a callback function from the primary parser, save it for
1044 * application to our scary parser. If the hook is not installed,
1045 * die a painful dead to warn the others.
1046 * @param string $name
1047 */
1048 private function requireFunctionHook( $name ) {
1049 global $wgParser;
1050 if( isset( $wgParser->mFunctionHooks[$name] ) ) {
1051 $this->functionHooks[$name] = $wgParser->mFunctionHooks[$name];
1052 } else {
1053 wfDie( "This test suite requires the '$name' function hook extension.\n" );
1054 }
1055 }
1056
1057 /*
1058 * Run the "tidy" command on text if the $wgUseTidy
1059 * global is true
1060 *
1061 * @param string $text the text to tidy
1062 * @return string
1063 * @static
1064 */
1065 private function tidy( $text ) {
1066 global $wgUseTidy;
1067 if ($wgUseTidy) {
1068 $text = Parser::tidy($text);
1069 }
1070 return $text;
1071 }
1072
1073 private function wellFormed( $text ) {
1074 $html =
1075 Sanitizer::hackDocType() .
1076 '<html>' .
1077 $text .
1078 '</html>';
1079
1080 $parser = xml_parser_create( "UTF-8" );
1081
1082 # case folding violates XML standard, turn it off
1083 xml_parser_set_option( $parser, XML_OPTION_CASE_FOLDING, false );
1084
1085 if( !xml_parse( $parser, $html, true ) ) {
1086 $err = xml_error_string( xml_get_error_code( $parser ) );
1087 $position = xml_get_current_byte_index( $parser );
1088 $fragment = $this->extractFragment( $html, $position );
1089 $this->mXmlError = "$err at byte $position:\n$fragment";
1090 xml_parser_free( $parser );
1091 return false;
1092 }
1093 xml_parser_free( $parser );
1094 return true;
1095 }
1096
1097 private function extractFragment( $text, $position ) {
1098 $start = max( 0, $position - 10 );
1099 $before = $position - $start;
1100 $fragment = '...' .
1101 $this->term->color( 34 ) .
1102 substr( $text, $start, $before ) .
1103 $this->term->color( 0 ) .
1104 $this->term->color( 31 ) .
1105 $this->term->color( 1 ) .
1106 substr( $text, $position, 1 ) .
1107 $this->term->color( 0 ) .
1108 $this->term->color( 34 ) .
1109 substr( $text, $position + 1, 9 ) .
1110 $this->term->color( 0 ) .
1111 '...';
1112 $display = str_replace( "\n", ' ', $fragment );
1113 $caret = ' ' .
1114 str_repeat( ' ', $before ) .
1115 $this->term->color( 31 ) .
1116 '^' .
1117 $this->term->color( 0 );
1118 return "$display\n$caret";
1119 }
1120 }
1121
1122 class AnsiTermColorer {
1123 function __construct() {
1124 }
1125
1126 /**
1127 * Return ANSI terminal escape code for changing text attribs/color
1128 *
1129 * @param string $color Semicolon-separated list of attribute/color codes
1130 * @return string
1131 */
1132 public function color( $color ) {
1133 global $wgCommandLineDarkBg;
1134 $light = $wgCommandLineDarkBg ? "1;" : "0;";
1135 return "\x1b[{$light}{$color}m";
1136 }
1137
1138 /**
1139 * Return ANSI terminal escape code for restoring default text attributes
1140 *
1141 * @return string
1142 */
1143 public function reset() {
1144 return $this->color( 0 );
1145 }
1146 }
1147
1148 /* A colour-less terminal */
1149 class DummyTermColorer {
1150 public function color( $color ) {
1151 return '';
1152 }
1153
1154 public function reset() {
1155 return '';
1156 }
1157 }
1158
1159 class TestRecorder {
1160 var $parent;
1161 var $term;
1162
1163 function __construct( $parent ) {
1164 $this->parent = $parent;
1165 $this->term = $parent->term;
1166 }
1167
1168 function start() {
1169 $this->total = 0;
1170 $this->success = 0;
1171 }
1172
1173 function record( $test, $result ) {
1174 $this->total++;
1175 $this->success += ($result ? 1 : 0);
1176 }
1177
1178 function end() {
1179 // dummy
1180 }
1181
1182 function report() {
1183 if( $this->total > 0 ) {
1184 $this->reportPercentage( $this->success, $this->total );
1185 } else {
1186 wfDie( "No tests found.\n" );
1187 }
1188 }
1189
1190 function reportPercentage( $success, $total ) {
1191 $ratio = wfPercent( 100 * $success / $total );
1192 print $this->term->color( 1 ) . "Passed $success of $total tests ($ratio)... ";
1193 if( $success == $total ) {
1194 print $this->term->color( 32 ) . "ALL TESTS PASSED!";
1195 } else {
1196 $failed = $total - $success ;
1197 print $this->term->color( 31 ) . "$failed tests failed!";
1198 }
1199 print $this->term->reset() . "\n";
1200 return ($success == $total);
1201 }
1202 }
1203
1204 class DbTestPreviewer extends TestRecorder {
1205 protected $lb; ///< Database load balancer
1206 protected $db; ///< Database connection to the main DB
1207 protected $curRun; ///< run ID number for the current run
1208 protected $prevRun; ///< run ID number for the previous run, if any
1209 protected $results; ///< Result array
1210
1211 /**
1212 * This should be called before the table prefix is changed
1213 */
1214 function __construct( $parent ) {
1215 parent::__construct( $parent );
1216 $this->lb = wfGetLBFactory()->newMainLB();
1217 // This connection will have the wiki's table prefix, not parsertest_
1218 $this->db = $this->lb->getConnection( DB_MASTER );
1219 }
1220
1221 /**
1222 * Set up result recording; insert a record for the run with the date
1223 * and all that fun stuff
1224 */
1225 function start() {
1226 global $wgDBtype, $wgDBprefix;
1227 parent::start();
1228
1229 if( ! $this->db->tableExists( 'testrun' )
1230 or ! $this->db->tableExists( 'testitem' ) )
1231 {
1232 print "WARNING> `testrun` table not found in database.\n";
1233 $this->prevRun = false;
1234 } else {
1235 // We'll make comparisons against the previous run later...
1236 $this->prevRun = $this->db->selectField( 'testrun', 'MAX(tr_id)' );
1237 }
1238 $this->results = array();
1239 }
1240
1241 function record( $test, $result ) {
1242 parent::record( $test, $result );
1243 $this->results[$test] = $result;
1244 }
1245
1246 function report() {
1247 if( $this->prevRun ) {
1248 // f = fail, p = pass, n = nonexistent
1249 // codes show before then after
1250 $table = array(
1251 'fp' => 'previously failing test(s) now PASSING! :)',
1252 'pn' => 'previously PASSING test(s) removed o_O',
1253 'np' => 'new PASSING test(s) :)',
1254
1255 'pf' => 'previously passing test(s) now FAILING! :(',
1256 'fn' => 'previously FAILING test(s) removed O_o',
1257 'nf' => 'new FAILING test(s) :(',
1258 'ff' => 'still FAILING test(s) :(',
1259 );
1260
1261 $prevResults = array();
1262
1263 $res = $this->db->select( 'testitem', array( 'ti_name', 'ti_success' ),
1264 array( 'ti_run' => $this->prevRun ), __METHOD__ );
1265 foreach ( $res as $row ) {
1266 if ( !$this->parent->regex
1267 || preg_match( "/{$this->parent->regex}/i", $row->ti_name ) )
1268 {
1269 $prevResults[$row->ti_name] = $row->ti_success;
1270 }
1271 }
1272
1273 $combined = array_keys( $this->results + $prevResults );
1274
1275 # Determine breakdown by change type
1276 $breakdown = array();
1277 foreach ( $combined as $test ) {
1278 if ( !isset( $prevResults[$test] ) ) {
1279 $before = 'n';
1280 } elseif ( $prevResults[$test] == 1 ) {
1281 $before = 'p';
1282 } else /* if ( $prevResults[$test] == 0 )*/ {
1283 $before = 'f';
1284 }
1285 if ( !isset( $this->results[$test] ) ) {
1286 $after = 'n';
1287 } elseif ( $this->results[$test] == 1 ) {
1288 $after = 'p';
1289 } else /*if ( $this->results[$test] == 0 ) */ {
1290 $after = 'f';
1291 }
1292 $code = $before . $after;
1293 if ( isset( $table[$code] ) ) {
1294 $breakdown[$code][$test] = $this->getTestStatusInfo( $test, $after );
1295 }
1296 }
1297
1298 # Write out results
1299 foreach ( $table as $code => $label ) {
1300 if( !empty( $breakdown[$code] ) ) {
1301 $count = count($breakdown[$code]);
1302 printf( "\n%4d %s\n", $count, $label );
1303 foreach ($breakdown[$code] as $differing_test_name => $statusInfo) {
1304 print " * $differing_test_name [$statusInfo]\n";
1305 }
1306 }
1307 }
1308 } else {
1309 print "No previous test runs to compare against.\n";
1310 }
1311 print "\n";
1312 parent::report();
1313 }
1314
1315 /**
1316 ** Returns a string giving information about when a test last had a status change.
1317 ** Could help to track down when regressions were introduced, as distinct from tests
1318 ** which have never passed (which are more change requests than regressions).
1319 */
1320 private function getTestStatusInfo($testname, $after) {
1321
1322 // If we're looking at a test that has just been removed, then say when it first appeared.
1323 if ( $after == 'n' ) {
1324 $changedRun = $this->db->selectField ( 'testitem',
1325 'MIN(ti_run)',
1326 array( 'ti_name' => $testname ),
1327 __METHOD__ );
1328 $appear = $this->db->selectRow ( 'testrun',
1329 array( 'tr_date', 'tr_mw_version' ),
1330 array( 'tr_id' => $changedRun ),
1331 __METHOD__ );
1332 return "First recorded appearance: "
1333 . date( "d-M-Y H:i:s", strtotime ( $appear->tr_date ) )
1334 . ", " . $appear->tr_mw_version;
1335 }
1336
1337 // Otherwise, this test has previous recorded results.
1338 // See when this test last had a different result to what we're seeing now.
1339 $conds = array(
1340 'ti_name' => $testname,
1341 'ti_success' => ($after == 'f' ? "1" : "0") );
1342 if ( $this->curRun ) {
1343 $conds[] = "ti_run != " . $this->db->addQuotes ( $this->curRun );
1344 }
1345
1346 $changedRun = $this->db->selectField ( 'testitem', 'MAX(ti_run)', $conds, __METHOD__ );
1347
1348 // If no record of ever having had a different result.
1349 if ( is_null ( $changedRun ) ) {
1350 if ($after == "f") {
1351 return "Has never passed";
1352 } else {
1353 return "Has never failed";
1354 }
1355 }
1356
1357 // Otherwise, we're looking at a test whose status has changed.
1358 // (i.e. it used to work, but now doesn't; or used to fail, but is now fixed.)
1359 // In this situation, give as much info as we can as to when it changed status.
1360 $pre = $this->db->selectRow ( 'testrun',
1361 array( 'tr_date', 'tr_mw_version' ),
1362 array( 'tr_id' => $changedRun ),
1363 __METHOD__ );
1364 $post = $this->db->selectRow ( 'testrun',
1365 array( 'tr_date', 'tr_mw_version' ),
1366 array( "tr_id > " . $this->db->addQuotes ( $changedRun) ),
1367 __METHOD__,
1368 array( "LIMIT" => 1, "ORDER BY" => 'tr_id' )
1369 );
1370
1371 if ( $post ) {
1372 $postDate = date( "d-M-Y H:i:s", strtotime ( $post->tr_date ) ) . ", {$post->tr_mw_version}";
1373 } else {
1374 $postDate = 'now';
1375 }
1376 return ( $after == "f" ? "Introduced" : "Fixed" ) . " between "
1377 . date( "d-M-Y H:i:s", strtotime ( $pre->tr_date ) ) . ", " . $pre->tr_mw_version
1378 . " and $postDate";
1379
1380 }
1381
1382 /**
1383 * Commit transaction and clean up for result recording
1384 */
1385 function end() {
1386 $this->lb->commitMasterChanges();
1387 $this->lb->closeAll();
1388 parent::end();
1389 }
1390
1391 }
1392
1393 class DbTestRecorder extends DbTestPreviewer {
1394 /**
1395 * Set up result recording; insert a record for the run with the date
1396 * and all that fun stuff
1397 */
1398 function start() {
1399 global $wgDBtype, $wgDBprefix, $options;
1400 $this->db->begin();
1401
1402 if( ! $this->db->tableExists( 'testrun' )
1403 or ! $this->db->tableExists( 'testitem' ) )
1404 {
1405 print "WARNING> `testrun` table not found in database. Trying to create table.\n";
1406 if ($wgDBtype === 'postgres')
1407 $this->db->sourceFile( dirname(__FILE__) . '/testRunner.postgres.sql' );
1408 else
1409 $this->db->sourceFile( dirname(__FILE__) . '/testRunner.sql' );
1410 echo "OK, resuming.\n";
1411 }
1412
1413 parent::start();
1414
1415 $this->db->insert( 'testrun',
1416 array(
1417 'tr_date' => $this->db->timestamp(),
1418 'tr_mw_version' => isset( $options['setversion'] ) ?
1419 $options['setversion'] : SpecialVersion::getVersion(),
1420 'tr_php_version' => phpversion(),
1421 'tr_db_version' => $this->db->getServerVersion(),
1422 'tr_uname' => php_uname()
1423 ),
1424 __METHOD__ );
1425 if ($wgDBtype === 'postgres')
1426 $this->curRun = $this->db->currentSequenceValue('testrun_id_seq');
1427 else
1428 $this->curRun = $this->db->insertId();
1429 }
1430
1431 /**
1432 * Record an individual test item's success or failure to the db
1433 * @param string $test
1434 * @param bool $result
1435 */
1436 function record( $test, $result ) {
1437 parent::record( $test, $result );
1438 $this->db->insert( 'testitem',
1439 array(
1440 'ti_run' => $this->curRun,
1441 'ti_name' => $test,
1442 'ti_success' => $result ? 1 : 0,
1443 ),
1444 __METHOD__ );
1445 }
1446 }