Merge "Produce RDF dump of all categories and subcategories in a wiki."
[lhc/web/wiklou.git] / tests / phpunit / MediaWikiTestCase.php
index 6a1f4b5..ed1f1ae 100644 (file)
@@ -1845,4 +1845,29 @@ abstract class MediaWikiTestCase extends PHPUnit_Framework_TestCase {
                $this->mergeMwGlobalArrayValue( 'wgHooks', [ $hookName => [ $handler ] ] );
        }
 
+       /**
+        * Check whether file contains given data.
+        * @param string $fileName
+        * @param string $actualData
+        * @param bool $createIfMissing If true, and file does not exist, create it with given data
+        *                              and skip the test.
+        * @param string $msg
+        * @since 1.30
+        */
+       protected function assertFileContains(
+               $fileName,
+               $actualData,
+               $createIfMissing = true,
+               $msg = ''
+       ) {
+               if ( $createIfMissing ) {
+                       if ( !file_exists( $fileName ) ) {
+                               file_put_contents( $fileName, $actualData );
+                               $this->markTestSkipped( 'Data file $fileName does not exist' );
+                       }
+               } else {
+                       self::assertFileExists( $fileName );
+               }
+               self::assertEquals( file_get_contents( $fileName ), $actualData, $msg );
+       }
 }