MediaWiki  1.29.2
UploadFromUrlTestSuite.php
Go to the documentation of this file.
1 <?php
2 
3 require_once dirname( __DIR__ ) . '/includes/upload/UploadFromUrlTest.php';
4 
5 class UploadFromUrlTestSuite extends PHPUnit_Framework_TestSuite {
6  public $savedGlobals = [];
7 
8  public static function addTables( &$tables ) {
9  $tables[] = 'user_properties';
10  $tables[] = 'filearchive';
11  $tables[] = 'logging';
12  $tables[] = 'updatelog';
13  $tables[] = 'iwlinks';
14 
15  return true;
16  }
17 
18  protected function setUp() {
19  global $wgParser, $wgParserConf, $IP, $messageMemc, $wgMemc, $wgUser,
23 
24  $tmpDir = $this->getNewTempDirectory();
25  $tmpGlobals = [];
26 
27  $tmpGlobals['wgScript'] = '/index.php';
28  $tmpGlobals['wgScriptPath'] = '/';
29  $tmpGlobals['wgArticlePath'] = '/wiki/$1';
30  $tmpGlobals['wgStylePath'] = '/skins';
31  $tmpGlobals['wgThumbnailScriptPath'] = false;
32  $tmpGlobals['wgLocalFileRepo'] = [
33  'class' => 'LocalRepo',
34  'name' => 'local',
35  'url' => 'http://example.com/images',
36  'hashLevels' => 2,
37  'transformVia404' => false,
38  'backend' => new FSFileBackend( [
39  'name' => 'local-backend',
40  'wikiId' => wfWikiID(),
41  'containerPaths' => [
42  'local-public' => "{$tmpDir}/test-repo/public",
43  'local-thumb' => "{$tmpDir}/test-repo/thumb",
44  'local-temp' => "{$tmpDir}/test-repo/temp",
45  'local-deleted' => "{$tmpDir}/test-repo/delete",
46  ]
47  ] ),
48  ];
49  foreach ( $tmpGlobals as $var => $val ) {
50  if ( array_key_exists( $var, $GLOBALS ) ) {
51  $this->savedGlobals[$var] = $GLOBALS[$var];
52  }
53  $GLOBALS[$var] = $val;
54  }
55 
56  $wgNamespaceProtection[NS_MEDIAWIKI] = 'editinterface';
57  $wgNamespaceAliases['Image'] = NS_FILE;
58  $wgNamespaceAliases['Image_talk'] = NS_FILE_TALK;
59 
65 
68  $wgUser = new User;
71  $wgParser = new StubObject( 'wgParser', $wgParserConf['class'], [ $wgParserConf ] );
73 
74  if ( $wgStyleDirectory === false ) {
75  $wgStyleDirectory = "$IP/skins";
76  }
77 
80  }
81 
82  protected function tearDown() {
83  foreach ( $this->savedGlobals as $var => $val ) {
84  $GLOBALS[$var] = $val;
85  }
86  // Restore backends
89 
90  parent::tearDown();
91  }
92 
98  private static function deleteFiles( $files ) {
99  foreach ( $files as $file ) {
100  if ( file_exists( $file ) ) {
101  unlink( $file );
102  }
103  }
104  }
105 
111  private static function deleteDirs( $dirs ) {
112  foreach ( $dirs as $dir ) {
113  if ( is_dir( $dir ) ) {
114  rmdir( $dir );
115  }
116  }
117  }
118 
125  private function setupUploadDir() {
126  global $IP;
127 
128  $dir = $this->getNewTempDirectory();
129 
130  wfDebug( "Creating upload directory $dir\n" );
131 
132  wfMkdirParents( $dir . '/3/3a', null, __METHOD__ );
133  copy( "$IP/tests/phpunit/data/upload/headbg.jpg", "$dir/3/3a/Foobar.jpg" );
134 
135  wfMkdirParents( $dir . '/0/09', null, __METHOD__ );
136  copy( "$IP/tests/phpunit/data/upload/headbg.jpg", "$dir/0/09/Bad.jpg" );
137 
138  return $dir;
139  }
140 
141  public static function suite() {
142  // Hack to invoke the autoloader required to get phpunit to recognize
143  // the UploadFromUrlTest class
144  class_exists( 'UploadFromUrlTest' );
145  $suite = new UploadFromUrlTestSuite( 'UploadFromUrlTest' );
146 
147  return $suite;
148  }
149 }
copy
and give any other recipients of the Program a copy of this License along with the Program You may charge a fee for the physical act of transferring a copy
Definition: COPYING.txt:87
$wgUser
$wgUser
Definition: Setup.php:781
$context
error also a ContextSource you ll probably need to make sure the header is varied on and they can depend only on the ResourceLoaderContext $context
Definition: hooks.txt:2612
$tables
this hook is for auditing only RecentChangesLinked and Watchlist RecentChangesLinked and Watchlist Do not use this to implement individual filters if they are compatible with the ChangesListFilter and ChangesListFilterGroup structure use sub classes of those in conjunction with the ChangesListSpecialPageStructuredFilters hook This hook can be used to implement filters that do not implement that or custom behavior that is not an individual filter e g Watchlist & $tables
Definition: hooks.txt:990
$wgNamespaceProtection
if( $wgScript===false) if( $wgLoadScript===false) if( $wgArticlePath===false) if(!empty( $wgActionPaths) &&!isset( $wgActionPaths['view'])) if( $wgResourceBasePath===null) if( $wgStylePath===false) if( $wgLocalStylePath===false) if( $wgExtensionAssetsPath===false) if( $wgLogo===false) if( $wgUploadPath===false) if( $wgUploadDirectory===false) if( $wgReadOnlyFile===false) if( $wgFileCacheDirectory===false) if( $wgDeletedDirectory===false) if( $wgGitInfoCacheDirectory===false && $wgCacheDirectory !==false) if( $wgEnableParserCache===false) if( $wgRightsIcon) if(isset( $wgFooterIcons['copyright']['copyright']) && $wgFooterIcons['copyright']['copyright']===[]) if(isset( $wgFooterIcons['poweredby']) &&isset( $wgFooterIcons['poweredby']['mediawiki']) && $wgFooterIcons['poweredby']['mediawiki']['src']===null) $wgNamespaceProtection[NS_MEDIAWIKI]
Unconditional protection for NS_MEDIAWIKI since otherwise it's too easy for a sysadmin to set $wgName...
Definition: Setup.php:157
$wgParser
$wgParser
Definition: Setup.php:796
wfMkdirParents
wfMkdirParents( $dir, $mode=null, $caller=null)
Make directory, and make all parent directories if they don't exist.
Definition: GlobalFunctions.php:2080
StubObject
Class to implement stub globals, which are globals that delay loading the their associated module cod...
Definition: StubObject.php:44
$wgMemc
globals will be eliminated from MediaWiki replaced by an application object which would be passed to constructors Whether that would be an convenient solution remains to be but certainly PHP makes such object oriented programming models easier than they were in previous versions For the time being MediaWiki programmers will have to work in an environment with some global context At the time of globals were initialised on startup by MediaWiki of these were configuration which are documented in DefaultSettings php There is no comprehensive documentation for the remaining however some of the most important ones are listed below They are typically initialised either in index php or in Setup php For a description of the see design txt $wgTitle Title object created from the request URL $wgOut OutputPage object for HTTP response $wgUser User object for the user associated with the current request $wgLang Language object selected by user preferences $wgContLang Language object associated with the wiki being viewed $wgParser Parser object Parser extensions register their hooks here $wgRequest WebRequest to get request data $wgMemc
Definition: globals.txt:25
CACHE_NONE
const CACHE_NONE
Definition: Defines.php:100
UploadFromUrlTestSuite\setUp
setUp()
Definition: UploadFromUrlTestSuite.php:18
UploadFromUrlTestSuite\addTables
static addTables(&$tables)
Definition: UploadFromUrlTestSuite.php:8
$messageMemc
globals will be eliminated from MediaWiki replaced by an application object which would be passed to constructors Whether that would be an convenient solution remains to be but certainly PHP makes such object oriented programming models easier than they were in previous versions For the time being MediaWiki programmers will have to work in an environment with some global context At the time of globals were initialised on startup by MediaWiki of these were configuration which are documented in DefaultSettings php There is no comprehensive documentation for the remaining however some of the most important ones are listed below They are typically initialised either in index php or in Setup php For a description of the see design txt $wgTitle Title object created from the request URL $wgOut OutputPage object for HTTP response $wgUser User object for the user associated with the current request $wgLang Language object selected by user preferences $wgContLang Language object associated with the wiki being viewed $wgParser Parser object Parser extensions register their hooks here $wgRequest WebRequest to get request data $messageMemc
Definition: globals.txt:25
NS_FILE
const NS_FILE
Definition: Defines.php:68
$parserMemc
controlled by $wgMainCacheType * $parserMemc
Definition: memcached.txt:78
ContextSource\getRequest
getRequest()
Get the WebRequest object.
Definition: ContextSource.php:78
DeferredUpdates\clearPendingUpdates
static clearPendingUpdates()
Clear all pending updates without performing them.
Definition: DeferredUpdates.php:351
User
User
Definition: All_system_messages.txt:425
UploadFromUrlTestSuite\$savedGlobals
$savedGlobals
Definition: UploadFromUrlTestSuite.php:6
php
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition: injection.txt:35
ContextSource\getLanguage
getLanguage()
Get the Language object.
Definition: ContextSource.php:143
FileBackendGroup\destroySingleton
static destroySingleton()
Destroy the singleton instance.
Definition: FileBackendGroup.php:58
UploadFromUrlTestSuite\tearDown
tearDown()
Definition: UploadFromUrlTestSuite.php:82
wfGetMainCache
wfGetMainCache()
Get the main cache object.
Definition: GlobalFunctions.php:3407
ContextSource\getOutput
getOutput()
Get the OutputPage object.
Definition: ContextSource.php:123
$IP
$IP
Definition: update.php:3
$wgLang
this class mediates it Skin Encapsulates a look and feel for the wiki All of the functions that render HTML and make choices about how to render it are here and are called from various other places when and is meant to be subclassed with other skins that may override some of its functions The User object contains a reference to a and so rather than having a global skin object we just rely on the global User and get the skin with $wgUser and also has some character encoding functions and other locale stuff The current user interface language is instantiated as $wgLang
Definition: design.txt:56
$wgParserCacheType
$wgParserCacheType
The cache type for storing article HTML.
Definition: DefaultSettings.php:2240
$dirs
$dirs
Definition: mergeMessageFileList.php:195
global
when a variable name is used in a it is silently declared as a new masking the global
Definition: design.txt:93
$GLOBALS
$GLOBALS['wgAutoloadClasses']['LocalisationUpdate']
Definition: Autoload.php:10
wfDebug
wfDebug( $text, $dest='all', array $context=[])
Sends a line to the debug log if enabled or, optionally, to a comment in output.
Definition: GlobalFunctions.php:999
$dir
$dir
Definition: Autoload.php:8
UploadFromUrlTestSuite\deleteFiles
static deleteFiles( $files)
Delete the specified files, if they exist.
Definition: UploadFromUrlTestSuite.php:98
RepoGroup\destroySingleton
static destroySingleton()
Destroy the singleton instance, so that a new one will be created next time singleton() is called.
Definition: RepoGroup.php:73
UploadFromUrlTestSuite\setupUploadDir
setupUploadDir()
Create a dummy uploads directory which will contain a couple of files in order to pass existence test...
Definition: UploadFromUrlTestSuite.php:125
wfWikiID
wfWikiID()
Get an ASCII string identifying this wiki This is used as a prefix in memcached keys.
Definition: GlobalFunctions.php:3011
RequestContext\resetMain
static resetMain()
Resets singleton returned by getMain().
Definition: RequestContext.php:494
$wgNamespaceAliases
$wgNamespaceAliases['Image']
The canonical names of namespaces 6 and 7 are, as of v1.14, "File" and "File_talk".
Definition: Setup.php:164
UploadFromUrlTestSuite
Definition: UploadFromUrlTestSuite.php:5
wfGetParserCacheStorage
wfGetParserCacheStorage()
Get the cache object used by the parser cache.
Definition: GlobalFunctions.php:3427
RequestContext\getMain
static getMain()
Static methods.
Definition: RequestContext.php:468
wfGetMessageCacheStorage
wfGetMessageCacheStorage()
Get the cache object used by the message cache.
Definition: GlobalFunctions.php:3417
UploadFromUrlTestSuite\suite
static suite()
Definition: UploadFromUrlTestSuite.php:141
FSFileBackend
Class for a file system (FS) based file backend.
Definition: FSFileBackend.php:42
UploadFromUrlTestSuite\deleteDirs
static deleteDirs( $dirs)
Delete the specified directories, if they exist.
Definition: UploadFromUrlTestSuite.php:111
as
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
Definition: distributors.txt:9
NS_MEDIAWIKI
const NS_MEDIAWIKI
Definition: Defines.php:70
$wgRequest
if(! $wgDBerrorLogTZ) $wgRequest
Definition: Setup.php:639
NS_FILE_TALK
const NS_FILE_TALK
Definition: Defines.php:69
$wgOut
$wgOut
Definition: Setup.php:791
$wgStyleDirectory
$wgStyleDirectory
Filesystem stylesheets directory.
Definition: DefaultSettings.php:246