wiki.techinc.nl/tests/phpunit/includes/api/ApiAccountCreationTest.php
Antoine Musso 2a00da0f0f raise timeout for ApiCreateAccountTest::testValid
The ApiCreateAccountTest::testValid() test does multiple API request
which might end up being a bit slow.  That randomly cause random
failures when running the test suite which tends to confuse people.

Change-Id: I35a6670c61c7917522b2472a3a8e782e97e837f4
2013-01-11 10:46:18 +01:00

144 lines
3.4 KiB
PHP

<?php
/**
* @group Database
* @group API
*/
class ApiCreateAccountTest extends ApiTestCase {
function setUp() {
parent::setUp();
LoginForm::setCreateaccountToken();
}
/**
* Test the account creation API with a valid request. Also
* make sure the new account can log in and is valid.
*
* This test does multiple API requests so it might end up being
* a bit slow. Raise the default timeout.
* @group medium
*/
function testValid() {
global $wgServer;
if ( !isset( $wgServer ) ) {
$this->markTestIncomplete( 'This test needs $wgServer to be set in LocalSettings.php' );
}
$password = User::randomPassword();
$ret = $this->doApiRequest( array(
'action' => 'createaccount',
'name' => 'Apitestnew',
'password' => $password,
'email' => 'test@example.com',
'realname' => 'Test Name'
) );
$result = $ret[0];
$this->assertNotInternalType( 'bool', $result );
$this->assertNotInternalType( 'null', $result['createaccount'] );
// Should first ask for token.
$a = $result['createaccount'];
$this->assertEquals( 'needtoken', $a['result'] );
$token = $a['token'];
// Finally create the account
$ret = $this->doApiRequest( array(
'action' => 'createaccount',
'name' => 'Apitestnew',
'password' => $password,
'token' => $token,
'email' => 'test@domain.test',
'realname' => 'Test Name' ), $ret[2]
);
$result = $ret[0];
$this->assertNotInternalType( 'bool', $result );
$this->assertEquals( 'success', $result['createaccount']['result'] );
// Try logging in with the new user.
$ret = $this->doApiRequest( array(
'action' => 'login',
'lgname' => 'Apitestnew',
'lgpassword' => $password,
)
);
$result = $ret[0];
$this->assertNotInternalType( 'bool', $result );
$this->assertNotInternalType( 'null', $result['login'] );
$a = $result['login']['result'];
$this->assertEquals( 'NeedToken', $a );
$token = $result['login']['token'];
$ret = $this->doApiRequest( array(
'action' => 'login',
'lgtoken' => $token,
'lgname' => 'Apitestnew',
'lgpassword' => $password,
), $ret[2]
);
$result = $ret[0];
$this->assertNotInternalType( 'bool', $result );
$a = $result['login']['result'];
$this->assertEquals( 'Success', $a );
}
/**
* Make sure requests with no names are invalid.
* @expectedException UsageException
*/
function testNoName() {
$ret = $this->doApiRequest( array(
'action' => 'createaccount',
'token' => LoginForm::getCreateaccountToken(),
'password' => 'password',
) );
}
/**
* Make sure requests with no password are invalid.
* @expectedException UsageException
*/
function testNoPassword() {
$ret = $this->doApiRequest( array(
'action' => 'createaccount',
'name' => 'testName',
'token' => LoginForm::getCreateaccountToken(),
) );
}
/**
* Make sure requests with existing users are invalid.
* @expectedException UsageException
*/
function testExistingUser() {
$this->doApiRequest( array(
'action' => 'createaccount',
'name' => 'Apitestsysop',
'token' => LoginForm::getCreateaccountToken(),
'password' => 'password',
'email' => 'test@domain.test',
) );
}
/**
* Make sure requests with invalid emails are invalid.
* @expectedException UsageException
*/
function testInvalidEmail() {
$this->doApiRequest( array(
'action' => 'createaccount',
'name' => 'Test User',
'token' => LoginForm::getCreateaccountToken(),
'password' => 'password',
'email' => 'sjlfsjklj',
) );
}
}