Merge "Add ability to filter based on rc_title in API"
[lhc/web/wiklou.git] / tests / phpunit / includes / resourceloader / ResourceLoaderTest.php
index f45f8ae..95006aa 100644 (file)
@@ -8,9 +8,7 @@ class ResourceLoaderTest extends ResourceLoaderTestCase {
                parent::setUp();
 
                $this->setMwGlobals( [
-                       'wgResourceLoaderLESSImportPaths' => [
-                               dirname( dirname( __DIR__ ) ) . '/data/less/common',
-                       ],
+                       'wgResourceLoaderLESSImportPaths' => [],
                        'wgResourceLoaderLESSVars' => [
                                'foo'  => '2px',
                                'Foo' => '#eeeeee',
@@ -86,7 +84,7 @@ class ResourceLoaderTest extends ResourceLoaderTestCase {
         */
        public function testRegisterInvalidName() {
                $resourceLoader = new EmptyResourceLoader();
-               $this->setExpectedException( 'MWException', "name 'test!invalid' is invalid" );
+               $this->setExpectedException( MWException::class, "name 'test!invalid' is invalid" );
                $resourceLoader->register( 'test!invalid', new ResourceLoaderTestModule() );
        }
 
@@ -95,10 +93,26 @@ class ResourceLoaderTest extends ResourceLoaderTestCase {
         */
        public function testRegisterInvalidType() {
                $resourceLoader = new EmptyResourceLoader();
-               $this->setExpectedException( 'MWException', 'ResourceLoader module info type error' );
+               $this->setExpectedException( MWException::class, 'ResourceLoader module info type error' );
                $resourceLoader->register( 'test', new stdClass() );
        }
 
+       /**
+        * @covers ResourceLoader::register
+        */
+       public function testRegisterDuplicate() {
+               $logger = $this->getMockBuilder( Psr\Log\LoggerInterface::class )->getMock();
+               $logger->expects( $this->once() )
+                       ->method( 'warning' );
+               $resourceLoader = new EmptyResourceLoader( null, $logger );
+
+               $module1 = new ResourceLoaderTestModule();
+               $module2 = new ResourceLoaderTestModule();
+               $resourceLoader->register( 'test', $module1 );
+               $resourceLoader->register( 'test', $module2 );
+               $this->assertSame( $module2, $resourceLoader->getModule( 'test' ) );
+       }
+
        /**
         * @covers ResourceLoader::getModuleNames
         */
@@ -248,6 +262,20 @@ class ResourceLoaderTest extends ResourceLoaderTestCase {
                $this->assertStringEqualsFile( $basePath . '/styles.css', $styles['all'] );
        }
 
+       /**
+        * @covers ResourceLoader::getLessCompiler
+        */
+       public function testLessImportDirs() {
+               $rl = new EmptyResourceLoader();
+               $lc = $rl->getLessCompiler();
+               $basePath = dirname( dirname( __DIR__ ) ) . '/data/less';
+               $lc->SetImportDirs( [
+                        "$basePath/common" => '',
+               ] );
+               $css = $lc->parseFile( "$basePath/module/use-import-dir.less" )->getCss();
+               $this->assertStringEqualsFile( "$basePath/module/styles.css", $css );
+       }
+
        public static function providePackedModules() {
                return [
                        [
@@ -261,7 +289,7 @@ class ResourceLoaderTest extends ResourceLoaderTestCase {
                                'jquery.foo,bar|jquery.ui.baz,quux',
                        ],
                        [
-                               'Regression fixed in r88706 with dotless names',
+                               'Regression fixed in r87497 (7fee86c38e) with dotless names',
                                [ 'foo', 'bar', 'baz' ],
                                'foo,bar,baz',
                        ],
@@ -336,7 +364,9 @@ class ResourceLoaderTest extends ResourceLoaderTestCase {
         */
        public function testAddSourceDupe() {
                $rl = new ResourceLoader;
-               $this->setExpectedException( 'MWException', 'ResourceLoader duplicate source addition error' );
+               $this->setExpectedException(
+                       MWException::class, 'ResourceLoader duplicate source addition error'
+               );
                $rl->addSource( 'foo', 'https://example.org/w/load.php' );
                $rl->addSource( 'foo', 'https://example.com/w/load.php' );
        }
@@ -346,7 +376,7 @@ class ResourceLoaderTest extends ResourceLoaderTestCase {
         */
        public function testAddSourceInvalid() {
                $rl = new ResourceLoader;
-               $this->setExpectedException( 'MWException', 'with no "loadScript" key' );
+               $this->setExpectedException( MWException::class, 'with no "loadScript" key' );
                $rl->addSource( 'foo',  [ 'x' => 'https://example.org/w/load.php' ] );
        }
 
@@ -446,7 +476,7 @@ mw.example();
                ResourceLoader::clearCache();
                $this->setMwGlobals( 'wgResourceLoaderDebug', true );
 
-               $rl = TestingAccessWrapper::newFromClass( 'ResourceLoader' );
+               $rl = TestingAccessWrapper::newFromClass( ResourceLoader::class );
                $this->assertEquals(
                        $case['expected'],
                        $rl->makeLoaderImplementScript(
@@ -465,8 +495,8 @@ mw.example();
         * @covers ResourceLoader::makeLoaderImplementScript
         */
        public function testMakeLoaderImplementScriptInvalid() {
-               $this->setExpectedException( 'MWException', 'Invalid scripts error' );
-               $rl = TestingAccessWrapper::newFromClass( 'ResourceLoader' );
+               $this->setExpectedException( MWException::class, 'Invalid scripts error' );
+               $rl = TestingAccessWrapper::newFromClass( ResourceLoader::class );
                $rl->makeLoaderImplementScript(
                        'test', // name
                        123, // scripts
@@ -753,7 +783,7 @@ mw.example();
                        'foo' => self::getSimpleModuleMock( 'foo();' ),
                        'ferry' => self::getFailFerryMock(),
                        'bar' => self::getSimpleModuleMock( 'bar();' ),
-                       'startup' => [ 'class' => 'ResourceLoaderStartUpModule' ],
+                       'startup' => [ 'class' => ResourceLoaderStartUpModule::class ],
                ] );
                $context = $this->getResourceLoaderContext(
                        [