Merge "Fixed spacing"
[lhc/web/wiklou.git] / tests / testHelpers.inc
1 <?php
2 /**
3 * Recording for passing/failing tests.
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 * @file
21 * @ingroup Testing
22 */
23
24 /**
25 * Interface to record parser test results.
26 *
27 * The ITestRecorder is a very simple interface to record the result of
28 * MediaWiki parser tests. One should call start() before running the
29 * full parser tests and end() once all the tests have been finished.
30 * After each test, you should use record() to keep track of your tests
31 * results. Finally, report() is used to generate a summary of your
32 * test run, one could dump it to the console for human consumption or
33 * register the result in a database for tracking purposes.
34 *
35 * @since 1.22
36 */
37 interface ITestRecorder {
38
39 /** Called at beginning of the parser test run */
40 public function start();
41
42 /** Called after each test */
43 public function record( $test, $result );
44
45 /** Called before finishing the test run */
46 public function report();
47
48 /** Called at the end of the parser test run */
49 public function end();
50
51 }
52
53 class TestRecorder implements ITestRecorder {
54 public $parent;
55 public $term;
56
57 function __construct( $parent ) {
58 $this->parent = $parent;
59 $this->term = $parent->term;
60 }
61
62 function start() {
63 $this->total = 0;
64 $this->success = 0;
65 }
66
67 function record( $test, $result ) {
68 $this->total++;
69 $this->success += ( $result ? 1 : 0 );
70 }
71
72 function end() {
73 // dummy
74 }
75
76 function report() {
77 if ( $this->total > 0 ) {
78 $this->reportPercentage( $this->success, $this->total );
79 } else {
80 throw new MWException( "No tests found.\n" );
81 }
82 }
83
84 function reportPercentage( $success, $total ) {
85 $ratio = wfPercent( 100 * $success / $total );
86 print $this->term->color( 1 ) . "Passed $success of $total tests ($ratio)... ";
87
88 if ( $success == $total ) {
89 print $this->term->color( 32 ) . "ALL TESTS PASSED!";
90 } else {
91 $failed = $total - $success;
92 print $this->term->color( 31 ) . "$failed tests failed!";
93 }
94
95 print $this->term->reset() . "\n";
96
97 return ( $success == $total );
98 }
99 }
100
101 class DbTestPreviewer extends TestRecorder {
102 protected $lb; // /< Database load balancer
103 protected $db; // /< Database connection to the main DB
104 protected $curRun; // /< run ID number for the current run
105 protected $prevRun; // /< run ID number for the previous run, if any
106 protected $results; // /< Result array
107
108 /**
109 * This should be called before the table prefix is changed
110 */
111 function __construct( $parent ) {
112 parent::__construct( $parent );
113
114 $this->lb = wfGetLBFactory()->newMainLB();
115 // This connection will have the wiki's table prefix, not parsertest_
116 $this->db = $this->lb->getConnection( DB_MASTER );
117 }
118
119 /**
120 * Set up result recording; insert a record for the run with the date
121 * and all that fun stuff
122 */
123 function start() {
124 parent::start();
125
126 if ( !$this->db->tableExists( 'testrun', __METHOD__ )
127 || !$this->db->tableExists( 'testitem', __METHOD__ )
128 ) {
129 print "WARNING> `testrun` table not found in database.\n";
130 $this->prevRun = false;
131 } else {
132 // We'll make comparisons against the previous run later...
133 $this->prevRun = $this->db->selectField( 'testrun', 'MAX(tr_id)' );
134 }
135
136 $this->results = array();
137 }
138
139 function record( $test, $result ) {
140 parent::record( $test, $result );
141 $this->results[$test] = $result;
142 }
143
144 function report() {
145 if ( $this->prevRun ) {
146 // f = fail, p = pass, n = nonexistent
147 // codes show before then after
148 $table = array(
149 'fp' => 'previously failing test(s) now PASSING! :)',
150 'pn' => 'previously PASSING test(s) removed o_O',
151 'np' => 'new PASSING test(s) :)',
152
153 'pf' => 'previously passing test(s) now FAILING! :(',
154 'fn' => 'previously FAILING test(s) removed O_o',
155 'nf' => 'new FAILING test(s) :(',
156 'ff' => 'still FAILING test(s) :(',
157 );
158
159 $prevResults = array();
160
161 $res = $this->db->select( 'testitem', array( 'ti_name', 'ti_success' ),
162 array( 'ti_run' => $this->prevRun ), __METHOD__ );
163
164 foreach ( $res as $row ) {
165 if ( !$this->parent->regex
166 || preg_match( "/{$this->parent->regex}/i", $row->ti_name )
167 ) {
168 $prevResults[$row->ti_name] = $row->ti_success;
169 }
170 }
171
172 $combined = array_keys( $this->results + $prevResults );
173
174 # Determine breakdown by change type
175 $breakdown = array();
176 foreach ( $combined as $test ) {
177 if ( !isset( $prevResults[$test] ) ) {
178 $before = 'n';
179 } elseif ( $prevResults[$test] == 1 ) {
180 $before = 'p';
181 } else /* if ( $prevResults[$test] == 0 )*/ {
182 $before = 'f';
183 }
184
185 if ( !isset( $this->results[$test] ) ) {
186 $after = 'n';
187 } elseif ( $this->results[$test] == 1 ) {
188 $after = 'p';
189 } else /*if ( $this->results[$test] == 0 ) */ {
190 $after = 'f';
191 }
192
193 $code = $before . $after;
194
195 if ( isset( $table[$code] ) ) {
196 $breakdown[$code][$test] = $this->getTestStatusInfo( $test, $after );
197 }
198 }
199
200 # Write out results
201 foreach ( $table as $code => $label ) {
202 if ( !empty( $breakdown[$code] ) ) {
203 $count = count( $breakdown[$code] );
204 printf( "\n%4d %s\n", $count, $label );
205
206 foreach ( $breakdown[$code] as $differing_test_name => $statusInfo ) {
207 print " * $differing_test_name [$statusInfo]\n";
208 }
209 }
210 }
211 } else {
212 print "No previous test runs to compare against.\n";
213 }
214
215 print "\n";
216 parent::report();
217 }
218
219 /**
220 * Returns a string giving information about when a test last had a status change.
221 * Could help to track down when regressions were introduced, as distinct from tests
222 * which have never passed (which are more change requests than regressions).
223 */
224 private function getTestStatusInfo( $testname, $after ) {
225 // If we're looking at a test that has just been removed, then say when it first appeared.
226 if ( $after == 'n' ) {
227 $changedRun = $this->db->selectField( 'testitem',
228 'MIN(ti_run)',
229 array( 'ti_name' => $testname ),
230 __METHOD__ );
231 $appear = $this->db->selectRow( 'testrun',
232 array( 'tr_date', 'tr_mw_version' ),
233 array( 'tr_id' => $changedRun ),
234 __METHOD__ );
235
236 return "First recorded appearance: "
237 . date( "d-M-Y H:i:s", strtotime( $appear->tr_date ) )
238 . ", " . $appear->tr_mw_version;
239 }
240
241 // Otherwise, this test has previous recorded results.
242 // See when this test last had a different result to what we're seeing now.
243 $conds = array(
244 'ti_name' => $testname,
245 'ti_success' => ( $after == 'f' ? "1" : "0" ) );
246
247 if ( $this->curRun ) {
248 $conds[] = "ti_run != " . $this->db->addQuotes( $this->curRun );
249 }
250
251 $changedRun = $this->db->selectField( 'testitem', 'MAX(ti_run)', $conds, __METHOD__ );
252
253 // If no record of ever having had a different result.
254 if ( is_null( $changedRun ) ) {
255 if ( $after == "f" ) {
256 return "Has never passed";
257 } else {
258 return "Has never failed";
259 }
260 }
261
262 // Otherwise, we're looking at a test whose status has changed.
263 // (i.e. it used to work, but now doesn't; or used to fail, but is now fixed.)
264 // In this situation, give as much info as we can as to when it changed status.
265 $pre = $this->db->selectRow( 'testrun',
266 array( 'tr_date', 'tr_mw_version' ),
267 array( 'tr_id' => $changedRun ),
268 __METHOD__ );
269 $post = $this->db->selectRow( 'testrun',
270 array( 'tr_date', 'tr_mw_version' ),
271 array( "tr_id > " . $this->db->addQuotes( $changedRun ) ),
272 __METHOD__,
273 array( "LIMIT" => 1, "ORDER BY" => 'tr_id' )
274 );
275
276 if ( $post ) {
277 $postDate = date( "d-M-Y H:i:s", strtotime( $post->tr_date ) ) . ", {$post->tr_mw_version}";
278 } else {
279 $postDate = 'now';
280 }
281
282 return ( $after == "f" ? "Introduced" : "Fixed" ) . " between "
283 . date( "d-M-Y H:i:s", strtotime( $pre->tr_date ) ) . ", " . $pre->tr_mw_version
284 . " and $postDate";
285 }
286
287 /**
288 * Commit transaction and clean up for result recording
289 */
290 function end() {
291 $this->lb->commitMasterChanges();
292 $this->lb->closeAll();
293 parent::end();
294 }
295 }
296
297 class DbTestRecorder extends DbTestPreviewer {
298 public $version;
299
300 /**
301 * Set up result recording; insert a record for the run with the date
302 * and all that fun stuff
303 */
304 function start() {
305 $this->db->begin( __METHOD__ );
306
307 if ( !$this->db->tableExists( 'testrun' )
308 || !$this->db->tableExists( 'testitem' )
309 ) {
310 print "WARNING> `testrun` table not found in database. Trying to create table.\n";
311 $this->db->sourceFile( $this->db->patchPath( 'patch-testrun.sql' ) );
312 echo "OK, resuming.\n";
313 }
314
315 parent::start();
316
317 $this->db->insert( 'testrun',
318 array(
319 'tr_date' => $this->db->timestamp(),
320 'tr_mw_version' => $this->version,
321 'tr_php_version' => PHP_VERSION,
322 'tr_db_version' => $this->db->getServerVersion(),
323 'tr_uname' => php_uname()
324 ),
325 __METHOD__ );
326 if ( $this->db->getType() === 'postgres' ) {
327 $this->curRun = $this->db->currentSequenceValue( 'testrun_id_seq' );
328 } else {
329 $this->curRun = $this->db->insertId();
330 }
331 }
332
333 /**
334 * Record an individual test item's success or failure to the db
335 *
336 * @param string $test
337 * @param bool $result
338 */
339 function record( $test, $result ) {
340 parent::record( $test, $result );
341
342 $this->db->insert( 'testitem',
343 array(
344 'ti_run' => $this->curRun,
345 'ti_name' => $test,
346 'ti_success' => $result ? 1 : 0,
347 ),
348 __METHOD__ );
349 }
350 }
351
352 class TestFileIterator implements Iterator {
353 private $file;
354 private $fh;
355 /**
356 * @var ParserTest|MediaWikiParserTest An instance of ParserTest (parserTests.php)
357 * or MediaWikiParserTest (phpunit)
358 */
359 private $parserTest;
360 private $index = 0;
361 private $test;
362 private $section = null;
363 /** String|null: current test section being analyzed */
364 private $sectionData = array();
365 private $lineNum;
366 private $eof;
367 # Create a fake parser tests which never run anything unless
368 # asked to do so. This will avoid running hooks for a disabled test
369 private $delayedParserTest;
370 private $nextSubTest = 0;
371
372 function __construct( $file, $parserTest ) {
373 $this->file = $file;
374 $this->fh = fopen( $this->file, "rt" );
375
376 if ( !$this->fh ) {
377 throw new MWException( "Couldn't open file '$file'\n" );
378 }
379
380 $this->parserTest = $parserTest;
381 $this->delayedParserTest = new DelayedParserTest();
382
383 $this->lineNum = $this->index = 0;
384 }
385
386 function rewind() {
387 if ( fseek( $this->fh, 0 ) ) {
388 throw new MWException( "Couldn't fseek to the start of '$this->file'\n" );
389 }
390
391 $this->index = -1;
392 $this->lineNum = 0;
393 $this->eof = false;
394 $this->next();
395
396 return true;
397 }
398
399 function current() {
400 return $this->test;
401 }
402
403 function key() {
404 return $this->index;
405 }
406
407 function next() {
408 if ( $this->readNextTest() ) {
409 $this->index++;
410 return true;
411 } else {
412 $this->eof = true;
413 }
414 }
415
416 function valid() {
417 return $this->eof != true;
418 }
419
420 function setupCurrentTest() {
421 // "input" and "result" are old section names allowed
422 // for backwards-compatibility.
423 $input = $this->checkSection( array( 'wikitext', 'input' ), false );
424 $result = $this->checkSection( array( 'html/php', 'html/*', 'html', 'result' ), false );
425 // some tests have "with tidy" and "without tidy" variants
426 $tidy = $this->checkSection( array( 'html/php+tidy', 'html+tidy' ), false );
427 if ( $tidy != false ) {
428 if ( $this->nextSubTest == 0 ) {
429 if ( $result != false ) {
430 $this->nextSubTest = 1; // rerun non-tidy variant later
431 }
432 $result = $tidy;
433 } else {
434 $this->nextSubTest = 0; // go on to next test after this
435 $tidy = false;
436 }
437 }
438
439 if ( !isset( $this->sectionData['options'] ) ) {
440 $this->sectionData['options'] = '';
441 }
442
443 if ( !isset( $this->sectionData['config'] ) ) {
444 $this->sectionData['config'] = '';
445 }
446
447 $isDisabled = preg_match( '/\\bdisabled\\b/i', $this->sectionData['options'] ) && !$this->parserTest->runDisabled;
448 $isParsoidOnly = preg_match( '/\\bparsoid\\b/i', $this->sectionData['options'] ) && $result == 'html' && !$this->parserTest->runParsoid;
449 $isFiltered = !preg_match( "/" . $this->parserTest->regex . "/i", $this->sectionData['test'] );
450 if ( $input == false || $result == false || $isDisabled || $isParsoidOnly || $isFiltered ) {
451 # disabled test
452 return false;
453 }
454
455 # We are really going to run the test, run pending hooks and hooks function
456 wfDebug( __METHOD__ . " unleashing delayed test for: {$this->sectionData['test']}" );
457 $hooksResult = $this->delayedParserTest->unleash( $this->parserTest );
458 if ( !$hooksResult ) {
459 # Some hook reported an issue. Abort.
460 throw new MWException( "Problem running hook" );
461 }
462
463 $this->test = array(
464 'test' => ParserTest::chomp( $this->sectionData['test'] ),
465 'input' => ParserTest::chomp( $this->sectionData[$input] ),
466 'result' => ParserTest::chomp( $this->sectionData[$result] ),
467 'options' => ParserTest::chomp( $this->sectionData['options'] ),
468 'config' => ParserTest::chomp( $this->sectionData['config'] ),
469 );
470 if ( $tidy != false ) {
471 $this->test['options'] .= " tidy";
472 }
473 return true;
474 }
475
476 function readNextTest() {
477 # Run additional subtests of previous test
478 while ( $this->nextSubTest > 0 ) {
479 if ( $this->setupCurrentTest() ) {
480 return true;
481 }
482 }
483
484 $this->clearSection();
485 # Reset hooks for the delayed test object
486 $this->delayedParserTest->reset();
487
488 while ( false !== ( $line = fgets( $this->fh ) ) ) {
489 $this->lineNum++;
490 $matches = array();
491
492 if ( preg_match( '/^!!\s*(\S+)/', $line, $matches ) ) {
493 $this->section = strtolower( $matches[1] );
494
495 if ( $this->section == 'endarticle' ) {
496 $this->checkSection( 'text' );
497 $this->checkSection( 'article' );
498
499 $this->parserTest->addArticle(
500 ParserTest::chomp( $this->sectionData['article'] ),
501 $this->sectionData['text'], $this->lineNum );
502
503 $this->clearSection();
504
505 continue;
506 }
507
508 if ( $this->section == 'endhooks' ) {
509 $this->checkSection( 'hooks' );
510
511 foreach ( explode( "\n", $this->sectionData['hooks'] ) as $line ) {
512 $line = trim( $line );
513
514 if ( $line ) {
515 $this->delayedParserTest->requireHook( $line );
516 }
517 }
518
519 $this->clearSection();
520
521 continue;
522 }
523
524 if ( $this->section == 'endfunctionhooks' ) {
525 $this->checkSection( 'functionhooks' );
526
527 foreach ( explode( "\n", $this->sectionData['functionhooks'] ) as $line ) {
528 $line = trim( $line );
529
530 if ( $line ) {
531 $this->delayedParserTest->requireFunctionHook( $line );
532 }
533 }
534
535 $this->clearSection();
536
537 continue;
538 }
539
540 if ( $this->section == 'endtransparenthooks' ) {
541 $this->checkSection( 'transparenthooks' );
542
543 foreach ( explode( "\n", $this->sectionData['transparenthooks'] ) as $line ) {
544 $line = trim( $line );
545
546 if ( $line ) {
547 $delayedParserTest->requireTransparentHook( $line );
548 }
549 }
550
551 $this->clearSection();
552
553 continue;
554 }
555
556 if ( $this->section == 'end' ) {
557 $this->checkSection( 'test' );
558 do {
559 if ( $this->setupCurrentTest() ) {
560 return true;
561 }
562 } while ( $this->nextSubTest > 0 );
563 # go on to next test (since this was disabled)
564 $this->clearSection();
565 $this->delayedParserTest->reset();
566 continue;
567 }
568
569 if ( isset( $this->sectionData[$this->section] ) ) {
570 throw new MWException( "duplicate section '$this->section' "
571 . "at line {$this->lineNum} of $this->file\n" );
572 }
573
574 $this->sectionData[$this->section] = '';
575
576 continue;
577 }
578
579 if ( $this->section ) {
580 $this->sectionData[$this->section] .= $line;
581 }
582 }
583
584 return false;
585 }
586
587 /**
588 * Clear section name and its data
589 */
590 private function clearSection() {
591 $this->sectionData = array();
592 $this->section = null;
593
594 }
595
596 /**
597 * Verify the current section data has some value for the given token
598 * name(s) (first parameter).
599 * Throw an exception if it is not set, referencing current section
600 * and adding the current file name and line number
601 *
602 * @param string|array $tokens Expected token(s) that should have been
603 * mentioned before closing this section
604 * @param bool $fatal True iff an exception should be thrown if
605 * the section is not found.
606 */
607 private function checkSection( $tokens, $fatal = true ) {
608 if ( is_null( $this->section ) ) {
609 throw new MWException( __METHOD__ . " can not verify a null section!\n" );
610 }
611 if ( !is_array( $tokens ) ) {
612 $tokens = array( $tokens );
613 }
614 if ( count( $tokens ) == 0 ) {
615 throw new MWException( __METHOD__ . " can not verify zero sections!\n" );
616 }
617
618 $data = $this->sectionData;
619 $tokens = array_filter( $tokens, function ( $token ) use ( $data ) {
620 return isset( $data[$token] );
621 } );
622
623 if ( count( $tokens ) == 0 ) {
624 if ( !$fatal ) {
625 return false;
626 }
627 throw new MWException( sprintf(
628 "'%s' without '%s' at line %s of %s\n",
629 $this->section,
630 implode( ',', $tokens ),
631 $this->lineNum,
632 $this->file
633 ) );
634 }
635 if ( count( $tokens ) > 1 ) {
636 throw new MWException( sprintf(
637 "'%s' with unexpected tokens '%s' at line %s of %s\n",
638 $this->section,
639 implode( ',', $tokens ),
640 $this->lineNum,
641 $this->file
642 ) );
643 }
644
645 $tokens = array_values( $tokens );
646 return $tokens[0];
647 }
648 }
649
650 /**
651 * A class to delay execution of a parser test hooks.
652 */
653 class DelayedParserTest {
654
655 /** Initialized on construction */
656 private $hooks;
657 private $fnHooks;
658 private $transparentHooks;
659
660 public function __construct() {
661 $this->reset();
662 }
663
664 /**
665 * Init/reset or forgot about the current delayed test.
666 * Call to this will erase any hooks function that were pending.
667 */
668 public function reset() {
669 $this->hooks = array();
670 $this->fnHooks = array();
671 $this->transparentHooks = array();
672 }
673
674 /**
675 * Called whenever we actually want to run the hook.
676 * Should be the case if we found the parserTest is not disabled
677 * @param ParserTest|NewParserTest $parserTest
678 */
679 public function unleash( &$parserTest ) {
680 if ( !( $parserTest instanceof ParserTest || $parserTest instanceof NewParserTest ) ) {
681 throw new MWException( __METHOD__ . " must be passed an instance of ParserTest or "
682 . "NewParserTest classes\n" );
683 }
684
685 # Trigger delayed hooks. Any failure will make us abort
686 foreach ( $this->hooks as $hook ) {
687 $ret = $parserTest->requireHook( $hook );
688 if ( !$ret ) {
689 return false;
690 }
691 }
692
693 # Trigger delayed function hooks. Any failure will make us abort
694 foreach ( $this->fnHooks as $fnHook ) {
695 $ret = $parserTest->requireFunctionHook( $fnHook );
696 if ( !$ret ) {
697 return false;
698 }
699 }
700
701 # Trigger delayed transparent hooks. Any failure will make us abort
702 foreach ( $this->transparentHooks as $hook ) {
703 $ret = $parserTest->requireTransparentHook( $hook );
704 if ( !$ret ) {
705 return false;
706 }
707 }
708
709 # Delayed execution was successful.
710 return true;
711 }
712
713 /**
714 * Similar to ParserTest object but does not run anything
715 * Use unleash() to really execute the hook
716 * @param string $hook
717 */
718 public function requireHook( $hook ) {
719 $this->hooks[] = $hook;
720 }
721
722 /**
723 * Similar to ParserTest object but does not run anything
724 * Use unleash() to really execute the hook function
725 * @param string $fnHook
726 */
727 public function requireFunctionHook( $fnHook ) {
728 $this->fnHooks[] = $fnHook;
729 }
730
731 /**
732 * Similar to ParserTest object but does not run anything
733 * Use unleash() to really execute the hook function
734 * @param string $hook
735 */
736 public function requireTransparentHook( $hook ) {
737 $this->transparentHooks[] = $hook;
738 }
739
740 }
741
742 /**
743 * Initialize and detect the DjVu files support
744 */
745 class DjVuSupport {
746
747 /**
748 * Initialises DjVu tools global with default values
749 */
750 public function __construct() {
751 global $wgDjvuRenderer, $wgDjvuDump, $wgDjvuToXML, $wgFileExtensions, $wgDjvuTxt;
752
753 $wgDjvuRenderer = $wgDjvuRenderer ? $wgDjvuRenderer : '/usr/bin/ddjvu';
754 $wgDjvuDump = $wgDjvuDump ? $wgDjvuDump : '/usr/bin/djvudump';
755 $wgDjvuToXML = $wgDjvuToXML ? $wgDjvuToXML : '/usr/bin/djvutoxml';
756 $wgDjvuTxt = $wgDjvuTxt ? $wgDjvuTxt : '/usr/bin/djvutxt';
757
758 if ( !in_array( 'djvu', $wgFileExtensions ) ) {
759 $wgFileExtensions[] = 'djvu';
760 }
761 }
762
763 /**
764 * Returns true if the DjVu tools are usable
765 *
766 * @return bool
767 */
768 public function isEnabled() {
769 global $wgDjvuRenderer, $wgDjvuDump, $wgDjvuToXML, $wgDjvuTxt;
770
771 return is_executable( $wgDjvuRenderer )
772 && is_executable( $wgDjvuDump )
773 && is_executable( $wgDjvuToXML )
774 && is_executable( $wgDjvuTxt );
775 }
776 }
777
778 /**
779 * Initialize and detect the tidy support
780 */
781 class TidySupport {
782 private $internalTidy;
783 private $externalTidy;
784
785 /**
786 * Determine if there is a usable tidy.
787 */
788 public function __construct() {
789 global $wgTidyBin;
790
791 $this->internalTidy = extension_loaded( 'tidy' ) &&
792 class_exists( 'tidy' );
793
794 $this->externalTidy = is_executable( $wgTidyBin ) ||
795 Installer::locateExecutableInDefaultPaths( array( $wgTidyBin ) )
796 !== false;
797 }
798
799 /**
800 * Returns true if we should use internal tidy.
801 *
802 * @return bool
803 */
804 public function isInternal() {
805 return $this->internalTidy;
806 }
807
808 /**
809 * Returns true if tidy is usable
810 *
811 * @return bool
812 */
813 public function isEnabled() {
814 return $this->internalTidy || $this->externalTidy;
815 }
816 }