diff options
Diffstat (limited to 'tests/phpunit/suites')
-rw-r--r-- | tests/phpunit/suites/ExtensionsParserTestSuite.php | 8 | ||||
-rw-r--r-- | tests/phpunit/suites/ExtensionsTestSuite.php | 47 | ||||
-rw-r--r-- | tests/phpunit/suites/LessTestSuite.php | 34 | ||||
-rw-r--r-- | tests/phpunit/suites/UploadFromUrlTestSuite.php | 207 |
4 files changed, 296 insertions, 0 deletions
diff --git a/tests/phpunit/suites/ExtensionsParserTestSuite.php b/tests/phpunit/suites/ExtensionsParserTestSuite.php new file mode 100644 index 00000000..3d68b241 --- /dev/null +++ b/tests/phpunit/suites/ExtensionsParserTestSuite.php @@ -0,0 +1,8 @@ +<?php +class ExtensionsParserTestSuite extends PHPUnit_Framework_TestSuite { + + public static function suite() { + return MediaWikiParserTest::suite( MediaWikiParserTest::NO_CORE ); + } + +} diff --git a/tests/phpunit/suites/ExtensionsTestSuite.php b/tests/phpunit/suites/ExtensionsTestSuite.php new file mode 100644 index 00000000..116065f8 --- /dev/null +++ b/tests/phpunit/suites/ExtensionsTestSuite.php @@ -0,0 +1,47 @@ +<?php +/** + * This test suite runs unit tests registered by extensions. + * See https://www.mediawiki.org/wiki/Manual:Hooks/UnitTestsList for details of + * how to register your tests. + */ + +class ExtensionsTestSuite extends PHPUnit_Framework_TestSuite { + public function __construct() { + parent::__construct(); + $paths = array(); + // Extensions can return a list of files or directories + wfRunHooks( 'UnitTestsList', array( &$paths ) ); + foreach ( $paths as $path ) { + if ( is_dir( $path ) ) { + // If the path is a directory, search for test cases. + // @since 1.24 + $suffixes = array( + 'Test.php', + ); + $fileIterator = new File_Iterator_Facade(); + $matchingFiles = $fileIterator->getFilesAsArray( $path, $suffixes ); + $this->addTestFiles( $matchingFiles ); + } else { + // Add a single test case or suite class + $this->addTestFile( $path ); + } + } + if ( !count( $paths ) ) { + $this->addTest( new DummyExtensionsTest( 'testNothing' ) ); + } + } + + public static function suite() { + return new self; + } +} + +/** + * Needed to avoid warnings like 'No tests found in class "ExtensionsTestSuite".' + * when no extensions with tests are used. + */ +class DummyExtensionsTest extends MediaWikiTestCase { + public function testNothing() { + $this->assertTrue( true ); + } +} diff --git a/tests/phpunit/suites/LessTestSuite.php b/tests/phpunit/suites/LessTestSuite.php new file mode 100644 index 00000000..26a784ad --- /dev/null +++ b/tests/phpunit/suites/LessTestSuite.php @@ -0,0 +1,34 @@ +<?php + +/** + * @author Sam Smith <samsmith@wikimedia.org> + */ +class LessTestSuite extends PHPUnit_Framework_TestSuite { + public function __construct() { + parent::__construct(); + + $resourceLoader = new ResourceLoader(); + + foreach ( $resourceLoader->getModuleNames() as $name ) { + $module = $resourceLoader->getModule( $name ); + if ( !$module || !$module instanceof ResourceLoaderFileModule ) { + continue; + } + + foreach ( $module->getAllStyleFiles() as $styleFile ) { + // TODO (phuedx, 2014-03-19) The + // ResourceLoaderFileModule class shouldn't + // know how to get a file's extension. + if ( $module->getStyleSheetLang( $styleFile ) !== 'less' ) { + continue; + } + + $this->addTest( new LessFileCompilationTest( $styleFile, $module ) ); + } + } + } + + public static function suite() { + return new static; + } +} diff --git a/tests/phpunit/suites/UploadFromUrlTestSuite.php b/tests/phpunit/suites/UploadFromUrlTestSuite.php new file mode 100644 index 00000000..d4a7bd36 --- /dev/null +++ b/tests/phpunit/suites/UploadFromUrlTestSuite.php @@ -0,0 +1,207 @@ +<?php + +require_once dirname( __DIR__ ) . '/includes/upload/UploadFromUrlTest.php'; + +class UploadFromUrlTestSuite extends PHPUnit_Framework_TestSuite { + public $savedGlobals = array(); + + public static function addTables( &$tables ) { + $tables[] = 'user_properties'; + $tables[] = 'filearchive'; + $tables[] = 'logging'; + $tables[] = 'updatelog'; + $tables[] = 'iwlinks'; + + return true; + } + + protected function setUp() { + global $wgParser, $wgParserConf, $IP, $messageMemc, $wgMemc, $wgUser, + $wgLang, $wgOut, $wgRequest, $wgStyleDirectory, + $wgEnableParserCache, $wgNamespaceAliases, $wgNamespaceProtection, + $parserMemc; + + $tmpGlobals = array(); + + $tmpGlobals['wgScript'] = '/index.php'; + $tmpGlobals['wgScriptPath'] = '/'; + $tmpGlobals['wgArticlePath'] = '/wiki/$1'; + $tmpGlobals['wgStylePath'] = '/skins'; + $tmpGlobals['wgThumbnailScriptPath'] = false; + $tmpGlobals['wgLocalFileRepo'] = array( + 'class' => 'LocalRepo', + 'name' => 'local', + 'url' => 'http://example.com/images', + 'hashLevels' => 2, + 'transformVia404' => false, + 'backend' => new FSFileBackend( array( + 'name' => 'local-backend', + 'wikiId' => wfWikiId(), + 'containerPaths' => array( + 'local-public' => wfTempDir() . '/test-repo/public', + 'local-thumb' => wfTempDir() . '/test-repo/thumb', + 'local-temp' => wfTempDir() . '/test-repo/temp', + 'local-deleted' => wfTempDir() . '/test-repo/delete', + ) + ) ), + ); + foreach ( $tmpGlobals as $var => $val ) { + if ( array_key_exists( $var, $GLOBALS ) ) { + $this->savedGlobals[$var] = $GLOBALS[$var]; + } + $GLOBALS[$var] = $val; + } + + $wgNamespaceProtection[NS_MEDIAWIKI] = 'editinterface'; + $wgNamespaceAliases['Image'] = NS_FILE; + $wgNamespaceAliases['Image_talk'] = NS_FILE_TALK; + + $wgEnableParserCache = false; + DeferredUpdates::clearPendingUpdates(); + $wgMemc = wfGetMainCache(); + $messageMemc = wfGetMessageCacheStorage(); + $parserMemc = wfGetParserCacheStorage(); + + $wgUser = new User; + $context = new RequestContext; + $wgLang = $context->getLanguage(); + $wgOut = $context->getOutput(); + $wgParser = new StubObject( 'wgParser', $wgParserConf['class'], array( $wgParserConf ) ); + $wgRequest = $context->getRequest(); + + if ( $wgStyleDirectory === false ) { + $wgStyleDirectory = "$IP/skins"; + } + + RepoGroup::destroySingleton(); + FileBackendGroup::destroySingleton(); + } + + protected function tearDown() { + foreach ( $this->savedGlobals as $var => $val ) { + $GLOBALS[$var] = $val; + } + // Restore backends + RepoGroup::destroySingleton(); + FileBackendGroup::destroySingleton(); + + $this->teardownUploadDir( $this->uploadDir ); + + parent::tearDown(); + } + + private $uploadDir; + private $keepUploads; + + /** + * Remove the dummy uploads directory + * @param string $dir + */ + private function teardownUploadDir( $dir ) { + if ( $this->keepUploads ) { + return; + } + + // delete the files first, then the dirs. + self::deleteFiles( + array( + "$dir/3/3a/Foobar.jpg", + "$dir/thumb/3/3a/Foobar.jpg/180px-Foobar.jpg", + "$dir/thumb/3/3a/Foobar.jpg/200px-Foobar.jpg", + "$dir/thumb/3/3a/Foobar.jpg/640px-Foobar.jpg", + "$dir/thumb/3/3a/Foobar.jpg/120px-Foobar.jpg", + + "$dir/0/09/Bad.jpg", + ) + ); + + self::deleteDirs( + array( + "$dir/3/3a", + "$dir/3", + "$dir/thumb/6/65", + "$dir/thumb/6", + "$dir/thumb/3/3a/Foobar.jpg", + "$dir/thumb/3/3a", + "$dir/thumb/3", + + "$dir/0/09/", + "$dir/0/", + + "$dir/thumb", + "$dir", + ) + ); + } + + /** + * Delete the specified files, if they exist. + * + * @param array $files Full paths to files to delete. + */ + private static function deleteFiles( $files ) { + foreach ( $files as $file ) { + if ( file_exists( $file ) ) { + unlink( $file ); + } + } + } + + /** + * Delete the specified directories, if they exist. Must be empty. + * + * @param array $dirs Full paths to directories to delete. + */ + private static function deleteDirs( $dirs ) { + foreach ( $dirs as $dir ) { + if ( is_dir( $dir ) ) { + rmdir( $dir ); + } + } + } + + /** + * Create a dummy uploads directory which will contain a couple + * of files in order to pass existence tests. + * + * @return string The directory + */ + private function setupUploadDir() { + global $IP; + + if ( $this->keepUploads ) { + $dir = wfTempDir() . '/mwParser-images'; + + if ( is_dir( $dir ) ) { + return $dir; + } + } else { + $dir = wfTempDir() . "/mwParser-" . mt_rand() . "-images"; + } + + wfDebug( "Creating upload directory $dir\n" ); + + if ( file_exists( $dir ) ) { + wfDebug( "Already exists!\n" ); + + return $dir; + } + + wfMkdirParents( $dir . '/3/3a', null, __METHOD__ ); + copy( "$IP/tests/phpunit/data/upload/headbg.jpg", "$dir/3/3a/Foobar.jpg" ); + + wfMkdirParents( $dir . '/0/09', null, __METHOD__ ); + copy( "$IP/tests/phpunit/data/upload/headbg.jpg", "$dir/0/09/Bad.jpg" ); + + return $dir; + } + + public static function suite() { + // Hack to invoke the autoloader required to get phpunit to recognize + // the UploadFromUrlTest class + class_exists( 'UploadFromUrlTest' ); + $suite = new UploadFromUrlTestSuite( 'UploadFromUrlTest' ); + + return $suite; + } +} |