MediaWiki  1.23.12
AutoLoaderTest.php
Go to the documentation of this file.
1 <?php
2 
4  protected function setUp() {
6 
7  parent::setUp();
8 
9  // Fancy dance to trigger a rebuild of AutoLoader::$autoloadLocalClassesLower
10  $this->testLocalClasses = array(
11  'TestAutoloadedLocalClass' => __DIR__ . '/../data/autoloader/TestAutoloadedLocalClass.php',
12  'TestAutoloadedCamlClass' => __DIR__ . '/../data/autoloader/TestAutoloadedCamlClass.php',
13  'TestAutoloadedSerializedClass' => __DIR__ . '/../data/autoloader/TestAutoloadedSerializedClass.php',
14  );
15  $this->setMwGlobals( 'wgAutoloadLocalClasses', $this->testLocalClasses + $wgAutoloadLocalClasses );
17 
18  $this->testExtensionClasses = array(
19  'TestAutoloadedClass' => __DIR__ . '/../data/autoloader/TestAutoloadedClass.php',
20  );
21  $this->setMwGlobals( 'wgAutoloadClasses', $this->testExtensionClasses + $wgAutoloadClasses );
22  }
23 
30  public function testAutoLoadConfig() {
31  $results = self::checkAutoLoadConf();
32 
33  $this->assertEquals(
34  $results['expected'],
35  $results['actual']
36  );
37  }
38 
39  protected static function checkAutoLoadConf() {
41 
42  // wgAutoloadLocalClasses has precedence, just like in includes/AutoLoader.php
44  $actual = array();
45 
46  $files = array_unique( $expected );
47 
48  foreach ( $files as $file ) {
49  // Only prefix $IP if it doesn't have it already.
50  // Generally local classes don't have it, and those from extensions and test suites do.
51  if ( substr( $file, 0, 1 ) != '/' && substr( $file, 1, 1 ) != ':' ) {
52  $filePath = "$IP/$file";
53  } else {
54  $filePath = $file;
55  }
56 
57  $contents = file_get_contents( $filePath );
58 
59  // We could use token_get_all() here, but this is faster
60  $matches = array();
61  preg_match_all( '/
62  ^ [\t ]* (?:
63  (?:final\s+)? (?:abstract\s+)? (?:class|interface) \s+
64  (?P<class> [a-zA-Z0-9_]+)
65  |
66  class_alias \s* \( \s*
67  ([\'"]) (?P<original> [^\'"]+) \g{-2} \s* , \s*
68  ([\'"]) (?P<alias> [^\'"]+ ) \g{-2} \s*
69  \) \s* ;
70  )
71  /imx', $contents, $matches, PREG_SET_ORDER );
72 
73  $namespaceMatch = array();
74  preg_match( '/
75  ^ [\t ]*
76  namespace \s+
77  ([a-zA-Z0-9_]+(\\\\[a-zA-Z0-9_]+)*)
78  \s* ;
79  /imx', $contents, $namespaceMatch );
80  $fileNamespace = $namespaceMatch ? $namespaceMatch[1] . '\\' : '';
81 
82  $classesInFile = array();
83  $aliasesInFile = array();
84 
85  foreach ( $matches as $match ) {
86  if ( !empty( $match['class'] ) ) {
87  $class = $fileNamespace . $match['class'];
88  $actual[$class] = $file;
89  $classesInFile[$class] = true;
90  } else {
91  $aliasesInFile[$match['alias']] = $match['original'];
92  }
93  }
94 
95  // Only accept aliases for classes in the same file, because for correct
96  // behavior, all aliases for a class must be set up when the class is loaded
97  // (see <https://bugs.php.net/bug.php?id=61422>).
98  foreach ( $aliasesInFile as $alias => $class ) {
99  if ( isset( $classesInFile[$class] ) ) {
100  $actual[$alias] = $file;
101  } else {
102  $actual[$alias] = "[original class not in $file]";
103  }
104  }
105  }
106 
107  return array(
108  'expected' => $expected,
109  'actual' => $actual,
110  );
111  }
112 
113  function testCoreClass() {
114  $this->assertTrue( class_exists( 'TestAutoloadedLocalClass' ) );
115  }
116 
117  function testExtensionClass() {
118  $this->assertTrue( class_exists( 'TestAutoloadedClass' ) );
119  }
120 
121  function testWrongCaseClass() {
122  $this->assertTrue( class_exists( 'testautoLoadedcamlCLASS' ) );
123  }
124 
126  $dummyCereal = 'O:29:"testautoloadedserializedclass":0:{}';
127  $uncerealized = unserialize( $dummyCereal );
128  $this->assertFalse( $uncerealized instanceof __PHP_Incomplete_Class,
129  "unserialize() can load classes case-insensitively." );
130  }
131 }
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
$wgAutoloadClasses
global $wgAutoloadClasses
Definition: TestsAutoLoader.php:24
AutoLoaderTest\setUp
setUp()
Definition: AutoLoaderTest.php:4
AutoLoaderTest\testWrongCaseSerializedClass
testWrongCaseSerializedClass()
Definition: AutoLoaderTest.php:125
AutoLoaderTest\testAutoLoadConfig
testAutoLoadConfig()
Assert that there were no classes loaded that are not registered with the AutoLoader.
Definition: AutoLoaderTest.php:30
MediaWikiTestCase\setMwGlobals
setMwGlobals( $pairs, $value=null)
Definition: MediaWikiTestCase.php:302
MediaWikiTestCase
Definition: MediaWikiTestCase.php:6
AutoLoader\resetAutoloadLocalClassesLower
static resetAutoloadLocalClassesLower()
Method to clear the protected class property $autoloadLocalClassesLower.
Definition: AutoLoader.php:1282
array
the array() calling protocol came about after MediaWiki 1.4rc1.
List of Api Query prop modules.
global
when a variable name is used in a it is silently declared as a new masking the global
Definition: design.txt:93
$matches
if(!defined( 'MEDIAWIKI')) if(!isset( $wgVersion)) $matches
Definition: NoLocalSettings.php:33
AutoLoaderTest\testWrongCaseClass
testWrongCaseClass()
Definition: AutoLoaderTest.php:121
AutoLoaderTest
Definition: AutoLoaderTest.php:3
$file
if(PHP_SAPI !='cli') $file
Definition: UtfNormalTest2.php:30
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
AutoLoaderTest\checkAutoLoadConf
static checkAutoLoadConf()
Definition: AutoLoaderTest.php:39
$wgAutoloadLocalClasses
global $wgAutoloadLocalClasses
Locations of core classes Extension classes are specified with $wgAutoloadClasses This array is a glo...
Definition: AutoLoader.php:28
AutoLoaderTest\testExtensionClass
testExtensionClass()
Definition: AutoLoaderTest.php:117
$IP
$IP
Definition: WebStart.php:88
AutoLoaderTest\testCoreClass
testCoreClass()
Definition: AutoLoaderTest.php:113