Split AutoloaderTest into a structure and class test
[lhc/web/wiklou.git] / tests / phpunit / includes / AutoLoaderTest.php
1 <?php
2
3 /**
4 * @covers AutoLoader
5 */
6 class AutoLoaderTest extends MediaWikiTestCase {
7 protected function setUp() {
8 parent::setUp();
9
10 // Fancy dance to trigger a rebuild of AutoLoader::$autoloadLocalClassesLower
11 $this->mergeMwGlobalArrayValue( 'wgAutoloadLocalClasses', [
12 'TestAutoloadedLocalClass' =>
13 __DIR__ . '/../data/autoloader/TestAutoloadedLocalClass.php',
14 'TestAutoloadedCamlClass' =>
15 __DIR__ . '/../data/autoloader/TestAutoloadedCamlClass.php',
16 'TestAutoloadedSerializedClass' =>
17 __DIR__ . '/../data/autoloader/TestAutoloadedSerializedClass.php',
18 ] );
19 AutoLoader::resetAutoloadLocalClassesLower();
20
21 $this->mergeMwGlobalArrayValue( 'wgAutoloadClasses', [
22 'TestAutoloadedClass' => __DIR__ . '/../data/autoloader/TestAutoloadedClass.php',
23 ] );
24 }
25
26 public function testCoreClass() {
27 $this->assertTrue( class_exists( 'TestAutoloadedLocalClass' ) );
28 }
29
30 public function testExtensionClass() {
31 $this->assertTrue( class_exists( 'TestAutoloadedClass' ) );
32 }
33
34 public function testWrongCaseClass() {
35 $this->setMwGlobals( 'wgAutoloadAttemptLowercase', true );
36
37 $this->assertTrue( class_exists( 'testautoLoadedcamlCLASS' ) );
38 }
39
40 public function testWrongCaseSerializedClass() {
41 $this->setMwGlobals( 'wgAutoloadAttemptLowercase', true );
42
43 $dummyCereal = 'O:29:"testautoloadedserializedclass":0:{}';
44 $uncerealized = unserialize( $dummyCereal );
45 $this->assertFalse( $uncerealized instanceof __PHP_Incomplete_Class,
46 "unserialize() can load classes case-insensitively." );
47 }
48 }