Merge "objectcache: add "pcGroup" option to WANObjectCache::getWithSetCallback()"
[lhc/web/wiklou.git] / tests / testHelpers.inc
index 76544a5..1369406 100644 (file)
@@ -44,9 +44,10 @@ interface ITestRecorder {
        /**
         * Called after each test
         * @param string $test
+        * @param integer $subtest
         * @param bool $result
         */
-       public function record( $test, $result );
+       public function record( $test, $subtest, $result );
 
        /**
         * Called before finishing the test run
@@ -74,7 +75,7 @@ class TestRecorder implements ITestRecorder {
                $this->success = 0;
        }
 
-       function record( $test, $result ) {
+       function record( $test, $subtest, $result ) {
                $this->total++;
                $this->success += ( $result ? 1 : 0 );
        }
@@ -147,9 +148,17 @@ class DbTestPreviewer extends TestRecorder {
                $this->results = [];
        }
 
-       function record( $test, $result ) {
-               parent::record( $test, $result );
-               $this->results[$test] = $result;
+       function getName( $test, $subtest ) {
+               if ( $subtest ) {
+                       return "$test subtest #$subtest";
+               } else {
+                       return $test;
+               }
+       }
+
+       function record( $test, $subtest, $result ) {
+               parent::record( $test, $subtest, $result );
+               $this->results[ $this->getName( $test, $subtest ) ] = $result;
        }
 
        function report() {
@@ -299,10 +308,9 @@ class DbTestPreviewer extends TestRecorder {
        }
 
        /**
-        * Commit transaction and clean up for result recording
+        * Close the DB connection
         */
        function end() {
-               $this->lb->commitMasterChanges();
                $this->lb->closeAll();
                parent::end();
        }
@@ -350,17 +358,25 @@ class DbTestRecorder extends DbTestPreviewer {
         * @param string $test
         * @param bool $result
         */
-       function record( $test, $result ) {
-               parent::record( $test, $result );
+       function record( $test, $subtest, $result ) {
+               parent::record( $test, $subtest, $result );
 
                $this->db->insert( 'testitem',
                        [
                                'ti_run' => $this->curRun,
-                               'ti_name' => $test,
+                               'ti_name' => $this->getName( $test, $subtest ),
                                'ti_success' => $result ? 1 : 0,
                        ],
                        __METHOD__ );
        }
+
+       /**
+        * Commit transaction and clean up for result recording
+        */
+       function end() {
+               $this->db->commit( __METHOD__ );
+               parent::end();
+       }
 }
 
 class TestFileIterator implements Iterator {
@@ -479,6 +495,7 @@ class TestFileIterator implements Iterator {
 
                $this->test = [
                        'test' => ParserTest::chomp( $this->sectionData['test'] ),
+                       'subtest' => $this->nextSubTest,
                        'input' => ParserTest::chomp( $this->sectionData[$input] ),
                        'result' => ParserTest::chomp( $this->sectionData[$result] ),
                        'options' => ParserTest::chomp( $this->sectionData['options'] ),
@@ -665,6 +682,27 @@ class TestFileIterator implements Iterator {
        }
 }
 
+/**
+ * An iterator for use as a phpunit data provider. Provides the test arguments
+ * in the order expected by NewParserTest::testParserTest().
+ */
+class TestFileDataProvider extends TestFileIterator {
+       function current() {
+               $test = parent::current();
+               if ( $test ) {
+                       return [
+                               $test['test'],
+                               $test['input'],
+                               $test['result'],
+                               $test['options'],
+                               $test['config'],
+                       ];
+               } else {
+                       return $test;
+               }
+       }
+}
+
 /**
  * A class to delay execution of a parser test hooks.
  */
@@ -799,30 +837,60 @@ class DjVuSupport {
  * Initialize and detect the tidy support
  */
 class TidySupport {
-       private $internalTidy;
-       private $externalTidy;
+       private $enabled;
+       private $config;
 
        /**
         * Determine if there is a usable tidy.
         */
-       public function __construct() {
-               global $wgTidyBin;
-
-               $this->internalTidy = extension_loaded( 'tidy' ) &&
-                       class_exists( 'tidy' ) && !wfIsHHVM();
-
-               $this->externalTidy = is_executable( $wgTidyBin ) ||
-                       Installer::locateExecutableInDefaultPaths( [ $wgTidyBin ] )
-                       !== false;
-       }
-
-       /**
-        * Returns true if we should use internal tidy.
-        *
-        * @return bool
-        */
-       public function isInternal() {
-               return $this->internalTidy;
+       public function __construct( $useConfiguration = false ) {
+               global $IP, $wgUseTidy, $wgTidyBin, $wgTidyInternal, $wgTidyConfig,
+                       $wgTidyConf, $wgTidyOpts;
+
+               $this->enabled = true;
+               if ( $useConfiguration ) {
+                       if ( $wgTidyConfig !== null ) {
+                               $this->config = $wgTidyConfig;
+                       } elseif ( $wgUseTidy ) {
+                               $this->config = [
+                                       'tidyConfigFile' => $wgTidyConf,
+                                       'debugComment' => false,
+                                       'tidyBin' => $wgTidyBin,
+                                       'tidyCommandLine' => $wgTidyOpts
+                               ];
+                               if ( $wgTidyInternal ) {
+                                       $this->config['driver'] = wfIsHHVM() ? 'RaggettInternalHHVM' : 'RaggettInternalPHP';
+                               } else {
+                                       $this->config['driver'] = 'RaggettExternal';
+                               }
+                       } else {
+                               $this->enabled = false;
+                       }
+               } else {
+                       $this->config = [
+                               'tidyConfigFile' => "$IP/includes/tidy/tidy.conf",
+                               'tidyCommandLine' => '',
+                       ];
+                       if ( extension_loaded( 'tidy' ) && class_exists( 'tidy' ) ) {
+                               $this->config['driver'] = wfIsHHVM() ? 'RaggettInternalHHVM' : 'RaggettInternalPHP';
+                       } else {
+                               if ( is_executable( $wgTidyBin ) ) {
+                                       $this->config['driver'] = 'RaggettExternal';
+                                       $this->config['tidyBin'] = $wgTidyBin;
+                               } else {
+                                       $path = Installer::locateExecutableInDefaultPaths( $wgTidyBin );
+                                       if ( $path !== false ) {
+                                               $this->config['driver'] = 'RaggettExternal';
+                                               $this->config['tidyBin'] = $wgTidyBin;
+                                       } else {
+                                               $this->enabled = false;
+                                       }
+                               }
+                       }
+               }
+               if ( !$this->enabled ) {
+                       $this->config = [ 'driver' => 'disabled' ];
+               }
        }
 
        /**
@@ -831,6 +899,10 @@ class TidySupport {
         * @return bool
         */
        public function isEnabled() {
-               return $this->internalTidy || $this->externalTidy;
+               return $this->enabled;
+       }
+
+       public function getConfig() {
+               return $this->config;
        }
 }