UploadFromUrlTestSuite.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. <?php
  2. require_once dirname( __DIR__ ) . '/includes/upload/UploadFromUrlTest.php';
  3. class UploadFromUrlTestSuite extends PHPUnit_Framework_TestSuite {
  4. public $savedGlobals = [];
  5. public static function addTables( &$tables ) {
  6. $tables[] = 'user_properties';
  7. $tables[] = 'filearchive';
  8. $tables[] = 'logging';
  9. $tables[] = 'updatelog';
  10. $tables[] = 'iwlinks';
  11. return true;
  12. }
  13. protected function setUp() {
  14. global $wgParser, $wgParserConf, $IP, $messageMemc, $wgMemc, $wgUser,
  15. $wgLang, $wgOut, $wgRequest, $wgStyleDirectory,
  16. $wgParserCacheType, $wgNamespaceAliases, $wgNamespaceProtection;
  17. $tmpDir = $this->getNewTempDirectory();
  18. $tmpGlobals = [];
  19. $tmpGlobals['wgScript'] = '/index.php';
  20. $tmpGlobals['wgScriptPath'] = '/';
  21. $tmpGlobals['wgArticlePath'] = '/wiki/$1';
  22. $tmpGlobals['wgStylePath'] = '/skins';
  23. $tmpGlobals['wgThumbnailScriptPath'] = false;
  24. $tmpGlobals['wgLocalFileRepo'] = [
  25. 'class' => LocalRepo::class,
  26. 'name' => 'local',
  27. 'url' => 'http://example.com/images',
  28. 'hashLevels' => 2,
  29. 'transformVia404' => false,
  30. 'backend' => new FSFileBackend( [
  31. 'name' => 'local-backend',
  32. 'wikiId' => wfWikiID(),
  33. 'containerPaths' => [
  34. 'local-public' => "{$tmpDir}/test-repo/public",
  35. 'local-thumb' => "{$tmpDir}/test-repo/thumb",
  36. 'local-temp' => "{$tmpDir}/test-repo/temp",
  37. 'local-deleted' => "{$tmpDir}/test-repo/delete",
  38. ]
  39. ] ),
  40. ];
  41. foreach ( $tmpGlobals as $var => $val ) {
  42. if ( array_key_exists( $var, $GLOBALS ) ) {
  43. $this->savedGlobals[$var] = $GLOBALS[$var];
  44. }
  45. $GLOBALS[$var] = $val;
  46. }
  47. $wgNamespaceProtection[NS_MEDIAWIKI] = 'editinterface';
  48. $wgNamespaceAliases['Image'] = NS_FILE;
  49. $wgNamespaceAliases['Image_talk'] = NS_FILE_TALK;
  50. $wgParserCacheType = CACHE_NONE;
  51. DeferredUpdates::clearPendingUpdates();
  52. $wgMemc = wfGetMainCache();
  53. $messageMemc = wfGetMessageCacheStorage();
  54. RequestContext::resetMain();
  55. $context = RequestContext::getMain();
  56. $wgUser = new User;
  57. $wgLang = $context->getLanguage();
  58. $wgOut = $context->getOutput();
  59. $wgParser = new StubObject( 'wgParser', $wgParserConf['class'], [ $wgParserConf ] );
  60. $wgRequest = $context->getRequest();
  61. if ( $wgStyleDirectory === false ) {
  62. $wgStyleDirectory = "$IP/skins";
  63. }
  64. RepoGroup::destroySingleton();
  65. FileBackendGroup::destroySingleton();
  66. }
  67. protected function tearDown() {
  68. foreach ( $this->savedGlobals as $var => $val ) {
  69. $GLOBALS[$var] = $val;
  70. }
  71. // Restore backends
  72. RepoGroup::destroySingleton();
  73. FileBackendGroup::destroySingleton();
  74. parent::tearDown();
  75. }
  76. public static function suite() {
  77. // Hack to invoke the autoloader required to get phpunit to recognize
  78. // the UploadFromUrlTest class
  79. class_exists( 'UploadFromUrlTest' );
  80. $suite = new UploadFromUrlTestSuite( 'UploadFromUrlTest' );
  81. return $suite;
  82. }
  83. }