GlobalTest: Add test for wfRandomString()
authorSergio Santoro <santoro.srg@gmail.com>
Wed, 23 Jul 2014 15:28:50 +0000 (17:28 +0200)
committerKrinkle <krinklemail@gmail.com>
Wed, 3 Sep 2014 16:28:16 +0000 (16:28 +0000)
Change-Id: I8e681ed6a32a4a13603cad3cd3dc56545e16220f

tests/phpunit/includes/GlobalFunctions/GlobalTest.php

index 84799ff..3acc48e 100644 (file)
@@ -59,13 +59,33 @@ class GlobalTest extends MediaWikiTestCase {
                );
        }
 
+       /*
+        * Test cases for random functions could hypothetically fail,
+        * even though they shouldn't.
+        */
+
        /**
         * @covers ::wfRandom
         */
        public function testRandom() {
-               # This could hypothetically fail, but it shouldn't ;)
                $this->assertFalse(
-                       wfRandom() == wfRandom() );
+                       wfRandom() == wfRandom()
+               );
+       }
+
+       /**
+        * @covers ::wfRandomString
+        */
+       public function testRandomString() {
+               $this->assertFalse(
+                       wfRandomString() == wfRandomString()
+               );
+               $this->assertEquals(
+                       strlen( wfRandomString( 10 ) ), 10
+               );
+               $this->assertTrue(
+                       preg_match( '/^[0-9a-f]+$/i', wfRandomString() ) === 1
+               );
        }
 
        /**