Index: branches/uploadwizard/phase3/maintenance/tests/phpunit/includes/api/ApiUploadTest.php |
— | — | @@ -32,23 +32,28 @@ |
33 | 33 | 'sysop' => new ApiTestUser( |
34 | 34 | 'Apitestsysop', |
35 | 35 | 'Api Test Sysop', |
36 | | - 'testpass', |
37 | 36 | 'api_test_sysop@sample.com', |
38 | 37 | array( 'sysop' ) |
39 | 38 | ), |
40 | 39 | 'uploader' => new ApiTestUser( |
41 | 40 | 'Apitestuser', |
42 | 41 | 'Api Test User', |
43 | | - 'testpass', |
44 | 42 | 'api_test_user@sample.com', |
45 | 43 | array() |
46 | 44 | ) |
47 | | - ); |
| 45 | + ); |
48 | 46 | |
49 | 47 | $wgUser = self::$users['sysop']->user; |
50 | 48 | |
51 | 49 | } |
52 | 50 | |
| 51 | + function tearDown() { |
| 52 | + // destroy the users |
| 53 | + |
| 54 | + global $wgMemc; |
| 55 | + $wgMemc = null; |
| 56 | + } |
| 57 | + |
53 | 58 | protected function doApiRequest( $params, $session = null ) { |
54 | 59 | $_SESSION = isset( $session ) ? $session : array(); |
55 | 60 | |
— | — | @@ -78,11 +83,6 @@ |
79 | 84 | } |
80 | 85 | } |
81 | 86 | |
82 | | - function tearDown() { |
83 | | - global $wgMemc; |
84 | | - $wgMemc = null; |
85 | | - } |
86 | | - |
87 | 87 | } |
88 | 88 | |
89 | 89 | class ApiUploadTest extends ApiTestCase { |
— | — | @@ -119,6 +119,7 @@ |
120 | 120 | */ |
121 | 121 | function testLogin() { |
122 | 122 | $user = self::$users['uploader']; |
| 123 | + |
123 | 124 | $params = array( |
124 | 125 | 'action' => 'login', |
125 | 126 | 'lgname' => $user->username, |
— | — | @@ -590,16 +591,28 @@ |
591 | 592 | public $groups; |
592 | 593 | public $user; |
593 | 594 | |
594 | | - function __construct( $username, $realname = 'Real Name', $password = 'testpass', $email = 'sample@sample.com', $groups = array() ) { |
| 595 | + function __construct( $username, $realname = 'Real Name', $email = 'sample@sample.com', $groups = array() ) { |
| 596 | + global $wgMinimalPasswordLength; |
| 597 | + |
595 | 598 | $this->username = $username; |
596 | 599 | $this->realname = $realname; |
597 | | - $this->password = $password; |
598 | 600 | $this->email = $email; |
599 | 601 | $this->groups = $groups; |
600 | 602 | |
| 603 | + // don't allow user to hardcode or select passwords -- people sometimes run tests |
| 604 | + // on live wikis. Sometimes we create sysop users in these tests. A sysop user with |
| 605 | + // a known password would be a Bad Thing. |
| 606 | + $this->password = User::randomPassword(); |
| 607 | + |
601 | 608 | $this->user = User::newFromName( $this->username ); |
602 | 609 | $this->user->load(); |
| 610 | + |
| 611 | + // In an ideal world we'd have a new wiki (or mock data store) for every single test. |
| 612 | + // But for now, we just need to create or update the user with the desired properties. |
| 613 | + // we particularly need the new password, since we just generated it randomly. |
| 614 | + // In core MediaWiki, there is no functionality to delete users, so this is the best we can do. |
603 | 615 | if ( !$this->user->getID() ) { |
| 616 | + // create the user |
604 | 617 | $this->user = User::createNew( |
605 | 618 | $this->username, array( |
606 | 619 | "email" => $this->email, |
— | — | @@ -609,14 +622,23 @@ |
610 | 623 | if ( !$this->user ) { |
611 | 624 | throw new Exception( "error creating user" ); |
612 | 625 | } |
613 | | - $this->user->setPassword( $this->password ); |
614 | | - if ( count( $this->groups ) ) { |
615 | | - foreach ( $this->groups as $group ) { |
616 | | - $this->user->addGroup( $group ); |
617 | | - } |
| 626 | + } |
| 627 | + |
| 628 | + // update the user to use the new random password and other details |
| 629 | + $this->user->setPassword( $this->password ); |
| 630 | + $this->user->setEmail( $this->email ); |
| 631 | + $this->user->setRealName( $this->realname ); |
| 632 | + // remove all groups, replace with any groups specified |
| 633 | + foreach ( $this->user->getGroups() as $group ) { |
| 634 | + $this->user->removeGroup( $group ); |
| 635 | + } |
| 636 | + if ( count( $this->groups ) ) { |
| 637 | + foreach ( $this->groups as $group ) { |
| 638 | + $this->user->addGroup( $group ); |
618 | 639 | } |
619 | | - $this->user->saveSettings(); |
620 | 640 | } |
| 641 | + $this->user->saveSettings(); |
| 642 | + |
621 | 643 | } |
622 | 644 | |
623 | 645 | |