Bidi isolate user names in block error paramters
[lhc/web/wiklou.git] / tests / phpunit / includes / registration / ExtensionRegistryTest.php
index 7120a91..5de1b0c 100644 (file)
@@ -1,5 +1,7 @@
 <?php
 
+use Wikimedia\ScopedCallback;
+
 /**
  * @covers ExtensionRegistry
  */
@@ -57,10 +59,29 @@ class ExtensionRegistryTest extends MediaWikiTestCase {
                $registry->loadFromQueue();
                $this->assertArrayHasKey( 'FooBar', $registry->getAllThings() );
                $this->assertTrue( $registry->isLoaded( 'FooBar' ) );
+               $this->assertTrue( $registry->isLoaded( 'FooBar', '*' ) );
                $this->assertSame( [ 'test' ], $registry->getAttribute( 'FooBarAttr' ) );
                $this->assertSame( [], $registry->getAttribute( 'NotLoadedAttr' ) );
        }
 
+       public function testLoadFromQueueWithConstraintWithVersion() {
+               $registry = new ExtensionRegistry();
+               $registry->queue( "{$this->dataDir}/good_with_version.json" );
+               $registry->loadFromQueue();
+               $this->assertTrue( $registry->isLoaded( 'FooBar', '>= 1.2.0' ) );
+               $this->assertFalse( $registry->isLoaded( 'FooBar', '^1.3.0' ) );
+       }
+
+       /**
+        * @expectedException LogicException
+        */
+       public function testLoadFromQueueWithConstraintWithoutVersion() {
+               $registry = new ExtensionRegistry();
+               $registry->queue( "{$this->dataDir}/good.json" );
+               $registry->loadFromQueue();
+               $registry->isLoaded( 'FooBar', '>= 1.2.0' );
+       }
+
        /**
         * @expectedException PHPUnit_Framework_Error
         */
@@ -380,4 +401,28 @@ class ExtensionRegistryTest extends MediaWikiTestCase {
                        ],
                ];
        }
+
+       public function testSetAttributeForTest() {
+               $registry = new ExtensionRegistry();
+               $registry->queue( "{$this->dataDir}/good.json" );
+               $registry->loadFromQueue();
+               // Sanity check that it worked
+               $this->assertSame( [ 'test' ], $registry->getAttribute( 'FooBarAttr' ) );
+               $reset = $registry->setAttributeForTest( 'FooBarAttr', [ 'override' ] );
+               // overridden properly
+               $this->assertSame( [ 'override' ], $registry->getAttribute( 'FooBarAttr' ) );
+               ScopedCallback::consume( $reset );
+               // reset properly
+               $this->assertSame( [ 'test' ], $registry->getAttribute( 'FooBarAttr' ) );
+       }
+
+       /**
+        * @expectedException Exception
+        * @expectedExceptionMessage The attribute 'foo' has already been overridden
+        */
+       public function testSetAttributeForTestDuplicate() {
+               $registry = new ExtensionRegistry();
+               $reset1 = $registry->setAttributeForTest( 'foo', [ 'val1' ] );
+               $reset2 = $registry->setAttributeForTest( 'foo', [ 'val2' ] );
+       }
 }