wiki.techinc.nl/tests/phpunit/includes/AutoLoaderTest.php
libraryupgrader 5357695270 build: Updating dependencies
composer:
* mediawiki/mediawiki-codesniffer: 36.0.0 → 37.0.0
  The following sniffs now pass and were enabled:
  * Generic.ControlStructures.InlineControlStructure
  * MediaWiki.PHPUnit.AssertCount.NotUsed

npm:
* svgo: 2.3.0 → 2.3.1
  * https://npmjs.com/advisories/1754 (CVE-2021-33587)

Change-Id: I2a9bbee2fecbf7259876d335f565ece4b3622426
2021-07-22 03:36:05 +00:00

69 lines
2.1 KiB
PHP

<?php
/**
* @covers AutoLoader
*/
class AutoLoaderTest extends MediaWikiIntegrationTestCase {
private $oldPsr4;
protected function setUp(): void {
parent::setUp();
// Fancy dance to trigger a rebuild of AutoLoader::$autoloadLocalClassesLower
$this->mergeMwGlobalArrayValue( 'wgAutoloadLocalClasses', [
'TestAutoloadedLocalClass' =>
__DIR__ . '/../data/autoloader/TestAutoloadedLocalClass.php',
'TestAutoloadedCamlClass' =>
__DIR__ . '/../data/autoloader/TestAutoloadedCamlClass.php',
'TestAutoloadedSerializedClass' =>
__DIR__ . '/../data/autoloader/TestAutoloadedSerializedClass.php',
] );
AutoLoader::resetAutoloadLocalClassesLower();
$this->mergeMwGlobalArrayValue( 'wgAutoloadClasses', [
'TestAutoloadedClass' => __DIR__ . '/../data/autoloader/TestAutoloadedClass.php',
] );
$this->oldPsr4 = AutoLoader::$psr4Namespaces;
AutoLoader::$psr4Namespaces['Test\\MediaWiki\\AutoLoader\\'] =
__DIR__ . '/../data/autoloader/psr4';
}
protected function tearDown(): void {
AutoLoader::$psr4Namespaces = $this->oldPsr4;
parent::tearDown();
}
public function testFind() {
$path = __DIR__ . '/../data/autoloader/TestAutoloadedLocalClass.php';
$this->assertSame( $path, AutoLoader::find( TestAutoloadedLocalClass::class ) );
}
public function testCoreClass() {
$this->assertTrue( class_exists( 'TestAutoloadedLocalClass' ) );
}
public function testExtensionClass() {
$this->assertTrue( class_exists( 'TestAutoloadedClass' ) );
}
public function testWrongCaseClass() {
$this->setMwGlobals( 'wgAutoloadAttemptLowercase', true );
$this->assertTrue( class_exists( 'testautoLoadedcamlCLASS' ) );
}
public function testWrongCaseSerializedClass() {
$this->setMwGlobals( 'wgAutoloadAttemptLowercase', true );
$dummyCereal = 'O:29:"testautoloadedserializedclass":0:{}';
$uncerealized = unserialize( $dummyCereal );
$this->assertFalse( $uncerealized instanceof __PHP_Incomplete_Class,
"unserialize() can load classes case-insensitively." );
}
public function testPsr4() {
$this->assertTrue( class_exists( 'Test\\MediaWiki\\AutoLoader\\TestFooBar' ) );
}
}