MediaWiki  1.23.8
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 = array();
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,
20  $wgLang, $wgOut, $wgRequest, $wgStyleDirectory,
21  $wgEnableParserCache, $wgNamespaceAliases, $wgNamespaceProtection,
23 
24  $tmpGlobals = array();
25 
26  $tmpGlobals['wgScript'] = '/index.php';
27  $tmpGlobals['wgScriptPath'] = '/';
28  $tmpGlobals['wgArticlePath'] = '/wiki/$1';
29  $tmpGlobals['wgStylePath'] = '/skins';
30  $tmpGlobals['wgThumbnailScriptPath'] = false;
31  $tmpGlobals['wgLocalFileRepo'] = array(
32  'class' => 'LocalRepo',
33  'name' => 'local',
34  'url' => 'http://example.com/images',
35  'hashLevels' => 2,
36  'transformVia404' => false,
37  'backend' => new FSFileBackend( array(
38  'name' => 'local-backend',
39  'wikiId' => wfWikiId(),
40  'containerPaths' => array(
41  'local-public' => wfTempDir() . '/test-repo/public',
42  'local-thumb' => wfTempDir() . '/test-repo/thumb',
43  'local-temp' => wfTempDir() . '/test-repo/temp',
44  'local-deleted' => wfTempDir() . '/test-repo/delete',
45  )
46  ) ),
47  );
48  foreach ( $tmpGlobals as $var => $val ) {
49  if ( array_key_exists( $var, $GLOBALS ) ) {
50  $this->savedGlobals[$var] = $GLOBALS[$var];
51  }
52  $GLOBALS[$var] = $val;
53  }
54 
55  $wgNamespaceProtection[NS_MEDIAWIKI] = 'editinterface';
56  $wgNamespaceAliases['Image'] = NS_FILE;
57  $wgNamespaceAliases['Image_talk'] = NS_FILE_TALK;
58 
59  $wgEnableParserCache = false;
64 
65  // $wgContLang = new StubContLang;
66  $wgUser = new User;
67  $context = new RequestContext;
68  $wgLang = $context->getLanguage();
69  $wgOut = $context->getOutput();
70  $wgParser = new StubObject( 'wgParser', $wgParserConf['class'], array( $wgParserConf ) );
71  $wgRequest = $context->getRequest();
72 
73  if ( $wgStyleDirectory === false ) {
74  $wgStyleDirectory = "$IP/skins";
75  }
76 
79  }
80 
81  protected function tearDown() {
82  foreach ( $this->savedGlobals as $var => $val ) {
83  $GLOBALS[$var] = $val;
84  }
85  // Restore backends
88 
89  $this->teardownUploadDir( $this->uploadDir );
90 
91  parent::tearDown();
92  }
93 
94  private $uploadDir;
95  private $keepUploads;
96 
100  private function teardownUploadDir( $dir ) {
101  if ( $this->keepUploads ) {
102  return;
103  }
104 
105  // delete the files first, then the dirs.
107  array(
108  "$dir/3/3a/Foobar.jpg",
109  "$dir/thumb/3/3a/Foobar.jpg/180px-Foobar.jpg",
110  "$dir/thumb/3/3a/Foobar.jpg/200px-Foobar.jpg",
111  "$dir/thumb/3/3a/Foobar.jpg/640px-Foobar.jpg",
112  "$dir/thumb/3/3a/Foobar.jpg/120px-Foobar.jpg",
113 
114  "$dir/0/09/Bad.jpg",
115  )
116  );
117 
119  array(
120  "$dir/3/3a",
121  "$dir/3",
122  "$dir/thumb/6/65",
123  "$dir/thumb/6",
124  "$dir/thumb/3/3a/Foobar.jpg",
125  "$dir/thumb/3/3a",
126  "$dir/thumb/3",
127 
128  "$dir/0/09/",
129  "$dir/0/",
130 
131  "$dir/thumb",
132  "$dir",
133  )
134  );
135  }
136 
142  private static function deleteFiles( $files ) {
143  foreach ( $files as $file ) {
144  if ( file_exists( $file ) ) {
145  unlink( $file );
146  }
147  }
148  }
149 
155  private static function deleteDirs( $dirs ) {
156  foreach ( $dirs as $dir ) {
157  if ( is_dir( $dir ) ) {
158  rmdir( $dir );
159  }
160  }
161  }
162 
169  private function setupUploadDir() {
170  global $IP;
171 
172  if ( $this->keepUploads ) {
173  $dir = wfTempDir() . '/mwParser-images';
174 
175  if ( is_dir( $dir ) ) {
176  return $dir;
177  }
178  } else {
179  $dir = wfTempDir() . "/mwParser-" . mt_rand() . "-images";
180  }
181 
182  wfDebug( "Creating upload directory $dir\n" );
183 
184  if ( file_exists( $dir ) ) {
185  wfDebug( "Already exists!\n" );
186 
187  return $dir;
188  }
189 
190  wfMkdirParents( $dir . '/3/3a', null, __METHOD__ );
191  copy( "$IP/skins/monobook/headbg.jpg", "$dir/3/3a/Foobar.jpg" );
192 
193  wfMkdirParents( $dir . '/0/09', null, __METHOD__ );
194  copy( "$IP/skins/monobook/headbg.jpg", "$dir/0/09/Bad.jpg" );
195 
196  return $dir;
197  }
198 
199  public static function suite() {
200  // Hack to invoke the autoloader required to get phpunit to recognize
201  // the UploadFromUrlTest class
202  class_exists( 'UploadFromUrlTest' );
203  $suite = new UploadFromUrlTestSuite( 'UploadFromUrlTest' );
204 
205  return $suite;
206  }
207 }
$wgUser
$wgUser
Definition: Setup.php:552
php
skin txt MediaWiki includes four core it has been set as the default in MediaWiki since the replacing Monobook it had been been the default skin since before being replaced by Vector largely rewritten in while keeping its appearance Several legacy skins were removed in the as the burden of supporting them became too heavy to bear Those in etc for skin dependent CSS etc for skin dependent JavaScript These can also be customised on a per user by etc This feature has led to a wide variety of user styles becoming that gallery is a good place to ending in php
Definition: skin.txt:62
$files
$files
Definition: importImages.php:67
$tables
namespace and then decline to actually register it RecentChangesLinked and Watchlist RecentChangesLinked and Watchlist e g Watchlist & $tables
Definition: hooks.txt:815
wfMkdirParents
wfMkdirParents( $dir, $mode=null, $caller=null)
Make directory, and make all parent directories if they don't exist.
Definition: GlobalFunctions.php:2590
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
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:85
$parserMemc
controlled by $wgMainCacheType * $parserMemc
Definition: memcached.txt:78
DeferredUpdates\clearPendingUpdates
static clearPendingUpdates()
Clear all pending updates without performing them.
Definition: DeferredUpdates.php:128
UploadFromUrlTestSuite\$savedGlobals
$savedGlobals
Definition: UploadFromUrlTestSuite.php:6
ContextSource\getLanguage
getLanguage()
Get the Language object.
Definition: ContextSource.php:154
FileBackendGroup\destroySingleton
static destroySingleton()
Destroy the singleton instance.
Definition: FileBackendGroup.php:55
UploadFromUrlTestSuite\tearDown
tearDown()
Definition: UploadFromUrlTestSuite.php:81
UploadFromUrlTestSuite\$keepUploads
$keepUploads
Definition: UploadFromUrlTestSuite.php:95
UploadFromUrlTestSuite\teardownUploadDir
teardownUploadDir( $dir)
Remove the dummy uploads directory.
Definition: UploadFromUrlTestSuite.php:100
wfGetMainCache
wfGetMainCache()
Get the main cache object.
Definition: GlobalFunctions.php:3966
$wgOut
$wgOut
Definition: Setup.php:562
array
the array() calling protocol came about after MediaWiki 1.4rc1.
List of Api Query prop modules.
$dirs
$dirs
Definition: mergeMessageFileList.php:163
global
when a variable name is used in a it is silently declared as a new masking the global
Definition: design.txt:93
RequestContext
Group all the pieces relevant to the context of a request into one instance.
Definition: RequestContext.php:30
UploadFromUrlTestSuite\deleteFiles
static deleteFiles( $files)
Delete the specified files, if they exist.
Definition: UploadFromUrlTestSuite.php:142
wfDebug
wfDebug( $text, $dest='all')
Sends a line to the debug log if enabled or, optionally, to a comment in output.
Definition: GlobalFunctions.php:933
RepoGroup\destroySingleton
static destroySingleton()
Destroy the singleton instance, so that a new one will be created next time singleton() is called.
Definition: RepoGroup.php:67
UploadFromUrlTestSuite\setupUploadDir
setupUploadDir()
Create a dummy uploads directory which will contain a couple of files in order to pass existence test...
Definition: UploadFromUrlTestSuite.php:169
$wgNamespaceAliases
$wgNamespaceAliases['Image']
The canonical names of namespaces 6 and 7 are, as of v1.14, "File" and "File_talk".
Definition: Setup.php:142
UploadFromUrlTestSuite
Definition: UploadFromUrlTestSuite.php:5
wfGetParserCacheStorage
wfGetParserCacheStorage()
Get the cache object used by the parser cache.
Definition: GlobalFunctions.php:3986
$file
if(PHP_SAPI !='cli') $file
Definition: UtfNormalTest2.php:30
wfGetMessageCacheStorage
wfGetMessageCacheStorage()
Get the cache object used by the message cache.
Definition: GlobalFunctions.php:3976
UploadFromUrlTestSuite\suite
static suite()
Definition: UploadFromUrlTestSuite.php:199
$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
wfTempDir
wfTempDir()
Tries to get the system directory for temporary files.
Definition: GlobalFunctions.php:2564
FSFileBackend
Class for a file system (FS) based file backend.
Definition: FSFileBackend.php:41
$wgParser
$wgParser
Definition: Setup.php:567
$dir
if(count( $args)==0) $dir
Definition: importImages.php:49
UploadFromUrlTestSuite\deleteDirs
static deleteDirs( $dirs)
Delete the specified directories, if they exist.
Definition: UploadFromUrlTestSuite.php:155
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
User
User
Definition: All_system_messages.txt:425
UploadFromUrlTestSuite\$uploadDir
$uploadDir
Definition: UploadFromUrlTestSuite.php:94
$wgNamespaceProtection
if(!isset( $wgVersion)) if( $wgScript===false) if( $wgLoadScript===false) if( $wgArticlePath===false) if(!empty( $wgActionPaths) &&!isset( $wgActionPaths['view'])) if( $wgStylePath===false) if( $wgLocalStylePath===false) if( $wgStyleDirectory===false) if( $wgExtensionAssetsPath===false) if( $wgLogo===false) if( $wgUploadPath===false) if( $wgUploadDirectory===false) if( $wgReadOnlyFile===false) if( $wgFileCacheDirectory===false) if( $wgDeletedDirectory===false) if(isset( $wgFileStore['deleted']['directory'])) if(isset( $wgFooterIcons['copyright']) &&isset( $wgFooterIcons['copyright']['copyright']) && $wgFooterIcons['copyright']['copyright']===array()) 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:135
NS_MEDIAWIKI
const NS_MEDIAWIKI
Definition: Defines.php:87
NS_FILE_TALK
const NS_FILE_TALK
Definition: Defines.php:86
$IP
$IP
Definition: WebStart.php:88
$GLOBALS
$GLOBALS['IP']
Definition: ComposerHookHandler.php:6