MediaWiki  1.23.2
TestUser.php
Go to the documentation of this file.
1 <?php
2 
6 class TestUser {
7  public $username;
8  public $password;
9  public $email;
10  public $groups;
11  public $user;
12 
13  public function __construct( $username, $realname = 'Real Name', $email = 'sample@example.com', $groups = array() ) {
14  $this->username = $username;
15  $this->realname = $realname;
16  $this->email = $email;
17  $this->groups = $groups;
18 
19  // don't allow user to hardcode or select passwords -- people sometimes run tests
20  // on live wikis. Sometimes we create sysop users in these tests. A sysop user with
21  // a known password would be a Bad Thing.
22  $this->password = User::randomPassword();
23 
24  $this->user = User::newFromName( $this->username );
25  $this->user->load();
26 
27  // In an ideal world we'd have a new wiki (or mock data store) for every single test.
28  // But for now, we just need to create or update the user with the desired properties.
29  // we particularly need the new password, since we just generated it randomly.
30  // In core MediaWiki, there is no functionality to delete users, so this is the best we can do.
31  if ( !$this->user->getID() ) {
32  // create the user
33  $this->user = User::createNew(
34  $this->username, array(
35  "email" => $this->email,
36  "real_name" => $this->realname
37  )
38  );
39  if ( !$this->user ) {
40  throw new Exception( "error creating user" );
41  }
42  }
43 
44  // update the user to use the new random password and other details
45  $this->user->setPassword( $this->password );
46  $this->user->setEmail( $this->email );
47  $this->user->setRealName( $this->realname );
48 
49  // Adjust groups by adding any missing ones and removing any extras
50  $currentGroups = $this->user->getGroups();
51  foreach ( array_diff( $this->groups, $currentGroups ) as $group ) {
52  $this->user->addGroup( $group );
53  }
54  foreach ( array_diff( $currentGroups, $this->groups ) as $group ) {
55  $this->user->removeGroup( $group );
56  }
57  $this->user->saveSettings();
58  }
59 }
TestUser\$username
$username
Definition: TestUser.php:7
php
skin txt MediaWiki includes four core it has been set as the default in MediaWiki since the replacing Monobook it had been been the default skin since before being replaced by Vector largely rewritten in while keeping its appearance Several legacy skins were removed in the as the burden of supporting them became too heavy to bear Those in etc for skin dependent CSS etc for skin dependent JavaScript These can also be customised on a per user by etc This feature has led to a wide variety of user styles becoming that gallery is a good place to ending in php
Definition: skin.txt:62
TestUser\$password
$password
Definition: TestUser.php:8
User\newFromName
static newFromName( $name, $validate='valid')
Static factory method for creation from username.
Definition: User.php:388
TestUser
Wraps the user object, so we can also retain full access to properties like password if we log in via...
Definition: TestUser.php:6
TestUser\$email
$email
Definition: TestUser.php:9
User\randomPassword
static randomPassword()
Return a random password.
Definition: User.php:950
array
the array() calling protocol came about after MediaWiki 1.4rc1.
List of Api Query prop modules.
User\createNew
static createNew( $name, $params=array())
Add a user to the database, return the user object.
Definition: User.php:3458
TestUser\$user
$user
Definition: TestUser.php:11
user
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such and we might be restricted by PHP settings such as safe mode or open_basedir We cannot assume that the software even has read access anywhere useful Many shared hosts run all users web applications under the same user
Definition: distributors.txt:9
as
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
Definition: distributors.txt:9
TestUser\__construct
__construct( $username, $realname='Real Name', $email='sample @example.com', $groups=array())
Definition: TestUser.php:13
TestUser\$groups
$groups
Definition: TestUser.php:10