Addshore has uploaded a new change for review. (
https://gerrit.wikimedia.org/r/333673 )
Change subject: DiscussionParserTest only create users when needed
......................................................................
DiscussionParserTest only create users when needed
This speeds up the tests from 2 mins to 50 seconds for me.
Change-Id: I8adb6c8fe783d1be8841a1139bb141da3b046f9d
---
M tests/phpunit/DiscussionParserTest.php
1 file changed, 41 insertions(+), 20 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Echo
refs/changes/73/333673/1
diff --git a/tests/phpunit/DiscussionParserTest.php
b/tests/phpunit/DiscussionParserTest.php
index 11eac70..399e246 100644
--- a/tests/phpunit/DiscussionParserTest.php
+++ b/tests/phpunit/DiscussionParserTest.php
@@ -13,15 +13,14 @@
protected $tablesUsed = [ 'user', 'revision', 'text', 'page' ];
/**
- * Users used in these tests: signature extraction, mentioned users,
... all
- * assume a user exists.
+ * Convenience users for use in these tests.
+ * Can be setup one by one using the setupTestUser() method
+ * Or all at once using the setupAllTestUsers() method
*
* @var array [username => [user preference => preference value]]
*/
protected $testUsers = [
- // username
'Werdna' => [
- // user preferences
'nickname' => '',
'fancysig' => '0',
],
@@ -129,23 +128,7 @@
protected function setUp() {
parent::setUp();
-
$this->setMwGlobals( [ 'wgDiff' => false ] );
-
- // users need to be added for each test, resetDB() removes them
- // TODO: Only add users needed for each test, instead of adding
them
- // all for every one.
- foreach ( $this->testUsers as $username => $preferences ) {
- $user = User::createNew( $username );
-
- // set signature preferences
- if ( $user ) {
- foreach ( $preferences as $option => $value ) {
- $user->setOption( $option, $value );
- }
- $user->saveSettings();
- }
- }
}
protected function tearDown() {
@@ -153,6 +136,30 @@
global $wgHooks;
unset( $wgHooks['BeforeEchoEventInsert'][999] );
+ }
+
+ private function setupAllTestUsers() {
+ foreach ( array_keys( $this->testUsers ) as $username ) {
+ $this->setupTestUser( $username );
+ }
+ }
+
+ private function setupTestUser( $username ) {
+ // Skip user creation requests that are not in the list (such
as IPs)
+ if ( !array_key_exists( $username, $this->testUsers ) ) {
+ return;
+ }
+
+ $preferences = $this->testUsers[$username];
+ $user = User::createNew( $username );
+
+ // Set signature preferences
+ if ( $user ) {
+ foreach ( $preferences as $option => $value ) {
+ $user->setOption( $option, $value );
+ }
+ $user->saveSettings();
+ }
}
public function provideHeaderExtractions() {
@@ -336,6 +343,8 @@
return;
}
}
+
+ $this->setupAllTestUsers();
$revision = $this->setupTestRevisionsForEventGeneration(
$newId, $oldId, $username, $lang, $pages, $title
@@ -649,6 +658,8 @@
public function testGenerateEventsForRevision_mentionStatus(
$newId, $oldId, $username, $lang, $pages, $title, $expected
) {
+ $this->setupAllTestUsers();
+
$revision = $this->setupTestRevisionsForEventGeneration(
$newId, $oldId, $username, $lang, $pages, $title
);
@@ -850,6 +861,7 @@
],
];
+ $this->setupTestUser( 'Admin' );
$revision = $this->setupTestRevisionsForEventGeneration(
747747749, 747747747, 'Admin', 'en', [], 'UTPage' );
$events = [];
@@ -1022,6 +1034,10 @@
* FIXME some of the app logic is in the test...
*/
public function testSigningDetection( $line, $expectedUser ) {
+ if( is_array( $expectedUser ) ) {
+ $this->setupTestUser( $expectedUser[1] );
+ }
+
if ( !EchoDiscussionParser::isSignedComment( $line ) ) {
$this->assertEquals( $expectedUser, false );
@@ -1250,6 +1266,7 @@
/** @dataProvider annotationData */
public function testAnnotation( $message, $diff, $user,
$expectedAnnotation ) {
+ $this->setupTestUser( $user );
$actual = EchoDiscussionParser::interpretDiff( $diff, $user );
$this->assertEquals( $expectedAnnotation, $actual, $message );
}
@@ -1593,6 +1610,8 @@
* @dataProvider provider_detectSectionTitleAndText
*/
public function testDetectSectionTitleAndText( $message, $expect,
$format, $name ) {
+ $this->setupTestUser( $name );
+
// str_replace because we want to replace multiple instances of
'%s' with the same value
$before = str_replace( '%s', '', $format );
$after = str_replace( '%s', self::signedMessage( $name ),
$format );
@@ -1727,6 +1746,7 @@
public function testGetUserMentions_validMention() {
$userName = 'Admin';
+ $this->setupTestUser( $userName );
$userId = User::newFromName( $userName )->getId();
$expectedUserMentions = [
'validMentions' => [ $userId => $userId ],
@@ -1739,6 +1759,7 @@
public function testGetUserMentions_ownMention() {
$userName = 'Admin';
+ $this->setupTestUser( $userName );
$userId = User::newFromName( 'Admin' )->getId();
$expectedUserMentions = [
'validMentions' => [],
--
To view, visit https://gerrit.wikimedia.org/r/333673
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I8adb6c8fe783d1be8841a1139bb141da3b046f9d
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Echo
Gerrit-Branch: master
Gerrit-Owner: Addshore <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits