From 6dc33107dcfe63b84eb96ff1bfc73bc191e7b612 Mon Sep 17 00:00:00 2001 From: Sergio Santoro Date: Wed, 23 Jul 2014 17:28:50 +0200 Subject: [PATCH] GlobalTest: Add test for wfRandomString() Change-Id: I8e681ed6a32a4a13603cad3cd3dc56545e16220f --- .../includes/GlobalFunctions/GlobalTest.php | 24 +++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/tests/phpunit/includes/GlobalFunctions/GlobalTest.php b/tests/phpunit/includes/GlobalFunctions/GlobalTest.php index 84799ff23e..3acc48e27c 100644 --- a/tests/phpunit/includes/GlobalFunctions/GlobalTest.php +++ b/tests/phpunit/includes/GlobalFunctions/GlobalTest.php @@ -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 + ); } /** -- 2.20.1