resourceloader: Add explicit tests for isValidModuleName()
authorTimo Tijhof <krinklemail@gmail.com>
Sat, 1 Jun 2019 22:30:46 +0000 (23:30 +0100)
committerKrinkle <krinklemail@gmail.com>
Sat, 1 Jun 2019 22:46:40 +0000 (22:46 +0000)
Mark the two basic integration tests as `@medium`.
These confirm that:
* The registration method throws on invalid names.
* The higher levels are able to support an empty string as name.

Change-Id: Ib8215408a28040986ae07f4b2421681bc885abad

tests/phpunit/includes/resourceloader/ResourceLoaderTest.php

index 85a47de..19113ad 100644 (file)
@@ -34,6 +34,42 @@ class ResourceLoaderTest extends ResourceLoaderTestCase {
                $this->assertSame( 1, $ranHook, 'Hook was called' );
        }
 
+       public static function provideInvalidModuleName() {
+               return [
+                       'name with 300 chars' => [ str_repeat( 'x', 300 ) ],
+                       'name with bang' => [ 'this!that' ],
+                       'name with comma' => [ 'this,that' ],
+                       'name with pipe' => [ 'this|that' ],
+               ];
+       }
+
+       public static function provideValidModuleName() {
+               return [
+                       'empty string' => [ '' ],
+                       'simple name' => [ 'this.and-that2' ],
+                       'name with 100 chars' => [ str_repeat( 'x', 100 ) ],
+                       'name with hash' => [ 'this#that' ],
+                       'name with slash' => [ 'this/that' ],
+                       'name with at' => [ 'this@that' ],
+               ];
+       }
+
+       /**
+        * @dataProvider provideInvalidModuleName
+        * @covers ResourceLoader
+        */
+       public function testIsValidModuleName_invalid( $name ) {
+               $this->assertFalse( ResourceLoader::isValidModuleName( $name ) );
+       }
+
+       /**
+        * @dataProvider provideValidModuleName
+        * @covers ResourceLoader
+        */
+       public function testIsValidModuleName_valid( $name ) {
+               $this->assertTrue( ResourceLoader::isValidModuleName( $name ) );
+       }
+
        /**
         * @covers ResourceLoader::register
         * @covers ResourceLoader::getModule
@@ -60,6 +96,7 @@ class ResourceLoaderTest extends ResourceLoaderTestCase {
 
        /**
         * @covers ResourceLoader::register
+        * @group medium
         */
        public function testRegisterEmptyString() {
                $module = new ResourceLoaderTestModule();
@@ -70,6 +107,7 @@ class ResourceLoaderTest extends ResourceLoaderTestCase {
 
        /**
         * @covers ResourceLoader::register
+        * @group medium
         */
        public function testRegisterInvalidName() {
                $resourceLoader = new EmptyResourceLoader();