(bug 38333) test blocked user cant createaccount
authorAntoine Musso <hashar@free.fr>
Fri, 13 Jul 2012 09:43:17 +0000 (11:43 +0200)
committerGerrit Code Review <gerrit@wikimedia.org>
Thu, 19 Jul 2012 08:19:15 +0000 (08:19 +0000)
This patch adds BlockTest::testBlockedUserCanNotCreateAccount() which
test that a new user can createaccount and that blocking him will
prevents to the createaccount right.

Does not solve bug 38333 though!

Change-Id: Ia10e26825d50d47b4770900ee91dea666337f969

tests/phpunit/includes/BlockTest.php

index f197da8..0c95b8d 100644 (file)
@@ -123,6 +123,67 @@ class BlockTest extends MediaWikiLangTestCase {
                );
        }
 
+       function testBlockedUserCanNotCreateAccount() {
+               $username = 'BlockedUserToCreateAccountWith';
+               $u = User::newFromName( $username );
+               $u->setPassword( 'NotRandomPass' );
+               $u->addToDatabase();
+               unset( $u );
+
+
+               // Sanity check
+               $this->assertNull(
+                       Block::newFromTarget( $username ),
+                       "$username should not be blocked"
+               );
+
+               // Reload user
+               $u = User::newFromName( $username );
+               $this->assertFalse(
+                       $u->isBlockedFromCreateAccount(),
+                       "Our sandbox user should be able to create account before being blocked"
+               );
+
+               // Foreign perspective (blockee not on current wiki)...
+               $block = new Block(
+                       /* $address */ $username,
+                       /* $user */ 14146,
+                       /* $by */ 0,
+                       /* $reason */ 'crosswiki block...',
+                       /* $timestamp */ wfTimestampNow(),
+                       /* $auto */ false,
+                       /* $expiry */ $this->db->getInfinity(),
+                       /* anonOnly */ false,
+                       /* $createAccount */ true,
+                       /* $enableAutoblock */ true,
+                       /* $hideName (ipb_deleted) */ true,
+                       /* $blockEmail */ true,
+                       /* $allowUsertalk */ false,
+                       /* $byName */ 'MetaWikiUser'
+               );
+               $block->insert();
+
+               // Reload block from DB
+               $userBlock = Block::newFromTarget( $username );
+               $this->assertTrue(
+                       (bool) $block->prevents( 'createaccount' ),
+                       "Block object in DB should prevents 'createaccount'"
+               );
+
+               $this->assertInstanceOf(
+                       'Block',
+                       $userBlock,
+                       "'$username' block block object should be existent"
+               );
+
+               // Reload user
+               $u = User::newFromName( $username );
+               $this->assertTrue(
+                       (bool) $u->isBlockedFromCreateAccount(),
+                       "Our sandbox user '$username' should NOT be able to create account"
+               );
+       }
+
        function testCrappyCrossWikiBlocks() {
                // Delete the last round's block if it's still there
                $oldBlock = Block::newFromTarget( 'UserOnForeignWiki' );