TranslateSandboxTest.php
Go to the documentation of this file.00001 <?php
00013 class TranslateSandboxTest extends MediaWikiTestCase {
00014 protected function setUp() {
00015 parent::setUp();
00016 $this->setMwGlobals( array(
00017 'wgTranslateUseSandbox' => true,
00018 'wgTranslateSandboxPromotedGroup' => 'translator',
00019 ) );
00020 }
00021
00022 public function testAddUser() {
00023 $user = TranslateSandbox::addUser( 'Test user', 'test@example.com', 'test password' );
00024 $this->assertTrue( $user->isLoggedIn(), 'User exists' );
00025
00026
00027 $groups = array_unique( $user->getGroups() );
00028 $this->assertSame( array( 'translate-sandboxed' ), $groups, 'User is in the sandboxed group' );
00029 }
00030
00031 public function testDeleteUser() {
00032 $user = TranslateSandbox::addUser( 'Test user2', 'test@example.com', 'test password' );
00033 TranslateSandbox::deleteUser( $user );
00034 $this->assertFalse( $user->isLoggedIn(), 'User no longer exists' );
00035 }
00036
00041 public function testDeleteUserPromoted() {
00042 $user = TranslateSandbox::addUser( 'Test user3', 'test@example.com', 'test password' );
00043 TranslateSandbox::promoteUser( $user );
00044 TranslateSandbox::deleteUser( $user );
00045 }
00046
00047 public function testGetUsers() {
00048 $atStart = TranslateSandbox::getUsers()->count();
00049
00050 $user = TranslateSandbox::addUser( 'Test user4', 'test@example.com', 'test password' );
00051
00052 $this->assertEquals(
00053 $atStart + 1, TranslateSandbox::getUsers()->count(),
00054 'One sandboxed user created'
00055 );
00056
00057 TranslateSandbox::deleteUser( $user );
00058 $this->assertEquals(
00059 $atStart, TranslateSandbox::getUsers()->count(),
00060 'No sandboxed users after deleted'
00061 );
00062 }
00063
00064 public function testGetUsersPromotion() {
00065 $atStart = TranslateSandbox::getUsers()->count();
00066
00067 $user = TranslateSandbox::addUser( 'Test user5', 'test@example.com', 'test password' );
00068 $this->assertEquals(
00069 $atStart + 1,
00070 TranslateSandbox::getUsers()->count(),
00071 'One sandboxed user created'
00072 );
00073
00074 TranslateSandbox::promoteUser( $user );
00075 $this->assertEquals(
00076 $atStart,
00077 TranslateSandbox::getUsers()->count(),
00078 'No sandboxed users after promotion'
00079 );
00080 }
00081
00082 public function testPromoteUser() {
00083 $user = TranslateSandbox::addUser( 'Test user6', 'test@example.com', 'test password' );
00084 TranslateSandbox::promoteUser( $user );
00085
00086 $this->assertContains( 'translator', $user->getGroups() );
00087 }
00088
00089 public function testPermissions() {
00090 $user = TranslateSandbox::addUser( 'Test user7', 'test@example.com', 'test password' );
00091 $title = Title::makeTitle( NS_USER_TALK, $user->getName() );
00092
00093 $this->assertFalse(
00094 $title->userCan( 'edit', $user ),
00095 'Sandboxed users cannot edit their own talk page'
00096 );
00097 TranslateSandbox::promoteUser( $user );
00098 $this->assertTrue(
00099 $title->userCan( 'edit', $user ),
00100 'Promoted users can edit their own talk page'
00101 );
00102 }
00103 }