MediaWiki  1.23.1
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  $classesInFile = array();
74  $aliasesInFile = array();
75 
76  foreach ( $matches as $match ) {
77  if ( !empty( $match['class'] ) ) {
78  $actual[$match['class']] = $file;
79  $classesInFile[$match['class']] = true;
80  } else {
81  $aliasesInFile[$match['alias']] = $match['original'];
82  }
83  }
84 
85  // Only accept aliases for classes in the same file, because for correct
86  // behavior, all aliases for a class must be set up when the class is loaded
87  // (see <https://bugs.php.net/bug.php?id=61422>).
88  foreach ( $aliasesInFile as $alias => $class ) {
89  if ( isset( $classesInFile[$class] ) ) {
90  $actual[$alias] = $file;
91  } else {
92  $actual[$alias] = "[original class not in $file]";
93  }
94  }
95  }
96 
97  return array(
98  'expected' => $expected,
99  'actual' => $actual,
100  );
101  }
102 
103  function testCoreClass() {
104  $this->assertTrue( class_exists( 'TestAutoloadedLocalClass' ) );
105  }
106 
107  function testExtensionClass() {
108  $this->assertTrue( class_exists( 'TestAutoloadedClass' ) );
109  }
110 
111  function testWrongCaseClass() {
112  $this->assertTrue( class_exists( 'testautoLoadedcamlCLASS' ) );
113  }
114 
116  $dummyCereal = 'O:29:"testautoloadedserializedclass":0:{}';
117  $uncerealized = unserialize( $dummyCereal );
118  $this->assertFalse( $uncerealized instanceof __PHP_Incomplete_Class,
119  "unserialize() can load classes case-insensitively." );
120  }
121 }
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:115
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:1272
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:111
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:107
$IP
$IP
Definition: WebStart.php:88
AutoLoaderTest\testCoreClass
testCoreClass()
Definition: AutoLoaderTest.php:103